Skip to content

Commit 8149de4

Browse files
Don't require MCPServerStreamableHTTP and MCPServerSSE url to be a keyword argument (#2758)
Co-authored-by: Douwe Maan <[email protected]>
1 parent 85d47a1 commit 8149de4

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

docs/mcp/client.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Then we can create the client:
121121
from pydantic_ai import Agent
122122
from pydantic_ai.mcp import MCPServerSSE
123123

124-
server = MCPServerSSE(url='http://localhost:3001/sse') # (1)!
124+
server = MCPServerSSE('http://localhost:3001/sse') # (1)!
125125
agent = Agent('openai:gpt-4o', toolsets=[server]) # (2)!
126126

127127

@@ -189,7 +189,7 @@ async def process_tool_call(
189189
return await call_tool(name, tool_args, {'deps': ctx.deps})
190190

191191

192-
server = MCPServerStdio('python', ['mcp_server.py'], process_tool_call=process_tool_call)
192+
server = MCPServerStdio('python', args=['mcp_server.py'], process_tool_call=process_tool_call)
193193
agent = Agent(
194194
model=TestModel(call_tools=['echo_deps']),
195195
deps_type=int,
@@ -216,12 +216,12 @@ from pydantic_ai.mcp import MCPServerSSE
216216

217217
# Create two servers with different prefixes
218218
weather_server = MCPServerSSE(
219-
url='http://localhost:3001/sse',
219+
'http://localhost:3001/sse',
220220
tool_prefix='weather' # Tools will be prefixed with 'weather_'
221221
)
222222

223223
calculator_server = MCPServerSSE(
224-
url='http://localhost:3002/sse',
224+
'http://localhost:3002/sse',
225225
tool_prefix='calc' # Tools will be prefixed with 'calc_'
226226
)
227227

@@ -263,7 +263,7 @@ http_client = httpx.AsyncClient(
263263
)
264264

265265
server = MCPServerSSE(
266-
url='http://localhost:3001/sse',
266+
'http://localhost:3001/sse',
267267
http_client=http_client, # (1)!
268268
)
269269
agent = Agent('openai:gpt-4o', toolsets=[server])
@@ -362,7 +362,7 @@ Using this server with an `Agent` will automatically allow sampling:
362362
from pydantic_ai import Agent
363363
from pydantic_ai.mcp import MCPServerStdio
364364

365-
server = MCPServerStdio(command='python', args=['generate_svg.py'])
365+
server = MCPServerStdio('python', args=['generate_svg.py'])
366366
agent = Agent('openai:gpt-4o', toolsets=[server])
367367

368368

@@ -382,7 +382,7 @@ You can disallow sampling by setting [`allow_sampling=False`][pydantic_ai.mcp.MC
382382
from pydantic_ai.mcp import MCPServerStdio
383383

384384
server = MCPServerStdio(
385-
command='python',
385+
'python',
386386
args=['generate_svg.py'],
387387
allow_sampling=False,
388388
)
@@ -502,7 +502,7 @@ async def handle_elicitation(
502502

503503
# Set up MCP server connection
504504
restaurant_server = MCPServerStdio(
505-
command='python', args=['restaurant_server.py'], elicitation_callback=handle_elicitation
505+
'python', args=['restaurant_server.py'], elicitation_callback=handle_elicitation
506506
)
507507

508508
# Create agent

pydantic_ai_slim/pydantic_ai/mcp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ def __init__(
445445
self,
446446
command: str,
447447
args: Sequence[str],
448+
*,
448449
env: dict[str, str] | None = None,
449450
cwd: str | Path | None = None,
450451
tool_prefix: str | None = None,
@@ -457,7 +458,6 @@ def __init__(
457458
sampling_model: models.Model | None = None,
458459
max_retries: int = 1,
459460
elicitation_callback: ElicitationFnT | None = None,
460-
*,
461461
id: str | None = None,
462462
):
463463
"""Build a new MCP server.
@@ -571,8 +571,8 @@ class _MCPServerHTTP(MCPServer):
571571

572572
def __init__(
573573
self,
574-
*,
575574
url: str,
575+
*,
576576
headers: dict[str, str] | None = None,
577577
http_client: httpx.AsyncClient | None = None,
578578
id: str | None = None,

0 commit comments

Comments
 (0)