Connect MCP Servers
If this page is useful, you should be able to copy these steps and ship a working MCP integration. This guide covers the full lifecycle:- Create MCP server config in control plane.
- Discover auth requirements from the MCP endpoint.
- Save auth config correctly.
- Attach server to one or more agents.
- Connect/disconnect at runtime from the user session.
The core MCP server contract
The MCP server config shape used by Console and backend APIs is:config.endpoint (not server_url) and keep auth nested under config.auth.
Step 1: Discover auth before saving config
Do this first for unknown endpoints.requires_authrecommended_auth_modetoken_urlauth_urlregister_urlresourcescopes
token_endpoint_auth_methods_supportedauthorization_serversresource_metadata_url
Step 1.5: Backend auto-discovery and config hydration
Yes, backend create/update can auto-discover and hydrate missing OAuth MCP auth fields. When you create an MCP server, backend can fill missing:auth_urltoken_urlregister_urlresourcescopes
WWW-Authenticate + resource metadata + OAuth AS metadata).
Step 2: Create MCP server (with correct auth mode)
Option A: Token auth
Option B: OAuth client credentials
Option C: OAuth authorization code (public PKCE)
client_id is omitted, backend can auto-register a public client through DCR (dynamic client registration), using discovered register_url.
Option D: OAuth authorization code (confidential PKCE)
client_id/client_secret are omitted, backend can auto-register a confidential client through DCR and persist returned credentials.
Step 2.5: DCR-first create flows (recommended when provider supports registration)
DCR registrations use this redirect URI:https://agentlink.wacht.services/service/mcp/consent/callback
Ensure your MCP OAuth provider allows this redirect URI.
Public PKCE with DCR
Send only endpoint + auth type (optionally scopes/resource). Backend discovers metadata and registers client when possible.Confidential PKCE with DCR
Same flow, but backend attempts registration methods supported by provider and stores generatedclient_id + client_secret.
Method preference is driven by provider metadata and falls back across:
client_secret_basicclient_secret_postnone
Read backend discovery hints from create response
Create responses include adiscovery_result object you can log/show in your admin UX:
Step 3: Attach MCP server to agent
Step 4: Runtime connect/disconnect in user session
Attach is control-plane. Connect/disconnect is runtime-plane per active agent session.useAgentMcpServers hooks.
Control-plane setup is already handled by the backend SDK examples above.
Troubleshooting that actually matters
401/403on connect: verify session ticket scope includes the target agent.connectsucceeds but tools fail: auth mode mismatch (tokenvs OAuth) or wrong scopes.- OAuth mode loops: wrong
resource,auth_url, or redirect registration. - Intermittent failures: check endpoint timeout/retry settings on MCP provider side.
- Only some tenants fail: compare per-tenant scope mapping and OAuth app/client config.
- DCR fails on create: provider may not expose
registration_endpoint/register_url; provideclient_id/client_secretmanually.
