create-mcp-kit 0.0.4 → 0.0.6
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/dist/index.js +11 -11
- package/package.json +3 -11
- package/template/{server-standard-js → server-js}/package.json.hbs +6 -5
- package/template/{server-standard-js → server-js}/src/services/web.js.hbs +1 -1
- package/template/server-js/tests/utils.js +16 -0
- package/template/server-js/vitest.config.js.hbs +24 -0
- package/template/server-js/vitest.global.js.hbs +25 -0
- package/template/server-js/vitest.setup.js.hbs +44 -0
- package/template/{server-standard-ts → server-ts}/package.json.hbs +8 -7
- package/template/{server-standard-ts → server-ts}/src/services/web.ts.hbs +1 -1
- package/template/server-ts/tests/utils.ts +20 -0
- package/template/server-ts/vitest.config.ts.hbs +24 -0
- package/template/server-ts/vitest.global.ts.hbs +25 -0
- package/template/server-ts/vitest.setup.ts.hbs +44 -0
- package/template/server-standard-js/vitest.config.js.hbs +0 -12
- package/template/server-standard-js/vitest.setup.js.hbs +0 -21
- package/template/server-standard-ts/vitest.config.ts.hbs +0 -12
- package/template/server-standard-ts/vitest.setup.ts.hbs +0 -27
- /package/template/{server-standard-js → server-js}/.env.hbs +0 -0
- /package/template/{server-standard-js → server-js}/.gitignore.hbs +0 -0
- /package/template/{server-standard-js → server-js}/.nvmrc.hbs +0 -0
- /package/template/{server-standard-js → server-js}/.prettierrc.hbs +0 -0
- /package/template/{server-standard-js → server-js}/LICENSE.hbs +0 -0
- /package/template/{server-standard-js → server-js}/_github/workflows/build.yml.hbs +0 -0
- /package/template/{server-standard-js → server-js}/_github/workflows/npm-publish.yml.hbs +0 -0
- /package/template/{server-standard-js → server-js}/_husky/commit-msg.hbs +0 -0
- /package/template/{server-standard-js → server-js}/_husky/pre-commit.hbs +0 -0
- /package/template/{server-standard-js → server-js}/changelog-option.js.hbs +0 -0
- /package/template/{server-standard-js → server-js}/commitlint.config.js.hbs +0 -0
- /package/template/{server-standard-js → server-js}/eslint.config.js.hbs +0 -0
- /package/template/{server-standard-js → server-js}/jsconfig.json.hbs +0 -0
- /package/template/{server-standard-js → server-js}/lint-staged.config.js.hbs +0 -0
- /package/template/{server-standard-js → server-js}/scripts/base.js.hbs +0 -0
- /package/template/{server-standard-js → server-js}/scripts/build.js.hbs +0 -0
- /package/template/{server-standard-js → server-js}/scripts/dev.js.hbs +0 -0
- /package/template/{server-standard-js → server-js}/src/constants/index.js +0 -0
- /package/template/{server-standard-js → server-js}/src/index.js.hbs +0 -0
- /package/template/{server-standard-js → server-js}/src/prompts/index.js +0 -0
- /package/template/{server-standard-js → server-js}/src/resources/index.js +0 -0
- /package/template/{server-standard-js → server-js}/src/services/index.js.hbs +0 -0
- /package/template/{server-standard-js → server-js}/src/services/stdio.js.hbs +0 -0
- /package/template/{server-standard-js → server-js}/src/tools/index.js +0 -0
- /package/template/{server-standard-js → server-js}/src/tools/registerGetData.js +0 -0
- /package/template/{server-standard-js → server-js}/src/utils/index.js +0 -0
- /package/template/{server-standard-js → server-js}/tests/prompts/index.test.js.hbs +0 -0
- /package/template/{server-standard-js → server-js}/tests/resources/index.test.js.hbs +0 -0
- /package/template/{server-standard-js → server-js}/tests/tools/index.test.js.hbs +0 -0
- /package/template/{server-standard-ts → server-ts}/.env.hbs +0 -0
- /package/template/{server-standard-ts → server-ts}/.gitignore.hbs +0 -0
- /package/template/{server-standard-ts → server-ts}/.nvmrc.hbs +0 -0
- /package/template/{server-standard-ts → server-ts}/.prettierrc.hbs +0 -0
- /package/template/{server-standard-ts → server-ts}/LICENSE.hbs +0 -0
- /package/template/{server-standard-ts → server-ts}/_github/workflows/build.yml.hbs +0 -0
- /package/template/{server-standard-ts → server-ts}/_github/workflows/npm-publish.yml.hbs +0 -0
- /package/template/{server-standard-ts → server-ts}/_husky/commit-msg.hbs +0 -0
- /package/template/{server-standard-ts → server-ts}/_husky/pre-commit.hbs +0 -0
- /package/template/{server-standard-ts → server-ts}/changelog-option.js.hbs +0 -0
- /package/template/{server-standard-ts → server-ts}/commitlint.config.js.hbs +0 -0
- /package/template/{server-standard-ts → server-ts}/eslint.config.js.hbs +0 -0
- /package/template/{server-standard-ts → server-ts}/lint-staged.config.js.hbs +0 -0
- /package/template/{server-standard-ts → server-ts}/scripts/base.js.hbs +0 -0
- /package/template/{server-standard-ts → server-ts}/scripts/build.js.hbs +0 -0
- /package/template/{server-standard-ts → server-ts}/scripts/dev.js.hbs +0 -0
- /package/template/{server-standard-ts → server-ts}/src/constants/index.ts +0 -0
- /package/template/{server-standard-ts → server-ts}/src/index.ts.hbs +0 -0
- /package/template/{server-standard-ts → server-ts}/src/prompts/index.ts +0 -0
- /package/template/{server-standard-ts → server-ts}/src/resources/index.ts +0 -0
- /package/template/{server-standard-ts → server-ts}/src/services/index.ts.hbs +0 -0
- /package/template/{server-standard-ts → server-ts}/src/services/stdio.ts.hbs +0 -0
- /package/template/{server-standard-ts → server-ts}/src/tools/index.ts +0 -0
- /package/template/{server-standard-ts → server-ts}/src/tools/registerGetData.ts +0 -0
- /package/template/{server-standard-ts → server-ts}/src/types/global.ts +0 -0
- /package/template/{server-standard-ts → server-ts}/src/types/index.ts +0 -0
- /package/template/{server-standard-ts → server-ts}/src/utils/index.ts +0 -0
- /package/template/{server-standard-ts → server-ts}/tests/prompts/index.test.ts.hbs +0 -0
- /package/template/{server-standard-ts → server-ts}/tests/resources/index.test.ts.hbs +0 -0
- /package/template/{server-standard-ts → server-ts}/tests/tools/index.test.ts.hbs +0 -0
- /package/template/{server-standard-ts → server-ts}/tests/vitest-global.d.ts.hbs +0 -0
- /package/template/{server-standard-ts → server-ts}/tsconfig.json.hbs +0 -0
package/dist/index.js
CHANGED
|
@@ -50,16 +50,6 @@ const group = await clack.group({
|
|
|
50
50
|
label: pc.blue("JavaScript")
|
|
51
51
|
}]
|
|
52
52
|
}),
|
|
53
|
-
template: () => clack.select({
|
|
54
|
-
message: "Project template:",
|
|
55
|
-
options: [{
|
|
56
|
-
value: "standard",
|
|
57
|
-
label: pc.magenta("Standard (recommended)")
|
|
58
|
-
}, {
|
|
59
|
-
value: "custom",
|
|
60
|
-
label: pc.blue("Custom")
|
|
61
|
-
}]
|
|
62
|
-
}),
|
|
63
53
|
transports: () => {
|
|
64
54
|
return clack.multiselect({
|
|
65
55
|
message: "Project Transport Type:",
|
|
@@ -81,6 +71,16 @@ const group = await clack.group({
|
|
|
81
71
|
]
|
|
82
72
|
});
|
|
83
73
|
},
|
|
74
|
+
template: () => clack.select({
|
|
75
|
+
message: "Project template:",
|
|
76
|
+
options: [{
|
|
77
|
+
value: "standard",
|
|
78
|
+
label: pc.magenta("Standard (recommended)")
|
|
79
|
+
}, {
|
|
80
|
+
value: "custom",
|
|
81
|
+
label: pc.blue("Custom")
|
|
82
|
+
}]
|
|
83
|
+
}),
|
|
84
84
|
plugins: ({ results }) => {
|
|
85
85
|
if (results.template !== "custom") return Promise.resolve([
|
|
86
86
|
"github-action",
|
|
@@ -126,7 +126,7 @@ const group = await clack.group({
|
|
|
126
126
|
clack.cancel("Operation cancelled.");
|
|
127
127
|
process.exit(0);
|
|
128
128
|
} });
|
|
129
|
-
const templatePath = join(__dirname, "../template", `${group.type}-${group.
|
|
129
|
+
const templatePath = join(__dirname, "../template", `${group.type}-${group.language}`);
|
|
130
130
|
const targetPath = resolve(process.cwd(), group.name);
|
|
131
131
|
if (!await fileExists(templatePath)) {
|
|
132
132
|
clack.log.error(`Template not found: ${templatePath}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-mcp-kit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "create mcp tool kit",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "zhensherlock",
|
|
@@ -43,17 +43,9 @@
|
|
|
43
43
|
"gradient-string": "^3.0.0",
|
|
44
44
|
"handlebars": "^4.7.8",
|
|
45
45
|
"picocolors": "^1.1.1",
|
|
46
|
-
"@mcp-tool-kit/shared": "^0.0.
|
|
47
|
-
},
|
|
48
|
-
"devDependencies": {
|
|
49
|
-
"@modelcontextprotocol/sdk": "^1.17.1",
|
|
50
|
-
"@types/express": "^5.0.3",
|
|
51
|
-
"@types/yargs": "^17.0.33",
|
|
52
|
-
"express": "^5.1.0",
|
|
53
|
-
"nanoid": "^5.1.5",
|
|
54
|
-
"yargs": "^17.7.2",
|
|
55
|
-
"zod": "^3.25.76"
|
|
46
|
+
"@mcp-tool-kit/shared": "^0.0.7"
|
|
56
47
|
},
|
|
48
|
+
"devDependencies": {},
|
|
57
49
|
"scripts": {
|
|
58
50
|
"clean:dist": "rimraf dist",
|
|
59
51
|
"build:types": "tsc --noEmit",
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
{{/if}}
|
|
32
32
|
{{#if (includes plugins 'vitest')}}
|
|
33
33
|
"test": "vitest run",
|
|
34
|
-
"
|
|
34
|
+
"report": "c8 report --reporter=lcov --reporter=html",
|
|
35
|
+
"coverage": "rimraf coverage && npm run test && npm run report",
|
|
35
36
|
{{/if}}
|
|
36
37
|
{{#if (includes plugins 'changelog')}}
|
|
37
38
|
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 -n changelog-option.js",
|
|
@@ -39,7 +40,7 @@
|
|
|
39
40
|
"prepare": "husky"
|
|
40
41
|
},
|
|
41
42
|
"dependencies": {
|
|
42
|
-
"@modelcontextprotocol/sdk": "^1.17.
|
|
43
|
+
"@modelcontextprotocol/sdk": "^1.17.2",
|
|
43
44
|
"dotenv": "^17.2.1",
|
|
44
45
|
{{#if (or (includes transports 'streamable') (includes transports 'sse'))}}
|
|
45
46
|
"express": "^5.1.0",
|
|
@@ -54,7 +55,7 @@
|
|
|
54
55
|
"@commitlint/config-conventional": "^19.8.1",
|
|
55
56
|
{{/if}}
|
|
56
57
|
{{#if (includes plugins 'inspector')}}
|
|
57
|
-
"@modelcontextprotocol/inspector": "^0.16.
|
|
58
|
+
"@modelcontextprotocol/inspector": "^0.16.3",
|
|
58
59
|
{{/if}}
|
|
59
60
|
{{#if (includes plugins 'vitest')}}
|
|
60
61
|
"@vitest/coverage-v8": "^3.2.4",
|
|
@@ -71,14 +72,14 @@
|
|
|
71
72
|
"cross-env": "^10.0.0",
|
|
72
73
|
"esbuild": "^0.25.8",
|
|
73
74
|
{{#if (includes plugins 'style')}}
|
|
74
|
-
"eslint": "^9.
|
|
75
|
+
"eslint": "^9.33.0",
|
|
75
76
|
"eslint-plugin-import": "^2.32.0",
|
|
76
77
|
"eslint-plugin-prettier": "^5.5.3",
|
|
77
78
|
"globals": "^16.3.0",
|
|
78
79
|
{{/if}}
|
|
79
80
|
"husky": "^9.1.7",
|
|
80
81
|
{{#if (includes plugins 'style')}}
|
|
81
|
-
"lint-staged": "^16.1.
|
|
82
|
+
"lint-staged": "^16.1.5",
|
|
82
83
|
{{/if}}
|
|
83
84
|
{{#if (includes plugins 'vitest')}}
|
|
84
85
|
"nyc": "^17.1.0",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{{#if (or (includes transports 'streamable') (includes transports 'sse'))}}
|
|
2
2
|
{{#if (includes transports 'streamable')}}
|
|
3
|
-
|
|
3
|
+
import { nanoid } from 'nanoid'
|
|
4
4
|
{{/if}}
|
|
5
5
|
import express from 'express'
|
|
6
6
|
{{#if (includes transports 'streamable')}}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function waitForValue(getterFn, checkInterval = 100, timeout = 10000) {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
const start = Date.now()
|
|
4
|
+
|
|
5
|
+
const intervalId = setInterval(() => {
|
|
6
|
+
const value = getterFn()
|
|
7
|
+
if (value) {
|
|
8
|
+
clearInterval(intervalId)
|
|
9
|
+
resolve(value)
|
|
10
|
+
} else if (Date.now() - start > timeout) {
|
|
11
|
+
clearInterval(intervalId)
|
|
12
|
+
reject(new Error('Timeout waiting for value'))
|
|
13
|
+
}
|
|
14
|
+
}, checkInterval)
|
|
15
|
+
})
|
|
16
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{{#if (includes plugins 'vitest')}}
|
|
2
|
+
import { defineConfig } from 'vitest/config'
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
test: {
|
|
6
|
+
{{#if (or (includes transports 'streamable') (includes transports 'sse'))}}
|
|
7
|
+
globalSetup: ['./vitest.global.js'],
|
|
8
|
+
{{/if}}
|
|
9
|
+
setupFiles: ['./vitest.setup.js'],
|
|
10
|
+
coverage: {
|
|
11
|
+
include: ['src/**/*.js'],
|
|
12
|
+
},
|
|
13
|
+
{{#if (or (includes transports 'streamable') (includes transports 'sse'))}}
|
|
14
|
+
pool: 'threads',
|
|
15
|
+
poolOptions: {
|
|
16
|
+
threads: {
|
|
17
|
+
maxThreads: 1,
|
|
18
|
+
minThreads: 1,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
{{/if}}
|
|
22
|
+
},
|
|
23
|
+
})
|
|
24
|
+
{{/if}}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{{#if (and (includes plugins 'vitest') (or (includes transports 'streamable') (includes transports 'sse')))}}
|
|
2
|
+
import { spawn } from 'child_process'
|
|
3
|
+
import { waitForValue } from './tests/utils.js'
|
|
4
|
+
|
|
5
|
+
export default async function setup() {
|
|
6
|
+
const webProcess = spawn('c8', ['--reporter=lcov', '--reporter=text', 'node', './src/index.js', 'web'], {
|
|
7
|
+
stdio: 'pipe',
|
|
8
|
+
env: {
|
|
9
|
+
...process.env,
|
|
10
|
+
NODE_V8_COVERAGE: './coverage/tmp',
|
|
11
|
+
},
|
|
12
|
+
})
|
|
13
|
+
let webStarted = false
|
|
14
|
+
webProcess.stdout?.on('data', async data => {
|
|
15
|
+
const output = data.toString()
|
|
16
|
+
if (output.includes('MCP server started')) {
|
|
17
|
+
webStarted = true
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
await waitForValue(() => webStarted)
|
|
21
|
+
return () => {
|
|
22
|
+
webProcess.kill('SIGINT')
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
{{/if}}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{{#if (includes plugins 'vitest')}}
|
|
2
|
+
import 'dotenv/config'
|
|
3
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
|
|
4
|
+
{{#if (includes transports 'stdio')}}
|
|
5
|
+
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'
|
|
6
|
+
{{/if}}
|
|
7
|
+
{{#if (includes transports 'streamable')}}
|
|
8
|
+
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'
|
|
9
|
+
{{/if}}
|
|
10
|
+
{{#if (includes transports 'sse')}}
|
|
11
|
+
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js'
|
|
12
|
+
{{/if}}
|
|
13
|
+
|
|
14
|
+
const client = new Client({
|
|
15
|
+
name: 'test-mcp-client',
|
|
16
|
+
version: '1.0.0',
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
{{#if (includes transports 'stdio')}}
|
|
20
|
+
const stdioClientTransport = new StdioClientTransport({
|
|
21
|
+
command: 'c8',
|
|
22
|
+
args: ['--reporter=lcov', '--reporter=text', 'node', './src/index.js'],
|
|
23
|
+
env: {
|
|
24
|
+
...process.env,
|
|
25
|
+
NODE_V8_COVERAGE: './coverage/tmp',
|
|
26
|
+
},
|
|
27
|
+
})
|
|
28
|
+
await client.connect(stdioClientTransport)
|
|
29
|
+
|
|
30
|
+
{{/if}}
|
|
31
|
+
{{#if (includes transports 'streamable')}}
|
|
32
|
+
const streamableBaseUrl = new URL('http://localhost:8401/mcp')
|
|
33
|
+
const streamableClientTransport = new StreamableHTTPClientTransport(new URL(streamableBaseUrl))
|
|
34
|
+
await client.connect(streamableClientTransport)
|
|
35
|
+
|
|
36
|
+
{{/if}}
|
|
37
|
+
{{#if (includes transports 'sse')}}
|
|
38
|
+
const sseBaseUrl = new URL('http://localhost:8401/sse')
|
|
39
|
+
const sseClientTransport = new SSEClientTransport(new URL(sseBaseUrl))
|
|
40
|
+
await client.connect(sseClientTransport)
|
|
41
|
+
|
|
42
|
+
{{/if}}
|
|
43
|
+
global.client = client
|
|
44
|
+
{{/if}}
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
{{/if}}
|
|
32
32
|
{{#if (includes plugins 'vitest')}}
|
|
33
33
|
"test": "vitest run",
|
|
34
|
-
"
|
|
34
|
+
"report": "c8 report --reporter=lcov --reporter=html",
|
|
35
|
+
"coverage": "rimraf coverage && npm run test && npm run report",
|
|
35
36
|
{{/if}}
|
|
36
37
|
{{#if (includes plugins 'changelog')}}
|
|
37
38
|
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 -n changelog-option.js",
|
|
@@ -39,7 +40,7 @@
|
|
|
39
40
|
"prepare": "husky"
|
|
40
41
|
},
|
|
41
42
|
"dependencies": {
|
|
42
|
-
"@modelcontextprotocol/sdk": "^1.17.
|
|
43
|
+
"@modelcontextprotocol/sdk": "^1.17.2",
|
|
43
44
|
"dotenv": "^17.2.1",
|
|
44
45
|
{{#if (or (includes transports 'streamable') (includes transports 'sse'))}}
|
|
45
46
|
"express": "^5.1.0",
|
|
@@ -54,15 +55,15 @@
|
|
|
54
55
|
"@commitlint/config-conventional": "^19.8.1",
|
|
55
56
|
{{/if}}
|
|
56
57
|
{{#if (includes plugins 'inspector')}}
|
|
57
|
-
"@modelcontextprotocol/inspector": "^0.16.
|
|
58
|
+
"@modelcontextprotocol/inspector": "^0.16.3",
|
|
58
59
|
{{/if}}
|
|
59
60
|
{{#if (or (includes transports 'streamable') (includes transports 'sse'))}}
|
|
60
61
|
"@types/express": "^5.0.3",
|
|
61
62
|
{{/if}}
|
|
62
63
|
"@types/yargs": "^17.0.33",
|
|
63
64
|
{{#if (includes plugins 'style')}}
|
|
64
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
65
|
-
"@typescript-eslint/parser": "^8.
|
|
65
|
+
"@typescript-eslint/eslint-plugin": "^8.39.1",
|
|
66
|
+
"@typescript-eslint/parser": "^8.39.1",
|
|
66
67
|
{{/if}}
|
|
67
68
|
{{#if (includes plugins 'vitest')}}
|
|
68
69
|
"@vitest/coverage-v8": "^3.2.4",
|
|
@@ -79,14 +80,14 @@
|
|
|
79
80
|
"cross-env": "^10.0.0",
|
|
80
81
|
"esbuild": "^0.25.8",
|
|
81
82
|
{{#if (includes plugins 'style')}}
|
|
82
|
-
"eslint": "^9.
|
|
83
|
+
"eslint": "^9.33.0",
|
|
83
84
|
"eslint-plugin-import": "^2.32.0",
|
|
84
85
|
"eslint-plugin-prettier": "^5.5.3",
|
|
85
86
|
"globals": "^16.3.0",
|
|
86
87
|
{{/if}}
|
|
87
88
|
"husky": "^9.1.7",
|
|
88
89
|
{{#if (includes plugins 'style')}}
|
|
89
|
-
"lint-staged": "^16.1.
|
|
90
|
+
"lint-staged": "^16.1.5",
|
|
90
91
|
{{/if}}
|
|
91
92
|
{{#if (includes plugins 'vitest')}}
|
|
92
93
|
"nyc": "^17.1.0",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{{#if (or (includes transports 'streamable') (includes transports 'sse'))}}
|
|
2
2
|
{{#if (includes transports 'streamable')}}
|
|
3
|
-
|
|
3
|
+
import { nanoid } from 'nanoid'
|
|
4
4
|
{{/if}}
|
|
5
5
|
import express from 'express'
|
|
6
6
|
{{#if (includes transports 'streamable')}}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function waitForValue<T>(
|
|
2
|
+
getterFn: () => T | undefined | null,
|
|
3
|
+
checkInterval = 100,
|
|
4
|
+
timeout = 10000,
|
|
5
|
+
): Promise<T> {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
const start = Date.now()
|
|
8
|
+
|
|
9
|
+
const intervalId = setInterval(() => {
|
|
10
|
+
const value = getterFn()
|
|
11
|
+
if (value) {
|
|
12
|
+
clearInterval(intervalId)
|
|
13
|
+
resolve(value)
|
|
14
|
+
} else if (Date.now() - start > timeout) {
|
|
15
|
+
clearInterval(intervalId)
|
|
16
|
+
reject(new Error('Timeout waiting for value'))
|
|
17
|
+
}
|
|
18
|
+
}, checkInterval)
|
|
19
|
+
})
|
|
20
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{{#if (includes plugins 'vitest')}}
|
|
2
|
+
import { defineConfig } from 'vitest/config'
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
test: {
|
|
6
|
+
{{#if (or (includes transports 'streamable') (includes transports 'sse'))}}
|
|
7
|
+
globalSetup: ['./vitest.global.ts'],
|
|
8
|
+
{{/if}}
|
|
9
|
+
setupFiles: ['./vitest.setup.ts'],
|
|
10
|
+
coverage: {
|
|
11
|
+
include: ['src/**/*.ts'],
|
|
12
|
+
},
|
|
13
|
+
{{#if (or (includes transports 'streamable') (includes transports 'sse'))}}
|
|
14
|
+
pool: 'threads',
|
|
15
|
+
poolOptions: {
|
|
16
|
+
threads: {
|
|
17
|
+
maxThreads: 1,
|
|
18
|
+
minThreads: 1,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
{{/if}}
|
|
22
|
+
},
|
|
23
|
+
})
|
|
24
|
+
{{/if}}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{{#if (and (includes plugins 'vitest') (or (includes transports 'streamable') (includes transports 'sse')))}}
|
|
2
|
+
import { spawn } from 'child_process'
|
|
3
|
+
import { waitForValue } from './tests/utils'
|
|
4
|
+
|
|
5
|
+
export default async function setup() {
|
|
6
|
+
const webProcess = spawn('c8', ['--reporter=lcov', '--reporter=text', 'tsx', './src/index.ts', 'web'], {
|
|
7
|
+
stdio: 'pipe',
|
|
8
|
+
env: {
|
|
9
|
+
...(process.env as Record<string, string>),
|
|
10
|
+
NODE_V8_COVERAGE: './coverage/tmp',
|
|
11
|
+
},
|
|
12
|
+
})
|
|
13
|
+
let webStarted = false
|
|
14
|
+
webProcess.stdout?.on('data', async data => {
|
|
15
|
+
const output = data.toString()
|
|
16
|
+
if (output.includes('MCP server started')) {
|
|
17
|
+
webStarted = true
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
await waitForValue(() => webStarted)
|
|
21
|
+
return () => {
|
|
22
|
+
webProcess.kill('SIGINT')
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
{{/if}}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{{#if (includes plugins 'vitest')}}
|
|
2
|
+
import 'dotenv/config'
|
|
3
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
|
|
4
|
+
{{#if (includes transports 'stdio')}}
|
|
5
|
+
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'
|
|
6
|
+
{{/if}}
|
|
7
|
+
{{#if (includes transports 'streamable')}}
|
|
8
|
+
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'
|
|
9
|
+
{{/if}}
|
|
10
|
+
{{#if (includes transports 'sse')}}
|
|
11
|
+
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js'
|
|
12
|
+
{{/if}}
|
|
13
|
+
|
|
14
|
+
const client = new Client({
|
|
15
|
+
name: 'test-mcp-client',
|
|
16
|
+
version: '1.0.0',
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
{{#if (includes transports 'stdio')}}
|
|
20
|
+
const stdioClientTransport = new StdioClientTransport({
|
|
21
|
+
command: 'c8',
|
|
22
|
+
args: ['--reporter=lcov', '--reporter=text', 'tsx', './src/index.ts'],
|
|
23
|
+
env: {
|
|
24
|
+
...process.env as Record<string, string>,
|
|
25
|
+
NODE_V8_COVERAGE: './coverage/tmp',
|
|
26
|
+
},
|
|
27
|
+
})
|
|
28
|
+
await client.connect(stdioClientTransport)
|
|
29
|
+
|
|
30
|
+
{{/if}}
|
|
31
|
+
{{#if (includes transports 'streamable')}}
|
|
32
|
+
const streamableBaseUrl = new URL('http://localhost:8401/mcp')
|
|
33
|
+
const streamableClientTransport = new StreamableHTTPClientTransport(new URL(streamableBaseUrl))
|
|
34
|
+
await client.connect(streamableClientTransport)
|
|
35
|
+
|
|
36
|
+
{{/if}}
|
|
37
|
+
{{#if (includes transports 'sse')}}
|
|
38
|
+
const sseBaseUrl = new URL('http://localhost:8401/sse')
|
|
39
|
+
const sseClientTransport = new SSEClientTransport(new URL(sseBaseUrl))
|
|
40
|
+
await client.connect(sseClientTransport)
|
|
41
|
+
|
|
42
|
+
{{/if}}
|
|
43
|
+
global.client = client
|
|
44
|
+
{{/if}}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{{#if (includes plugins 'vitest')}}
|
|
2
|
-
import 'dotenv/config'
|
|
3
|
-
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
|
|
4
|
-
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'
|
|
5
|
-
|
|
6
|
-
const serverParams = new StdioClientTransport({
|
|
7
|
-
command: 'nyc',
|
|
8
|
-
args: ['--merge-async', '--reporter=lcov', '--reporter=text', 'node', './src/index.js'],
|
|
9
|
-
env: {
|
|
10
|
-
...process.env,
|
|
11
|
-
NODE_V8_COVERAGE: './coverage/tmp',
|
|
12
|
-
},
|
|
13
|
-
})
|
|
14
|
-
const client = new Client({
|
|
15
|
-
name: 'test-mcp-client',
|
|
16
|
-
version: '1.0.0',
|
|
17
|
-
})
|
|
18
|
-
await client.connect(serverParams)
|
|
19
|
-
|
|
20
|
-
global.client = client
|
|
21
|
-
{{/if}}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
{{#if (includes plugins 'vitest')}}
|
|
2
|
-
import 'dotenv/config'
|
|
3
|
-
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
|
|
4
|
-
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'
|
|
5
|
-
|
|
6
|
-
const serverParams = new StdioClientTransport({
|
|
7
|
-
command: 'nyc',
|
|
8
|
-
args: [
|
|
9
|
-
'--merge-async',
|
|
10
|
-
'--reporter=lcov',
|
|
11
|
-
'--reporter=text',
|
|
12
|
-
'tsx',
|
|
13
|
-
'./src/index.ts',
|
|
14
|
-
],
|
|
15
|
-
env: {
|
|
16
|
-
...process.env as Record<string, string>,
|
|
17
|
-
NODE_V8_COVERAGE: './coverage/tmp',
|
|
18
|
-
},
|
|
19
|
-
})
|
|
20
|
-
const client = new Client({
|
|
21
|
-
name: 'test-mcp-client',
|
|
22
|
-
version: '1.0.0',
|
|
23
|
-
})
|
|
24
|
-
await client.connect(serverParams)
|
|
25
|
-
|
|
26
|
-
global.client = client
|
|
27
|
-
{{/if}}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|