Model Context Protocol (MCP)#
This page presents all APIs and classes related to Model Context Protocol (MCP).
Client Transports#
- class pyagentspec.mcp.clienttransport.SessionParameters(*, read_timeout_seconds=60)#
Bases:
BaseModel
Class to specify parameters of the MCP client session.
- Parameters:
read_timeout_seconds (float) –
- class pyagentspec.mcp.clienttransport.StdioTransport(*, id=<factory>, name, description=None, metadata=<factory>, min_agentspec_version=AgentSpecVersionEnum.v25_4_1, max_agentspec_version=AgentSpecVersionEnum.v25_4_1, session_parameters=<factory>, command, args=<factory>, env=None, cwd=None)#
Bases:
ClientTransport
Base transport for connecting to an MCP server via subprocess with stdio.
This is a base class that can be subclassed for specific command-based transports like Python, Node, Uvx, etc.
Warning
Stdio should be used for local prototyping only.
- Parameters:
id (str) – A unique identifier for this Component
name (str) – Name of this Component
description (str | None) – Optional description of this Component
metadata (Dict[str, Any] | None) – Optional, additional metadata related to this Component
min_agentspec_version (AgentSpecVersionEnum) –
max_agentspec_version (AgentSpecVersionEnum) –
session_parameters (SessionParameters) – Arguments for the MCP session.
command (str) – The executable to run to start the server.
args (List[str]) – Command line arguments to pass to the executable.
env (Dict[str, str] | None) –
cwd (str | None) – The working directory to use when spawning the process.
- args: List[str]#
Command line arguments to pass to the executable.
- command: str#
The executable to run to start the server.
- cwd: str | None#
The working directory to use when spawning the process.
- env: Dict[str, str] | None#
The environment to use when spawning the process.
If not specified, the result of get_default_environment() will be used.
- class pyagentspec.mcp.clienttransport.SSETransport(*, id=<factory>, name, description=None, metadata=<factory>, min_agentspec_version=AgentSpecVersionEnum.v25_4_1, max_agentspec_version=AgentSpecVersionEnum.v25_4_1, session_parameters=<factory>, url, headers=None)#
Bases:
RemoteTransport
Transport implementation that connects to an MCP server via Server-Sent Events.
- Parameters:
id (str) – A unique identifier for this Component
name (str) – Name of this Component
description (str | None) – Optional description of this Component
metadata (Dict[str, Any] | None) – Optional, additional metadata related to this Component
min_agentspec_version (AgentSpecVersionEnum) –
max_agentspec_version (AgentSpecVersionEnum) –
session_parameters (SessionParameters) – Arguments for the MCP session.
url (str) – The URL of the server.
headers (Dict[str, str] | None) – The headers to send to the server.
- class pyagentspec.mcp.clienttransport.SSEmTLSTransport(*, id=<factory>, name, description=None, metadata=<factory>, min_agentspec_version=AgentSpecVersionEnum.v25_4_1, max_agentspec_version=AgentSpecVersionEnum.v25_4_1, session_parameters=<factory>, url, headers=None, key_file, cert_file, ca_file)#
Bases:
SSETransport
Transport layer for SSE with mTLS (mutual Transport Layer Security).
This transport establishes a secure, mutually authenticated TLS connection to the MCP server using client certificates. Production deployments MUST use this transport to ensure both client and server identities are verified.
Notes
Users MUST provide a valid client certificate (PEM format) and private key.
Users MUST provide (or trust) the correct certificate authority (CA) for the server they’re connecting to.
The client certificate/key and CA certificate paths can be managed via secrets, config files, or secure environment variables in any production system.
Executors should ensure that these files are rotated and managed securely.
- Parameters:
id (str) – A unique identifier for this Component
name (str) – Name of this Component
description (str | None) – Optional description of this Component
metadata (Dict[str, Any] | None) – Optional, additional metadata related to this Component
min_agentspec_version (AgentSpecVersionEnum) –
max_agentspec_version (AgentSpecVersionEnum) –
session_parameters (SessionParameters) – Arguments for the MCP session.
url (str) – The URL of the server.
headers (Dict[str, str] | None) – The headers to send to the server.
key_file (str) – The path to the client’s private key file (PEM format). If None, mTLS cannot be performed.
cert_file (str) – The path to the client’s certificate chain file (PEM format). If None, mTLS cannot be performed.
ca_file (str) – The path to the trusted CA certificate file (PEM format) to verify the server. If None, system cert store is used.
- ca_file: str#
The path to the trusted CA certificate file (PEM format) to verify the server. If None, system cert store is used.
- cert_file: str#
The path to the client’s certificate chain file (PEM format). If None, mTLS cannot be performed.
- key_file: str#
The path to the client’s private key file (PEM format). If None, mTLS cannot be performed.
- class pyagentspec.mcp.clienttransport.StreamableHTTPTransport(*, id=<factory>, name, description=None, metadata=<factory>, min_agentspec_version=AgentSpecVersionEnum.v25_4_1, max_agentspec_version=AgentSpecVersionEnum.v25_4_1, session_parameters=<factory>, url, headers=None)#
Bases:
RemoteTransport
Transport implementation that connects to an MCP server via Streamable HTTP.
- Parameters:
id (str) – A unique identifier for this Component
name (str) – Name of this Component
description (str | None) – Optional description of this Component
metadata (Dict[str, Any] | None) – Optional, additional metadata related to this Component
min_agentspec_version (AgentSpecVersionEnum) –
max_agentspec_version (AgentSpecVersionEnum) –
session_parameters (SessionParameters) – Arguments for the MCP session.
url (str) – The URL of the server.
headers (Dict[str, str] | None) – The headers to send to the server.
- class pyagentspec.mcp.clienttransport.StreamableHTTPmTLSTransport(*, id=<factory>, name, description=None, metadata=<factory>, min_agentspec_version=AgentSpecVersionEnum.v25_4_1, max_agentspec_version=AgentSpecVersionEnum.v25_4_1, session_parameters=<factory>, url, headers=None, key_file, cert_file, ca_file)#
Bases:
StreamableHTTPTransport
Transport layer for streamable HTTP with mTLS (mutual Transport Layer Security).
This transport establishes a secure, mutually authenticated TLS connection to the MCP server using client certificates. Production deployments MUST use this transport to ensure both client and server identities are verified.
Notes
Users MUST provide a valid client certificate (PEM format) and private key.
Users MUST provide (or trust) the correct certificate authority (CA) for the server they’re connecting to.
The client certificate/key and CA certificate paths can be managed via secrets, config files, or secure environment variables in any production system.
Executors should ensure that these files are rotated and managed securely.
- Parameters:
id (str) – A unique identifier for this Component
name (str) – Name of this Component
description (str | None) – Optional description of this Component
metadata (Dict[str, Any] | None) – Optional, additional metadata related to this Component
min_agentspec_version (AgentSpecVersionEnum) –
max_agentspec_version (AgentSpecVersionEnum) –
session_parameters (SessionParameters) – Arguments for the MCP session.
url (str) – The URL of the server.
headers (Dict[str, str] | None) – The headers to send to the server.
key_file (str) – The path to the client’s private key file (PEM format). If None, mTLS cannot be performed.
cert_file (str) – The path to the client’s certificate chain file (PEM format). If None, mTLS cannot be performed.
ca_file (str) – The path to the trusted CA certificate file (PEM format) to verify the server. If None, system cert store is used.
- ca_file: str#
The path to the trusted CA certificate file (PEM format) to verify the server. If None, system cert store is used.
- cert_file: str#
The path to the client’s certificate chain file (PEM format). If None, mTLS cannot be performed.
- key_file: str#
The path to the client’s private key file (PEM format). If None, mTLS cannot be performed.
Tools#
See MCP Tool