MCP Clients & Investigations
Connect Claude Code, Codex, and Streamable HTTP MCP clients to Cockpit Context and understand tool behavior, caching, and cost accounting.
Cockpit Context exposes its investigation agent over the Model Context Protocol at /mcp on your public origin (for example https://context.example.com/mcp). Every MCP request is stateless over Streamable HTTP: both the 2025 handshake protocol and the 2026-07-28 per-request protocol are supported (GET /mcp returns 405).
Clients authenticate as a specific Cockpit Context user via OAuth 2.1 or a revocable API token (cockpit_context_…). An MCP credential can only invoke the MCP tools below—it can never call browser oRPC procedures, view or modify SSH keys, change settings, read other conversations, or mint new tokens.
Authentication Methods
Manage credentials in the web dashboard under Access → MCP tokens and Access → Connections.
| Aspect | OAuth 2.1 | Personal API Token |
|---|---|---|
| Best for | Interactive coding agents (Claude Code, Codex) | CI pipelines, agent harnesses, headless scripts |
| Secret handling | Dynamic registration or CIMD with PKCE and RFC 8707 resource; auto-refreshes |
cockpit_context_… secret shown once; stored as lookup prefix + HMAC digest |
| Lifetime | Access token: 10 min; refresh token: 72 h of inactivity | Optional expiry up to 1 year, or never (up to 50 active tokens per account) |
| Proposal controls | Chosen on the OAuth consent page; editable in Access → Connections | Chosen at creation; editable in Access → MCP tokens |
| Revocation | Revoke immediately under Access → Connections | Revoke or Regenerate (in-place rotation, audited) under Access → MCP tokens |
Without a valid bearer credential, /mcp returns 401 with WWW-Authenticate: Bearer resource_metadata="<origin>/.well-known/oauth-protected-resource/mcp", allowing OAuth-capable clients to discover /.well-known/oauth-protected-resource[/mcp] and /.well-known/oauth-authorization-server/api/auth. Dynamic client registration is rate-limited to 60 registrations per hour server-wide, and abandoned registrations are purged after one day.
Tip: To isolate an agent fleet or CI harness from your personal packages and SSH keys, have an administrator invite a dedicated ordinary user (Admin → Users) and create API tokens under that account.
Connecting Clients
Claude Code
With OAuth (recommended for interactive use):
claude mcp add --transport http cockpit-context https://context.example.com/mcp
Run /mcp inside Claude Code and choose Authenticate for cockpit-context. Sign in on the browser consent screen, verify the client name and callback host (localhost:<port>), and choose whether the connection may propose or auto-approve packages.
With an API token:
claude mcp add --transport http cockpit-context https://context.example.com/mcp \
--header "Authorization: Bearer <API_TOKEN>"
Pass --scope user to enable it across all projects, or --scope project to write .mcp.json. Never commit a raw token—reference an environment variable in .mcp.json ("Authorization": "Bearer ${COCKPIT_CONTEXT_TOKEN}").
Codex
With an API token: export COCKPIT_CONTEXT_TOKEN via your shell or secret store, then register the server:
codex mcp add cockpit-context --url https://context.example.com/mcp \
--bearer-token-env-var COCKPIT_CONTEXT_TOKEN
codex mcp list
With OAuth:
codex mcp add cockpit-context --url https://context.example.com/mcp
codex mcp login cockpit-context
Generic Streamable HTTP Clients
Any MCP client supporting Streamable HTTP can connect using:
{
"mcpServers": {
"cockpit-context": {
"type": "http",
"url": "https://context.example.com/mcp",
"headers": {
"Authorization": "Bearer <API_TOKEN>"
}
}
}
}
Omit headers if your client supports MCP OAuth discovery (PKCE + RFC 8707 resource).
MCP Tools Reference
Every connection has two boolean flags: may propose packages and auto-approve proposals. When may propose packages is disabled, propose_dependency and get_proposal are hidden from tools/list and unavailable.
| Tool | Arguments | Behavior & Output |
|---|---|---|
list_dependencies |
(none) | Lists the acting user’s registered packages: identifier, display_name, ecosystem, default_ref, and versions already checked out. |
query_dependency |
{ identifier, question, version?, ref?, wait_seconds? } |
Resolves the requested version/ref (cloning or fetching if needed), runs an investigation, streams progress roughly every 20 s, and waits up to wait_seconds. Returns status: "completed" with answer, version_resolved: { sha, from }, and usage, or status: "running" with query_id. |
get_query_result |
{ query_id, wait_seconds? } |
Waits on an active query_id owned by the user and returns its current status, final answer, and usage once finished. |
propose_dependency |
{ ecosystem, name, git_url?, version?, reason } |
Requests adding a dependency. Waits for human approval on the Proposals page unless auto-approve is enabled (SSH packages never auto-approve). |
get_proposal |
{ proposal_id } |
Returns pending, approved (with the new package identifier), or rejected (with the user’s reason). |
Example First Query
{
"identifier": "npm:react",
"version": "19.3.1",
"question": "Where is useState implemented and how does it schedule updates?",
"wait_seconds": 30
}
Waiting, Streaming, and Polling
- Dispatched tool calls return a
text/event-stream(SSE) response whose headers flush immediately. - Cockpit Context writes a
: keepaliveSSE comment every 15 seconds regardless of investigation activity so reverse proxies and Cloudflare Tunnels do not close the connection with a 524 timeout. Progress notifications arrive roughly every 20 seconds. wait_secondsdefaults to and is capped byCOCKPIT_CONTEXT_MCP_WAIT_SECONDS(900 s by default).- If
query_dependencyreturnsstatus: "running"with aquery_id, always pollget_query_resultusing thatquery_id. Do not callquery_dependencyagain just because a client wait timed out—disconnecting or ending a wait does not cancel a running investigation.
Version, Tag, and Monorepo Resolution
When a package is configured, you supply its Git URL, optional monorepo subdirectory, default ref, optional tag pattern, and package notes.
- Strict resolution: Specifying
versionorrefresolves to an exact commit SHA. An unresolvable version fails with an error rather than silently falling back to the default branch. - Stale branch indicator: If a branch fetch fails and cached refs are used instead, the response includes
version_resolved.stale: truealong withfetched_atso the agent can judge freshness. - Snapshot packages: For private repos cloned with a one-time SSH key, Cockpit Context never fetches automatically. Asking for a ref absent from the snapshot returns
PACKAGE_SNAPSHOT_REF_MISSING; the owner must refresh the snapshot in the web UI. - Fetch & version caching: Exact versions, tags, and full commit SHAs are cached in memory for
COCKPIT_CONTEXT_VERSION_CACHE_TTL_SECONDS(default300, max1000entries;0disables). Branches always resolve afresh, refetching remotes when the last fetch is older thanCOCKPIT_CONTEXT_FETCH_INTERVAL_SECONDS(default300).
Deduplication, Caching, and Rate Limits
Cockpit Context deduplicates and caches answers strictly within one user’s account, never across users:
- In-flight deduplication (
reused: "running_query"): If an identicalquery_dependencyarrives while the first run is still active, the second caller joins the existing investigation, receives the samequery_id, and shares the result without triggering a second model run. - Completed answer cache (
reused: "answer"): Completed, unsteered, unstopped investigations are cached in memory forCOCKPIT_CONTEXT_ANSWER_CACHE_TTL_SECONDS(default3600s, max500entries; disable withCOCKPIT_CONTEXT_ANSWER_CACHE_ENABLED=false). - Cache key: User ID, package, requested
version/ref, resolved commit SHA, package notes, subdirectory, effective checkout overview (user override or generated summary), whitespace-normalized question (case-sensitive), and model/run configuration. Package edits, overview edits/reverts, explicit repository refreshes, or deletes invalidate affected entries.
Built-In Rate & Concurrency Budgets
Every limit applies uniformly to all roles (no admin exemption):
| Limit | Environment Variable | Default |
|---|---|---|
| Pre-auth HTTP requests per client IP | (built-in) | 120 / min |
| Post-auth HTTP requests per credential | (built-in) | 240 / min |
| MCP tool calls per credential | COCKPIT_CONTEXT_MCP_TOOL_CALLS_PER_MINUTE |
120 / min |
query_dependency calls per credential |
COCKPIT_CONTEXT_MCP_QUERIES_PER_HOUR |
30 / hour |
query_dependency calls per user (all credentials) |
COCKPIT_CONTEXT_MCP_QUERIES_PER_USER_PER_HOUR |
120 / hour (0 = off) |
| Queued runs per user (web + MCP combined) | COCKPIT_CONTEXT_MAX_QUEUED_RUNS_PER_USER |
20 (0 = unlimited) |
| Concurrent main runs per user | COCKPIT_CONTEXT_MAX_CONCURRENT_RUNS_PER_USER |
3 |
| Concurrent runs globally | COCKPIT_CONTEXT_MAX_CONCURRENT_RUNS |
4 |
Concurrent get_query_result waits per user |
COCKPIT_CONTEXT_MAX_MCP_RESULT_WAITS_PER_USER |
10 |
Exceeding the per-user hourly cap returns QUERY_LIMIT with retry_after_seconds without consuming the credential’s own hourly budget. Exceeding queued runs returns BUSY. Reused queries still count against query rate budgets.
Live Dashboard Control & Cost Tracking
Every MCP investigation appears immediately in the owner’s web dashboard (Ongoing):
- Watch live: Stream tool calls, sub-helper activity, and turns over SSE (
conversations.watch). - Steer or stop: Send steering instructions mid-run (
conversations.steer) or stop an investigation (conversations.stop). A steered or stopped run is never cached for reuse. - Follow up or retry: Continue finished investigations with web follow-ups (web follow-ups stay in the conversation and do not notify the original MCP client), retry runs that ended without an answer, or pin up to 12 conversations to your home screen.
Query Cost Accounting (usage)
Every finished MCP result (completed, plus failed, stopped, or interrupted runs that incurred model calls) includes a usage object in both structuredContent and JSON text:
{
"query_id": "run_01j...",
"status": "completed",
"answer": "...",
"usage": {
"cost_usd_micros": 41830,
"priced": true,
"input_tokens": 61200,
"output_tokens": 3100,
"cached_input_tokens": 48000,
"model": "anthropic/claude-sonnet-4.5"
}
}
cost_usd_micros: Integer millionths of a US dollar (for example41830=$0.04183), summing the main run, any delegated helper runs (COCKPIT_CONTEXT_HELPER_MODEL), and any mid-run dashboard steering.- Unpriced calls: If any model call in the run lacked pricing from the provider,
pricedisfalseandcost_usd_microsisnull(never0). In the web dashboard, partially priced conversations display as a lower bound (e.g.,≥ $0.04, some calls unpriced) orUnknown. - Reused queries: A result with
reused: "answer"orreused: "running_query"reports zero new spend inusage(cost_usd_micros: 0,priced: true,model: null) and places the original run’s spend inoriginal_usagefor reference only. Harnesses tallying spend must count eachquery_idonce against the originating caller and never sumoriginal_usage. - Transient
usage: null: If usage could not be read when returning the answer, callget_query_resultwith thequery_id; treatnullas unknown, never0. - Operator cost auditing: Each
agent_rundatabase row storesgenerationIds(from OpenRouter’sx-generation-idheader) so operators can reconcile billed calls directly against OpenRouter’sGET /api/v1/generation?id=<id>endpoint.