Repository navigation
Description
Context
Two places need the ProPR MCP from inside an agent container: the report step when the definition enables the propr_mcp capability (read-only context), and every acting step (issue 10), which acts on the report exclusively through existing MCP tools (create_task, create_todo, comment_on_pull_request, …). The MCP server authenticates OAuth bearer tokens bound to a user, a grant, scopes and repositories, and re-checks instance membership and GitHub repository access on every call (McpPolicy.authenticate). We reuse that entire authorization path by minting a delegated grant for the agent's owner that is:
- scoped to the definition's repositories only,
- scope-limited by phase: report →
read; action →read,plan,execute(nevermerge,deploy,manage,review), - short-lived (expires after 2 hours) and revoked as soon as the phase ends,
- labelled so it is visible on the Connected apps page (
/mcp/apps) as "ProPR Agent: " and its calls appear in the MCP access log.
The worker cannot import the API package, so issuance is an internal API endpoint authenticated with an HMAC over the run id signed with the existing SYSTEM_TASK_SECRET (same trust root as signed system tasks/reverts).
Requirements
packages/api/mcp/agentRunGrants.ts:AGENT_RUN_MCP_CLIENT_ID = 'propr-agent-runs'registered as an internal public client (no redirect URIs; cannot be used for interactive OAuth).issueAgentRunGrant({ ownerId, definitionName, runId, phase, repositories })→{ grantId, accessToken, expiresAt }built on the existingMcpOAuthProvider/McpStoregrant + access-token persistence (the same code path used after browser consent), withmembershipSource: 'agent_run'andresource = config.resource.revokeAgentRunGrant(grantId)using the existing grant revocation (the same as the Connected apps "Revoke" button).- Fails with
MCP_DISABLEDwhen MCP is not enabled, andGITHUB_AUTHORIZATION_REQUIREDwhen the owner has no stored GitHub user grant (githubUserGrantService.resolve) — the MCP principal needs one.
- Internal routes (registered in
server.tsbefore the session auth guard, like the desktop pairing exceptions, but protected by HMAC):POST /api/internal/agent-runs/:runId/mcp-grantsbody{ phase, ts, signature }→{ grantId, url, token, expiresAt }. Verifies signature (HMAC-SHA256(SYSTEM_TASK_SECRET, runId + ':' + phase + ':' + ts)),|now - ts| < 5 min, and that the run exists and is inrunning(report) oracting(action). Repositories and owner are read from the run snapshot — never from the request body.POST /api/internal/agent-runs/:runId/mcp-grants/revokewith the same signed body (POST so the HMAC body is carried uniformly).- Rate-limited with the existing pairing/discovery limiter.
- Worker client
src/jobs/agentRuns/mcpGrantClient.ts:requestAgentRunMcpGrant(runId, phase)/revokeAgentRunMcpGrant(runId, grantId)callingPROPR_INTERNAL_API_URL(defaulthttp://api:4000). The URL handed to the container isPROPR_AGENT_MCP_URL(default${PROPR_INTERNAL_API_URL}/api/mcp) because containers reach the API over the Docker network, not the public origin. - Executor integration (issue 7 + 10): request a grant when the policy needs MCP, pass it to
toolPolicyForCapabilities, and revoke infinally. - Tests:
packages/api/test/agentRunGrants.test.ts(signature, replay window, wrong state, scope/repository restriction of the resulting principal viaMcpPolicy.authenticate).
Implementation Specification
- The token is never stored in
agent_runs, never logged, and only passed as a container env var (issue 8). - Expiry is a backstop; revocation on phase end is the primary control. A daemon sweep (issue 12) also revokes grants of runs that reached a terminal state (crash recovery).
- Record
grant_idper phase in a new nullable column? Not required: store grant ids inmcp_recordsmetadata keyed by run id so the sweep can find them (kind: 'agent_run_grant', id: <runId>:<phase>).
Acceptance Criteria
- A forged or expired signature returns 401; a valid signature for a
completedrun returns 409. - The issued token authenticates on
/api/mcp, lists only the definition's repositories, andcreate_taskon a repository outside the scope is denied. - A report-phase token cannot call
create_task(requires execute). - After revoke, the token is rejected.
- The grant appears on
/mcp/appslabelled with the agent name, and calls appear in the MCP access log.
Created by ProPR AI Planner
Activity
propr-dev commentedon Oct 6, 2026
Suggested Implementation:
Implementation Approach
We reuse ProPR's MCP authorization end to end instead of inventing a second permission system for agents: the acting agent is "the owner, through a narrowly scoped, short-lived connected app". Every MCP call therefore gets the same scope checks, per-call repository re-authorization, instance membership checks, idempotent receipts and access logging as a human's chat client.
Why an internal HMAC endpoint: grant issuance needs the API's MCP store, encryption key and OAuth provider; the worker runs in a different process/image and must not hold the MCP encryption key.
SYSTEM_TASK_SECRETis already the shared trust root between API and worker for signed system tasks, so we reuse it rather than introducing a new secret.Alternatives rejected: (a) giving the acting container the owner's GitHub token and letting it call GitHub directly — bypasses ProPR's tools and receipts; (b) a long-lived per-definition token — larger blast radius, harder to revoke.
File:
packages/api/mcp/agentRunGrants.ts(new file)Why this file: Mints and revokes delegated grants on top of the existing OAuth grant store, so the MCP policy layer treats agent runs exactly like any other connected app.
Add
issueDelegatedGrantandrevokeGrantmethods toMcpOAuthProvider(packages/api/mcp/oauth.ts) by extracting the existing "persist grant + mint access token" and "revoke grant" code into these reusable methods (no behavior change for browser consent). The delegated grant has no refresh token.File:
packages/api/routes/agentRunInternalRoutes.ts(new file)Why this file: The only bridge from the worker to grant issuance, authenticated by HMAC and validated against the run's own snapshot.
File:
packages/api/server.tsWhy this file: Registers the internal routes ahead of the session guard (they use HMAC, not sessions), next to the other documented pre-auth exceptions.
(
getMcpGrantIssuer()is a small export frommcp/server.tsreturningoauthGrantIssuer(provider)oncemountMcphas initialized the provider, ornull.) Note the revoke route usesPOST .../revokeinstead ofDELETEso the HMAC body is carried uniformly.File:
src/jobs/agentRuns/mcpGrantClient.ts(new file)Why this file: Worker side of the bridge; used by both executors.
File:
src/jobs/processAgentRunJob.tsWhy this file: The report phase obtains MCP access only when the definition enables it.
File:
packages/api/test/agentRunGrants.test.ts(new file)Why this file: Covers the security properties: signature, freshness, state gating, least-privilege scopes.
Add an integration test in the same file using the in-memory MCP fixture from
mcpTaskSubmissions.test.ts: issue an action grant foracme/web, callcreate_taskonacme/other→REPOSITORY_FORBIDDEN; issue a report grant →create_taskfails withrequires execute.propr-dev commentedon Oct 6, 2026
🤖 AI processing has started for this issue using claude agent with claude-opus-5-5 model.
I'll analyze the problem and work on a solution. This may take a few minutes.
Processing Details:
claudeclaude-opus-5-52808/claude-opus-5-5-agents-v1-9-17-run-scoped-20261006-2058-twh2800-epic-agents-v1-y7tissue-2808-20261006-2058-claude-opus-5-5-twh🔍 Track Task Execution
Issue #2808 is implemented. Agent containers now get a short-lived Pr…
Issue #2808 is implemented. Agent containers now get a short-lived Pr…