Background
The MCP specification 2025-11-25 adheres to the Authorization Code Grant in OAuth 2.1. Therefore, conformance tests for authorization servers must verify whether the authorization server correctly implements the Authorization Code Grant.
First Step
As a first step, this issue focuses on implementing positive test cases for the Authorization Code Grant.
Specification References
Key Requirements from Specification
Authorization Response
| Keyword |
Statement |
| MUST |
The URI in the authorization response MUST match the redirect_uri parameter in the authorization request |
| MUST |
The code parameter MUST be present in the authorization response query parameters |
| MUST |
The code parameter MUST have a value |
| MUST |
The state parameter MUST match the state parameter in the authorization request query parameters if the state parameter is present in the authorization request query parameters |
| MUST |
The iss parameter MUST match the issuer claim of authorization server metadata if the iss parameter is present in the authorization response query parameters |
| MUST |
The code, state and iss parameters MUST NOT appear more than once |
| MUST |
The code_challenge parameter MUST NOT be present in the authorization response query parameters |
| MUST |
The error parameter MUST NOT be present in the authorization response query parameters |
Token Response
| Keyword |
Statement |
| MUST |
HTTP response status code of token response MUST be 200 OK |
| MUST |
Content-Type header of token response MUST be application/json |
| MUST |
Cache-Control header of token response MUST be no-store |
| MUST |
Token response MUST return a JSON object including access_token and token_type |
Approach
Authorization Code Grant tests for the authorization response output an authorization request URL to the console and start callback server. Testers access the output URL in their browser and complete the authentication process. Then, callback server receives a authorization response and validate it. Authorization Code Grant tests for the token response are direct HTTP probes. These tests send a POST request to the token endpoint and validate the response.
These require:
- A tester set an authorization server to a client
- An
authorization CLI command that accepts --url <authorization-server-issuer-url> --client-id <client-id> --secret <client-secret> --port <callback server port> (e.g., --url https://auth.example.com --client-id test-client --secret MlAbxvNDZNnsZ67Ie6KENtzpA5mTh3ZK --port 3000)
- A new runner (
runner/authorization-code-grant.ts) for executing these scenarios
- The scenario creates an authorization request, starts callback server
- A tester sends the authorization request in their browser and completes the authentication process
- Callback server receives an authorization response and the scenario validates the authorization response
- The scenario sends a token request with
client_secret_port, and validates the token response
Suggested Checks
Check: authorization-response
Spec: "The response is a URL."
Receive an authorization response from a tester → validate:
- URL matches the
redirect_uri parameter
- The
code parameter is present
- The
code parameter has a value
- The
state parameter in the authorization response query parameters matches the state parameter in the authorization request query parameters
- The
iss parameter matches the issuer claim of authorization server metadata if present
- The
code_challenge parameter is not present
- The
error parameter is not present
Check: token-response
Spec: "The response is a JSON object... The authorization server MUST return HTTP 200 with Content-Type application/json."
Send POST request to the token endpoint → validate:
- HTTP 200 status code
Content-Type: application/json
Cache-Control: no-store
- Body is valid JSON containing
access_token, token_type
Scenarios to Cover
Positive Tests for Authorization Response
- URL matches the
redirect_uri parameter
- The
code parameter is present
- The
state parameter matches the state parameter in the authorization response query parameters
- The
iss parameter matches the issuer claim of authorization server metadata if present
code_challenge and error parameters are not present
Negative Tests for Authorization Response
- An authorization server returns an error to tester's browser → callback server timeout (5min) → FAILURE
- URL is incorrect → FAILURE
code is not present → FAILURE
state and iss are incorrect → FAILURE
code, state and iss parameters appear more than once → FAILURE
code_challenge or error parameters are present → FAILURE
Positive Tests for Token Response
- Token endpoint returns HTTP 200 with correct
Content-Type
- Cache-Control header is set to
no-store
- Response body contains all required fields (
access_token, token_type)
Negative Tests for Token Response
- Endpoint returns non-200 status code → FAILURE
- Endpoint returns non-JSON content type → FAILURE
- Response headers are not set correctly → FAILURE
- Response body missing required fields → FAILURE
Implementation Notes
New Files
src/scenarios/authorization-server/authorization-code-grant.ts — Scenario implementation
src/scenarios/authorization-server/authorization-code-grant.test.ts — Unit tests
src/scenarios/client/auth/helpers/createCallbackServer.ts — Callback server implementation
Modified Files
src/runner/authorization-server.ts — Add metadata response body and secret to arguments
src/scenarios/authorization-server/authorization-server-metadata.ts — Add metadata response body and secret to arguments
src/scenarios/authorization-server/authorization-server-metadata.test.ts — Add metadata response body and secret to arguments
src/types.ts — Modify arguments
src/schemas.ts — Add clientId, secret, port command option
src/scenarios/index.ts — Register the new scenario
src/index.ts — Add clientId, secret, port command option and metadata response body to arguments
Patterns to Follow
- Validation for authorization response should fail fast: authorization code check
- Validation for token response should fail fast: status code, parse JSON, no body
To do
- Automation of launching the tester's browser and sending authorization requests
- Documentation of options for running MCP authorization server Conformance Tests
- Documentation of the settings that should be pre-registered in the MCP authorization server
Background
The MCP specification 2025-11-25 adheres to the Authorization Code Grant in OAuth 2.1. Therefore, conformance tests for authorization servers must verify whether the authorization server correctly implements the Authorization Code Grant.
First Step
As a first step, this issue focuses on implementing positive test cases for the Authorization Code Grant.
Specification References
Key Requirements from Specification
Authorization Response
redirect_uriparameter in the authorization requestcodeparameter MUST be present in the authorization response query parameterscodeparameter MUST have a valuestateparameter MUST match the state parameter in the authorization request query parameters if the state parameter is present in the authorization request query parametersissparameter MUST match the issuer claim of authorization server metadata if the iss parameter is present in the authorization response query parameterscode,stateandissparameters MUST NOT appear more than oncecode_challengeparameter MUST NOT be present in the authorization response query parameterserrorparameter MUST NOT be present in the authorization response query parametersToken Response
application/jsonno-storeaccess_tokenandtoken_typeApproach
Authorization Code Grant tests for the authorization response output an authorization request URL to the console and start callback server. Testers access the output URL in their browser and complete the authentication process. Then, callback server receives a authorization response and validate it. Authorization Code Grant tests for the token response are direct HTTP probes. These tests send a POST request to the token endpoint and validate the response.
These require:
authorizationCLI command that accepts--url <authorization-server-issuer-url> --client-id <client-id> --secret <client-secret> --port <callback server port>(e.g.,--url https://auth.example.com --client-id test-client --secret MlAbxvNDZNnsZ67Ie6KENtzpA5mTh3ZK --port 3000)runner/authorization-code-grant.ts) for executing these scenariosclient_secret_port, and validates the token responseSuggested Checks
Check:
authorization-responseSpec: "The response is a URL."
Receive an authorization response from a tester → validate:
redirect_uriparametercodeparameter is presentcodeparameter has a valuestateparameter in the authorization response query parameters matches thestateparameter in the authorization request query parametersissparameter matches the issuer claim of authorization server metadata if presentcode_challengeparameter is not presenterrorparameter is not presentCheck:
token-responseSpec: "The response is a JSON object... The authorization server MUST return HTTP 200 with Content-Type application/json."
Send POST request to the token endpoint → validate:
Content-Type: application/jsonCache-Control: no-storeaccess_token,token_typeScenarios to Cover
Positive Tests for Authorization Response
redirect_uriparametercodeparameter is presentstateparameter matches thestateparameter in the authorization response query parametersissparameter matches the issuer claim of authorization server metadata if presentcode_challengeanderrorparameters are not presentNegative Tests for Authorization Response
codeis not present → FAILUREstateandissare incorrect → FAILUREcode,stateandissparameters appear more than once → FAILUREcode_challengeorerrorparameters are present → FAILUREPositive Tests for Token Response
Content-Typeno-storeaccess_token,token_type)Negative Tests for Token Response
Implementation Notes
New Files
src/scenarios/authorization-server/authorization-code-grant.ts— Scenario implementationsrc/scenarios/authorization-server/authorization-code-grant.test.ts— Unit testssrc/scenarios/client/auth/helpers/createCallbackServer.ts— Callback server implementationModified Files
src/runner/authorization-server.ts— Add metadata response body and secret to argumentssrc/scenarios/authorization-server/authorization-server-metadata.ts— Add metadata response body and secret to argumentssrc/scenarios/authorization-server/authorization-server-metadata.test.ts— Add metadata response body and secret to argumentssrc/types.ts— Modify argumentssrc/schemas.ts— AddclientId,secret,portcommand optionsrc/scenarios/index.ts— Register the new scenariosrc/index.ts— AddclientId,secret,portcommand option and metadata response body to argumentsPatterns to Follow
To do