@vyriy/create 0.8.8 → 0.8.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +125 -68
- package/README.md +2 -0
- package/package.json +13 -3
- package/plan/plan.d.ts +1 -1
- package/preset/index.d.ts +5 -0
- package/preset/index.js +6 -0
- package/preset/mcp.d.ts +2 -0
- package/preset/mcp.js +531 -0
- package/preset/ssg.js +202 -369
- package/preset/types.d.ts +1 -1
package/preset/mcp.js
ADDED
|
@@ -0,0 +1,531 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, resolve } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import packageJson from '../package.json' with { type: 'json' };
|
|
5
|
+
import { baseToolingFiles } from './tooling.js';
|
|
6
|
+
const presetDir = dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const agentsPath = [
|
|
8
|
+
resolve(presetDir, '../../../AGENTS.md'),
|
|
9
|
+
resolve(presetDir, '../../../../AGENTS.md'),
|
|
10
|
+
].find(existsSync) ?? '';
|
|
11
|
+
const agentsContent = agentsPath ? readFileSync(agentsPath, 'utf8') : '';
|
|
12
|
+
export const mcp = ({ name, description }) => ({
|
|
13
|
+
'package.json': JSON.stringify({
|
|
14
|
+
name,
|
|
15
|
+
version: '0.0.0',
|
|
16
|
+
description,
|
|
17
|
+
private: true,
|
|
18
|
+
type: 'module',
|
|
19
|
+
agents: './AGENTS.md',
|
|
20
|
+
packageManager: packageJson.packageManager,
|
|
21
|
+
engines: {
|
|
22
|
+
node: packageJson.engines.node,
|
|
23
|
+
},
|
|
24
|
+
workspaces: [
|
|
25
|
+
'workspaces/*',
|
|
26
|
+
],
|
|
27
|
+
scripts: {
|
|
28
|
+
storybook: 'cross-env STORYBOOK_DISABLE_TELEMETRY=1 storybook dev -p 6006 --disable-telemetry',
|
|
29
|
+
check: 'run-s lint build test',
|
|
30
|
+
fix: "run-s 'fix:*'",
|
|
31
|
+
start: "run-p 'start:*'",
|
|
32
|
+
lint: "run-s 'lint:*'",
|
|
33
|
+
build: "run-s 'build:*'",
|
|
34
|
+
test: "run-s 'test:*'",
|
|
35
|
+
'fix:prettier': 'prettier . --write',
|
|
36
|
+
'fix:eslint': 'eslint . --fix',
|
|
37
|
+
'start:mcp': 'sh workspaces/mcp/bin/start.sh',
|
|
38
|
+
'lint:ts': 'tsc',
|
|
39
|
+
'lint:prettier': 'prettier . --check',
|
|
40
|
+
'lint:eslint': 'eslint .',
|
|
41
|
+
'build:mcp': 'sh workspaces/mcp/bin/build.sh',
|
|
42
|
+
'build:storybook': 'cross-env STORYBOOK_DISABLE_TELEMETRY=1 storybook build --quiet --disable-telemetry',
|
|
43
|
+
'test:jest': 'jest --coverage=false',
|
|
44
|
+
prebuild: 'rimraf dist',
|
|
45
|
+
postinstall: 'husky',
|
|
46
|
+
},
|
|
47
|
+
dependencies: {
|
|
48
|
+
'@modelcontextprotocol/sdk': '^1.29.0',
|
|
49
|
+
'@vyriy/typescript-config': `^${packageJson.version}`,
|
|
50
|
+
typescript: packageJson.peerDependencies.typescript,
|
|
51
|
+
'@vyriy/prettier-config': `^${packageJson.version}`,
|
|
52
|
+
prettier: packageJson.peerDependencies.prettier,
|
|
53
|
+
'@vyriy/eslint-config': `^${packageJson.version}`,
|
|
54
|
+
eslint: packageJson.peerDependencies.eslint,
|
|
55
|
+
'@vyriy/jest-config': `^${packageJson.version}`,
|
|
56
|
+
jest: packageJson.peerDependencies.jest,
|
|
57
|
+
'@vyriy/storybook-config': `^${packageJson.version}`,
|
|
58
|
+
storybook: packageJson.peerDependencies.storybook,
|
|
59
|
+
'@vyriy/path': `^${packageJson.version}`,
|
|
60
|
+
husky: packageJson.peerDependencies.husky,
|
|
61
|
+
'npm-run-all2': packageJson.peerDependencies['npm-run-all2'],
|
|
62
|
+
'cross-env': packageJson.peerDependencies['cross-env'],
|
|
63
|
+
rimraf: packageJson.peerDependencies.rimraf,
|
|
64
|
+
'@vyriy/webpack-config': `^${packageJson.version}`,
|
|
65
|
+
tsx: packageJson.peerDependencies.tsx,
|
|
66
|
+
webpack: packageJson.peerDependencies.webpack,
|
|
67
|
+
'webpack-cli': packageJson.peerDependencies['webpack-cli'],
|
|
68
|
+
'@vyriy/handler': `^${packageJson.version}`,
|
|
69
|
+
'@vyriy/router': `^${packageJson.version}`,
|
|
70
|
+
'@vyriy/server': `^${packageJson.version}`,
|
|
71
|
+
zod: '^4.4.3',
|
|
72
|
+
},
|
|
73
|
+
}, null, 2) + '\n',
|
|
74
|
+
'README.md': `# MCP
|
|
75
|
+
|
|
76
|
+
Minimal Streamable HTTP MCP server generated by the Vyriy MCP preset.
|
|
77
|
+
|
|
78
|
+
The project contains one runtime workspace:
|
|
79
|
+
|
|
80
|
+
- \`workspaces/mcp\` - MCP server exposed over \`/mcp\` with one \`hello_world\` tool.
|
|
81
|
+
|
|
82
|
+
## Requirements
|
|
83
|
+
|
|
84
|
+
- Node.js \`>=24.0.0\`
|
|
85
|
+
- Yarn \`4.17.0\`
|
|
86
|
+
|
|
87
|
+
## Install
|
|
88
|
+
|
|
89
|
+
\`\`\`bash
|
|
90
|
+
yarn install
|
|
91
|
+
\`\`\`
|
|
92
|
+
|
|
93
|
+
## Run
|
|
94
|
+
|
|
95
|
+
\`\`\`bash
|
|
96
|
+
yarn start:mcp
|
|
97
|
+
\`\`\`
|
|
98
|
+
|
|
99
|
+
The default MCP endpoint is:
|
|
100
|
+
|
|
101
|
+
\`\`\`txt
|
|
102
|
+
http://localhost:3000/mcp
|
|
103
|
+
\`\`\`
|
|
104
|
+
|
|
105
|
+
The healthcheck endpoint is:
|
|
106
|
+
|
|
107
|
+
\`\`\`txt
|
|
108
|
+
http://localhost:3000/healthcheck
|
|
109
|
+
\`\`\`
|
|
110
|
+
|
|
111
|
+
Override the bind address or port when needed:
|
|
112
|
+
|
|
113
|
+
\`\`\`bash
|
|
114
|
+
HOST=0.0.0.0 PORT=3003 yarn start:mcp
|
|
115
|
+
\`\`\`
|
|
116
|
+
|
|
117
|
+
## Call The Tool
|
|
118
|
+
|
|
119
|
+
\`\`\`bash
|
|
120
|
+
curl -s http://localhost:3000/mcp \\
|
|
121
|
+
-H 'content-type: application/json' \\
|
|
122
|
+
-H 'accept: application/json, text/event-stream' \\
|
|
123
|
+
-d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"hello_world","arguments":{"name":"Vyriy"}}}'
|
|
124
|
+
\`\`\`
|
|
125
|
+
|
|
126
|
+
The tool returns a text response:
|
|
127
|
+
|
|
128
|
+
\`\`\`txt
|
|
129
|
+
Hello, Vyriy!
|
|
130
|
+
\`\`\`
|
|
131
|
+
|
|
132
|
+
## Build
|
|
133
|
+
|
|
134
|
+
\`\`\`bash
|
|
135
|
+
yarn build:mcp
|
|
136
|
+
\`\`\`
|
|
137
|
+
|
|
138
|
+
The build writes the production bundle and package metadata to \`dist\`.
|
|
139
|
+
|
|
140
|
+
## Validate
|
|
141
|
+
|
|
142
|
+
\`\`\`bash
|
|
143
|
+
yarn lint
|
|
144
|
+
yarn test
|
|
145
|
+
yarn build
|
|
146
|
+
\`\`\`
|
|
147
|
+
`,
|
|
148
|
+
'doc.mdx': `import { Meta, Markdown } from '@storybook/addon-docs/blocks';
|
|
149
|
+
import ReadMe from './README.md?raw';
|
|
150
|
+
|
|
151
|
+
<Meta title="MCP" />
|
|
152
|
+
|
|
153
|
+
<Markdown>{ReadMe}</Markdown>
|
|
154
|
+
`,
|
|
155
|
+
'AGENTS.md': agentsContent,
|
|
156
|
+
'.editorconfig': `# https://editorconfig.org
|
|
157
|
+
root = true
|
|
158
|
+
|
|
159
|
+
[*]
|
|
160
|
+
charset = utf-8
|
|
161
|
+
end_of_line = lf
|
|
162
|
+
insert_final_newline = true
|
|
163
|
+
trim_trailing_whitespace = true
|
|
164
|
+
|
|
165
|
+
indent_style = space
|
|
166
|
+
indent_size = 2
|
|
167
|
+
|
|
168
|
+
max_line_length = 100
|
|
169
|
+
|
|
170
|
+
[*.md]
|
|
171
|
+
trim_trailing_whitespace = false
|
|
172
|
+
max_line_length = off
|
|
173
|
+
|
|
174
|
+
[*.{yml,yaml}]
|
|
175
|
+
indent_size = 2
|
|
176
|
+
|
|
177
|
+
[*.json]
|
|
178
|
+
indent_size = 2
|
|
179
|
+
|
|
180
|
+
[*.{ts,tsx,js,jsx}]
|
|
181
|
+
indent_size = 2
|
|
182
|
+
|
|
183
|
+
[*.sh]
|
|
184
|
+
indent_size = 2
|
|
185
|
+
`,
|
|
186
|
+
'.gitignore': `.yarn/*
|
|
187
|
+
!.yarn/cache
|
|
188
|
+
!.yarn/patches
|
|
189
|
+
!.yarn/plugins
|
|
190
|
+
!.yarn/releases
|
|
191
|
+
!.yarn/sdks
|
|
192
|
+
!.yarn/versions
|
|
193
|
+
|
|
194
|
+
.DS_Store
|
|
195
|
+
.idea
|
|
196
|
+
node_modules
|
|
197
|
+
coverage
|
|
198
|
+
dist
|
|
199
|
+
storybook-static
|
|
200
|
+
*storybook.log
|
|
201
|
+
consumer
|
|
202
|
+
|
|
203
|
+
.claude
|
|
204
|
+
.codex
|
|
205
|
+
.agents
|
|
206
|
+
|
|
207
|
+
!/**/.gitkeep
|
|
208
|
+
`,
|
|
209
|
+
'.npmrc': 'engine-strict=true\n',
|
|
210
|
+
'.nvmrc': 'lts/krypton\n',
|
|
211
|
+
'.yarnrc.yml': 'nodeLinker: node-modules\nnpmMinimalAgeGate: 0\n',
|
|
212
|
+
'.husky/commit-msg': '#!/bin/sh\n',
|
|
213
|
+
'.husky/post-checkout': '#!/bin/sh\n\nyarn\n',
|
|
214
|
+
'.husky/post-merge': '#!/bin/sh\n\nyarn\n',
|
|
215
|
+
'.husky/pre-commit': '#!/bin/sh\n\nyarn check\n',
|
|
216
|
+
'.husky/pre-push': '#!/bin/sh\n\nyarn check\n',
|
|
217
|
+
'yarn.lock': '',
|
|
218
|
+
...baseToolingFiles,
|
|
219
|
+
'.prettierignore': 'node_modules\ndist\ncoverage\nstorybook-static\nconsumer\n',
|
|
220
|
+
'workspaces/mcp/bin/build.sh': `#!/usr/bin/env sh
|
|
221
|
+
|
|
222
|
+
set -e
|
|
223
|
+
|
|
224
|
+
scriptdir="$PWD/workspaces/mcp"
|
|
225
|
+
|
|
226
|
+
NODE_ENV=production npx webpack --config "$scriptdir/webpack.config.ts"
|
|
227
|
+
|
|
228
|
+
cp "$scriptdir/package.json" dist/package.json
|
|
229
|
+
npm pkg delete "type" --prefix dist
|
|
230
|
+
npm pkg delete "private" --prefix dist
|
|
231
|
+
npm install --prefix dist
|
|
232
|
+
rm dist/package-lock.json
|
|
233
|
+
`,
|
|
234
|
+
'workspaces/mcp/bin/start.sh': `#!/usr/bin/env sh
|
|
235
|
+
|
|
236
|
+
set -e
|
|
237
|
+
|
|
238
|
+
: "\${LOG_LEVEL:=info}"
|
|
239
|
+
: "\${HOST:=0.0.0.0}"
|
|
240
|
+
: "\${PORT:=3000}"
|
|
241
|
+
|
|
242
|
+
printf 'MCP endpoint: http://%s:%s/mcp\\n' "$HOST" "$PORT" >&2
|
|
243
|
+
|
|
244
|
+
exec env NODE_ENV=production LOG_LEVEL="$LOG_LEVEL" HOST="$HOST" PORT="$PORT" node --import tsx "$PWD/workspaces/mcp/index.ts"
|
|
245
|
+
`,
|
|
246
|
+
'workspaces/mcp/doc.mdx': `import { Meta, Markdown } from '@storybook/addon-docs/blocks';
|
|
247
|
+
import ReadMe from './README.md?raw';
|
|
248
|
+
|
|
249
|
+
<Meta title="Workspaces/MCP" />
|
|
250
|
+
|
|
251
|
+
<Markdown>{ReadMe}</Markdown>
|
|
252
|
+
`,
|
|
253
|
+
'workspaces/mcp/README.md': `# @w/mcp
|
|
254
|
+
|
|
255
|
+
Streamable HTTP MCP server workspace.
|
|
256
|
+
|
|
257
|
+
The workspace exposes one default tool:
|
|
258
|
+
|
|
259
|
+
- \`hello_world\` - returns a greeting for the provided \`name\`.
|
|
260
|
+
|
|
261
|
+
## Run
|
|
262
|
+
|
|
263
|
+
\`\`\`bash
|
|
264
|
+
yarn start:mcp
|
|
265
|
+
\`\`\`
|
|
266
|
+
|
|
267
|
+
## Build
|
|
268
|
+
|
|
269
|
+
\`\`\`bash
|
|
270
|
+
yarn build:mcp
|
|
271
|
+
\`\`\`
|
|
272
|
+
|
|
273
|
+
## Test
|
|
274
|
+
|
|
275
|
+
\`\`\`bash
|
|
276
|
+
yarn jest workspaces/mcp --runInBand --coverage=false
|
|
277
|
+
\`\`\`
|
|
278
|
+
`,
|
|
279
|
+
'workspaces/mcp/webpack.config.ts': `import { path } from '@vyriy/path';
|
|
280
|
+
import { ssr, external } from '@vyriy/webpack-config';
|
|
281
|
+
|
|
282
|
+
export default ssr(
|
|
283
|
+
'@w/mcp',
|
|
284
|
+
{
|
|
285
|
+
path: path('dist'),
|
|
286
|
+
filename: 'index.js',
|
|
287
|
+
library: { type: 'commonjs2' },
|
|
288
|
+
},
|
|
289
|
+
(config) => ({
|
|
290
|
+
...config,
|
|
291
|
+
externals: [external({ allowlist: [/^@w/, /^@vyriy/] })],
|
|
292
|
+
}),
|
|
293
|
+
);
|
|
294
|
+
`,
|
|
295
|
+
'workspaces/mcp/package.json': JSON.stringify({
|
|
296
|
+
name: '@w/mcp',
|
|
297
|
+
version: '0.0.0',
|
|
298
|
+
private: true,
|
|
299
|
+
type: 'module',
|
|
300
|
+
dependencies: {
|
|
301
|
+
'@modelcontextprotocol/sdk': '^1.29.0',
|
|
302
|
+
zod: '^4.4.3',
|
|
303
|
+
},
|
|
304
|
+
}, null, 2) + '\n',
|
|
305
|
+
'workspaces/mcp/types.ts': `import type { z } from 'zod';
|
|
306
|
+
|
|
307
|
+
export type ToolResult = {
|
|
308
|
+
content: Array<{
|
|
309
|
+
type: 'text';
|
|
310
|
+
text: string;
|
|
311
|
+
}>;
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
export type ToolDefinition<Input extends z.ZodRawShape> = {
|
|
315
|
+
name: string;
|
|
316
|
+
description: string;
|
|
317
|
+
inputSchema: Input;
|
|
318
|
+
handler: (input: z.infer<z.ZodObject<Input>>) => ToolResult | Promise<ToolResult>;
|
|
319
|
+
};
|
|
320
|
+
`,
|
|
321
|
+
'workspaces/mcp/mcp.ts': `import type { z } from 'zod';
|
|
322
|
+
import type { ToolCallback } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
323
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
324
|
+
import { z as schema } from 'zod';
|
|
325
|
+
|
|
326
|
+
import type { ToolDefinition } from './types.js';
|
|
327
|
+
|
|
328
|
+
const helloWorldTool = {
|
|
329
|
+
name: 'hello_world',
|
|
330
|
+
description: 'Return a small hello-world greeting.',
|
|
331
|
+
inputSchema: {
|
|
332
|
+
name: schema.string().default('world').describe('Name to greet.'),
|
|
333
|
+
},
|
|
334
|
+
handler: ({ name }) => ({
|
|
335
|
+
content: [
|
|
336
|
+
{
|
|
337
|
+
type: 'text',
|
|
338
|
+
text: \`Hello, \${name}!\`,
|
|
339
|
+
},
|
|
340
|
+
],
|
|
341
|
+
}),
|
|
342
|
+
} satisfies ToolDefinition<{
|
|
343
|
+
name: z.ZodDefault<z.ZodString>;
|
|
344
|
+
}>;
|
|
345
|
+
|
|
346
|
+
const registerTool = <Input extends z.ZodRawShape>(server: McpServer, tool: ToolDefinition<Input>) => {
|
|
347
|
+
const callback = ((args: unknown) => tool.handler(args as z.infer<z.ZodObject<Input>>)) as ToolCallback<Input>;
|
|
348
|
+
|
|
349
|
+
server.registerTool(
|
|
350
|
+
tool.name,
|
|
351
|
+
{
|
|
352
|
+
description: tool.description,
|
|
353
|
+
inputSchema: tool.inputSchema,
|
|
354
|
+
},
|
|
355
|
+
callback,
|
|
356
|
+
);
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
export const createMcpServer = () => {
|
|
360
|
+
const server = new McpServer({
|
|
361
|
+
name: '@w/mcp',
|
|
362
|
+
version: '0.0.0',
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
registerTool(server, helloWorldTool);
|
|
366
|
+
|
|
367
|
+
return server;
|
|
368
|
+
};
|
|
369
|
+
`,
|
|
370
|
+
'workspaces/mcp/server.ts': `import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
371
|
+
import type { AddressInfo } from 'node:net';
|
|
372
|
+
|
|
373
|
+
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
374
|
+
import { create } from '@vyriy/handler';
|
|
375
|
+
import { createHttpRouter } from '@vyriy/router';
|
|
376
|
+
import { httpServer } from '@vyriy/server';
|
|
377
|
+
import { getBody } from '@vyriy/server/body';
|
|
378
|
+
|
|
379
|
+
import { createMcpServer } from './mcp.js';
|
|
380
|
+
|
|
381
|
+
const HTTP_HEADERS = {
|
|
382
|
+
'access-control-allow-headers': 'content-type, mcp-protocol-version',
|
|
383
|
+
'access-control-allow-methods': 'GET, POST, OPTIONS',
|
|
384
|
+
'access-control-allow-origin': '*',
|
|
385
|
+
'x-content-type-options': 'nosniff',
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
const json = (res: ServerResponse, statusCode: number, body: unknown) => {
|
|
389
|
+
res.writeHead(statusCode, { 'content-type': 'application/json; charset=utf-8' });
|
|
390
|
+
res.end(JSON.stringify(body));
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
const jsonRpcError = (res: ServerResponse, statusCode: number, code: number, message: string) =>
|
|
394
|
+
json(res, statusCode, {
|
|
395
|
+
jsonrpc: '2.0',
|
|
396
|
+
error: { code, message },
|
|
397
|
+
id: null,
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
const readJsonBody = async (req: IncomingMessage) => {
|
|
401
|
+
const body = (await getBody(req))?.trim();
|
|
402
|
+
|
|
403
|
+
return body ? (JSON.parse(body) as unknown) : undefined;
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
const handleMcpRequest = async (req: IncomingMessage, res: ServerResponse) => {
|
|
407
|
+
if ((req.method ?? 'GET') !== 'POST') {
|
|
408
|
+
jsonRpcError(res, 405, -32000, 'Method not allowed.');
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const server = createMcpServer();
|
|
413
|
+
const transport = new StreamableHTTPServerTransport({
|
|
414
|
+
sessionIdGenerator: undefined,
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
try {
|
|
418
|
+
const body = await readJsonBody(req);
|
|
419
|
+
|
|
420
|
+
await server.connect(transport);
|
|
421
|
+
await transport.handleRequest(req, res, body);
|
|
422
|
+
} catch (error) {
|
|
423
|
+
console.error(error);
|
|
424
|
+
|
|
425
|
+
if (!res.headersSent) {
|
|
426
|
+
jsonRpcError(res, 500, -32603, 'Internal server error.');
|
|
427
|
+
}
|
|
428
|
+
} finally {
|
|
429
|
+
await transport.close();
|
|
430
|
+
await server.close();
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
export const createHttpHandler = () => {
|
|
435
|
+
const router = createHttpRouter();
|
|
436
|
+
|
|
437
|
+
router.all('/mcp', handleMcpRequest);
|
|
438
|
+
|
|
439
|
+
router.fallback((_req, res) => {
|
|
440
|
+
json(res, 404, {
|
|
441
|
+
message: 'Not found.',
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
return create.httpApi({
|
|
446
|
+
headers: HTTP_HEADERS,
|
|
447
|
+
healthcheck: {
|
|
448
|
+
body: {
|
|
449
|
+
ok: true,
|
|
450
|
+
name: '@w/mcp',
|
|
451
|
+
transport: 'streamable-http',
|
|
452
|
+
},
|
|
453
|
+
},
|
|
454
|
+
})(router.handle());
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
export const startHttpServer = async () => {
|
|
458
|
+
const server = httpServer(createHttpHandler());
|
|
459
|
+
|
|
460
|
+
await new Promise<void>((resolve, reject) => {
|
|
461
|
+
if (server.listening) {
|
|
462
|
+
resolve();
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
server.once('error', reject);
|
|
467
|
+
server.once('listening', resolve);
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
const address = server.address() as AddressInfo;
|
|
471
|
+
|
|
472
|
+
console.warn(\`MCP HTTP server listening on http://localhost:\${address.port}/mcp\`);
|
|
473
|
+
|
|
474
|
+
return server;
|
|
475
|
+
};
|
|
476
|
+
`,
|
|
477
|
+
'workspaces/mcp/index.ts': `import { startHttpServer } from './server.js';
|
|
478
|
+
|
|
479
|
+
void startHttpServer().catch((error: unknown) => {
|
|
480
|
+
console.error(error);
|
|
481
|
+
process.exitCode = 1;
|
|
482
|
+
});
|
|
483
|
+
`,
|
|
484
|
+
'workspaces/mcp/mcp.test.ts': `import { describe, expect, it, jest } from '@jest/globals';
|
|
485
|
+
|
|
486
|
+
const registerToolMock = jest.fn();
|
|
487
|
+
|
|
488
|
+
jest.mock('@modelcontextprotocol/sdk/server/mcp.js', () => ({
|
|
489
|
+
McpServer: jest.fn().mockImplementation((config) => ({
|
|
490
|
+
config,
|
|
491
|
+
registerTool: registerToolMock,
|
|
492
|
+
})),
|
|
493
|
+
}));
|
|
494
|
+
|
|
495
|
+
describe('workspaces/mcp/mcp.ts', () => {
|
|
496
|
+
it('creates an MCP server with the hello_world tool', async () => {
|
|
497
|
+
const { createMcpServer } = await import('./mcp.js');
|
|
498
|
+
|
|
499
|
+
const server = createMcpServer();
|
|
500
|
+
|
|
501
|
+
expect(server).toHaveProperty('config', {
|
|
502
|
+
name: '@w/mcp',
|
|
503
|
+
version: '0.0.0',
|
|
504
|
+
});
|
|
505
|
+
expect(registerToolMock).toHaveBeenCalledWith(
|
|
506
|
+
'hello_world',
|
|
507
|
+
expect.objectContaining({
|
|
508
|
+
description: 'Return a small hello-world greeting.',
|
|
509
|
+
}),
|
|
510
|
+
expect.any(Function),
|
|
511
|
+
);
|
|
512
|
+
});
|
|
513
|
+
});
|
|
514
|
+
`,
|
|
515
|
+
'workspaces/mcp/index.test.ts': `import { describe, expect, it, jest } from '@jest/globals';
|
|
516
|
+
|
|
517
|
+
const startHttpServerMock = jest.fn(() => Promise.resolve());
|
|
518
|
+
|
|
519
|
+
jest.mock('./server.js', () => ({
|
|
520
|
+
startHttpServer: startHttpServerMock,
|
|
521
|
+
}));
|
|
522
|
+
|
|
523
|
+
describe('workspaces/mcp/index.ts', () => {
|
|
524
|
+
it('starts the MCP HTTP server', async () => {
|
|
525
|
+
await import('./index.js');
|
|
526
|
+
|
|
527
|
+
expect(startHttpServerMock).toHaveBeenCalledTimes(1);
|
|
528
|
+
});
|
|
529
|
+
});
|
|
530
|
+
`,
|
|
531
|
+
});
|