python-mcp-server

python-mcp-server

Enables deterministic static analysis of Python code, providing tools to inspect classes, functions, imports, dependencies, and more, without executing the code.

Category
访问服务器

README

python-mcp-server

MCP (Model Context Protocol) server for deterministic static analysis of Python code, built with LibCST + Jedi.

Motivation

This project is inspired by the deterministic analysis approach of cobol-mcp-server. Just as that project demonstrates that COBOL can be analyzed deterministically via AST (without AI), python-mcp-server applies the same principle to the Python ecosystem:

  • LibCST — parses source code into a concrete AST, guaranteeing 100% deterministic analysis (no guesswork).
  • Jedi — optional type resolution for finding definitions and references (on-demand, no classpath required).
  • No code execution — only static syntax analysis.

The result is an MCP server that exposes Python code analysis tools to any MCP client (OpenCode, Claude Desktop, etc.).

Tools

Tool Description
load_python_project Loads a project from local path, Git URL, or archive (.zip/.tar.gz)
unload_python_project Removes a loaded project from memory
list_loaded_projects Lists all projects currently in memory
project_metadata Shows project metadata (build, modules, classes, functions)
detect_build_system Detects the build system (pip, poetry, pdm, hatch, uv, conda, etc.)
detect_framework Detects frameworks/libs in use (Flask, Django, FastAPI, SQLAlchemy, etc.)
list_modules Lists all Python modules in the project
list_classes Lists all classes in the project
list_functions Lists all functions and methods in the project
inspect_class Deep-dives into a class: bases, methods, decorators, docstring
inspect_function Deep-dives into a function: signature, parameters, body, decorators
list_imports Lists all imports in the project
list_decorators Lists all decorators used with their frequencies
find_decorated_elements Finds classes/functions decorated with a specific decorator
class_hierarchy Shows inheritance hierarchy (bases and direct subclasses)
search_source Searches text in the project source code
multi_file_search Searches text across all loaded projects simultaneously
find_definition Finds the definition of a symbol (requires type_resolution=True)
find_references Finds references to a symbol (requires type_resolution=True)
get_file_content Reads the raw source content of any file in the project
get_source_range Returns specific source lines with line numbers from a file
validate_code_reference Checks if a class, function, or variable exists (EXISTS/NOT_FOUND)
resolve_type Resolves a type name to its definition, tracing imports across the project
inspect_module Deep-dives into a module: docstring, variables, functions, classes, imports
call_chain Static call graph: shows which functions are called and which call a given function
variable_xref Cross-references a variable: shows declarations, writes, and reads across the project
list_enums Lists all enum classes with their members and values
module_dependency_graph Builds a dependency map showing which modules import which
list_methods_by_return_type Finds all functions/methods that return a specific type annotation
find_entry_points Finds where the program starts: if name, console_scripts, web apps, CLI apps, async runners
list_api_endpoints Lists all API route/endpoint definitions (FastAPI, Flask, Starlette, Django) with paths and handlers
extract_environment_dependencies Extracts environment variable reads, config file loads, and Pydantic Field(env=...)
list_side_effects Classifies functions by side effects: FILE_IO, NETWORK, DB, LOG, MUTATION, or PURE
analyze_error_handling Analyzes error handling: custom exceptions, raises, try/except patterns, bare excepts
list_public_api Shows the public API surface: all, init.py re-exports, top-level public definitions
find_test_mapping Maps production code to tests by analyzing test file imports
extract_domain_vocabulary Extracts domain-specific vocabulary — key entities, module docstrings, domain terms

Building the .pyz (fat-pyz)

Important: shiv must be installed in the Python interpreter that you use to build the wheel. The resulting .pyz will then be runnable on any Python 3.8+ system interpreter, but the build itself must be done with a Python version you want to ship wheels for.

The package layout is src/pymcp/ (declared in pyproject.toml via setuptools.packages.find), so shiv discovers it automatically when run from the project root.

Build inside a venv (recommended)

# 1. Create / activate a venv (use any Python 3.8+ interpreter)
python -m venv .venv
source .venv/bin/activate

# 2. Install build tooling
pip install shiv

# 3. Build the fat .pyz from the project root
shiv -o python-mcp-server.pyz -e pymcp.main:main -p "/usr/bin/env python3" .

For reproducible builds, create the venv with a pinned interpreter, e.g. python3.11 -m venv .venv. This guarantees the bundled wheels match the target Python's ABI.

Why this matters

  • shiv resolves dependencies via pip, which downloads wheels built for the active interpreter's ABI (e.g. cp311 for Python 3.11).
  • If you build with Python 3.14 and try to run the .pyz with the system's Python 3.11, you'll get zipimport.ZipImportError because the bundled cp314 wheels are not compatible.
  • The pyproject.toml pins requires-python = ">=3.8". Make sure the Python used to build the .pyz is the same major.minor you intend to run it with.

Smoke test

./python-mcp-server.pyz   # starts the MCP server on stdio and logs to /tmp/python_mcp_server.log

The resulting .pyz is standalone — it includes all dependencies (mcp, libcst, jedi, GitPython) and works with any Python 3.8+ interpreter.

You can also run the installed entrypoint directly:

python-mcp-server

OpenCode Configuration

Add the following to your opencode.json or opencode.yml:

{
  "mcpServers": {
    "python-mcp-server": {
      "command": "python",
      "args": ["python-mcp-server.pyz"],
      "transport": "stdio"
    }
  }
}

Or if installed as a package:

{
  "mcpServers": {
    "python-mcp-server": {
      "command": "python-mcp-server",
      "transport": "stdio"
    }
  }
}

Environment Variables

Variable Default Description
PYMCP_LOG_FILE /tmp/python_mcp_server.log Log file path
PYMCP_LOG_LEVEL INFO Log level (DEBUG, INFO, WARNING, ERROR)

Dependencies

  • mcp >= 1.0.0
  • libcst >= 1.0.0
  • jedi >= 0.19.0
  • GitPython >= 3.1.0

License

MIT — see LICENSE.

推荐服务器

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

官方
精选