pydantic

MCP Run Python

Community pydantic
Updated

MCP server to run Python code in a sandbox.

MCP Run Python

Model Context Protocol server to run Python code in a sandbox.

The code is executed using Pyodide in Deno and is thereforeisolated from the rest of the operating system.

See https://ai.pydantic.dev/mcp/run-python/ for complete documentation.

The server can be run with deno installed using:

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

where:

  • -N -R=node_modules -W=node_modules (alias of--allow-net --allow-read=node_modules --allow-write=node_modules) allowsnetwork access and read+write access to ./node_modules. These are requiredso pyodide can download and cache the Python standard library and packages
  • --node-modules-dir=auto tells deno to use a local node_modules directory
  • stdio runs the server with theStdio MCP transport— suitable for running the process as a subprocess locally
  • sse runs the server with theSSE MCP transport— running the server as an HTTP server to connect locally or remotely
  • warmup will run a minimal Python script to download and cache the Pythonstandard library. This is also useful to check the server is runningcorrectly.

Here's an example of using @pydantic/mcp-run-python with 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.data)
    #> There are 9,208 days between January 1, 2000, and March 18, 2025.w

if __name__ == '__main__':
    import asyncio
    asyncio.run(main())

MCP Server · Populars

MCP Server · New

    appwrite

    Appwrite MCP server

    Appwrite’s MCP server. Operating your backend has never been easier.

    Community appwrite
    pydantic

    Pydantic Validation

    Data validation using Python type hints

    Community pydantic
    arangodb

    Python-Arango

    The official ArangoDB Python driver.

    Community arangodb
    probelabs

    Probe

    Probe is an AI-friendly, fully local, semantic code search engine which which works with for large codebases. The final missing building block for next generation of AI coding tools.

    Community probelabs
    probelabs

    Docs MCP Server

    Turn any github repo to MCP server, and chat with code or docs

    Community probelabs