Skip to content

Commit 4a14def

Browse files
committed
Use env var for scenario name instead of positional arg
Pass scenario name via MCP_CONFORMANCE_SCENARIO env var instead of as a positional argument. This is non-breaking for existing clients that just accept <server-url>. The env var approach is consistent with how context (including private keys for JWT auth) is already passed via MCP_CONFORMANCE_CONTEXT.
1 parent 336e13a commit 4a14def

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ npx @modelcontextprotocol/conformance client --command "<client-command>" --scen
6767
- `--timeout` - Timeout in milliseconds (default: 30000)
6868
- `--verbose` - Show verbose output
6969

70-
The framework appends `<scenario-name> <server-url>` as arguments to your command. Your client should accept these two positional arguments.
70+
The framework appends `<server-url>` as an argument to your command and sets the `MCP_CONFORMANCE_SCENARIO` environment variable to the scenario name. For scenarios that require additional context (e.g., client credentials), the `MCP_CONFORMANCE_CONTEXT` environment variable contains a JSON object with scenario-specific data.
7171

7272
### Server Testing
7373

examples/clients/typescript/everything-client.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
/**
44
* Everything client - a single conformance test client that handles all scenarios.
55
*
6-
* Usage: everything-client <scenario-name> <server-url>
6+
* Usage: everything-client <server-url>
7+
*
8+
* The scenario name is read from the MCP_CONFORMANCE_SCENARIO environment variable,
9+
* which is set by the conformance test runner.
710
*
811
* This client routes to the appropriate behavior based on the scenario name,
912
* consolidating all the individual test clients into one.
@@ -177,11 +180,16 @@ registerScenario('elicitation-defaults', runElicitationDefaultsClient);
177180
// ============================================================================
178181

179182
async function main(): Promise<void> {
180-
const scenarioName = process.argv[2];
181-
const serverUrl = process.argv[3];
183+
const scenarioName = process.env.MCP_CONFORMANCE_SCENARIO;
184+
const serverUrl = process.argv[2];
182185

183186
if (!scenarioName || !serverUrl) {
184-
console.error('Usage: everything-client <scenario-name> <server-url>');
187+
console.error(
188+
'Usage: MCP_CONFORMANCE_SCENARIO=<scenario> everything-client <server-url>'
189+
);
190+
console.error(
191+
'\nThe MCP_CONFORMANCE_SCENARIO env var is set automatically by the conformance runner.'
192+
);
185193
console.error('\nAvailable scenarios:');
186194
for (const name of Object.keys(scenarioHandlers).sort()) {
187195
console.error(` - ${name}`);

src/runner/client.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ async function executeClient(
2121
): Promise<ClientExecutionResult> {
2222
const commandParts = command.split(' ');
2323
const executable = commandParts[0];
24-
const args = [...commandParts.slice(1), scenarioName, serverUrl];
24+
const args = [...commandParts.slice(1), serverUrl];
2525

2626
let stdout = '';
2727
let stderr = '';
2828
let timedOut = false;
2929

30-
// Build environment with optional context
30+
// Build environment with scenario name and optional context
3131
const env = { ...process.env };
32+
env.MCP_CONFORMANCE_SCENARIO = scenarioName;
3233
if (context) {
3334
env.MCP_CONFORMANCE_CONTEXT = JSON.stringify(context);
3435
}
@@ -98,9 +99,7 @@ export async function runConformanceTest(
9899
console.error(`Starting scenario: ${scenarioName}`);
99100
const urls = await scenario.start();
100101

101-
console.error(
102-
`Executing client: ${clientCommand} ${scenarioName} ${urls.serverUrl}`
103-
);
102+
console.error(`Executing client: ${clientCommand} ${urls.serverUrl}`);
104103
if (urls.context) {
105104
console.error(`With context: ${JSON.stringify(urls.context)}`);
106105
}

0 commit comments

Comments
 (0)