Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions docs/mcp/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ deno run \
from pydantic_ai import Agent
from pydantic_ai.mcp import MCPServerSSE

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


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


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

# Create two servers with different prefixes
weather_server = MCPServerSSE(
url='http://localhost:3001/sse',
'http://localhost:3001/sse',
tool_prefix='weather' # Tools will be prefixed with 'weather_'
)

calculator_server = MCPServerSSE(
url='http://localhost:3002/sse',
'http://localhost:3002/sse',
tool_prefix='calc' # Tools will be prefixed with 'calc_'
)

Expand Down Expand Up @@ -263,7 +263,7 @@ http_client = httpx.AsyncClient(
)

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

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


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

server = MCPServerStdio(
command='python',
'python',
args=['generate_svg.py'],
allow_sampling=False,
)
Expand Down Expand Up @@ -502,7 +502,7 @@ async def handle_elicitation(

# Set up MCP server connection
restaurant_server = MCPServerStdio(
command='python', args=['restaurant_server.py'], elicitation_callback=handle_elicitation
'python', args=['restaurant_server.py'], elicitation_callback=handle_elicitation
)

# Create agent
Expand Down
4 changes: 2 additions & 2 deletions pydantic_ai_slim/pydantic_ai/mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ def __init__(
self,
command: str,
args: Sequence[str],
*,
env: dict[str, str] | None = None,
cwd: str | Path | None = None,
tool_prefix: str | None = None,
Expand All @@ -469,7 +470,6 @@ def __init__(
sampling_model: models.Model | None = None,
max_retries: int = 1,
elicitation_callback: ElicitationFnT | None = None,
*,
id: str | None = None,
):
"""Build a new MCP server.
Expand Down Expand Up @@ -583,8 +583,8 @@ class _MCPServerHTTP(MCPServer):

def __init__(
self,
*,
url: str,
*,
headers: dict[str, str] | None = None,
http_client: httpx.AsyncClient | None = None,
id: str | None = None,
Expand Down