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
Copy file name to clipboardExpand all lines: docs/mcp/client.md
+53Lines changed: 53 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -163,6 +163,59 @@ async def main():
163
163
164
164
1. See [MCP Run Python](https://github.com/pydantic/mcp-run-python) for more information.
165
165
166
+
## Loading MCP Servers from Configuration
167
+
168
+
Instead of creating MCP server instances individually in code, you can load multiple servers from a JSON configuration file using [`load_mcp_servers()`][pydantic_ai.mcp.load_mcp_servers].
169
+
170
+
This is particularly useful when you need to manage multiple MCP servers or want to configure servers externally without modifying code.
171
+
172
+
### Configuration Format
173
+
174
+
The configuration file should be a JSON file with an `mcpServers` object containing server definitions. Each server is identified by a unique key and contains the configuration for that server type:
175
+
176
+
```json {title="mcp_config.json"}
177
+
{
178
+
"mcpServers": {
179
+
"python-runner": {
180
+
"command": "uv",
181
+
"args": ["run", "mcp-run-python", "stdio"]
182
+
},
183
+
"weather-api": {
184
+
"url": "http://localhost:3001/sse"
185
+
},
186
+
"calculator": {
187
+
"url": "http://localhost:8000/mcp"
188
+
}
189
+
}
190
+
}
191
+
```
192
+
193
+
!!! note
194
+
The MCP server is only inferred to be an SSE server because of the `/sse` suffix.
195
+
Any other server with the "url" field will be inferred to be a Streamable HTTP server.
196
+
197
+
We made this decision given that the SSE transport is deprecated.
0 commit comments