软件架构分析服务器

SGraph MCP Server 是一个为AI代理提供即时访问软件架构、依赖关系和影响分析的MCP服务器,通过预计算的sgraph模型实现高效分析。

  • by softagram
  • Python
  • 本地部署
  • 3 星标
  • 更新于
在 GitHub 查看 softagram/sgraph-mcp-server

使用说明

SGraph MCP服务器

一 主控程序 服务器,通过预先计算,使AI代理能够即时访问软件架构、依赖关系和影响分析 sgraph 模型。一个工具调用可以替换数十个grep/read循环。

为什么?

AI代理通过一次读取一个文件来发现代码结构。对于这样的问题 “这个函数叫什么?”,这意味着grep,read,grep again,read again。..数十次往返,数千个令牌,以及仍然错过间接呼叫者的结果。

SGraph预先计算完整的依赖图。同样的问题需要 一个电话 并返回 每位来电者 带有类型信息。

传统(grep/read) SGraph MCP
“这个函数叫什么?” 多个grep+读取周期 sgraph_get_element_dependencies
“如果我改变这个,会有什么问题?” 手动跟踪,很容易错过 sgraph_analyze_change_impact
“显示模块结构” ls+读取+滚动 sgraph_get_element_structure
每次查询的时间 秒(多次往返) 毫秒(缓存)
准确性 文本匹配(嘈杂) 语义图(精确)

快速开始

1.安装

git clone https://github.com/softagram/sgraph-mcp-server.git
cd sgraph-mcp-server
uv sync

2.启动服务器

# With Claude Code profile (recommended)
uv run python -m src.server --profile claude-code

# With auto-loaded model (skip the load_model step)
uv run python -m src.server --profile claude-code \
  --auto-load /path/to/model.xml.zip \
  --default-scope /Project/src

3.连接您的AI代理

Claude Code / Cursor (.mcp.json)

创建 .mcp.json 在项目根目录中:

{
  "mcpServers": {
    "sgraph": {
      "command": "uv",
      "args": [
        "run", "--directory", "/path/to/sgraph-mcp-server",
        "python", "-m", "src.server",
        "--profile", "claude-code",
        "--transport", "stdio",
        "--auto-load", "/path/to/model.xml.zip"
      ]
    }
  }
}
Alternative: SSE transport (any MCP client, via mcp-remote)

Stdio是推荐的本地使用的传输方式——无端口、无网桥、直接IPC。SSE适用于只能使用HTTP的客户端,或者当您想在多个客户端之间共享一个长时间运行的服务器时。

以SSE模式启动服务器:

uv run python -m src.server --profile claude-code --transport sse --port 8008

然后通过以下方式连接任何MCP客户端 mcp-remote 桥梁:

{
  "mcpServers": {
    "sgraph": {
      "command": "npx",
      "args": ["-y", "mcp-remote", "http://localhost:8008/sse"]
    }
  }
}
Where do sgraph models come from?

sgraph模型(.xml.zip 文件)由以下人员生成 Softagram 代码分析还是开源 sgraph命令行界面工具.

这些模型将您的代码库表示为层次图:

/Project
  /Project/src
    /Project/src/auth/login.py
      /Project/src/auth/login.py/LoginHandler        (class)
        /Project/src/auth/login.py/LoginHandler/validate  (method)
  /Project/External
    /Project/External/Python/requests                 (third-party)

每个元素都可以有 协会 (依赖关系)到其他元素,形成一个完整的依赖关系图。

工具

这 克劳德密码 profile提供了6个针对AI辅助开发进行优化的工具:

工具 功能 何时使用
sgraph_search_elements 按模式查找符号 “UserService类在哪里?”
sgraph_get_element_dependencies 查询传入/传出deps “什么调用此函数?”
sgraph_get_element_structure 探索层次结构 “此模块中有什么?”
sgraph_analyze_change_impact 多层次影响分析 “如果我改变这一点,会有什么问题?”
sgraph_audit 架构健康检查 “是否存在循环依赖关系?”
sgraph_security_audit 安全态势概述 “有任何暴露的秘密或CVE吗?”

关键工具是 sgraph_get_element_dependencies 以其 result_level 用于控制抽象的参数:

result_level=None  ->  /Project/src/auth/login.py/LoginHandler/validate  (raw)
result_level=4     ->  /Project/src/auth/login.py                        (file)
result_level=3     ->  /Project/src/auth                                 (directory)
result_level=2     ->  /Project/src                                      (component)

有关工作流和示例的完整工具参考,请参阅 SGRAPH_FOR_CLAUDE_CODE.md.

Legacy profile (14 tools)

这 legacy profile提供了完整的原始工具集以实现向后兼容性:

基本操作: sgraph_load_model, sgraph_get_root_element, sgraph_get_element, sgraph_get_element_incoming_associations, sgraph_get_element_outgoing_associations

搜索: sgraph_search_elements_by_name, sgraph_get_elements_by_type, sgraph_search_elements_by_attributes

分析: sgraph_get_subtree_dependencies, sgraph_get_dependency_chain, sgraph_get_multiple_elements, sgraph_get_model_overview, sgraph_get_high_level_dependencies

uv run python -m src.server --profile legacy

对话示例

You: "What would break if I rename the validate() method in auth/login.py?"

Agent calls: sgraph_analyze_change_impact(element_path="/Project/src/auth/login.py/LoginHandler/validate")

Result:
  5 callers in 3 files
  - /Project/src/api/routes.py (2 call sites)
  - /Project/src/middleware/auth.py (2 call sites)
  - /Project/tests/test_auth.py (1 call site)
  Warning: bidirectional dependency with /Project/src/middleware

建筑

MCP Client Request
       |
[Tools Layer]     src/tools/        -- MCP tool definitions, input validation
       |
[Services Layer]  src/services/     -- Business logic (search, deps, security)
       |
[Core Layer]      src/core/         -- Model management, data conversion
       |
[SGraph Library]                    -- Graph operations (sgraph package)

看 建筑.md 详细设计。

发展

# Run tests
uv run python tests/run_all_tests.py
uv run python tests/run_all_tests.py unit          # Unit only
uv run python tests/run_all_tests.py integration   # Integration only

# Lint
uv run ruff check src/

# Run a single test file
uv run python -m pytest tests/unit/test_collect_deps.py -v

看 贡献.md 如何做出贡献。

关于

由...建造 Softagram 使用开源 sgraph 图书馆。根据以下许可 麻省理工学院.