Skip to content

fix(api): name the client on OAuth events, and tell agents what a tool's first sentence leaves out - #3537

Merged
fforootd merged 4 commits into
mainfrom
claude/festive-hamilton-y0f0dx
Dec 2, 2026
Merged

fforootd merged 4 commits into
mainfrom
claude/festive-hamilton-y0f0dx

Conversation

@fforootd

@fforootd fforootd commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Context

Summary

The client on the events the OAuth endpoints write (first commit)

  • 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. Filtering GET /events by client_id found every call Claude made but none of the tokens it was issued.
  • audit.EmitSpec takes a ClientID, which overrides the request's. It is set on:
    • auth.request.created: the client the authorization request names;
    • auth.request.exchange.failed: the client that presented the code;
    • auth.token.issued and auth.token.revoked of a code or refresh grant: the grant's client.
  • The payloads keep their client_id, so no event schema changes. The events catalog says which client each names.

What a tool's first sentence leaves out (second commit)

  • The MCP endpoint shows an agent only the first sentence of an operation's description (ADR 092 §3). Claude guessed wrong from that:
    • search without project_id reads only the 10 newest projects a person can act on. The admin lives in the platform project, which isn't among them, so the search found nothing.
    • listProjectMembers reads owning teams and grants. Platform operators hold neither, so the platform project's list was empty, with no word why.
    • listEvents didn't say which of a sign-in's events means what, or that only request.api carries the caller's IP.
  • An operation may now add x-zitadel-agent-note: one or two sentences the tool's description adds after the method and path. These three operations have one. A test holds each note under 400 bytes, on an offered operation, ending a sentence.
  • Budget: the tool list goes from 129,436 to 130,195 bytes, so the test's budget rises from 130,000 to 132,000 (ADR 092 §3: growth is a decision). Whole descriptions would have added about 40,000 bytes. Using the first paragraph would add almost nothing, because most first paragraphs are a single sentence.
  • project_id on a tool: every tool described it as defaulting to the credential's project, also on search, which declares its own optional one. An operation's own optional project_id now carries that operation's words; the default is said where the endpoint fills it in and on the document's shared optional one.
  • The descriptions say the notes too: listEvents and listProjectMembers now say in their descriptions what their notes say, as the OpenAPI rules promise.
  • Instructions: the server's instructions said a project_id left out "is that credential's project". For a person's token that is their home project, which holds their account and not necessarily their work. They now say so.
  • Docs: ADR 092 and the OpenAPI AGENTS.md describe the note.

Validation

  • Go tests for internal/audit, internal/service, internal/mcp and cmd/cloud-launcher pass.
    • The new client_id assertions in auth_request_test.go and refresh_grant_test.go fail (42 failed assertions) with the service change stashed.
    • The new MCP tests are TestToolDescriptionCarriesTheAgentNote and TestAgentNotesStayShort.
  • go test -tags sqlite_integration ./internal/api/integration_test/ -run 'OAuth|Code|Event|Refresh|MCP' passes.
  • turbo run generate --filter=@zitadel/server and --filter=@zitadel/api: only the bundled spec changed.
  • pnpm run check-openapi-rules passes.
  • turbo run lint --filter=@zitadel/server --continue: 14 of 15 tasks pass.
    • format fails on internal/flowengine/sso_test.go, a file this PR doesn't touch. The container's gofmt is older than the toolchain; $(go env GOROOT)/bin/gofmt -l is clean.
    • go vet on the changed packages and scripts/go-lint.mjs pass.
  • node scripts/check-pr-title.mjs passes.
  • Not run: the Postgres and Spanner lanes. Nothing in this PR touches storage.

Release notes / changeset

  • Changeset: .changeset/oauth-events-client.md (@zitadel/server, patch). The events the released authorization and token endpoints write name their client in client_id.
  • The unreleased parts edit their pending changesets, as .changeset/README.md asks:
    • .changeset/oauth-refresh-tokens.md: the refresh grant's events name its client.
    • .changeset/mcp-endpoint.md: a tool's description adds a note where the first sentence would mislead.

Notes

https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U


Generated by Claude Code

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
Copilot AI balanced review requested due to automatic review settings December 2, 2026 00:37
@vercel

vercel Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cloud Ready Ready Preview Dec 2, 2026 3:35am UTC

Request Review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-12-02T00:47:17.065629Z 081d881 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

🦋 Changeset detected

Latest commit: e95767c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 27 packages
Name Type
@zitadel/server Minor
@zitadel/api Minor
@zitadel/components Minor
@zitadel/cli Minor
@zitadel/config Minor
@zitadel/sdk-angular Minor
@zitadel/sdk-core Minor
@zitadel/sdk-next Minor
@zitadel/sdk-nuxt Minor
@zitadel/sdk-qwik Minor
@zitadel/sdk-react Minor
@zitadel/sdk-solid Minor
@zitadel/sdk-svelte Minor
@zitadel/sdk-tanstack-start Minor
@zitadel/sdk-vue Minor
@zitadel/testing Minor
@zitadel/cloud Patch
@zitadel/client-sdk-contract Patch
@zitadel/sdk-qwik-router Minor
@zitadel/sdk-solid-start Minor
@zitadel/sdk-sveltekit Minor
@zitadel/server-sdk-contract Patch
@zitadel/server-darwin-arm64 Minor
@zitadel/server-darwin-x64 Minor
@zitadel/server-linux-arm64 Minor
@zitadel/server-linux-x64 Minor
@zitadel/server-win32-x64 Minor

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new patch changeset should be folded into the existing unreleased feature changesets, retaining their higher version bumps as required by the repository guidelines.

1 open issue
What changed in this PR

This PR adds OAuth client attribution to audit events and clarifies MCP tool guidance for agents using the API.

Changes:

  • Populate OAuth events’ client_id, with regression assertions.
  • Add concise agent notes to three tools and clarify default project selection.
  • Update documentation, the tool-list budget, and release notes.
File Description
docs/​design/​api/​events-catalog.md Documents OAuth client attribution.
docs/​adrs/​092-mcp-server.md Records agent notes and budget changes.
apps/​api/​internal/​service/​session.go Attributes issued tokens to clients.
apps/​api/​internal/​service/​refresh_grant.go Attributes refresh-grant events to clients.
apps/​api/​internal/​service/​refresh_grant_test.go Checks refresh-grant client attribution.
apps/​api/​internal/​service/​auth_request.go Attributes authorization-request events to clients.
apps/​api/​internal/​service/​auth_request_test.go Checks authorization-event client attribution.
apps/​api/​internal/​mcp/​handler.go Appends notes and clarifies project defaults.
apps/​api/​internal/​mcp/​catalog.go Reads agent notes from OpenAPI.
apps/​api/​internal/​mcp/​catalog_test.go Checks notes and adjusts list budget.
apps/​api/​internal/​audit/​emit.go Supports explicit client attribution.
apps/​api/​internal/​audit/​emit_test.go Checks client override and fallback.
apps/​api/​api/​openapi/​endpoints/​search/​methods.yaml Explains search scope and limits.
apps/​api/​api/​openapi/​endpoints/​projects/​by_id/​members/​methods.yaml Explains platform-operator omission.
apps/​api/​api/​openapi/​endpoints/​events/​methods.yaml Adds sign-in investigation guidance.
apps/​api/​api/​openapi/​bundled/​openapi.json Includes generated agent notes.
apps/​api/​api/​openapi/​AGENTS.md Defines agent-note authoring guidance.
.changeset/​oauth-events-client-and-agent-notes.md Adds server release notes.

Review effort: Balanced

…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
…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
@fforootd
fforootd added this pull request to the merge queue Dec 2, 2026
Merged via the queue into main with commit 37af320 Dec 2, 2026
19 checks passed
@fforootd
fforootd deleted the claude/festive-hamilton-y0f0dx branch December 2, 2026 05:28
@github-project-automation github-project-automation Bot moved this from Inbox to Done in Engineering Kanban Dec 2, 2026
fforootd pushed a commit that referenced this pull request Dec 2, 2026
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
fforootd pushed a commit that referenced this pull request Dec 2, 2026
#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
fforootd pushed a commit that referenced this pull request Dec 2, 2026
Picks up #3537, which landed on main first.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U

This branch was successfully deployed

1 active deployment
Preview — e95767c9 Deployed Dec 2, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants