Repository navigation
新增 StarRocks MCP Server(apikey 鉴权、读写分离、SQL 安全审计、监控) - #1
Draft
removecode wants to merge 5 commits into
Draft
removecode wants to merge 5 commits into
removecode wants to merge 5 commits into
Conversation
- FastMCP streamable-http 服务,通过 X-API-Key/Authorization Header 鉴权,apikey 与 角色(read/readwrite)、访问范围(catalog/database scope)映射,映射存储用可插拔 AuthProvider 接口(v1 提供 YAML 实现) - StarRocks 侧只读/读写两个账号分别建连接池(pymysql + DBUtils.PooledDB),apikey 不接触真实数据库账号密码 - 两个 MCP 工具:get_database_info_tool(分层结构理解,兼容 catalog.database.table 三段式命名)、execute_sql(真正执行,带安全审计) - SQL 安全审计:语句分类、角色白名单、DDL/DCL 一律禁止、访问范围 best-effort 校验 (无法判断时 fail-closed)、SELECT 强制 LIMIT 保护 - Prometheus /metrics 指标 + 按 apikey 记录的 SQLite 审计日志 - 当前环境无真实 StarRocks,提供 MockConnectionPool 复现用户给出的 paimon.csc.ods_csc_log_audit 示例,支持端到端手动验证和自动化测试 - 58 个 pytest 单测全部通过(auth/audit/schema/execute/metrics/审计日志/ 进程内 ASGI 集成测试) Co-authored-by: daydayup <removecode@users.noreply.github.com>
把 Plan 模式产出的实施计划保存到 starrocks-mcp/docs/plan.md,并从 README 链接过去, 方便后续追溯设计决策(架构图、鉴权/连接池/安全审计/监控的设计原因等)。 Co-authored-by: daydayup <removecode@users.noreply.github.com>
- 新增 MCP 工具 get_connection_status:分别探测只读/读写连接池,返回 connected/mode/message - 增强 GET /healthz:真实驱动连不上库时返回 503,并带上可读原因;mock 模式返回 mode=mock - get_database_info / execute_sql 遇到连接类错误时,改写成明确的「数据库未连接」提示 - 启动时主动探活一次,失败打错误日志(不阻止进程启动,便于排查) - 新增 docs/api.md 完整接口文档,并在 README 中链接 - 补充连通性相关单测;全量 69 个测试通过 Co-authored-by: daydayup <removecode@users.noreply.github.com>
- 配置支持推荐的 users: 写法(用户 -> api_key hash / 角色 / scope) - 兼容旧的 api_keys: 写法(条目增加 username 字段) - ApiKeyPermission 增加 username;请求鉴权后可反查用户 - request_log 增加 username 列,execute_sql 审计日志优先记用户名 - 更新示例配置、README、docs/api.md;71 个测试通过 Co-authored-by: daydayup <removecode@users.noreply.github.com>
- 提供 settings.local.yaml / apikeys.local.yaml(mock + 本地测试 key) - 增加 scripts/start-local.sh 一键启动 - 增加 docs/local-cursor.md:本机启动步骤与 Cursor MCP 配置示例 Co-authored-by: daydayup <removecode@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
独立 Python 项目
starrocks-mcp/:StarRocks 多租户 MCP 服务(Streamable HTTP + apikey 鉴权 + 读写分离 + SQL 安全审计 + 监控)。本次能力摘要
users:配置);请求带 apikey,服务端反查usernamerequest_log.username),同时保留api_key_idget_connection_status/get_database_info_tool/execute_sql/healthz探测数据库连通性;连不上返回 503docs/api.md)用户映射配置示例
查审计:
测试
71 个 pytest 全部通过。