A per-instance connection supervisor restarts the original server config
with exponential backoff when the transport closes, re-runs tool discovery
on success, and atomically replaces the previous generation. Default policy
retries for ~2.5 minutes (10 attempts, 500ms→30s doubling) before giving up
and unregistering the server's tools.
New config block reconnect { enabled, initialDelayMs, maxDelayMs, maxAttempts }
on both transports; misconfiguration fails plugin load. A connection that
survives past the stability window (maxDelayMs) resets the attempt budget,
so occasional crashes recover indefinitely while a crash loop still exhausts
the cap.
Integrates with the upstream failOnStartupError: the initial sync uses
registrationFailure:'throw' when that flag is set so a squatted namespace
still rejects activation.
Fixes #1746
77 lines
2.4 KiB
TypeScript
77 lines
2.4 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 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.' },
|
|
],
|
|
}))
|
|
|
|
server.registerTool('crash', {
|
|
title: 'Crash Tool',
|
|
description: 'Replies, then exits the server process (crash-recovery test).',
|
|
inputSchema: {},
|
|
}, async () => {
|
|
// Exit AFTER the response flushes so the caller observes a clean result
|
|
// followed by a transport close, like a real post-reply crash.
|
|
setTimeout(() => process.exit(7), 25)
|
|
return { content: [{ type: 'text', text: 'crashing' }] }
|
|
})
|
|
|
|
// Dotted name: legal in MCP, illegal in the DeepSeek function-name contract.
|
|
// Exercises the bridge's normalize-and-hash public-name path end to end.
|
|
server.registerTool('admin.reset', {
|
|
title: 'Admin Reset Tool',
|
|
description: 'Tool with a dotted name (normalization test).',
|
|
inputSchema: {},
|
|
}, async () => ({
|
|
content: [{ type: 'text', text: 'reset done' }],
|
|
}))
|
|
|
|
const transport = new StdioServerTransport()
|
|
await server.connect(transport)
|