RepoGraph-Honest MCP Server

RepoGraph-Honest MCP Server

An MCP server that validates generated code against project structure and installed dependencies, catching undefined symbols, wrong API calls, dead code, and type mismatches in real time. It provides tools for project indexing, symbol/API checking, sandboxed execution, file scanning, and code analysis.

Category
访问服务器

README

RepoGraph-Honest MCP Server

CI License: MIT Python

A lightweight Model Context Protocol (MCP) server that catches code hallucinations in real time — undefined symbols, wrong library API calls, dead code, and obvious type mismatches — by verifying generated code against your project structure and installed dependencies.

RepoGraph-Honest is a self-contained extraction of the "honest action routing" idea. Instead of trusting a code model blindly, it checks the symbols and APIs the model emits before they reach your editor.

It is not a heavyweight ML system: it needs only mcp, tree-sitter, and tree-sitter-python — no torch / transformers.


Table of contents


Features

Capability Tool What it does
Project indexing index_project Builds a symbol index (functions / classes / variables) from a directory; caches results across calls
Dependency APIs load_project_deps Loads public API signatures from requirements.txt / pyproject.toml
Symbol check check_symbol Verifies an identifier is defined in the project
API check check_api Verifies a library API call is correct (e.g. pd.read_exel → suggestions)
Sandbox exec execute_code Runs code in a subprocess sandbox; returns stdout/stderr + error type
File scan scan_file Scans a whole file for undefined calls
Package APIs load_package_apis Loads/caches API signatures for one package
Stats get_project_stats Index statistics
Type check validate_types Lightweight AST-based structural checks (None iteration, wrong arg counts, etc.)
Dead code find_dead_code Finds symbols that appear unused; supports entrypoints and ignore patterns
Similar code find_similar_code Finds function-level code clones across the project
Call graph explore_call_graph Explores callers and callees of a symbol
Search search_code Regex search across project source files
Tool routing choose_tool Maps a natural-language query to the best tool

Installation

# from source
git clone https://github.com/Fengrru/repograph-honest-mcp.git
cd repograph-honest-mcp
pip install -e .

# or just the runtime deps
pip install -r requirements.txt

Python ≥ 3.10 is required.


Running the server

# as a module (stdio transport — what MCP clients expect)
python -m repograph_honest.mcp.server

# via the launcher script
python scripts/run_mcp_server.py

# HTTP/SSE transport (optional)
python scripts/run_mcp_server.py --transport sse --host 127.0.0.1 --port 8000

Connecting to an MCP client

Add this to your client's MCP configuration (Cursor, Claude Desktop, VS Code, etc.):

{
  "mcpServers": {
    "repograph-honest": {
      "command": "python",
      "args": ["-m", "repograph_honest.mcp.server"],
      "cwd": "/absolute/path/to/repograph-honest-mcp"
    }
  }
}

After restarting the client, the tools above become available.


Tool reference

All tools are exposed by the MCP server. They can also be called directly from Python (see examples/).

index_project(root_path: str, force_rebuild: bool = False) -> dict

Build (or reuse) the project symbol index.

index_project("/path/to/project")
# => {"success": True, "symbols_indexed": 42, "root": "...", "cached": False}

load_project_deps(root_path: str) -> dict

Parse requirements.txt or pyproject.toml and load the public API signatures of listed packages.

load_project_deps("/path/to/project")
# => {"success": True, "packages_loaded": ["requests", "pytest"], "total_apis": 1204}

check_symbol(symbol_name: str, file_path: str | None = None) -> dict

Check whether a symbol is defined in the indexed project.

Symbols are stored with their full module-qualified name, e.g. pkg.core.main.

check_symbol("pkg.core.main")
# => {"success": True, "symbol": "pkg.core.main", "defined": True, "location": {...}}

check_api(api_name: str) -> dict

Check whether a library API exists and get suggestions for typos.

check_api("math.sqrt")   # valid
check_api("math.sqrtt")  # invalid + suggestions

execute_code(code: str, prelude: str = "", known_names: list[str] | None = None) -> dict

Run code in a fresh subprocess with a temporary working directory and timeout.

execute_code("print(1 + 1)")
# => {"success": True, "output": "2", ...}

scan_file(file_path: str) -> dict

Scan a file for undefined calls using AST analysis.

scan_file("/path/to/project/bad.py")
# => {"success": True, "issues": [{"type": "undefined_call", "name": "...", "line": 7}]}

validate_types(code: str) -> dict

Lightweight structural checks on a code snippet:

  • iterating over None
  • wrong argument counts for common builtins (len, sum, etc.)
  • calling constant values
  • string methods on non-string constants
validate_types("for x in None:\n    pass")
# => {"success": True, "issues": [{"type": "none_iteration", ...}]}

find_dead_code(entrypoints: list[str] | None, ignore_patterns: list[str] | None, include_tests: bool = True) -> dict

Find symbols that appear unused. Provide entrypoints to keep known roots alive.

find_dead_code(entrypoints=["pkg.cli.main"])
# => {"success": True, "dead_symbols": [...], "count": 3}

explore_call_graph(symbol_name: str) -> dict

Return definitions, callers, and callees of a symbol.

explore_call_graph("pkg.core.helper")
# => {"success": True, "callers": [...], "callees": [...]}

search_code(pattern: str, glob: str = "*.py") -> dict

Regex search across project source files.

search_code(r"def \w+_helper")

Typical workflow

  1. index_project on your repo root → builds the symbol table (cached).
  2. load_project_deps → loads dependency APIs.
  3. Ask your coding agent to generate code; before accepting, it can:
    • check_symbol("pkg.core.my_helper") → ensure it really exists,
    • check_api("pandas.read_csv") → confirm the API name,
    • execute_code(...) → actually run the snippet and surface errors,
    • find_dead_code() → detect newly orphaned code.

Architecture

repograph-honest-mcp/
├── repograph_honest/
│   ├── mcp/            # FastMCP server + tool implementations
│   │   ├── server.py   # entry point (mcp.run)
│   │   ├── tools.py    # tool logic
│   │   └── knowledge_base.py  # installed package API cache
│   ├── honest/         # honest action routing
│   │   ├── router.py   # HonestRouter + ToolIntent routing
│   │   └── symbol_index.py    # project-wide symbol index + cache
│   ├── structure/      # tree-sitter based extraction
│   │   ├── extractor.py
│   │   └── relations.py
│   └── sandbox/        # sandboxed execution
├── scripts/
│   └── run_mcp_server.py
├── tests/
├── .github/workflows/  # CI
│   └── ci.yml
├── pyproject.toml
├── requirements.txt
└── README.md

Key design decisions:

  • AST-first: call graphs and file scans use ast instead of fragile regex.
  • Module-qualified symbols: the index stores pkg.module.func so cross-file references are unambiguous.
  • Lazy loading + caching: dependency APIs and project indices are cached and invalidated by content hash.
  • Thread-safe global state: tool state is protected by a lock so concurrent MCP requests do not race.

Development

pip install -e ".[dev]"
pytest
ruff check repograph_honest tests scripts
ruff format repograph_honest tests scripts

See CONTRIBUTING.md for pull-request guidelines.


Sandbox security

execute_code runs in a subprocess with timeout protection, a temporary working directory, and optional Unix resource limits. It is safe against accidental infinite loops and simple mistakes, but it is not a hardened security boundary against malicious code. For untrusted code, run inside a container or dedicated virtual machine.


Contributing

Contributions are welcome! Please read CONTRIBUTING.md first.


Changelog

See CHANGELOG.md.


License

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选