Skip to content

feat(client): support custom claims in PrivateKeyJwtProvider#1875

Open
JosephDoUrden wants to merge 1 commit intomodelcontextprotocol:mainfrom
JosephDoUrden:feat/private-key-jwt-custom-claims
Open

feat(client): support custom claims in PrivateKeyJwtProvider#1875
JosephDoUrden wants to merge 1 commit intomodelcontextprotocol:mainfrom
JosephDoUrden:feat/private-key-jwt-custom-claims

Conversation

@JosephDoUrden
Copy link
Copy Markdown

Summary

Expose the existing claims parameter from createPrivateKeyJwtAuth in the PrivateKeyJwtProviderOptions interface, allowing custom claims to be included in the JWT client assertion.

Closes #1477

Motivation

Enterprise deployments often need additional claims in the client assertion JWT (e.g., tenant_id, role) to scope the access token with finer granularity than scopes alone allow. Currently, users must either:

  • Use StaticPrivateKeyJwtProvider and manage JWT signing themselves (adding jose as a direct dependency and re-implementing audience discovery)
  • Build a custom addClientAuthentication function

Since createPrivateKeyJwtAuth already supports a claims parameter internally, this change simply threads it through PrivateKeyJwtProviderOptions — minimal surface area change with significant usability improvement.

Changes

  • packages/client/src/client/authExtensions.ts:
    • Added optional claims?: Record<string, unknown> to PrivateKeyJwtProviderOptions
    • Pass claims through to createPrivateKeyJwtAuth in the constructor
  • packages/client/test/client/authExtensions.test.ts:
    • Added test verifying custom claims appear in the signed JWT via createPrivateKeyJwtAuth
    • Added test verifying custom claims pass through PrivateKeyJwtProvider

Test plan

  • All 352 client tests pass (350 existing + 2 new)
  • Build passes (pnpm build:all)
  • Typecheck passes (pnpm typecheck:all)
  • Lint + Prettier pass (pnpm lint:all)
  • Lefthook pre-push hooks pass

AI Disclosure

AI assistance (Claude) was used for issue research. The implementation was written and reviewed by the author.

Expose the existing `claims` parameter from `createPrivateKeyJwtAuth` in
the `PrivateKeyJwtProviderOptions` interface, allowing custom claims to
be included in the JWT client assertion.

This enables enterprise scenarios where additional claims (e.g.,
tenant_id) help scope the access token with finer granularity than
scopes alone, without requiring clients to manage JWT signing directly.

Closes modelcontextprotocol#1477
@JosephDoUrden JosephDoUrden requested a review from a team as a code owner April 10, 2026 10:46
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 10, 2026

⚠️ No Changeset found

Latest commit: 2c37dfb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 10, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@1875

@modelcontextprotocol/server

npm i https://pkg.pr.new/@modelcontextprotocol/server@1875

@modelcontextprotocol/express

npm i https://pkg.pr.new/@modelcontextprotocol/express@1875

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/@modelcontextprotocol/fastify@1875

@modelcontextprotocol/hono

npm i https://pkg.pr.new/@modelcontextprotocol/hono@1875

@modelcontextprotocol/node

npm i https://pkg.pr.new/@modelcontextprotocol/node@1875

commit: 2c37dfb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support custom claims in PrivateKeyJwtProvider

1 participant