-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathserver.ts
More file actions
57 lines (47 loc) · 1.74 KB
/
server.ts
File metadata and controls
57 lines (47 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env node
import { createRequire } from 'node:module';
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { MCP_SYSTEM_PROMPT } from './generated/mcp-prompt.js';
import { SessionManager } from './session-manager.js';
import { registerAllTools } from './tools/index.js';
const require = createRequire(import.meta.url);
const { version } = require('../package.json');
// Validate MCP_PRESET at startup so misconfiguration fails fast instead of
// silently falling back to 'legacy'. Tool registration is wired to legacy via
// the static MCP_TOOL_CATALOG + dispatchIntentTool imports in tools/intent.ts;
// the resolved id is not plumbed further yet. When a non-legacy preset lands,
// pass the id into registerAllTools() so it can route through the registry.
const PRESETS_SUPPORTED = new Set(['legacy']);
const requestedPreset = process.env.MCP_PRESET ?? 'legacy';
if (!PRESETS_SUPPORTED.has(requestedPreset)) {
console.error(`SuperDoc MCP: unknown preset "${requestedPreset}". Supported: ${[...PRESETS_SUPPORTED].join(', ')}.`);
process.exit(2);
}
const server = new McpServer(
{
name: 'superdoc',
version,
},
{
instructions: MCP_SYSTEM_PROMPT,
},
);
const sessions = new SessionManager();
registerAllTools(server, sessions);
const transport = new StdioServerTransport();
async function main(): Promise<void> {
await server.connect(transport);
}
main().catch((err) => {
console.error('SuperDoc MCP server failed to start:', err);
process.exit(1);
});
process.on('SIGINT', async () => {
await sessions.closeAll();
process.exit(0);
});
process.on('SIGTERM', async () => {
await sessions.closeAll();
process.exit(0);
});