Repository navigation
feat(api): let an MCP tool return only the fields an agent names - #3540
Conversation
A tool whose operation answers a resource, or a page of them, takes `fields`: dot-paths, as the CLI's `--fields` takes them. The endpoint asks the API as always and cuts the answer, so each resource keeps those paths and a page keeps next_page_token. A path that matched nothing in a non-empty answer is named beside the result. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmRRBTn7WmrnkFEFMDy
The OAuth endpoints authenticate no bearer, so the events they write took an empty client_id from the request and named the client only in the payload. A filter on client_id then missed the tokens a client was issued. EmitSpec takes the client, and auth.request.created, auth.request.exchange.failed and the auth.token.issued and auth.token.revoked of a code or refresh grant set it. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
The MCP endpoint shows only the first sentence of an operation's description, and agents guessed wrong from it: search without project_id read only a person's newest projects, listProjectMembers left out platform operators, and listEvents said nothing about how to read one sign-in. An operation may now say the rest in x-zitadel-agent-note, which the tool's description adds; the list's budget rises to 132,000 bytes for it. The server's instructions no longer say that a project_id left out is always the credential's project without saying what that is for a person. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
🦋 Changeset detectedLatest commit: 192a2dd The changes in this PR will be included in the next version bump. This PR includes changesets to release 27 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
🟡 Changes recommended
Active issues cause empty 202 responses to lose their acknowledgement and status, while explicit fields: null bypasses validation and returns the full response.
2 open issues
What changed in this PR
Adds optional field selection to MCP tools, reducing agent context usage without changing API requests or authorization.
Changes:
- Detects resource and page responses and exposes a
fieldsargument. - Filters successful responses and reports unmatched paths.
- Adds tests, documents the contract, and adjusts the tool-list size budget.
| File | Description |
|---|---|
docs/adrs/092-mcp-server.md |
Documents field selection and the revised size budget. |
apps/api/internal/mcp/handler.go |
Integrates field selection into tool calls. |
apps/api/internal/mcp/handler_test.go |
Tests filtering, validation, and unchanged refusals. |
apps/api/internal/mcp/fields.go |
Implements path validation and response filtering. |
apps/api/internal/mcp/catalog.go |
Detects response shapes and declares fields. |
apps/api/internal/mcp/catalog_test.go |
Tests catalog behavior and updates the size budget. |
.changeset/mcp-endpoint.md |
Adds field selection to release notes. |
Review effort: Balanced
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmRRBTn7WmrnkFEFMDy
…ential The MCP endpoint offered no operation whose answer holds a credential, so an agent could not register an application, invite a person or start a project's claim. Zitadel is to be driven by agents, with the caller's credential deciding what it may do, so publishApplication, createInvitation and createProjectClaim become tools. x-zitadel-returns-secret now words the tool: its description says the answer holds a credential, to pass to the user and write nowhere else. The three such operations an application calls while a user signs in stay out by their plane. The list's budget rises to 142,000 bytes for the three tools. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
…ng changesets The MCP endpoint and refresh tokens have not been released, so what this branch changes about them belongs in their pending changesets (.changeset/README.md). The authorization and token endpoints have been, so the client on their events keeps a patch changeset of its own. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
…into claude/mcp-secret-answers # Conflicts: # .changeset/mcp-endpoint.md
Prepared to stack #3540 on #3542 once the user agrees. listBudget stays 142,000: 79 tools weigh 141,620 bytes, 69 of them with fields. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmRRBTn7WmrnkFEFMDy
… a credential Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmRRBTn7WmrnkFEFMDy
… three tools A review found the ADR's claim wrong that a client secret a tool returns is ended by rotating it: only a retry with the request's Idempotency-Key replaces a secret, and a tool sends no header. The ADR now says what ends each credential, the operator's reference no longer says such an operation is never a tool, and the amendment no longer names a guard that only #3543 adds. createInvitation and createProjectClaim are now called through their tools against the real API. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
…l/nextgen into mcp-tool-fields
…rop the credential hint - A path takes at most 256 bytes; paths are split and ordered once per call, not once per resource. - The question before a destructive call no longer shows fields, which only cuts the answer and could push project_id out of the 600-byte cut. - The instructions no longer suggest leaving out a credential a tool answers with: a show-once secret cut that way is lost. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmRRBTn7WmrnkFEFMDy
…in full A review found two places where the MCP tools still misled. Every tool described project_id as defaulting to the credential's project, also on search, which declares its own optional one and reads a person's projects when it is left out: an operation's own optional project_id now carries that operation's words. And the descriptions of listEvents and listProjectMembers did not say what their agent notes say, though the OpenAPI rules promise they do: both now say it. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
…into claude/mcp-secret-answers # Conflicts: # docs/adrs/092-mcp-server.md
…l/nextgen into mcp-tool-fields # Conflicts: # docs/adrs/092-mcp-server.md
…s are kept The note on a tool that answers with a credential told an agent to pass it to the user and write it nowhere else. A coding agent's proper place for a client secret is the store the user keeps secrets in, such as the app's env file, so the note now allows that. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
A credential publishApplication, createInvitation or createProjectClaim answers with is shown once; a path that cut it out would lose it. Their tools no longer declare fields and refuse it as an unknown argument. The list is 156 bytes lighter: 79 tools weigh 141,497 bytes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmRRBTn7WmrnkFEFMDy
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmRRBTn7WmrnkFEFMDy
… question The endpoint asks the person at the client before a destructive call and refuses the call from a client that cannot ask. cancelInvitation is what ends an invitation's link, which createInvitation now hands to an agent, so a client on an older protocol revision could not end one that leaked. An operation may now say x-zitadel-unasked: the endpoint sends its call as it is. Its tool keeps the protocol's destructive hint, so a client can ask its own user, and no longer says the user is asked. cancelInvitation is the one operation marked, and a test names the marked ones, since each is a decision. The CLI is unchanged and still asks. ADR 092 also records that a client secret is to be replaced through an operation of its own, in a later change. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
Picks up #3545, which the base branch did not hold. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
#3537 landed on main as one commit. This branch already holds its changes through the old base branch, so the merge takes nothing from it: it only records main as an ancestor, so that the pull request shows its own change. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
…n is promised The ADR index and ADR 092's summary still said every destructive call is confirmed. The OpenAPI rules read as if any removal that ends access should be marked x-zitadel-unasked; they now say only cancelInvitation is, by ADR 092 §6, and name the test that holds it. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
Takes x-zitadel-unasked and operation.asks() beside the fields argument: the catalog keeps both new fields, the server's instructions keep both sentences, and the changeset says both. 79 tools weigh 141,563 bytes, so ADR 092 §3's combined figure stands. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
Picks up what landed on main in between: #3538, #3541, #3539 and #3543. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
#3542 landed on main as one commit. This branch already holds its changes through the old base branch, so the merge takes nothing from it: it only records main as an ancestor, so that the pull request shows its own change. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
Picks up #3546 and #3547, which landed after #3542. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U

Context
fieldschange.docs/adrs/092-mcp-server.md). An agent investigating events on the hosted cloud filled its context with whole event envelopes when it needed two fields per event.Summary
next_page_tokenand one list), take an optionalfieldsargument: dot-paths, as the CLI's--fieldstakes them (apps/cli/src/cli/core/columns.ts). 66 of the 79 tools take it. The 10 that answer no JSON body do not, and neither do the three whose answer holds a credential shown once (publishApplication,createInvitation,createProjectClaim, markedx-zitadel-returns-secret): a path that cut the credential out would lose it, so they refusefieldsas an unknown argument.internal/mcp/fields.go). Each resource keeps the named paths, nested as they were; a page keepsnext_page_token. Values are kept as the API wrote them (numbers as written, no HTML escaping). A refusal and an empty answer (createGrant's 202) come back as withoutfields. The API contract and its authorization do not change.occured_at) does not read as data the project lacks. The answer is not judged against the response schema, whose open objects (an event'spayload) cannot say which paths exist. Afieldsvalue that is not a list of dot-paths (includingnull) is refused before any request; an operation that answers no resource refusesfieldsas any unknown argument, before anyone is asked to confirm.fields(checked against the bundled spec);TestNoOperationTakesAParameterCalledFieldsandinputSchemakeep it that way.{"type":"array","items":{"type":"string"}}) on each tool and explained once in the server'sinstructions.fields, which only cuts the answer (a long path could otherwise pushproject_idout of the question's 600-byte cut).Validation
go test -race -count=1 ./internal/mcp/(new tests: catalog shape detection, page and resource cuts, unmatched-path note, empty page, refusal and empty answer untouched, malformed,nulland over-longfields, the destructive-call question withoutfields,fieldson an operation without a resource)main(192a2dd):go vetandgo test -count=1for./internal/mcp/,./internal/api/and./cmd/server/, the wholego test -tags sqlite_integration ./internal/api/integration_test/,turbo run generatefor@zitadel/serverand@zitadel/api(no drift),pnpm run check-openapi-rules,scripts/go-lint.mjsgo vet ./...,go test -count=1 ./internal/mcp/,go test -count=1 -tags sqlite_integration ./internal/api/integration_test/ -run TestMCPmain:go test -count=1 ./...inapps/api(after building the console, whichcmd/serverembeds),gofmt -l,go run ./tools/analyzers/cmd/analyzers ./internal/mcp/...node scripts/check-pr-title.mjs,node scripts/check-changesets-status.mjs --pendingRelease notes / changeset
.changeset/mcp-endpoint.md(edited, still unreleased) — adds that a tool returning a resource or a page takesfields, beside fix(api): name the client on OAuth events, and tell agents what a tool's first sentence leaves out #3537's and feat(api): offer an MCP client the operations that answer with a credential #3542's sentences. Lists@zitadel/server.Notes
listBudgetstays at feat(api): offer an MCP client the operations that answer with a credential #3542's 142,000. Measured on the head merged withmain: 79 tools weigh 141,563 bytes;fieldsis about 3,400 of that. ADR 092 §3 gives the combined figures.operationanddocumentOperationstructs incatalog.go(theanswersfield andResponsesbesideunaskedandAgentNote), the server'sinstructionsinhandler.go(both sentences kept), ADR 092 §3 and the changeset.cancelInvitation, which feat(api): offer an MCP client the operations that answer with a credential #3542 sends without the endpoint's question, takes nofields: it answers with no content.gofmtreportsinternal/flowengine/sso_test.go, which is onmainand untouched here.invoked_byevents PR (feat(api): record on a request's event that the MCP endpoint invoked it #3541), which stays againstmain.https://claude.ai/code/session_0137eGmRRBTn7WmrnkFEFMDy
Generated by Claude Code