Skip to content

API Reference parrot.mcp.agent_mount

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

parrot.mcp.agent_mount

View source

AgentMCPMount — per-agent Streamable HTTP endpoints (FEAT-477, Module 2).

Builds one :class:~parrot.mcp.transports.streamable_http.StreamableHttpMCPServer per exposed agent at {base_path}/{agent_name}, mirroring the mount pattern A2AServer.setup() already proves (a2a/server.py:231). Each per-agent server is registered with that agent's exposure set (FEAT-477 TASK-2600) plus its own tool_manager tools, minus internal plumbing.

Optionally publishes an aggregate /mcp endpoint (spec §2 Overview #2) exposing every agent's tools as {agent}__{tool}. Both name forms resolve to the same canonical PBAC resource, mcp:agent:{name}:tool:{tool} — the aggregate is naming sugar, never its own authorization path. This is enforced, not just documented: _AggregateMCPServer runs through the same _guard()/PBACGuard gate as every per-agent _AgentBoundMCPServer (see "Identity + PBAC wiring" below) — an aggregate name never bypasses the per-agent decision.

OQ5 — agent reload. Agents are held by name only and resolved through BotManager.get_bots() on every tools/list/tools/call. When BotManager.reload_agent() swaps an agent's instance, the next call rebuilds that agent's tool registrations rather than serving the exposure set of a garbage-collected instance.

Identity + PBAC wiring (FEAT-477 TASK-2610). TASK-2604/2605 built principal resolution and PBAC filtering/re-verification (PBACGuard, resolve_principal) as standalone, importable pieces, but no task ever connected them to a live per-agent server — this module is where that happens: _AgentBoundMCPServer overrides _guard() to resolve the caller into a PermissionContext and publish it on _pctx_var (the same mechanism DatasetManager uses), then routes tools/list/ tools/call through a PBACGuard built once per mounted agent. AgentMCPMount accepts a pbac_resolver/audit_sink (mirroring TASK-2603's policy_filter seam) and an auth_template — an MCPServerConfig whose auth fields (auth_method, oauth2_*, api_key_store) are copied onto every per-agent config, since nothing upstream of this task ever gave a mount a way to require authentication at all. oauth2_resource_server_url is always taken from the mount's own AgentMCPMountConfig.resource_server_url (RFC 8707 audience scoping is a mount-level concept per the spec's data model) even when the template carries no OAuth settings of its own.

Class AgentMCPMount

Mounts one MCP endpoint per configured agent on a shared aiohttp app.

Parameter Type Default Description
bot_manager Any The BotManager whose agents are exposed. Held by reference and queried by name on every call (get_bots()) — never a cached agent instance (OQ5).
config AgentMCPMountConfig The AgentMCPMountConfig describing which agents to mount, under which base path, and whether the aggregate is enabled.
policy_filter ToolPolicyFilter | None None Optional (agent_name, tool_name) -> bool (or awaitable) hook used to filter the per-agent tool-catalog resource (TASK-2603) by the calling principal's policy — the same decision path as tools/list. None (default) means everything is visible.
pbac_resolver PBACResolver | None None Optional (pctx, resource, required_permissions) -> bool PBAC resolver (the PBACPermissionResolver.can_execute shape) enforcing tools/list/tools/call (TASK-2605). None (default) denies every call (deny-by-default).
audit_sink AuditSink | None None Optional callback invoked with every tools/call decision and every principal-resolution failure. None (default) only logs.
auth_template MCPServerConfig | None None Optional MCPServerConfig whose auth-related fields (auth_method, oauth2_*, api_key_store, api_key_header) are copied onto every per-agent MCPServerConfig this mount builds — nothing upstream of this mount otherwise has a way to require authentication on it. oauth2_resource_server_url is always taken from config .resource_server_url regardless (RFC 8707 audience scoping is mount-level, not template-level). None (default) mounts with AuthMethod.NONE, matching MCPServerConfig's own default.

Method AgentMCPMount.setup

Register one endpoint per configured agent (plus the optional aggregate) on app.

setup(app: web.Application) -> web.Application

Parameter Type Default Description
app web.Application The shared aiohttp application to mount onto.

Returns: web.Application — The same app, for chaining (matches BotManager.setup()'s own return convention).

Raises:

  • ValueError — If an agent name contains the aggregate separator __, or if a mount's base path collides with an already registered route/transport.

Method AgentMCPMount.canonical_resource

Build the canonical PBAC resource string for agent_name/tool_name.

canonical_resource(agent_name: str, tool_name: str) -> str

Parameter Type Default Description
agent_name str Configured agent name.
tool_name str Tool name as registered (per-agent form).

Returns: str — The canonical resource string, mcp:agent:{name}:tool:{tool}.

Method AgentMCPMount.canonical_resource_from_aggregate

Resolve an aggregate {agent}__{tool} name to its canonical resource.

canonical_resource_from_aggregate(aggregate_name: str) -> str

Parameter Type Default Description
aggregate_name str A name published on the aggregate endpoint, of the form {agent}__{tool}.

Returns: str — The same canonical resource string canonical_resource would produce for the equivalent per-agent name — both forms are naming sugar over one authorization path.

Raises:

  • ValueError — If aggregate_name does not contain the __ separator.

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