MCPcopy Create free account
hub / github.com/openai/openai-agents-python / MCPServerStreamableHttp

Class MCPServerStreamableHttp

src/agents/mcp/server.py:1364–1689  ·  view source on GitHub ↗

MCP server implementation that uses the Streamable HTTP transport. See the [spec] (https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#streamable-http) for details.

Source from the content-addressed store, hash-verified

1362
1363
1364class MCPServerStreamableHttp(_MCPServerWithClientSession):
1365 """MCP server implementation that uses the Streamable HTTP transport. See the [spec]
1366 (https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#streamable-http)
1367 for details.
1368 """
1369
1370 def __init__(
1371 self,
1372 params: MCPServerStreamableHttpParams,
1373 cache_tools_list: bool = False,
1374 name: str | None = None,
1375 client_session_timeout_seconds: float | None = 5,
1376 tool_filter: ToolFilter = None,
1377 use_structured_content: bool = False,
1378 max_retry_attempts: int = 0,
1379 retry_backoff_seconds_base: float = 1.0,
1380 message_handler: MessageHandlerFnT | None = None,
1381 require_approval: RequireApprovalSetting = None,
1382 failure_error_function: ToolErrorFunction | None | _UnsetType = _UNSET,
1383 tool_meta_resolver: MCPToolMetaResolver | None = None,
1384 custom_data_extractor: MCPToolCustomDataExtractor | None = None,
1385 ):
1386 """Create a new MCP server based on the Streamable HTTP transport.
1387
1388 Args:
1389 params: The params that configure the server. This includes the URL of the server,
1390 the headers to send to the server, the timeout for the HTTP request, the
1391 timeout for the Streamable HTTP connection, whether we need to
1392 terminate on close, and an optional custom HTTP client factory.
1393
1394 cache_tools_list: Whether to cache the tools list. If `True`, the tools list will be
1395 cached and only fetched from the server once. If `False`, the tools list will be
1396 fetched from the server on each call to `list_tools()`. The cache can be
1397 invalidated by calling `invalidate_tools_cache()`. You should set this to `True`
1398 if you know the server will not change its tools list, because it can drastically
1399 improve latency (by avoiding a round-trip to the server every time).
1400
1401 name: A readable name for the server. If not provided, we'll create one from the
1402 URL.
1403
1404 client_session_timeout_seconds: the read timeout passed to the MCP ClientSession.
1405 tool_filter: The tool filter to use for filtering tools.
1406 use_structured_content: Whether to use `tool_result.structured_content` when calling an
1407 MCP tool. Defaults to False for backwards compatibility - most MCP servers still
1408 include the structured content in the `tool_result.content`, and using it by
1409 default will cause duplicate content. You can set this to True if you know the
1410 server will not duplicate the structured content in the `tool_result.content`.
1411 max_retry_attempts: Number of times to retry failed list_tools/call_tool calls.
1412 Defaults to no retries.
1413 retry_backoff_seconds_base: The base delay, in seconds, for exponential
1414 backoff between retries.
1415 message_handler: Optional handler invoked for session messages as delivered by the
1416 ClientSession.
1417 require_approval: Approval policy for tools on this server. Accepts "always"/"never",
1418 a dict of tool names to those values, or an object with always/never tool lists.
1419 failure_error_function: Optional function used to convert MCP tool failures into
1420 a model-visible error message. If explicitly set to None, tool errors will be
1421 raised instead of converted. If left unset, the agent-level configuration (or

Calls

no outgoing calls