This MCP server enables you to safely execute Python code in a sandboxed environment. It uses Pyodide running in Deno to isolate the execution from your operating system, providing a secure way to run Python code within your applications.
To use the MCP Run Python server, you need to have Deno installed on your system. Once Deno is set up, you can run the server using the following command:
deno run \
-N -R=node_modules -W=node_modules --node-modules-dir=auto \
jsr:@pydantic/mcp-run-python [stdio|sse|warmup]
The command arguments include:
-N -R=node_modules -W=node_modules
: Provides network access and read/write permissions to the ./node_modules
directory--node-modules-dir=auto
: Configures Deno to use a local node_modules
directorystdio
: Runs the server using Stdio MCP transport (suitable for subprocess usage)sse
: Runs the server as an HTTP server with SSE transport (for local or remote connections)warmup
: Downloads and caches the Python standard library (useful for initial setup)Before using the server in production, it's recommended to warm it up to cache the Python standard library:
deno run \
-N -R=node_modules -W=node_modules --node-modules-dir=auto \
jsr:@pydantic/mcp-run-python warmup
Here's how to integrate the MCP Run Python server 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.output)
#> There are 9,208 days between January 1, 2000, and March 18, 2025.
if __name__ == '__main__':
import asyncio
asyncio.run(main())
This example shows how to:
For complete documentation, visit the official documentation at https://ai.pydantic.dev/mcp/run-python/.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.