modelcontextprotocol / modelcontextprotocol/php-sdk
[Client] Implement client_credentials grant (client_secret_basic + private_key_jwt)
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 1.6k
- Forks
- 173
- Avg merge
- 2d 49m
- Merged PRs (30d)
- 23
Description
Context
For non-interactive / machine-to-machine MCP clients, the client_credentials grant (RFC 6749 §4.4) is used directly against token_endpoint. Two client authentication shapes are required by conformance:
- Basic:
Authorization: Basic base64(client_id:client_secret)+ bodygrant_type=client_credentials. - JWT assertion (private_key_jwt, RFC 7521/7523): body
client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer+client_assertion=<signed JWT>. JWT signed with the client's private key (ES256/RS256),iss+sub=client_id,aud=token_endpoint,jti=random,exp=now+60s.
Scope
Mcp\Client\Auth\Grant\ClientCredentialsGrantwith pluggable assertion signer.- JWT signing: prefer a thin built-in using
openssl_signto avoid heavy deps; if dep is preferred, chooselcobucci/jwt(modern, typed) overfirebase/php-jwt. - Configure via
Builder::setOAuthClient($id, $secret)orBuilder::setOAuthClientWithKey($id, $privateKeyPem, $algorithm).
Conformance scenarios unblocked
auth/client-credentials-basic, auth/client-credentials-jwt.
Dependencies
Blocked by: #318 (token_endpoint), #321 (auth methods).
Acceptance
- Unit tests for both shapes; JWT signing verified against a fixture public key.
- Decision on JWT dep documented in PR description.
cc @soyuka
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the blocked work in #318 for token_endpoint and #321 for auth methods, then inspect Mcp\Client\Auth\Grant\ClientCredentialsGrant and the Builder OAuth client configuration points named here. Run or add coverage for auth/client-credentials-basic and auth/client-credentials-jwt, including verification against the fixture public key. Done means both authentication shapes pass unit tests and the JWT dependency decision is documented in the PR description.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- api, authentication, security
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100