Discovery must happen before delegation when the target agent is not explicitly known.
- Check bridge health — verify the bridge is operational via
bridge_health - Call
agents_discover— retrieve list of available agents - Filter by capability — pass
capabilityparameter to narrow results - Select agent — choose the most appropriate agent by ID
- Create session — use the selected
agentIdinsessions_createortasks_delegate
- On first use — always discover on initial power activation
- On explicit request — when user asks to see available agents
- On routing failure — when selected agent is unavailable
- Never speculatively — don't discover without a concrete need
McpAgenticServer resolves agents across two executor backends:
- InProcessExecutor — agents registered via
register() - WorkerExecutor — agents registered via
registerWorker()
In-process agents always take priority over workers. When an agentId exists in both executors, the in-process agent handles the request.
- Check executor cache (populated on
start()) - On cache miss, call
discover()onInProcessExecutorfirst - If not found, call
discover()onWorkerExecutor - Cache the result for subsequent lookups
- Cache is invalidated on
register()orregisterWorker()
- If
defaultAgentIdis set inMcpAgenticServerConfig, it is used when noagentIdis specified - If no
defaultAgentIdand noagentId, theInProcessExecutoruses the first registered agent - If no in-process agents exist, the
WorkerExecutoris used
Agents expose their identity and capabilities through discovery:
{
"id": "my-agent",
"capabilities": ["code-analysis", "debugging"],
"status": "ready"
}When an agent supports multiple AI providers (e.g., MultiProviderCompanionAgent), the discovery response includes an optional providers field with enriched metadata:
{
"id": "multi-provider-agent",
"capabilities": ["general"],
"status": "ready",
"providers": [
{
"id": "openai",
"models": ["gpt-4o", "gpt-4o-mini"],
"kind": "llm",
"capabilities": { "streaming": true, "tools": true, "vision": true, "jsonMode": true },
"displayName": "OpenAI"
},
{
"id": "anthropic",
"models": ["claude-sonnet-4-20250514"],
"kind": "llm",
"capabilities": { "streaming": true, "tools": true, "vision": true, "jsonMode": false },
"displayName": "Anthropic"
},
{
"id": "google-gemini",
"models": ["gemini-2.0-flash"],
"kind": "llm",
"capabilities": { "streaming": false, "tools": false, "vision": true, "jsonMode": true },
"displayName": "Google Gemini"
}
]
}Each provider entry may include:
kind— provider type ('llm','embedding','reranker'). Defaults to'llm'if not set.capabilities— self-reported capabilities (streaming,tools,vision,jsonMode). Omitted if the provider has no capabilities metadata.displayName— human-readable name (e.g.,"OpenAI","Google Gemini")description— provider description
The providers field is only present when the agent has a ProviderRegistry with registered providers. Agents without multi-provider support omit this field entirely.
- ready — agent is available for new sessions
Note: The
AgentInfotype also defines'busy'and'unavailable'statuses, but the current executor implementations always return'ready'. Dynamic status tracking (e.g., marking agents as busy when all sessions are in use) may be added in a future version.
Pass capability to agents_discover to filter results:
agents_discover({ capability: "code-analysis" })
→ [{ id: "my-agent", capabilities: ["code-analysis", "debugging"], status: "ready" }]
Only agents whose capabilities array includes the specified capability are returned.
When agents support multiple AI providers, use agents_discover to find available providers and their models before creating a session.
- Call
agents_discover— retrieve agent list including provider information - Inspect
providersfield — check which AI providers are available and their supported models - Select provider — choose the appropriate provider based on task requirements
- Create session with provider — pass
metadata.providertosessions_create
- By model availability — choose the provider that supports the model you need (e.g.,
gpt-4o→openai,claude-sonnet-4-20250514→anthropic) - By capability match — some providers may be better suited for specific tasks (e.g., code generation, creative writing)
- By cost/latency tradeoff — different providers have different pricing and response times
- Default provider — when no provider is specified, the agent uses its configured
defaultProviderId
agents_discover({})
→ [{
id: "multi-provider-agent",
capabilities: ["general"],
status: "ready",
providers: [
{ id: "openai", models: ["gpt-4o", "gpt-4o-mini"] },
{ id: "anthropic", models: ["claude-sonnet-4-20250514"] }
]
}]
sessions_create({
agentId: "multi-provider-agent",
metadata: { provider: "anthropic" }
})
→ { sessionId: "abc-123", agentId: "multi-provider-agent", status: "active" }
If metadata.provider specifies an unregistered provider id, sessions_create fails with BridgeError.config('Provider "{id}" is not registered in the ProviderRegistry').
- Use discovery results as source of truth — never invent agents
- Preserve session affinity — all requests in a session go to the same executor
- Never silently reroute — report any routing changes explicitly
- Validate before routing — ensure agent is available and capable
Once a session is created:
- The session is bound to the executor that created it
McpAgenticServerresolves the executor for session-based operations (sessions_prompt,sessions_status,sessions_close,sessions_cancel) by checking which executor owns thesessionId- In-process executor is checked first, then worker executor
When routing fails:
- Report the error — include
BridgeErrortype and message - Explain reason — agent not found, no agents registered, etc.
- Suggest alternatives — use
agents_discoverto find available agents - Preserve session — keep session valid if possible
- Agent not found —
BridgeError.upstream('Agent not found: {agentId}') - No agents registered —
BridgeError.config('No agents registered') - Session not found —
BridgeError.upstream('Session not found: {sessionId}') - Executor not started —
BridgeError.internal('Executor not started')