Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions examples/servers/typescript/sep-2322-mrtr-broken-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,68 @@ handlers['tools/call'] = (params) => {
};
}

case 'test_input_required_result_request_state': {
if (!inputResponses) {
return {
resultType: 'input_required',
inputRequests: {
confirm: {
method: 'elicitation/create',
params: {
message: 'Confirm?',
requestedSchema: {
type: 'object',
properties: { ok: { type: 'boolean' } },
required: ['ok']
}
}
}
},
requestState: 'request-state-negative-fixture'
};
}
if (
params.requestState !== 'request-state-negative-fixture' ||
!inputResponses['confirm']
) {
throw {
code: -32602,
message: 'Expected echoed state and confirm response'
};
}
const mode = process.env.MRTR_REQUEST_STATE_MODE || 'missing-marker';
if (mode === 'jsonrpc-error') {
throw { code: -32602, message: 'State rejected' };
}
if (mode === 'input-required') {
return { resultType: 'input_required', requestState: 'still-pending' };
}
const isError =
mode === 'tool-error' || mode === 'tool-error-with-marker';
const marker =
mode === 'valid' ||
mode === 'valid-second-text' ||
mode === 'tool-error-with-marker';
return {
resultType: 'complete',
isError,
content:
mode === 'empty-content'
? []
: [
...(mode === 'valid-second-text'
? [{ type: 'text', text: 'Context' }]
: []),
{
type: 'text',
text: marker
? 'state-ok: requestState validated'
: 'State rejected'
}
]
};
}

case 'test_input_required_result_capabilities': {
// BUG 4: Conformant on its face — `requestState` satisfies "at least one
// of inputRequests or requestState" — but it names no input request, so
Expand Down
22 changes: 22 additions & 0 deletions src/scenarios/server/input-required-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,28 @@ Implement a tool named \`test_input_required_result_request_state\` (no argument
r2Errors.push(
'Expected complete result after retry with requestState'
);
} else {
if (r2Result.isError === true) {
r2Errors.push(
'Tool result reported isError: true after retry with requestState'
);
}
const content = r2Result.content;
const hasStateMarker =
Array.isArray(content) &&
content.some(
(block) =>
typeof block === 'object' &&
block !== null &&
block.type === 'text' &&
typeof block.text === 'string' &&
block.text.includes('state-ok')
);
if (!hasStateMarker) {
r2Errors.push(
'Expected text content containing the fixture marker "state-ok"'
);
}
}

checks.push({
Expand Down
63 changes: 60 additions & 3 deletions src/scenarios/server/negative-mrtr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
InputRequiredResultResultTypeScenario,
InputRequiredResultUnsupportedMethodsScenario,
InputRequiredResultTamperedStateScenario,
InputRequiredResultCapabilityCheckScenario
InputRequiredResultCapabilityCheckScenario,
InputRequiredResultRequestStateScenario
} from './input-required-result';
import {
formatWireViolation,
Expand Down Expand Up @@ -47,11 +48,15 @@ function getFreePort(): Promise<number> {
});
}

function startServer(scriptPath: string, port: number): Promise<ChildProcess> {
function startServer(
scriptPath: string,
port: number,
extraEnv: NodeJS.ProcessEnv = {}
): Promise<ChildProcess> {
return new Promise((resolve, reject) => {
const isWindows = process.platform === 'win32';
const proc = spawn('npx', ['tsx', scriptPath], {
env: { ...process.env, PORT: port.toString() },
env: { ...process.env, ...extraEnv, PORT: port.toString() },
stdio: ['ignore', 'pipe', 'pipe'],
shell: isWindows
});
Expand Down Expand Up @@ -158,3 +163,55 @@ describe('SEP-2322 MRTR negative tests', () => {
expect(capabilityCheck?.details?.untestable).toBe(true);
}, 10000);
});

// Issue #505: completion type alone does not establish fixture success.
describe('SEP-2322 request-state completion semantics', () => {
it.each([
['valid', 'SUCCESS'],
['valid-second-text', 'SUCCESS'],
['missing-marker', 'FAILURE'],
['empty-content', 'FAILURE'],
['tool-error', 'FAILURE'],
['tool-error-with-marker', 'FAILURE'],
['jsonrpc-error', 'FAILURE'],
['input-required', 'FAILURE']
])(
'request-state %s emits %s',
async (mode, expected) => {
const port = await getFreePort();
let proc: ChildProcess | null = null;
try {
proc = await startServer(
path.join(
process.cwd(),
'examples/servers/typescript/sep-2322-mrtr-broken-server.ts'
),
port,
{ MRTR_REQUEST_STATE_MODE: mode }
);
const checks = await new InputRequiredResultRequestStateScenario().run(
testContext(`http://localhost:${port}/mcp`)
);
// Prove the second check was reached with a valid round-1 prerequisite.
expect(
checks.find((c) => c.id === 'sep-2322-request-state-incomplete')
?.status
).toBe('SUCCESS');
const complete = checks.filter(
(c) => c.id === 'sep-2322-request-state-complete'
);
expect(complete).toHaveLength(1);
expect(complete[0].status).toBe(expected);
if (mode.startsWith('tool-error')) {
expect(complete[0].errorMessage).toContain('isError');
}
if (mode === 'missing-marker' || mode === 'empty-content') {
expect(complete[0].errorMessage).toContain('state-ok');
}
} finally {
await stopServer(proc);
}
},
20000
);
});