You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@deno --version > /dev/null 2>&1|| (printf "\033[0;31m✖ Error: deno is not installed, but is needed for mcp-run-python\033[0m\n Please install deno: https://docs.deno.com/runtime/getting_started/installation/\n"&&exit 1)
14
-
15
11
.PHONY: install
16
-
install: .uv .pre-commit .deno ## Install the package, dependencies, and pre-commit for local development
12
+
install: .uv .pre-commit ## Install the package, dependencies, and pre-commit for local development
Copy file name to clipboardExpand all lines: docs/mcp/client.md
+25-25Lines changed: 25 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ Pydantic AI comes with two ways to connect to MCP servers:
19
19
-[`MCPServerSSE`][pydantic_ai.mcp.MCPServerSSE] which connects to an MCP server using the [HTTP SSE](https://spec.modelcontextprotocol.io/specification/2024-11-05/basic/transports/#http-with-sse) transport
20
20
-[`MCPServerStdio`][pydantic_ai.mcp.MCPServerStdio] which runs the server as a subprocess and connects to it using the [stdio](https://spec.modelcontextprotocol.io/specification/2024-11-05/basic/transports/#stdio) transport
21
21
22
-
Examples of all three are shown below; [mcp-run-python](run-python.md) is used as the MCP server in all examples.
22
+
Examples of all three are shown below.
23
23
24
24
Each MCP server instance is a [toolset](../toolsets.md) and can be registered with an [`Agent`][pydantic_ai.Agent] using the `toolsets` argument.
result =await agent.run('How many days between 2000-01-01 and 2025-03-18?')
62
+
result =await agent.run('What is 7 plus 5')
63
63
print(result.output)
64
-
#> There are 9,208 days between January 1, 2000, and March 18, 2025.
64
+
#> The answer is 12.
65
65
```
66
66
67
67
1. Define the MCP server with the URL used to connect.
@@ -97,19 +97,26 @@ Will display as follows:
97
97
[`MCPServerSSE`][pydantic_ai.mcp.MCPServerSSE] connects over HTTP using the [HTTP + Server Sent Events transport](https://spec.modelcontextprotocol.io/specification/2024-11-05/basic/transports/#http-with-sse) to a server.
98
98
99
99
!!! note
100
-
[`MCPServerSSE`][pydantic_ai.mcp.MCPServerSSE] requires an MCP server to be running and accepting HTTP connections before running the agent. Running the server is not managed by Pydantic AI.
100
+
The SSE transport in MCP is deprecated, you should use Streamable HTTP instead.
101
+
102
+
Before creating the SSE client, we need to run a server that supports the SSE transport.
103
+
101
104
102
-
The name "HTTP" is used since this implementation will be adapted in future to use the new
103
-
[Streamable HTTP](https://github.com/modelcontextprotocol/specification/pull/206) currently in development.
result =await agent.run('How many days between 2000-01-01 and 2025-03-18?')
130
+
result =await agent.run('What is 7 plus 5')
124
131
print(result.output)
125
-
#> There are 9,208 days between January 1, 2000, and March 18, 2025.
132
+
#> The answer is 12.
126
133
```
127
134
128
135
1. Define the MCP server with the URL used to connect.
@@ -133,23 +140,16 @@ _(This example is complete, it can be run "as is" — you'll need to add `asynci
133
140
134
141
### MCP "stdio" Server
135
142
136
-
The other transport offered by MCP is the [stdio transport](https://spec.modelcontextprotocol.io/specification/2024-11-05/basic/transports/#stdio) where the server is run as a subprocess and communicates with the client over `stdin` and `stdout`. In this case, you'd use the [`MCPServerStdio`][pydantic_ai.mcp.MCPServerStdio] class.
143
+
MCP also offers [stdio transport](https://spec.modelcontextprotocol.io/specification/2024-11-05/basic/transports/#stdio) where the server is run as a subprocess and communicates with the client over `stdin` and `stdout`. In this case, you'd use the [`MCPServerStdio`][pydantic_ai.mcp.MCPServerStdio] class.
144
+
145
+
In this example [mcp-run-python](https://github.com/pydantic/mcp-run-python) is used as the MCP server.
137
146
138
147
```python {title="mcp_stdio_client.py"}
139
148
from pydantic_ai import Agent
140
149
from pydantic_ai.mcp import MCPServerStdio
141
150
142
151
server = MCPServerStdio( # (1)!
143
-
'deno',
144
-
args=[
145
-
'run',
146
-
'-N',
147
-
'-R=node_modules',
148
-
'-W=node_modules',
149
-
'--node-modules-dir=auto',
150
-
'jsr:@pydantic/mcp-run-python',
151
-
'stdio',
152
-
]
152
+
'uvx', args=['mcp-run-python', 'stdio'],
153
153
)
154
154
agent = Agent('openai:gpt-4o', toolsets=[server])
155
155
@@ -161,7 +161,7 @@ async def main():
161
161
#> There are 9,208 days between January 1, 2000, and March 18, 2025.
162
162
```
163
163
164
-
1. See [MCP Run Python](run-python.md) for more information.
164
+
1. See [MCP Run Python](https://github.com/pydantic/mcp-run-python) for more information.
Copy file name to clipboardExpand all lines: docs/mcp/overview.md
-8Lines changed: 0 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,11 +19,3 @@ Some examples of what this means:
19
19
- Pydantic AI could use a web search service implemented as an MCP server to implement a deep research agent
20
20
- Cursor could connect to the [Pydantic Logfire](https://github.com/pydantic/logfire-mcp) MCP server to search logs, traces and metrics to gain context while fixing a bug
21
21
- Pydantic AI, or any other MCP client could connect to our [Run Python](run-python.md) MCP server to run arbitrary Python code in a sandboxed environment
22
-
23
-
## MCP Servers
24
-
25
-
To add functionality to Pydantic AI while making it as widely usable as possible, we're implementing some functionality as MCP servers.
26
-
27
-
So far, we've only implemented one MCP server as part of Pydantic AI:
28
-
29
-
-[Run Python](run-python.md): A sandboxed Python interpreter that can run arbitrary code, with a focus on security and safety.
0 commit comments