关于 mcp-pyright
mcp-pyright 将 Pyright 语言服务器功能提供给 Python 开发者和兼容 MCP 的客户端,涵盖类型检查、代码导航、补全与格式化。
主要功能
- 01Python 类型检查
- 02悬停查看类型信息
- 03代码补全
- 04查找定义和引用
- 05文档符号与代码格式化
适用场景
- 01检查 Python 代码的类型错误
- 02编辑时查看符号类型
- 03在代码中查找定义和引用
- 04通过 MCP 客户端格式化 Python 代码
MCP 相关
该 MCP 服务将 Pyright 语言服务器功能作为工具提供给兼容 MCP 的客户端。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
工具
7收录的工具列表 · 更新于 3 周前
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| code | any | 否 | Python 代码字符串(与 file_path 互斥)。 |
| file_path | any | 否 | Python 文件路径(与 code 互斥)。 |
| python_path | any | 否 | 可选的 Python 解释器路径。 |
| type_checker_mode | string | 否 | 类型检查模式:“basic”、“strict”或“overload”(默认:“basic”)。 |
详细介绍
mcp-pyright
提供 Pyright 语言服务器功能的 MCP 服务
mcp-name: io.github.daedalus/mcp-pyright
安装
pip install mcp-pyright
使用方法
该 MCP 服务可与任何兼容 MCP 的客户端搭配使用。它提供以下工具:
类型检查
from mcp_pyright import mcp
# Run type checking
result = check_types(code="x: int = 'hello'")
获取悬浮信息
# Get type information at position
result = get_hover(code="x: int = 1", position=0)
获取补全
# Get code completions
result = get_completions(code="prin", position=4)
获取定义
# Find definition location
result = get_definition(code="def foo(): pass\nfoo()", position=15)
查找引用
# Find all references
result = find_references(code="x = 1\nx", position=5)
获取文档符号
# Get all symbols in document
result = get_document_symbols(code="class Foo: pass\ndef bar(): pass")
格式化代码
# Format Python code
result = format_code(code="x=1\ny=2")
开发
git clone https://github.com/daedalus/mcp-pyright.git
cd mcp-pyright
pip install -e ".[test]"
# run tests
pytest
# format
ruff format src/ tests/
# lint
ruff check src/ tests/
# type check
mypy src/
许可证
MIT
评论
支持 Markdown
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。