praval.mcp.client
Tools-only MCP client integration for Praval agents.
Classes
|
Async tools-only MCP client with bounded execution and cleanup. |
|
Configuration for one stdio or Streamable HTTP MCP server. |
Exceptions
Raised when an MCP operation is attempted after closure. |
|
Raised when an MCP connection cannot be established. |
|
Base error for Praval MCP client operations. |
|
Raised for invalid MCP tool discovery or registration state. |
- class praval.mcp.client.MCPClient(config)[source]
Bases:
objectAsync tools-only MCP client with bounded execution and cleanup.
- Parameters:
config (MCPServerConfig)
- __init__(config)[source]
- Parameters:
config (MCPServerConfig)
- property connected: bool
Return whether the MCP session is active.
- async connect()[source]
Connect and initialize the configured MCP server exactly once.
- Return type:
None
- async close()[source]
Close the MCP session and any stdio process; safe to call twice.
- Return type:
None
- async list_tools()[source]
Discover MCP tools and convert their schemas to Praval ToolSpecs.
- Return type:
List[ToolSpec]
- async register_tools(agent)[source]
Discover tools and register async handlers on an Agent.
- Return type:
List[ToolSpec]- Parameters:
agent (Any)
- exception praval.mcp.client.MCPClientClosedError[source]
Bases:
MCPErrorRaised when an MCP operation is attempted after closure.
- exception praval.mcp.client.MCPConnectionError[source]
Bases:
MCPErrorRaised when an MCP connection cannot be established.
- exception praval.mcp.client.MCPError[source]
Bases:
RuntimeErrorBase error for Praval MCP client operations.
- class praval.mcp.client.MCPServerConfig(**data)[source]
Bases:
BaseModelConfiguration for one stdio or Streamable HTTP MCP server.
- Parameters:
name (str)
transport (Literal['stdio', 'streamable_http'])
command (str | None)
args (List[str])
env (Dict[str, str] | None)
cwd (Path | None)
url (str | None)
headers (Dict[str, str])
connection_timeout (float)
tool_timeout (float)
tool_name_prefix (str | None)
require_approval (bool)
max_result_size (int)
- model_config: ClassVar[ConfigDict] = {'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- name: str
- transport: Literal['stdio', 'streamable_http']
- command: str | None
- args: List[str]
- env: Dict[str, str] | None
- cwd: Path | None
- url: str | None
- headers: Dict[str, str]
- connection_timeout: float
- tool_timeout: float
- tool_name_prefix: str | None
- require_approval: bool
- max_result_size: int
- validate_transport()[source]
Validate mutually exclusive transport settings and URL security.
- Return type:
- property resolved_tool_name_prefix: str
Return the configured namespace prefix or the server-name default.