Skip to content

Commit 23c133a

Browse files
fix(mcp): update package configuration and enhance server functionality (#2985)
* fix(mcp): update package configuration and enhance server functionality - Added Node.js engine requirement to package.json, specifying a minimum version of 20. - Replaced the usage of `getMcpPrompt` with a direct import of `MCP_SYSTEM_PROMPT` in server.ts for improved prompt management. - Refactored `registerAllTools` and `registerIntentTools` functions to remove unnecessary async/await, enhancing performance. - Introduced new test suite for MCP dist bundle to validate server functionality and tool interactions. - Generated new catalog and prompt files to support the updated toolset and ensure proper integration.
1 parent a494a3e commit 23c133a

12 files changed

Lines changed: 4497 additions & 202 deletions

File tree

apps/mcp/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"name": "@superdoc-dev/mcp",
33
"version": "0.2.0",
44
"type": "module",
5+
"engines": {
6+
"node": ">=20"
7+
},
58
"bin": {
69
"superdoc-mcp": "./dist/index.js"
710
},
@@ -15,12 +18,11 @@
1518
"typecheck": "tsc --noEmit"
1619
},
1720
"dependencies": {
18-
"@superdoc-dev/sdk": "workspace:*",
19-
"@superdoc/document-api": "workspace:*",
2021
"@modelcontextprotocol/sdk": "^1.26.0",
2122
"zod": "^4.3.6"
2223
},
2324
"devDependencies": {
25+
"@superdoc/document-api": "workspace:*",
2426
"@superdoc/super-editor": "workspace:*",
2527
"superdoc": "workspace:*",
2628
"@types/bun": "catalog:",
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { beforeAll, describe, expect, it } from 'bun:test';
2+
import { execFile } from 'node:child_process';
3+
import { resolve } from 'node:path';
4+
import { promisify } from 'node:util';
5+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
6+
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
7+
8+
const execFileAsync = promisify(execFile);
9+
10+
const MCP_ROOT = resolve(import.meta.dir, '../..');
11+
const BLANK_DOCX = resolve(import.meta.dir, '../../../../shared/common/data/blank.docx');
12+
const DIST_ENTRY = resolve(MCP_ROOT, 'dist/index.js');
13+
14+
function textContent(result: Awaited<ReturnType<Client['callTool']>>): string {
15+
const content = 'content' in result ? result.content : [];
16+
const first = (content as Array<{ type: string; text?: string }>)[0];
17+
return first?.text ?? '';
18+
}
19+
20+
function parseContent(result: Awaited<ReturnType<Client['callTool']>>): unknown {
21+
return JSON.parse(textContent(result));
22+
}
23+
24+
describe('MCP dist bundle', () => {
25+
beforeAll(async () => {
26+
await execFileAsync('bun', ['build', 'src/index.ts', '--outdir', 'dist', '--target', 'node', '--format', 'esm'], {
27+
cwd: MCP_ROOT,
28+
});
29+
});
30+
31+
it('starts the bundled Node server and runs open/read/close over stdio', async () => {
32+
const transport = new StdioClientTransport({
33+
command: 'node',
34+
args: [DIST_ENTRY],
35+
stderr: 'pipe',
36+
});
37+
const client = new Client({ name: 'dist-bundle-test-client', version: '1.0.0' });
38+
39+
await client.connect(transport);
40+
try {
41+
const { tools } = await client.listTools();
42+
expect(tools.map((tool) => tool.name)).toContain('superdoc_open');
43+
expect(tools.map((tool) => tool.name)).toContain('superdoc_get_content');
44+
45+
const openResult = await client.callTool({ name: 'superdoc_open', arguments: { path: BLANK_DOCX } });
46+
expect(openResult).not.toHaveProperty('isError');
47+
const opened = parseContent(openResult) as { session_id: string };
48+
expect(opened.session_id).toBeString();
49+
50+
const infoResult = await client.callTool({
51+
name: 'superdoc_get_content',
52+
arguments: { session_id: opened.session_id, action: 'info' },
53+
});
54+
expect(infoResult).not.toHaveProperty('isError');
55+
expect(textContent(infoResult)).toBeTruthy();
56+
57+
const closeResult = await client.callTool({
58+
name: 'superdoc_close',
59+
arguments: { session_id: opened.session_id },
60+
});
61+
expect(parseContent(closeResult)).toEqual({ closed: true });
62+
} finally {
63+
await transport.close();
64+
}
65+
});
66+
});

0 commit comments

Comments
 (0)