Skip to content

Add openai strict mode support for mcp #1437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
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
14 changes: 14 additions & 0 deletions pydantic_ai_slim/pydantic_ai/mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class MCPServer(ABC):
"""

is_running: bool = False
strict: bool | None = None

_client: ClientSession
_read_stream: MemoryObjectReceiveStream[JSONRPCMessage | Exception]
Expand Down Expand Up @@ -64,6 +65,7 @@ async def list_tools(self) -> list[ToolDefinition]:
name=tool.name,
description=tool.description or '',
parameters_json_schema=tool.inputSchema,
strict=self.strict,
)
for tool in tools.tools
]
Expand Down Expand Up @@ -150,6 +152,12 @@ async def main():
If you want to inherit the environment variables from the parent process, use `env=os.environ`.
"""

strict: bool | None = None
"""Whether to enforce (vendor-specific) strict JSON schema validation for tool calls.

See [`ToolDefinition`][pydantic_ai.tools.ToolDefinition] for more info.
"""

@asynccontextmanager
async def client_streams(
self,
Expand Down Expand Up @@ -220,6 +228,12 @@ async def main():
and may be closed. Defaults to 5 minutes (300 seconds).
"""

strict: bool | None = None
"""Whether to enforce (vendor-specific) strict JSON schema validation for tool calls.

See [`ToolDefinition`][pydantic_ai.tools.ToolDefinition] for more info.
"""

@asynccontextmanager
async def client_streams(
self,
Expand Down