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
22 changes: 22 additions & 0 deletions examples/servers/typescript/everything-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,28 @@ function createMcpServer() {
}
);

// Input validation tool (SEP-1303): the SDK validates arguments against
// this schema before the handler runs.
mcpServer.registerTool(
'test_input_validation',
{
description: 'Tests that schema-invalid arguments are rejected',
inputSchema: {
value: z
.number()
.int()
.min(1)
.max(10)
.describe('An integer from 1 to 10')
}
},
async (args: { value: number }) => {
return {
content: [{ type: 'text', text: `executed: ${args.value}` }]
};
}
);

// Image content tool
mcpServer.registerTool(
'test_image_content',
Expand Down
83 changes: 83 additions & 0 deletions examples/servers/typescript/no-input-validation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env node

/**
* Negative fixture for tools-call-input-validation (SEP-1303): publishes an
* inputSchema for test_input_validation but, like any handler on the
* low-level Server API, never checks tools/call arguments against it, so the
* tool runs on schema-invalid input and the check can be shown to emit
* FAILURE.
*/

import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
import {
CallToolRequestSchema,
ListToolsRequestSchema
} from '@modelcontextprotocol/sdk/types.js';
import express from 'express';

function createServer() {
const server = new Server(
{ name: 'no-input-validation', version: '1.0.0' },
{ capabilities: { tools: {} } }
);

server.setRequestHandler(ListToolsRequestSchema, async () => ({
tools: [
{
name: 'test_input_validation',
description: 'Publishes a schema but does not enforce it',
inputSchema: {
type: 'object',
properties: {
value: { type: 'integer', minimum: 1, maximum: 10 }
},
required: ['value']
}
}
]
}));

server.setRequestHandler(CallToolRequestSchema, async (request) => ({
content: [
{
type: 'text',
text: `executed: ${JSON.stringify(request.params.arguments?.value)}`
}
]
}));

return server;
}

const app = express();
app.use(express.json());

app.post('/mcp', async (req, res) => {
try {
const server = createServer();
const transport = new StreamableHTTPServerTransport({
sessionIdGenerator: undefined
});
await server.connect(transport);
await transport.handleRequest(req, res, req.body);
} catch (error) {
if (!res.headersSent) {
res.status(500).json({
jsonrpc: '2.0',
error: {
code: -32603,
message: `Internal error: ${error instanceof Error ? error.message : String(error)}`
},
id: null
});
}
}
});

const PORT = parseInt(process.env.PORT || '3010', 10);
app.listen(PORT, '127.0.0.1', () => {
console.log(
`No input validation negative test server running on http://localhost:${PORT}/mcp`
);
});
2 changes: 2 additions & 0 deletions src/scenarios/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ToolsCallInputValidationScenario } from './server/tools-input-validation';
import {
Scenario,
ClientScenario,
Expand Down Expand Up @@ -190,6 +191,7 @@ const allClientScenariosList: ClientScenario[] = [
new ToolsCallMultipleContentTypesScenario(),
new ToolsCallWithLoggingScenario(),
new ToolsCallErrorScenario(),
new ToolsCallInputValidationScenario(),
new ToolsCallWithProgressScenario(),
new ToolsCallSamplingScenario(),
new ToolsCallElicitationScenario(),
Expand Down
42 changes: 42 additions & 0 deletions src/scenarios/server/negative.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { DNSRebindingProtectionScenario } from './dns-rebinding';
import { ResourcesNotFoundErrorScenario } from './resources';
import { CachingScenario } from './caching';
import { ToolsListScenario } from './tools';
import { ToolsCallInputValidationScenario } from './tools-input-validation';
import {
JsonSchema2020_12Scenario,
sep2106KeywordCheckStatus
Expand Down Expand Up @@ -465,6 +466,47 @@ describe('Server scenario negative tests', () => {
}, 10000);
});

describe('tools-call-input-validation (SEP-1303)', () => {
let serverProcess: ChildProcess | null = null;
const PORT = 3010;

beforeAll(async () => {
serverProcess = await startServer(
path.join(
process.cwd(),
'examples/servers/typescript/no-input-validation.ts'
),
PORT
);
}, 35000);

afterAll(async () => {
await stopServer(serverProcess);
});

it('emits FAILURE for input-validation-rejected against a server that executes tools on schema-invalid arguments', async () => {
const scenario = new ToolsCallInputValidationScenario();
const checks = await scenario.run(
testContext(`http://localhost:${PORT}/mcp`, '2025-11-25')
);

expect(
checks.find((c) => c.id === 'tools-call-input-validation-valid')?.status
).toBe('SUCCESS');
const rejected = checks.find(
(c) => c.id === 'sep-1303-input-validation-rejected'
);
expect(rejected?.status).toBe('FAILURE');
expect(rejected?.errorMessage).toContain('wrong type');
expect(rejected?.errorMessage).toContain('missing required property');
expect(rejected?.errorMessage).toContain('out of range');
expect(
checks.find((c) => c.id === 'sep-1303-input-validation-tool-error')
?.status
).toBe('WARNING');
}, 15000);
});

describe('tools-name-format', () => {
let serverProcess: ChildProcess | null = null;
const PORT = 3009;
Expand Down
Loading