Prove the full MCP protocol flow works end-to-end against real servers: - Self-written fixture server: tool discovery, execution, error handling, image placeholder, toolPrefix, and clean disposal - @modelcontextprotocol/server-everything: echo, get-sum, get-tiny-image - @modelcontextprotocol/server-filesystem: write_file + read_file round-trip, list_directory with world-verification All 15 tests keyless and deterministic (no API key needed).
56 lines
1.6 KiB
TypeScript
56 lines
1.6 KiB
TypeScript
/**
|
|
* Minimal MCP server over stdio for e2e testing of the dsh-mcp-client plugin.
|
|
* Registers controlled tools with predictable behavior for asserting edge cases.
|
|
*
|
|
* Run: node --import tsx fixture-server.ts
|
|
*/
|
|
|
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
import { z } from 'zod'
|
|
|
|
const server = new McpServer(
|
|
{ name: 'fixture-server', version: '1.0.0' },
|
|
{ capabilities: { tools: { listChanged: true } } },
|
|
)
|
|
|
|
server.registerTool('add', {
|
|
title: 'Add Tool',
|
|
description: 'Adds two numbers.',
|
|
inputSchema: { a: z.number().describe('First number'), b: z.number().describe('Second number') },
|
|
}, async args => ({
|
|
content: [{ type: 'text', text: String(args.a + args.b) }],
|
|
}))
|
|
|
|
server.registerTool('greet', {
|
|
title: 'Greet Tool',
|
|
description: 'Greets a person by name.',
|
|
inputSchema: { name: z.string().describe('Name to greet') },
|
|
}, async args => ({
|
|
content: [{ type: 'text', text: `Hello, ${args.name}!` }],
|
|
}))
|
|
|
|
server.registerTool('fail', {
|
|
title: 'Fail Tool',
|
|
description: 'Always returns an error.',
|
|
inputSchema: {},
|
|
}, async () => ({
|
|
content: [{ type: 'text', text: 'Something went wrong' }],
|
|
isError: true,
|
|
}))
|
|
|
|
server.registerTool('image', {
|
|
title: 'Image Tool',
|
|
description: 'Returns an image content block.',
|
|
inputSchema: {},
|
|
}, async () => ({
|
|
content: [
|
|
{ type: 'text', text: 'Here is an image:' },
|
|
{ type: 'image', data: 'iVBORw0KGgo=', mimeType: 'image/png' },
|
|
{ type: 'text', text: 'End of image.' },
|
|
],
|
|
}))
|
|
|
|
const transport = new StdioServerTransport()
|
|
await server.connect(transport)
|