Skip to content

Commit 5d68a29

Browse files
committed
Use MCP_CONFORMANCE_SCENARIO env var in auth-test client
Update auth-test.ts and test helper to use the new MCP_CONFORMANCE_SCENARIO env var instead of putting scenario in the context object. This aligns with the everything-client pattern from PR #54.
1 parent feb8870 commit 5d68a29

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

examples/clients/typescript/auth-test.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ const CIMD_CLIENT_METADATA_URL =
2727
* See: https://github.com/modelcontextprotocol/conformance/issues/51
2828
*/
2929
interface ConformanceContext {
30-
scenario: string;
3130
client_id?: string;
3231
// For JWT auth (private_key_jwt)
3332
private_key_pem?: string;
@@ -44,7 +43,8 @@ function getContext(
4443
}
4544
const contextJson = process.env.MCP_CONFORMANCE_CONTEXT;
4645
if (!contextJson) {
47-
throw new Error('MCP_CONFORMANCE_CONTEXT environment variable is required');
46+
// Context is optional - only needed for client credentials scenarios
47+
return {};
4848
}
4949
return JSON.parse(contextJson);
5050
}
@@ -53,10 +53,9 @@ function getContext(
5353
* Create an OAuth provider based on the scenario type.
5454
*/
5555
function createProviderForScenario(
56+
scenario: string,
5657
context: ConformanceContext
5758
): OAuthClientProvider | undefined {
58-
const { scenario } = context;
59-
6059
// Client credentials scenarios use the dedicated provider classes
6160
if (scenario === 'auth/client-credentials-jwt') {
6261
if (
@@ -101,7 +100,15 @@ export async function runClient(
101100
serverUrl: string,
102101
passedContext?: Record<string, unknown>
103102
): Promise<void> {
103+
const scenario = process.env.MCP_CONFORMANCE_SCENARIO;
104+
if (!scenario) {
105+
throw new Error(
106+
'MCP_CONFORMANCE_SCENARIO environment variable is required'
107+
);
108+
}
109+
104110
const context = getContext(passedContext);
111+
logger.debug('Scenario:', scenario);
105112
logger.debug('Parsed context:', JSON.stringify(context, null, 2));
106113

107114
const client = new Client(
@@ -110,7 +117,10 @@ export async function runClient(
110117
);
111118

112119
// Check if this is a client credentials scenario
113-
const clientCredentialsProvider = createProviderForScenario(context);
120+
const clientCredentialsProvider = createProviderForScenario(
121+
scenario,
122+
context
123+
);
114124

115125
let transport: StreamableHTTPClientTransport;
116126

src/scenarios/client/auth/test_helpers/testClient.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,12 @@ export async function runClientAgainstScenario(
125125
const urls = await scenario.start();
126126
const serverUrl = urls.serverUrl;
127127

128-
// Build context with scenario name
129-
const context = {
130-
...urls.context,
131-
scenario: scenarioName
132-
};
128+
// Context contains scenario-specific data (credentials, etc.)
129+
const context = urls.context;
130+
131+
// Set scenario env var for inline runners
132+
const previousScenario = process.env.MCP_CONFORMANCE_SCENARIO;
133+
process.env.MCP_CONFORMANCE_SCENARIO = scenarioName;
133134

134135
try {
135136
// Run the client
@@ -191,6 +192,12 @@ export async function runClientAgainstScenario(
191192
}
192193
}
193194
} finally {
195+
// Restore previous env var
196+
if (previousScenario !== undefined) {
197+
process.env.MCP_CONFORMANCE_SCENARIO = previousScenario;
198+
} else {
199+
delete process.env.MCP_CONFORMANCE_SCENARIO;
200+
}
194201
// Stop the scenario server
195202
await scenario.stop();
196203
}

0 commit comments

Comments
 (0)