MCP Python解释器
模型上下文协议 (MCP) 服务器允许 LLM 与 Python 环境交互、读取和写入文件、执行 Python 代码以及管理开发工作流程。
特征
环境管理:列出并使用不同的 Python 环境(系统和 conda)
代码执行:在任何可用环境中运行 Python 代码或脚本
软件包管理:列出已安装的软件包并安装新的软件包
文件操作:
读取任何类型的文件(文本、源代码、二进制)
写入文本和二进制文件
Python 提示符:用于常见 Python 任务(如函数创建和调试)的模板
安装
���可以使用 pip 安装 MCP Python 解释器:
或者使用 uv:
与 Claude Desktop 一起使用
打开 Claude Desktop,点击菜单,然后点击设置
转到“开发者”选项卡并单击“编辑配置”
将以下内容添加到您的
claude_desktop_config.json
中:
对于 Windows:
重启Claude桌面
您现在应该在聊天界面中看到 MCP 工具图标
--dir
参数是必需的,用于指定所有文件的保存和执行位置。这有助于将 MCP 服务器隔离到特定目录,从而维护安全性。
先决条件
确保已安装
uv
。如果没有,请使用以下命令安装:对于 Windows:
可用工具
Python解释器提供以下工具:
环境和包管理
list_python_environments :列出所有可用的 Python 环境(系统和 conda)
list_installed_packages :列出特定环境中安装的软件包
install_package :在特定环境中安装 Python 包
代码执行
run_python_code :在特定环境中执行 Python 代码
run_python_file :在特定环境中执行 Python 文件
文件操作
read_file :读取任何文件类型的内容,并附带大小和安全限制
支持语法高亮的文本文件
显示二进制文件的十六进制表示
write_file :使用文本或二进制内容创建或覆盖文件
write_python_file :专门创建或覆盖 Python 文件
list_directory :列出目录中的 Python 文件
可用资源
python://environments :列出所有可用的 Python 环境
python://packages/{env_name} :列出特定环境已安装的软件包
python://file/{file_path} :获取 Python 文件的内容
python://directory/{directory_path} :列出目录中的所有 Python 文件
提示
python_function_template :为 Python 函数生成模板
refactor_python_code :帮助重构 Python 代码
debug_python_error :帮助调试 Python 错误
示例用法
以下是您可以要求 Claude 使用此 MCP 服务器执行的操作的一些示例:
“显示我的系统上所有可用的 Python 环境”
“在我的 conda-base 环境中运行此 Python 代码:print(‘Hello, world!’)”
“创建一个名为‘hello.py’的新 Python 文件,其中包含一个执行 hello 函数”
“读取我的‘data.json’文件的内容”
“使用这些设置写入一个新的配置文件...”
“列出我的系统 Python 环境中安装的所有包”
“在我的系统 Python 环境中安装请求包”
“使用以下参数运行 data_analysis.py:--input=data.csv --output=results.csv”
文件处理能力
MCP Python 解释器现在支持全面的文件操作:
读取最大 1MB 的文本和二进制文件
写入文本和二进制文件
源代码文件的语法高亮
二进制文件的十六进制表示
严格的文件路径安全(仅在工作目录内)
安全注意事项
此 MCP 服务器可以访问您的 Python 环境和文件系统。主要安全功能包括:
隔离工作目录
文件大小限制
防止在工作目录之外写入
显式覆盖保护
在运行您不完全理解的代码或文件操作时务必保持谨慎。
执照
麻省理工学院
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
Tools
模型上下文协议服务器允许 LLM 与 Python 环境交互、执行代码和管理指定工作目录中的文件。
Related MCP Servers
- -securityAlicense-qualityA Model Context Protocol server that extracts and analyzes Python code structures, focusing on import/export relationships between files to help LLMs understand code context.Last updated -6MIT License
- -securityAlicense-qualityA Model Context Protocol server that enables seamless execution of commands, Python code, web content fetching, and reusable task management with secure credentials handling.Last updated -2MIT License
- -securityAlicense-qualityA Python implementation of the Model Context Protocol that allows applications to provide standardized context for LLMs, enabling creation of servers that expose data and functionality to LLM applications through resources, tools, and prompts.Last updated -MIT License
- AsecurityFlicenseAqualityA Model Context Protocol server that allows LLMs to interact with Python environments, enabling code execution, file operations, package management, and development workflows.Last updated -9