Skip to content

API Reference parrot.mcp.client

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.mcp.client

View source

Class AuthCredential

Type-safe credential container with validation.

Validates that required fields are present based on the chosen scheme.

Fields:

Field Type Default Description
scheme AuthScheme Authentication scheme
token Optional[str] Bearer/OAuth2 token
api_key Optional[str] API key
api_key_header Optional[str] 'X-API-Key' Header name for API key
use_bearer_prefix bool False If True, prepend 'Bearer ' to API key value
username Optional[str] Username for basic auth
password Optional[str] Password for basic auth
cert_path Optional[str] Path to client certificate
key_path Optional[str] Path to client key
ca_cert_path Optional[str] Path to CA certificate
aws_access_key Optional[str] AWS access key
aws_secret_key Optional[str] AWS secret key
aws_region Optional[str] 'us-east-1' AWS region
aws_service Optional[str] 'execute-api' AWS service name

Method AuthCredential.validate_scheme_requirements

Validate that required fields are set for chosen scheme.

validate_scheme_requirements()

Method AuthCredential.get_auth_headers

Generate appropriate auth headers based on scheme.

get_auth_headers() -> Dict[str, str]

Returns: Dict[str, str] — Dictionary of authentication headers

Class AuthCredential.Config

Class AuthScheme

Type-safe authentication schemes.

Class MCPAuthHandler

Handles various authentication types for MCP servers.

Parameter Type Default Description
auth_type str
auth_config Dict[str, Any]

Method MCPAuthHandler.get_auth_headers

Get authentication headers based on auth type.

get_auth_headers() -> Dict[str, str]

Returns: Dict[str, str]

Class MCPClientConfig

Complete configuration for external MCP server connection.

Supports both static configuration and dynamic behavior through header_provider and token_supplier callbacks.

Parameter Type Default Description
name str
url Optional[str] None
command Optional[str] None
args Optional[List[str]] None
env Optional[Dict[str, str]] None
description Optional[str] None
auth_credential Optional[AuthCredential] None
auth_type Optional[AuthScheme] None
auth_config Dict[str, Any] dict()
token_supplier Optional[Callable[[], Optional[str]]] None
transport str 'auto'
base_path Optional[str] None
events_path Optional[str] None
socket_path Optional[str] None
headers Dict[str, str] dict()
header_provider Optional[Callable[[ReadonlyContext], Dict[str, str]]] None
tool_filter Optional[Union[List[str], Callable[[ToolPredicate], bool]]] None
allowed_tools Optional[List[str]] None
blocked_tools Optional[List[str]] None
require_confirmation Union[bool, Callable[[str, Dict[str, Any]], bool]] False
tool_name_prefix Optional[str] None
timeout float 30.0
retry_count int 3
startup_delay float 0.5
rate_limit_max_retries int 2
rate_limit_max_wait float 60.0
rate_limit_base_delay float 1.0
kill_timeout float 5.0
quic_config Any None
oauth2 Optional[MCPOAuth2Config] None
auth_preset Optional[str] None
user_id Optional[str] None
inject_broker_credential bool False
credential_provider Optional[str] None

Fields:

Field Type Default Description
name str
url Optional[str] None
command Optional[str] None
args Optional[List[str]] None
env Optional[Dict[str, str]] None
description Optional[str] None
auth_credential Optional[AuthCredential] None
auth_type Optional[AuthScheme] None
auth_config Dict[str, Any] field(default_factory=dict)
token_supplier Optional[Callable[[], Optional[str]]] None
transport str 'auto'
base_path Optional[str] None
events_path Optional[str] None
socket_path Optional[str] None
headers Dict[str, str] field(default_factory=dict)
header_provider Optional[Callable[[ReadonlyContext], Dict[str, str]]] None
tool_filter Optional[Union[List[str], Callable[[ToolPredicate], bool]]] None
allowed_tools Optional[List[str]] None
blocked_tools Optional[List[str]] None
require_confirmation Union[bool, Callable[[str, Dict[str, Any]], bool]] False
tool_name_prefix Optional[str] None
timeout float 30.0
retry_count int 3
startup_delay float 0.5
rate_limit_max_retries int 2
rate_limit_max_wait float 60.0
rate_limit_base_delay float 1.0
kill_timeout float 5.0
quic_config Any None
oauth2 Optional[MCPOAuth2Config] field(default=None)
auth_preset Optional[str] field(default=None)
user_id Optional[str] field(default=None)
inject_broker_credential bool False
credential_provider Optional[str] None

Method MCPClientConfig.get_headers

Get merged static, auth, and dynamic headers.

Order of precedence (later overrides earlier):

  1. Static headers from self.headers
  2. Auth headers from auth_credential.get_auth_headers()
  3. Dynamic headers from header_provider(context)

get_headers(context: Optional[ReadonlyContext] = None) -> Dict[str, str]

Parameter Type Default Description
context Optional[ReadonlyContext] None Optional ReadonlyContext for dynamic header generation

Returns: Dict[str, str] — Merged dictionary of all headers

Method MCPClientConfig.validate_transport

Validate transport-specific configuration.

validate_transport() -> None

Raises:

  • ValueError — If configuration is invalid for the specified transport

Method MCPClientConfig.from_yaml_config

Load from YAML configuration with validation.

from_yaml_config(config_dict: Dict[str, Any], config_abs_path: str = '') -> MCPClientConfig

Parameter Type Default Description
config_dict Dict[str, Any] Dictionary loaded from YAML file
config_abs_path str '' Absolute path to YAML file (for error messages)

Returns: MCPClientConfig — MCPClientConfig instance

Raises:

  • ValueError — If configuration is invalid

Class MCPConnectionError

MCP connection related errors.

Alias MCPOAuth2Config

Re-exported from parrot.mcp.oauth2_config.MCPOAuth2Config.

Class MCPRateLimitError

Raised when an MCP server rejects a request with a rate-limit error.

Subclasses :class:MCPConnectionError so existing except blocks keep working, while callers that want backoff can catch this type specifically and honour retry_after.

Parameter Type Default Description
message str
retry_after Optional[float] None
code int RATE_LIMIT_ERROR_CODE
raw_error Optional[Dict[str, Any]] None

Attributes:

Attribute Type Description
retry_after Suggested seconds to wait before retrying, already normalized to a delay relative to now (absolute epoch hints are converted). None when the server gave no usable hint.
code The JSON-RPC error code (usually -32429).
raw_error The original JSON-RPC error object from the server.

Attribute RATE_LIMIT_ERROR_CODE

Alias ReadonlyContext

Re-exported from parrot.mcp.context.ReadonlyContext.

Alias ToolPredicate

Re-exported from parrot.mcp.filtering.ToolPredicate.

Alias get_mcp_oauth2_preset

Re-exported from parrot.mcp.oauth2_config.get_mcp_oauth2_preset.

Function parse_retry_after

Normalize a server-provided retry hint into seconds-from-now.

Servers are inconsistent about how they express retryAfter. This accepts the three common forms and always returns a non-negative delay in seconds (or None when the value is missing/uninterpretable):

  • plain delay in seconds (HTTP Retry-After style): 5, 2.5
  • absolute epoch seconds: 1782259200
  • absolute epoch milliseconds: 1782259200009 (e.g. Fireflies)

parse_retry_after(value: Any, *, now: Optional[float] = None) -> Optional[float]

Parameter Type Default Description
value Any The raw retryAfter value from the error payload.
now Optional[float] None Override for the current epoch seconds (testing hook).

Returns: Optional[float] — Seconds to wait before retrying, clamped to >= 0, or None.

Function raise_for_jsonrpc_error

Translate a JSON-RPC error object into the right exception.

Rate-limit errors (code -32429 or data.type == 'rate_limit_exceeded') become :class:MCPRateLimitError carrying a normalized retry_after; everything else becomes a generic :class:MCPConnectionError.

Always raises — never returns normally.

raise_for_jsonrpc_error(error: Dict[str, Any]) -> None

Parameter Type Default Description
error Dict[str, Any]

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally