Skip to main content
Glama
pydantic

mcp-run-python

Official
by pydantic

MCP 运行 Python

模型上下文协议服务器在沙箱中运行 Python 代码。

该代码使用Deno中的Pyodide执行,因此与操作系统的其余部分隔离。

请参阅https://ai.pydantic.dev/mcp/run-python/以获取完整文档。

可以使用以下命令安装deno来运行服务器:

deno run \
  -N -R=node_modules -W=node_modules --node-modules-dir=auto \
  jsr:@pydantic/mcp-run-python [stdio|sse|warmup]

在哪里:

  • -N -R=node_modules -W=node_modules--allow-net --allow-read=node_modules --allow-write=node_modules的别名)允许网络访问以及对./node_modules的读写访问。这些是 pyodide 下载和缓存 Python 标准库和软件包所必需的。

  • --node-modules-dir=auto告诉 deno 使用本地node_modules目录

  • stdio使用Stdio MCP 传输运行服务器 - 适合在本地将进程作为子进程运行

  • sse使用SSE MCP 传输运行服务器 — 将服务器作为 HTTP 服务器运行,以便进行本地或远程连接

  • warmup将运行一个精简的 Python 脚本来下载并缓存 Python 标准库。这对于检查服务器是否正常运行也很有用。

以下是使用@pydantic/mcp-run-python与 PydanticAI 的示例:

from pydantic_ai import Agent
from pydantic_ai.mcp import MCPServerStdio

import logfire

logfire.configure()
logfire.instrument_mcp()
logfire.instrument_pydantic_ai()

server = MCPServerStdio('deno',
    args=[
        'run',
        '-N',
        '-R=node_modules',
        '-W=node_modules',
        '--node-modules-dir=auto',
        'jsr:@pydantic/mcp-run-python',
        'stdio',
    ])
agent = Agent('claude-3-5-haiku-latest', mcp_servers=[server])


async def main():
    async with agent.run_mcp_servers():
        result = await agent.run('How many days between 2000-01-01 and 2025-03-18?')
    print(result.output)
    #> There are 9,208 days between January 1, 2000, and March 18, 2025.w

if __name__ == '__main__':
    import asyncio
    asyncio.run(main())
-
license - not tested
-
quality - not tested
A
maintenance

Maintenance

Maintainers
9hResponse time
2dRelease cycle
177Releases (12mo)
Issues opened vs closed

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/pydantic/pydantic-ai'

If you have feedback or need assistance with the MCP directory API, please join our Discord server