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.
Pydantic AI supports [Model Context Protocol (MCP)](https://modelcontextprotocol.io) in three ways:
3
+
Pydantic AI supports [Model Context Protocol (MCP)](https://modelcontextprotocol.io) in two ways:
4
4
5
5
1.[Agents](../agents.md) act as an MCP Client, connecting to MCP servers to use their tools, [learn more …](client.md)
6
6
2. Agents can be used within MCP servers, [learn more …](server.md)
7
-
3. As part of Pydantic AI, we're building a number of MCP servers, [see below](#mcp-servers)
8
7
9
8
## What is MCP?
10
9
@@ -18,12 +17,4 @@ Some examples of what this means:
18
17
19
18
- Pydantic AI could use a web search service implemented as an MCP server to implement a deep research agent
20
19
- 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
-
- 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.
20
+
- Pydantic AI, or any other MCP client could connect to our [Run Python](https://github.com/pydantic/mcp-run-python) MCP server to run arbitrary Python code in a sandboxed environment
0 commit comments