Skip to content

feat(api): let an MCP client choose tool sets, and reads only, by its URL - #3555

Merged
fforootd merged 5 commits into
mainfrom
claude/mcp-tool-sets
Dec 2, 2026
Merged

fforootd merged 5 commits into
mainfrom
claude/mcp-tool-sets

Conversation

@fforootd

@fforootd fforootd commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Context

The endpoint's tool list was at its limit: 141,563 of 142,000 bytes in 79 tools, and buildRelease was dropped for its size. The shape here was decided on 2026-12-02 after a check of current practice: clients that defer tool definitions (Claude, Cursor) no longer pay for a long list up front, clients that load everything limit the count of tools, and the closest comparable server lets the person narrow the list in the client's configuration. So every tool keeps its whole schema, and a person narrows by URL.

Summary

  • URL grammar.
    • /api/v1/mcp/x/{set,...} lists the named tool sets.
    • /readonly, after that or on its own, lists only the tools that read.
    • A set is a spec tag in snake_case: 19 sets, one tag per operation. all names every set.
    • A plain URL is unchanged: everything the credential's scopes allow.
  • Enforced at the call. A write on a read-only URL, or a tool outside the named sets, is refused before any request is made, with the URL to use instead. An unknown set gets a 404 that names the valid sets.
  • Not a boundary of the credential. A URL limits what that connection is offered and accepts. The same token is taken at the plain endpoint, so a read-only URL guarantees nothing about the credential; the scopes stay the boundary. ADR 092 §3 says so.
  • Instructions. The server's instructions say which sets this connection lists, which exist, and how to choose. They name each heavy tool the credential can call, with the URL that lists it.
  • buildRelease (37,150 bytes, over the 16,000 per-tool cap) is no longer dropped. It is in a set of its own, build_release, listed only where the URL names it.
  • OAuth. Every URL below the endpoint has protected-resource metadata whose resource is exactly that URL (RFC 9728 §3.3). The platform issuer reads such a URL as the endpoint at authorize, code exchange and refresh (ProtectedAPI.Narrowed), and only a path of lowercase letters, digits, underscores, commas and slashes below the endpoint is read that way. The token's audience and the API's audience check are unchanged. A query, fragment or dot segment stays invalid_target.
  • Budget. Three tests replace listBudget:
    • 16,000 bytes per tool;
    • 80,000 bytes for the list a default consent yields (every .read scope): 43 tools and 61,226 bytes today;
    • at most 100 tools on a plain URL: 79 today.
  • Contract. The set names are pinned by TestToolSetsAreTheSpecsTags: a renamed tag would break a configured URL.

Validation

Run by the session that wrote the change, in its cloud container:

  • go test ./internal/mcp/ ./internal/oauth/ ./internal/api/; go test -run MCP ./cmd/server/.
  • go test -tags sqlite_integration ./internal/api/integration_test/: 267 pass, including a narrowed URL against the real API (it lists the sets; a write on /readonly is refused and nothing is created).
  • go vet ./... and the repository's analyzers.
  • A local server with oauth.enabled, driven by the official MCP Go SDK client with Claude Code's client metadata document, on /api/v1/mcp/x/users,teams/readonly: the challenge and the metadata name that URL, the client asks resource=<that URL>, and the issuer accepts it and redirects to sign-in. Before this change it answered invalid_target.
  • The TypeScript SDK 1.32.2, read from source: it accepts a resource equal to the URL or a parent path, and asks for the metadata's resource.
  • Not run: a full browser sign-in on a narrowed URL, and the MCP Inspector. No end-user client has connected to a narrowed URL yet.
  • The full go test ./... fails only the three console-embed mux tests, because the Console is not built in that container.

Run again when opening this draft, on the four commits cherry-picked onto current main:

  • go vet ./internal/mcp/ ./internal/oauth/
  • go test ./internal/mcp/ ./internal/oauth/
  • go test -run MCP ./cmd/server/
  • go test -tags sqlite_integration ./internal/api/integration_test/ -run MCP
  • node scripts/check-pr-title.mjs --title "…"

Release notes / changeset

  • Changeset: .changeset/mcp-endpoint.md (pending, extended; @zitadel/server). A client can connect to a narrower list by URL, and buildRelease is listed where the URL names build_release.

Notes

  • Numbers for review. The three budget numbers are proposals; ADR 092 §3 gives how each was measured.
  • The ceiling after ADR 094's step 5. That step adds 6 tools to the catalog (85 with it alone, about 97 with the other open drafts that add tools): under the 100-tool ceiling by about three, so the ceiling binds at the next addition after it. The other 19 operations it opens to a person's token are existing tools.
  • Measured, not built.
    • outputSchema would add 374,041 bytes across 70 tools (listEvents and getEvent 47 KB each, from the event payload's oneOf), 2.6 times today's list. Not declared until event schemas can be summarized.
    • As search hits, the names and first sentences read well. getSchema ("Returns a schema by ID.") would search better saying "user schema", which is open question 11's ground.
  • For other open work that adds tools: a new tool must fit 16,000 bytes, keep the read-scope list under 80,000 bytes and the plain list at 100 tools at most. A new operation needs exactly one spec tag; a new tag is a new set, and TestToolSetsAreTheSpecsTags must be updated.
  • An earlier design on the writing session's branch (request bodies listed without their schema, read on demand) was taken back out before this draft; these four commits do not contain it.
  • Written in the session https://claude.ai/code/session_0137eGmRZfCYDgfwMBn4935W; the commits were cherry-picked onto main and the draft opened by the coordinating session below.

https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U


Generated by Claude Code

… URL

The MCP endpoint lists every tool its credential's scopes cover, which a
client that loads every tool carries in full and counts against a cap of
its own. A person now narrows the list by the URL they configure the client
with, which a client that can set a URL and nothing else can do too:

  /api/v1/mcp/x/{set,...}            the tool sets named
  /api/v1/mcp/readonly               every set, reads only
  /api/v1/mcp/x/{set,...}/readonly

A set is the operations of one of the spec's tags, in snake_case, or all of
them (all). A URL that names a set the endpoint lacks is refused with the
sets it has. What a URL does not list is not called: a write on a URL that
reads only, and a tool of a set the URL does not name, are refused before a
request is made, saying how the person lists it. The server's instructions
say which sets a connection lists and how to choose them.

A tool heavier than 16,000 bytes is no longer left out: it is in a set of
its own, named after it, listed only where the URL names it. That is
buildRelease (build_release) today.

A URL below the endpoint is a resource of its own: its challenge names its
metadata, served below the endpoint's, whose resource is that URL, as RFC
9728 §3.3 has a client check.

The budget becomes three checks: 16,000 bytes per tool, 80,000 bytes for
the list a default consent yields (every scope that reads), and at most 100
tools on a plain URL. The set names are contract, held by a test.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmRZfCYDgfwMBn4935W
(cherry picked from commit 1c7a6e9)
…lient asks a token for it

An MCP client connected to a URL that chooses tool sets, such as
/api/v1/mcp/x/users/readonly, names that URL as the resource it asks a
token for: the Go SDK takes the URL it connects to as the resource and
requires the endpoint's metadata to name it exactly (RFC 9728 §3.3), and
the TypeScript SDK asks for what the metadata names. The platform project's
issuer refused it as invalid_target.

ProtectedAPI.Narrowed names the identifiers whose URLs below them are the
same API: the MCP endpoint's. The issuer reads such a resource as the
endpoint at the authorization request, the code exchange and the refresh,
so the token carries the endpoint as its audience and the API takes it as
before. Only a path of lowercase letters, digits, underscores, commas and
slashes is below the endpoint: a query, a fragment or a dot segment is
still invalid_target, and no customer project's issuer narrows anything.

The URL narrows what a client is offered; the scopes a person consents to
remain what the token allows.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmRZfCYDgfwMBn4935W
(cherry picked from commit d97fad6)
…question 4

§3 says how a person narrows the tool list by the URL a client connects to
(the spec's tags as tool sets, and reads only, enforced at the call), that
a heavy tool is listed only by name, and that the list's budget is three
checks: 16,000 bytes per tool, 80,000 for the list a default consent
yields, and 100 tools on a plain URL. §8 says a URL below the endpoint has
metadata of its own, which the issuer reads as the endpoint. Open question
4 is answered, as Proposed, with the sources read on 2026-12-02, and the
bare-body design that was built and taken out joins the rejected
alternatives, with a smaller default list, a query or header form, and
search-and-execute tools.

The pending changeset for the endpoint says what a narrower URL lists.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmRZfCYDgfwMBn4935W
(cherry picked from commit fada043)
…RL that lists it

The server's instructions named the heavy tools' sets whatever the
credential, and only the URL grammar. They now name each heavy tool the
credential's scopes cover and the URL does not list, with the URL that
lists it beside what this one lists (/api/v1/mcp/x/all,build_release), so
an agent learns that buildRelease exists and how the person turns it on. A
URL that reads only names none, since it never lists a write.

ADR 092 §3 says plainly that a URL is no boundary of the credential, and
how each of the budget's numbers was measured, ADR 094 step 5 included.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmRZfCYDgfwMBn4935W
(cherry picked from commit 0903921)
@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 8:33am UTC

Request Review

@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

🦋 Changeset detected

Latest commit: 64f1d8e

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/cli Minor
@zitadel/testing Minor
@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
@zitadel/api Minor
@zitadel/components 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-qwik-router Minor
@zitadel/sdk-react Minor
@zitadel/sdk-solid Minor
@zitadel/sdk-solid-start Minor
@zitadel/sdk-svelte Minor
@zitadel/sdk-sveltekit Minor
@zitadel/sdk-tanstack-start Minor
@zitadel/sdk-vue Minor
@zitadel/cloud Patch
@zitadel/client-sdk-contract Patch
@zitadel/server-sdk-contract Patch

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

ADR 092 §3 and its answer to open question 4 said step 5 opens about 25
more operations and would pass the 100-tool ceiling. It makes six
operations tools that are none today (createProject, updateMyUser,
completeProjectClaim, lookupInvitation, acceptInvitation,
rejectInvitation), about 97 with the other sessions' additions: under 100,
so the ceiling binds at the next addition after it. The other operations
it opens to a person's token are tools already, and change only how many
a person is shown.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmRZfCYDgfwMBn4935W
(cherry picked from commit 435f0e8)
@fforootd
fforootd marked this pull request as ready for review December 2, 2026 14:08
Copilot AI balanced review requested due to automatic review settings December 2, 2026 14:08
@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-02T14:13:16.901777Z 64f1d8e Draft marked ready
ℹ️ 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.

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

Set deduplication allows unauthenticated callers to exhaust CPU through quadratic work, and read-only refusal hints can point to URLs that still exclude the requested tool.

2 open issues
What changed in this PR

Adds URL-selected tool sets and read-only connections to the API’s MCP endpoint, while keeping credential scopes as the authorization boundary.

Changes:

  • Filters tool lists and calls by URL, with explicit access to buildRelease.
  • Supports narrowed URLs in OAuth discovery, authorization, token exchange and refresh.
  • Updates contract documentation and tests for filtering, routing and tool budgets.
File Description
docs/​adrs/​092-mcp-server.md Documents URL selection and revised budgets.
apps/​api/​internal/​oauth/​token.go Normalizes narrowed resources during token requests.
apps/​api/​internal/​oauth/​token_test.go Tests narrowed-resource code exchange.
apps/​api/​internal/​oauth/​refresh_test.go Tests refresh with narrowed resources.
apps/​api/​internal/​oauth/​authorize.go Recognizes narrowed platform resources.
apps/​api/​internal/​oauth/​authorize_test.go Tests resource acceptance and rejection.
apps/​api/​internal/​mcp/​sets.go Implements URL selection and guidance.
apps/​api/​internal/​mcp/​sets_test.go Tests filtering, refusals and discovery.
apps/​api/​internal/​mcp/​handler.go Enforces selections and serves resource metadata.
apps/​api/​internal/​mcp/​handler_test.go Adds narrowed-connection test helpers.
apps/​api/​internal/​mcp/​catalog.go Reads operation tags for tool sets.
apps/​api/​internal/​mcp/​catalog_test.go Pins set names and revised budgets.
apps/​api/​internal/​api/​integration_test/​mcp_test.go Tests narrowed connections against the API.
apps/​api/​cmd/​server/​server.go Mounts narrowed endpoints and metadata routes.
apps/​api/​cmd/​server/​mux_test.go Tests endpoint routing and discovery.
.changeset/​mcp-endpoint.md Updates customer-facing release notes.

Review effort: Balanced

Comment on lines +100 to +112
for name := range strings.SplitSeq(names, ",") {
switch {
case known == nil && !setNameSyntax(name):
return selection{}, fmt.Errorf("the MCP endpoint has no tool set %q: a set's name is lowercase letters, digits and underscores",
printable(name))
case known != nil && name != allSets && !slices.Contains(known, name):
return selection{}, fmt.Errorf("the MCP endpoint has no tool set %q: its tool sets are %s, and %s for every one of them",
printable(name), strings.Join(known, ", "), allSets)
}
if !slices.Contains(chosen.sets, name) {
chosen.sets = append(chosen.sets, name)
}
}
Comment on lines +510 to +515
if chosen.readOnly && !named.op.readOnly {
return failure(map[string]any{
"message": named.op.id + " changes the project, and this connection reads only, so it was not sent",
"hint": "The person connects the client to the endpoint's URL without /" + readOnlySegment + " to let it write.",
})
}
@fforootd
fforootd added this pull request to the merge queue Dec 2, 2026
Merged via the queue into main with commit 0b3ea4e Dec 2, 2026
18 of 19 checks passed
@fforootd
fforootd deleted the claude/mcp-tool-sets branch December 2, 2026 14:32
@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
main replaced the one budget on the whole tool list with three checks
(#3555), so the raise this branch made to that budget goes. A person's
own reads fit them: 86 tools on a plain URL, and 50 tools, 66,412 bytes,
on the list a default consent yields. The tool-set tests expect the own
reads in the users set, and ADR 092's measured figures say so.

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
main replaced the one budget on the whole tool list with three checks
(#3555), so the raise this branch made to that budget goes. The tool
fits them: 80 tools on a plain URL, and the list a default consent
yields is unchanged in count.

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
…-api

main chose tool sets by URL (#3555): the catalog keeps this branch's asksWhereItCan beside main's tags, and the one budget on the tool list gives way to main's three checks.

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

This branch was successfully deployed

1 active deployment
Preview — 64f1d8ed 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