@@ -49,13 +49,7 @@ where:
4949- ` example ` will run a minimal Python script using ` numpy ` , useful for checking that the package is working, for the code
5050 to run successfully, you'll need to install ` numpy ` using ` uvx mcp-run-python --deps numpy example `
5151
52- ## Usage in codes as an MCP server
53-
54- ``` bash
55- pip install mcp-run-python
56- # or
57- uv add mcp-run-python
58- ```
52+ ## Usage with Pydantic AI
5953
6054Then you can use ` mcp-run-python ` with Pydantic AI:
6155
@@ -70,7 +64,7 @@ logfire.configure()
7064logfire.instrument_mcp()
7165logfire.instrument_pydantic_ai()
7266
73- server = MCPServerStdio(' deno ' , args = deno_args_prepare( ' stdio' ) )
67+ server = MCPServerStdio(' uvx ' , args = [ ' mcp-run-python@latest ' , ' stdio' ], timeout = 10 )
7468agent = Agent(' claude-3-5-haiku-latest' , toolsets = [server])
7569
7670
@@ -85,9 +79,48 @@ if __name__ == '__main__':
8579 asyncio.run(main())
8680```
8781
88- ** Note** : ` deno_args_prepare ` can take ` deps ` as a keyword argument to install dependencies.
89- As well as returning the args needed to run ` mcp_run_python ` , ` deno_args_prepare ` installs the dependencies
90- so they can be used by the server.
82+ ## Usage in codes as an MCP server
83+
84+ First install the ` mcp-run-python ` package:
85+
86+ ``` bash
87+ pip install mcp-run-python
88+ # or
89+ uv add mcp-run-python
90+ ```
91+
92+ With ` mcp-run-python ` installed, you can also run deno directly with ` prepare_deno_env ` or ` async_prepare_deno_env `
93+
94+
95+ ``` python
96+ from pydantic_ai import Agent
97+ from pydantic_ai.mcp import MCPServerStdio
98+ from mcp_run_python import async_prepare_deno_env
99+
100+ import logfire
101+
102+ logfire.configure()
103+ logfire.instrument_mcp()
104+ logfire.instrument_pydantic_ai()
105+
106+
107+ async def main ():
108+ async with async_prepare_deno_env(' stdio' ) as deno_env:
109+ server = MCPServerStdio(' deno' , args = deno_env.args, cwd = deno_env.cwd, timeout = 10 )
110+ agent = Agent(' claude-3-5-haiku-latest' , toolsets = [server])
111+ async with agent:
112+ result = await agent.run(' How many days between 2000-01-01 and 2025-03-18?' )
113+ print (result.output)
114+ # > There are 9,208 days between January 1, 2000, and March 18, 2025.w
115+
116+ if __name__ == ' __main__' :
117+ import asyncio
118+ asyncio.run(main())
119+ ```
120+
121+ ** Note** : ` prepare_deno_env ` can take ` deps ` as a keyword argument to install dependencies.
122+ As well as returning the args needed to run ` mcp_run_python ` , ` prepare_deno_env ` creates a new deno environment
123+ and installs the dependencies so they can be used by the server.
91124
92125## Usage in code with ` code_sandbox `
93126
0 commit comments