Skip to content

Commit e467c9e

Browse files
authored
docs: add mcp objects.inv (#2685)
1 parent 234606f commit e467c9e

File tree

3 files changed

+37
-74
lines changed

3 files changed

+37
-74
lines changed

docs/mcp/client.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ Pydantic AI supports sampling as both a client and server. See the [server](./se
318318

319319
Sampling is automatically supported by Pydantic AI agents when they act as a client.
320320

321-
To be able to use sampling, an MCP server instance needs to have a [`sampling_model`][pydantic_ai.mcp.MCPServerStdio.sampling_model] set. This can be done either directly on the server using the constructor keyword argument or the property, or by using [`agent.set_mcp_sampling_model()`][pydantic_ai.Agent.set_mcp_sampling_model] to set the agent's model or one specified as an argument as the sampling model on all MCP servers registered with that agent.
321+
To be able to use sampling, an MCP server instance needs to have a [`sampling_model`][pydantic_ai.mcp.MCPServer.sampling_model] set. This can be done either directly on the server using the constructor keyword argument or the property, or by using [`agent.set_mcp_sampling_model()`][pydantic_ai.Agent.set_mcp_sampling_model] to set the agent's model or one specified as an argument as the sampling model on all MCP servers registered with that agent.
322322

323323
Let's say we have an MCP server that wants to use sampling (in this case to generate an SVG as per the tool arguments).
324324

@@ -380,7 +380,7 @@ async def main():
380380

381381
_(This example is complete, it can be run "as is" with Python 3.10+)_
382382

383-
You can disallow sampling by setting [`allow_sampling=False`][pydantic_ai.mcp.MCPServerStdio.allow_sampling] when creating the server reference, e.g.:
383+
You can disallow sampling by setting [`allow_sampling=False`][pydantic_ai.mcp.MCPServer.allow_sampling] when creating the server reference, e.g.:
384384

385385
```python {title="sampling_disallowed.py" hl_lines="6" py="3.10"}
386386
from pydantic_ai.mcp import MCPServerStdio

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ plugins:
243243
- url: https://fastapi.tiangolo.com/objects.inv
244244
- url: https://typing-extensions.readthedocs.io/en/latest/objects.inv
245245
- url: https://rich.readthedocs.io/en/stable/objects.inv
246+
- url: https://modelcontextprotocol.github.io/python-sdk/objects.inv
246247
# waiting for https://github.com/encode/httpx/discussions/3091#discussioncomment-11205594
247248
- llmstxt:
248249
enabled: !ENV [CI, false]

pydantic_ai_slim/pydantic_ai/mcp.py

Lines changed: 34 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,49 @@ class MCPServer(AbstractToolset[Any], ABC):
5656
"""
5757

5858
tool_prefix: str | None
59+
"""A prefix to add to all tools that are registered with the server.
60+
61+
If not empty, will include a trailing underscore(`_`).
62+
63+
e.g. if `tool_prefix='foo'`, then a tool named `bar` will be registered as `foo_bar`
64+
"""
65+
5966
log_level: mcp_types.LoggingLevel | None
67+
"""The log level to set when connecting to the server, if any.
68+
69+
See <https://modelcontextprotocol.io/specification/2025-03-26/server/utilities/logging#logging> for more details.
70+
71+
If `None`, no log level will be set.
72+
"""
73+
6074
log_handler: LoggingFnT | None
75+
"""A handler for logging messages from the server."""
76+
6177
timeout: float
78+
"""The timeout in seconds to wait for the client to initialize."""
79+
6280
read_timeout: float
81+
"""Maximum time in seconds to wait for new messages before timing out.
82+
83+
This timeout applies to the long-lived connection after it's established.
84+
If no new messages are received within this time, the connection will be considered stale
85+
and may be closed. Defaults to 5 minutes (300 seconds).
86+
"""
87+
6388
process_tool_call: ProcessToolCallback | None
89+
"""Hook to customize tool calling and optionally pass extra metadata."""
90+
6491
allow_sampling: bool
92+
"""Whether to allow MCP sampling through this client."""
93+
6594
sampling_model: models.Model | None
95+
"""The model to use for sampling."""
96+
6697
max_retries: int
98+
"""The maximum number of times to retry a tool call."""
99+
67100
elicitation_callback: ElicitationFnT | None = None
101+
"""Callback function to handle elicitation requests from the server."""
68102

69103
_id: str | None
70104

@@ -407,49 +441,15 @@ async def main():
407441

408442
# last fields are re-defined from the parent class so they appear as fields
409443
tool_prefix: str | None
410-
"""A prefix to add to all tools that are registered with the server.
411-
412-
If not empty, will include a trailing underscore(`_`).
413-
414-
e.g. if `tool_prefix='foo'`, then a tool named `bar` will be registered as `foo_bar`
415-
"""
416-
417444
log_level: mcp_types.LoggingLevel | None
418-
"""The log level to set when connecting to the server, if any.
419-
420-
See <https://modelcontextprotocol.io/specification/2025-03-26/server/utilities/logging#logging> for more details.
421-
422-
If `None`, no log level will be set.
423-
"""
424-
425445
log_handler: LoggingFnT | None
426-
"""A handler for logging messages from the server."""
427-
428446
timeout: float
429-
"""The timeout in seconds to wait for the client to initialize."""
430-
431447
read_timeout: float
432-
"""Maximum time in seconds to wait for new messages before timing out.
433-
434-
This timeout applies to the long-lived connection after it's established.
435-
If no new messages are received within this time, the connection will be considered stale
436-
and may be closed. Defaults to 5 minutes (300 seconds).
437-
"""
438-
439448
process_tool_call: ProcessToolCallback | None
440-
"""Hook to customize tool calling and optionally pass extra metadata."""
441-
442449
allow_sampling: bool
443-
"""Whether to allow MCP sampling through this client."""
444-
445450
sampling_model: models.Model | None
446-
"""The model to use for sampling."""
447-
448451
max_retries: int
449-
"""The maximum number of times to retry a tool call."""
450-
451452
elicitation_callback: ElicitationFnT | None = None
452-
"""Callback function to handle elicitation requests from the server."""
453453

454454
def __init__(
455455
self,
@@ -569,53 +569,15 @@ class _MCPServerHTTP(MCPServer):
569569

570570
# last fields are re-defined from the parent class so they appear as fields
571571
tool_prefix: str | None
572-
"""A prefix to add to all tools that are registered with the server.
573-
574-
If not empty, will include a trailing underscore (`_`).
575-
576-
For example, if `tool_prefix='foo'`, then a tool named `bar` will be registered as `foo_bar`
577-
"""
578-
579572
log_level: mcp_types.LoggingLevel | None
580-
"""The log level to set when connecting to the server, if any.
581-
582-
See <https://modelcontextprotocol.io/introduction#logging> for more details.
583-
584-
If `None`, no log level will be set.
585-
"""
586-
587573
log_handler: LoggingFnT | None
588-
"""A handler for logging messages from the server."""
589-
590574
timeout: float
591-
"""Initial connection timeout in seconds for establishing the connection.
592-
593-
This timeout applies to the initial connection setup and handshake.
594-
If the connection cannot be established within this time, the operation will fail.
595-
"""
596-
597575
read_timeout: float
598-
"""Maximum time in seconds to wait for new messages before timing out.
599-
600-
This timeout applies to the long-lived connection after it's established.
601-
If no new messages are received within this time, the connection will be considered stale
602-
and may be closed. Defaults to 5 minutes (300 seconds).
603-
"""
604-
605576
process_tool_call: ProcessToolCallback | None
606-
"""Hook to customize tool calling and optionally pass extra metadata."""
607-
608577
allow_sampling: bool
609-
"""Whether to allow MCP sampling through this client."""
610-
611578
sampling_model: models.Model | None
612-
"""The model to use for sampling."""
613-
614579
max_retries: int
615-
"""The maximum number of times to retry a tool call."""
616-
617580
elicitation_callback: ElicitationFnT | None = None
618-
"""Callback function to handle elicitation requests from the server."""
619581

620582
def __init__(
621583
self,

0 commit comments

Comments
 (0)