loading…
Search for a command to run...
loading…
An MCP server leveraging the Rust-based ty type checker to provide AI models with high-performance, semantic Python code analysis and structural navigation. It
An MCP server leveraging the Rust-based ty type checker to provide AI models with high-performance, semantic Python code analysis and structural navigation. It enables precise symbol searching, cross-file renaming, and diagnostic reporting to improve code understanding and editing accuracy.
基于 ty 类型检查器的 MCP 服务器,为 AI 提供精确的 Python 代码语义分析能力。
所有工具返回 JSON 格式的结构化数据:
// 成功
{"status": "ok", "data": {...}}
// 错误
{"status": "error", "message": "..."}
// 未找到
{"status": "not_found", "message": "..."}
| 工具 | 功能 | LSP 接口 |
|---|---|---|
search_symbol |
关键词搜索符号,返回文件名+行号 | workspace/symbol |
list_file_symbols |
列出文件中的所有符号结构 | textDocument/documentSymbol |
| 工具 | 功能 | LSP 接口 |
|---|---|---|
start_project |
初始化项目分析 | initialize |
get_definition |
跳转到符号定义 | textDocument/definition |
find_usages |
查找所有引用 | textDocument/references |
get_type_info |
获取类型信息 | textDocument/hover |
get_diagnostics |
获取类型错误 | textDocument/publishDiagnostics |
get_completions |
代码补全建议 | textDocument/completion |
analyze_file |
文件综合分析 | 多个接口组合 |
| 工具 | 功能 | LSP 接口 |
|---|---|---|
safe_rename |
跨文件安全重命名符号 | textDocument/rename |
get_code_actions |
获取可用的快速修复 | textDocument/codeAction |
apply_code_action |
应用指定的代码操作 | textDocument/codeAction |
get_edit_preview |
预览代码修改内容 | textDocument/codeAction |
为什么代码编辑功能很重要?
传统 AI 修改代码的方式是"生成新代码",这容易产生幻觉或遗漏。 而基于 ty 的编辑是语义级精确计算:
AI 发指令 → ty 分析类型系统 → 计算精确的 diff → 应用修改
这种方式的优势:
确保已安装 ty:
# 使用 uv 安装
uv tool install ty
# 或使用 pipx
pipx install ty
# 克隆项目
git clone https://github.com/yourusername/mcp-ty.git
cd mcp-ty
# 使用 uv 安装
uv sync
在 Cursor 的 MCP 配置文件中添加:
{
"mcpServers": {
"ty-context-engine": {
"command": "uv",
"args": [
"--directory",
"D:/PythonProjectAll/mcp-ty",
"run",
"mcp-ty"
]
}
}
}
编辑 claude_desktop_config.json:
{
"mcpServers": {
"ty-context-engine": {
"command": "uv",
"args": [
"--directory",
"/path/to/mcp-ty",
"run",
"mcp-ty"
]
}
}
}
首先,让 AI 初始化要分析的项目:
请初始化项目 D:/MyPythonProject 进行类型分析
AI 会调用 start_project 工具。
在 src/models/user.py 的第 45 行第 10 列,帮我找到这个函数的定义
找出 User 类在整个项目中的所有使用位置
告诉我 src/services/auth.py 第 23 行的 session 变量是什么类型
检查 src/api/routes.py 有没有类型错误
┌─────────────┐ stdio ┌─────────────┐ JSON-RPC ┌─────────┐
│ AI Client │ ◄────────────► │ MCP Server │ ◄───────────────► │ ty │
│ (Cursor) │ │ (FastMCP) │ │ server │
└─────────────┘ └─────────────┘ └─────────┘
| 场景 | grep/文本搜索 | ty 语义分析 |
|---|---|---|
搜索 User |
返回几千个匹配 | 只返回 class User 的定义 |
| 查找方法调用 | 可能匹配注释和字符串 | 只匹配真正的方法调用 |
| 理解类型 | 无法推断 | 精确显示推断类型 |
| 重构安全性 | 容易改错 | 找到所有真实引用 |
ty 提供的是代码结构语义,不是自然语言语义:
process_order 函数的所有调用链建议:将 ty 的结构化检索与 RAG 向量搜索结合,是目前最强的 AI 代码理解方案。
# 安装开发依赖
uv sync --dev
# 运行测试
uv run pytest
# 类型检查
uv run ty check
MIT
Добавь это в claude_desktop_config.json и перезапусти Claude Desktop.
{
"mcpServers": {
"mcp-ty": {
"command": "npx",
"args": []
}
}
}