SGraph MCP Server

SGraph MCP Server

Gives AI agents instant access to software architecture, dependencies, and impact analysis through pre-computed sgraph models, replacing dozens of grep/read cycles with a single tool call.

Category
访问服务器

README

SGraph MCP Server

Python 3.13+ License: MIT CI

An MCP server that gives AI agents instant access to software architecture, dependencies, and impact analysis through pre-computed sgraph models. One tool call replaces dozens of grep/read cycles.

Why?

AI agents discover code structure by reading files one at a time. For a question like "what calls this function?", that means grep, read, grep again, read again... Dozens of round-trips, thousands of tokens, and results that still miss indirect callers.

SGraph pre-computes the full dependency graph. The same question takes one call and returns every caller with type information.

Traditional (grep/read) SGraph MCP
"What calls this function?" Multiple grep + read cycles sgraph_get_element_dependencies
"What breaks if I change this?" Manual trace, easy to miss sgraph_analyze_change_impact
"Show module structure" ls + read + scroll sgraph_get_element_structure
Time per query Seconds (many round-trips) Milliseconds (cached)
Accuracy Text matching (noisy) Semantic graph (precise)

Quick Start

1. Install

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

2. Start the server

# 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. Connect your AI agent

<details> <summary><strong>Claude Code / Cursor (.mcp.json)</strong></summary>

Create .mcp.json in your project root:

{
  "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"
      ]
    }
  }
}

</details>

<details> <summary><strong>Alternative: SSE transport (any MCP client, via <code>mcp-remote</code>)</strong></summary>

Stdio is the recommended transport for local use — no port, no bridge, direct IPC. SSE is available for clients that can only speak HTTP or when you want to share one long-running server across multiple clients.

Start the server in SSE mode:

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

Then connect any MCP client via the mcp-remote bridge:

{
  "mcpServers": {
    "sgraph": {
      "command": "npx",
      "args": ["-y", "mcp-remote", "http://localhost:8008/sse"]
    }
  }
}

</details>

<details> <summary><strong>Where do sgraph models come from?</strong></summary>

sgraph models (.xml.zip files) are produced by Softagram code analysis or the open-source sgraph CLI tools.

The models represent your codebase as a hierarchical graph:

/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)

Each element can have associations (dependencies) to other elements, forming a complete dependency graph.

</details>

Tools

The claude-code profile provides 6 tools optimized for AI-assisted development:

Tool What it does When to use
sgraph_search_elements Find symbols by pattern "Where is the UserService class?"
sgraph_get_element_dependencies Query incoming/outgoing deps "What calls this function?"
sgraph_get_element_structure Explore hierarchy "What's inside this module?"
sgraph_analyze_change_impact Multi-level impact analysis "What breaks if I change this?"
sgraph_audit Architectural health checks "Any circular dependencies?"
sgraph_security_audit Security posture overview "Any exposed secrets or CVEs?"

The key tool is sgraph_get_element_dependencies with its result_level parameter for controlling abstraction:

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)

For the full tool reference with workflows and examples, see SGRAPH_FOR_CLAUDE_CODE.md.

<details> <summary><strong>Legacy profile (14 tools)</strong></summary>

The legacy profile provides the full original tool set for backwards compatibility:

Basic Operations: sgraph_load_model, sgraph_get_root_element, sgraph_get_element, sgraph_get_element_incoming_associations, sgraph_get_element_outgoing_associations

Search: sgraph_search_elements_by_name, sgraph_get_elements_by_type, sgraph_search_elements_by_attributes

Analysis: 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

</details>

Example Conversation

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

Architecture

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)

See ARCHITECTURE.md for the detailed design.

Development

# 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

See CONTRIBUTING.md for how to contribute.

About

Built by Softagram using the open-source sgraph library. Licensed under MIT.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选