MCP (Model Context Protocol)¶
MCP integration for AI-Parrot.
MCPToolAdapter ¶
Adapts AI-Parrot AbstractTool to MCP tool format.
Tools marked routing_meta["requires_confirmation"] (e.g. the
destructive members of a toolkit's confirming_tools) get an MCP-side
guard: a required confirm boolean is injected into their input
schema and the call is rejected unless confirm=true is passed —
the stdio transport has no interactive HITL channel, so the explicit
argument is the confirmation record.
Source code in packages/ai-parrot/src/parrot/mcp/adapter.py
to_mcp_tool_definition ¶
Convert AbstractTool to MCP tool definition.
Source code in packages/ai-parrot/src/parrot/mcp/adapter.py
execute
async
¶
Execute the AI-Parrot tool and convert result to MCP format.
Source code in packages/ai-parrot/src/parrot/mcp/adapter.py
MCPResource
dataclass
¶
Represents an MCP Resource.
Resources are read-only data sources exposed by the server.
to_dict ¶
Convert to MCP protocol dictionary.
Source code in packages/ai-parrot/src/parrot/mcp/resources.py
MCPServerBase ¶
Bases: ABC
Base class for MCP servers (core, transport-agnostic).
Source code in packages/ai-parrot/src/parrot/mcp/server_base.py
register_tool ¶
Register an AI-Parrot tool with the MCP server.
Source code in packages/ai-parrot/src/parrot/mcp/server_base.py
register_tools ¶
handle_initialize
async
¶
Handle MCP initialize request.
Source code in packages/ai-parrot/src/parrot/mcp/server_base.py
handle_tools_list
async
¶
Handle tools/list request.
Source code in packages/ai-parrot/src/parrot/mcp/server_base.py
handle_tools_call
async
¶
Handle tools/call request.
Source code in packages/ai-parrot/src/parrot/mcp/server_base.py
start
abstractmethod
async
¶
LocalServerConfig
dataclass
¶
LocalServerConfig(name: str = 'parrot-mcp-local', version: str = '1.0.0', description: str = '', log_level: str = 'WARNING')
Lightweight config for local-only MCP servers.
LocalMCPServerBase ¶
Bases: MCPServerBase
Extension point for local (in-process) MCP transports.
Local transports (e.g. stdio) may reserve stdout as the JSON-RPC channel, so all logging must go to stderr instead of a default handler that could write to stdout.
Source code in packages/ai-parrot/src/parrot/mcp/local_server.py
StdioMCPServer ¶
Bases: LocalMCPServerBase
MCP server using stdio transport (core, local-only).
Source code in packages/ai-parrot/src/parrot/mcp/local_server.py
start
async
¶
Start the stdio MCP server.
Source code in packages/ai-parrot/src/parrot/mcp/local_server.py
AgentMethodTool ¶
Bases: AbstractTool
An agent method reified as a real AbstractTool.
Built by :func:build_exposure_set from a @mcp_tool-marked method.
name, description and args_schema come from the method's
MCPToolDeclaration; _execute() invokes the bound method on the
owning agent. The agent is held by weak reference only so this
tool never drags the agent into tool-serialization paths and never
creates a reference cycle (spec §7 Risks).
The agent is resolved per call, never cached as a bound method, so
a reloaded agent (BotManager.reload_agent()) is picked up transparently
by any mount holding this tool (spec OQ5).
Initialize the reified tool.
| PARAMETER | DESCRIPTION |
|---|---|
agent
|
The owning agent instance. Held by weak reference only.
TYPE:
|
method_name
|
Name of the async method on
TYPE:
|
declaration
|
The
TYPE:
|
Source code in packages/ai-parrot/src/parrot/mcp/agent_tools.py
MCPToolDeclaration ¶
Bases: BaseModel
Declaration metadata attached by @mcp_tool.
All fields except the hint/limit flags are mandatory — there is no schema inference in v1 (spec §1 Non-Goals). Registration must fail loudly if any mandatory field is missing.
| ATTRIBUTE | DESCRIPTION |
|---|---|
name |
MCP tool name exposed to clients.
TYPE:
|
description |
Human-readable tool description surfaced to MCP clients.
TYPE:
|
args_schema |
Pydantic model describing the tool's call arguments.
TYPE:
|
returns |
Pydantic model describing the tool's return payload.
TYPE:
|
scope |
PBAC action/resource scope enforced when the tool is invoked.
TYPE:
|
read_only_hint |
Maps to the MCP
TYPE:
|
idempotent_hint |
Maps to the MCP
TYPE:
|
requires_confirmation |
Maps to
TYPE:
|
max_result_tokens |
Per-tool result-size cap;
TYPE:
|
build_exposure_set ¶
Scan agent for @mcp_tool-marked methods and build its exposure set.
Walks the agent's class for coroutine methods carrying an
MCPToolDeclaration (attached via MCP_TOOL_ATTR), validates there are
no name collisions — neither among the decorated methods themselves nor
against tools already registered in agent.tool_manager — and reifies
each into an AgentMethodTool.
The returned exposure set is a plain list. It is never registered
into agent.tool_manager (OQ2) — callers (the MCP mount, TASK-2602)
are responsible for what they do with it.
| PARAMETER | DESCRIPTION |
|---|---|
agent
|
The agent instance to scan. Must expose
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[AgentMethodTool]
|
The agent's exposure set — one |
list[AgentMethodTool]
|
method. Empty if the agent declares none. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If two decorated methods declare the same MCP tool
name, or a decorated name collides with an existing
|
Source code in packages/ai-parrot/src/parrot/mcp/agent_tools.py
mcp_tool ¶
mcp_tool(*, name: str, description: str, args_schema: type[BaseModel], returns: type[BaseModel], scope: str, read_only_hint: bool = False, idempotent_hint: bool = False, requires_confirmation: bool = False, max_result_tokens: int | None = None) -> Callable[[F], F]
Mark a bound agent method as externally callable over MCP.
Marks only. Reification into an AgentMethodTool happens at
configure() time (TASK-2600). The decorated method is NEVER
registered into the owning agent's ToolManager and does not become
LLM-callable inside that agent (spec OQ2 — the single most important
invariant of this feature).
| PARAMETER | DESCRIPTION |
|---|---|
name
|
MCP tool name exposed to clients.
TYPE:
|
description
|
Human-readable tool description.
TYPE:
|
args_schema
|
Pydantic model describing the call arguments. Mandatory — no schema inference in v1.
TYPE:
|
returns
|
Pydantic model describing the return payload. Mandatory.
TYPE:
|
scope
|
PBAC action/resource scope enforced at call time.
TYPE:
|
read_only_hint
|
MCP
TYPE:
|
idempotent_hint
|
MCP
TYPE:
|
requires_confirmation
|
Whether MCP callers must pass
TYPE:
|
max_result_tokens
|
Per-tool result-size cap overriding the mount
default. Defaults to
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Callable[[F], F]
|
A decorator that attaches an |
Callable[[F], F]
|
async method and returns it unchanged. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the decorated callable is not an |