create-mcp-kit 0.0.3 → 0.0.4

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.
Files changed (75) hide show
  1. package/dist/index.js +98 -14
  2. package/package.json +4 -2
  3. package/template/{standard-js/_prettierrc → server-standard-js/.prettierrc.hbs} +2 -0
  4. package/template/{standard-js/LICENSE → server-standard-js/LICENSE.hbs} +1 -1
  5. package/template/{standard-ts/_github/workflows/build.yml → server-standard-js/_github/workflows/build.yml.hbs} +3 -1
  6. package/template/{standard-ts/_github/workflows/npm-publish.yml → server-standard-js/_github/workflows/npm-publish.yml.hbs} +3 -1
  7. package/template/server-standard-js/_husky/commit-msg.hbs +3 -0
  8. package/template/server-standard-js/_husky/pre-commit.hbs +3 -0
  9. package/template/{standard-ts/changelog-option.js → server-standard-js/changelog-option.js.hbs} +2 -0
  10. package/template/{standard-js/commitlint.config.js → server-standard-js/commitlint.config.js.hbs} +2 -0
  11. package/template/{standard-js/eslint.config.js → server-standard-js/eslint.config.js.hbs} +7 -1
  12. package/template/{standard-js/jsconfig.json → server-standard-js/jsconfig.json.hbs} +4 -0
  13. package/template/{standard-js/lint-staged.config.js → server-standard-js/lint-staged.config.js.hbs} +2 -0
  14. package/template/{standard-js/package.json → server-standard-js/package.json.hbs} +44 -9
  15. package/template/{standard-js/scripts/base.js → server-standard-js/scripts/base.js.hbs} +9 -3
  16. package/template/{standard-js/src/index.js → server-standard-js/src/index.js.hbs} +27 -1
  17. package/template/{standard-js/src/services/index.js → server-standard-js/src/services/index.js.hbs} +8 -0
  18. package/template/{standard-js/src/services/stdio.js → server-standard-js/src/services/stdio.js.hbs} +2 -0
  19. package/template/{standard-js/src/services/web.js → server-standard-js/src/services/web.js.hbs} +19 -2
  20. package/template/{standard-ts/tests/prompts/index.test.ts → server-standard-js/tests/prompts/index.test.js.hbs} +2 -0
  21. package/template/{standard-ts/tests/resources/index.test.ts → server-standard-js/tests/resources/index.test.js.hbs} +2 -0
  22. package/template/{standard-ts/tests/tools/index.test.ts → server-standard-js/tests/tools/index.test.js.hbs} +2 -0
  23. package/template/{standard-js/vitest.config.js → server-standard-js/vitest.config.js.hbs} +2 -0
  24. package/template/{standard-js/vitest.setup.js → server-standard-js/vitest.setup.js.hbs} +2 -0
  25. package/template/{standard-ts/_prettierrc → server-standard-ts/.prettierrc.hbs} +2 -0
  26. package/template/{standard-ts/LICENSE → server-standard-ts/LICENSE.hbs} +1 -1
  27. package/template/{standard-js/_github/workflows/build.yml → server-standard-ts/_github/workflows/build.yml.hbs} +3 -1
  28. package/template/{standard-js/_github/workflows/npm-publish.yml → server-standard-ts/_github/workflows/npm-publish.yml.hbs} +3 -1
  29. package/template/server-standard-ts/_husky/commit-msg.hbs +3 -0
  30. package/template/server-standard-ts/_husky/pre-commit.hbs +3 -0
  31. package/template/{standard-js/changelog-option.js → server-standard-ts/changelog-option.js.hbs} +2 -0
  32. package/template/{standard-ts/commitlint.config.js → server-standard-ts/commitlint.config.js.hbs} +2 -0
  33. package/template/{standard-ts/eslint.config.js → server-standard-ts/eslint.config.js.hbs} +6 -0
  34. package/template/{standard-ts/lint-staged.config.js → server-standard-ts/lint-staged.config.js.hbs} +2 -0
  35. package/template/{standard-ts/package.json → server-standard-ts/package.json.hbs} +48 -11
  36. package/template/{standard-ts/scripts/base.js → server-standard-ts/scripts/base.js.hbs} +9 -3
  37. package/template/{standard-ts/src/index.ts → server-standard-ts/src/index.ts.hbs} +28 -2
  38. package/template/{standard-ts/src/services/index.ts → server-standard-ts/src/services/index.ts.hbs} +8 -0
  39. package/template/{standard-ts/src/services/stdio.ts → server-standard-ts/src/services/stdio.ts.hbs} +2 -0
  40. package/template/{standard-ts/src/services/web.ts → server-standard-ts/src/services/web.ts.hbs} +19 -2
  41. package/template/{standard-js/tests/prompts/index.test.js → server-standard-ts/tests/prompts/index.test.ts.hbs} +2 -0
  42. package/template/{standard-js/tests/resources/index.test.js → server-standard-ts/tests/resources/index.test.ts.hbs} +2 -0
  43. package/template/{standard-js/tests/tools/index.test.js → server-standard-ts/tests/tools/index.test.ts.hbs} +2 -0
  44. package/template/{standard-ts/tests/vitest-global.d.ts → server-standard-ts/tests/vitest-global.d.ts.hbs} +2 -0
  45. package/template/{standard-ts/tsconfig.json → server-standard-ts/tsconfig.json.hbs} +4 -0
  46. package/template/{standard-ts/vitest.config.ts → server-standard-ts/vitest.config.ts.hbs} +2 -0
  47. package/template/{standard-ts/vitest.setup.ts → server-standard-ts/vitest.setup.ts.hbs} +2 -0
  48. package/template/standard-js/_husky/commit-msg +0 -1
  49. package/template/standard-js/_husky/pre-commit +0 -1
  50. package/template/standard-ts/_husky/commit-msg +0 -1
  51. package/template/standard-ts/_husky/pre-commit +0 -1
  52. /package/template/{standard-js/_env → server-standard-js/.env.hbs} +0 -0
  53. /package/template/{standard-js/_gitignore → server-standard-js/.gitignore.hbs} +0 -0
  54. /package/template/{standard-js/_nvmrc → server-standard-js/.nvmrc.hbs} +0 -0
  55. /package/template/{standard-js/scripts/build.js → server-standard-js/scripts/build.js.hbs} +0 -0
  56. /package/template/{standard-js/scripts/dev.js → server-standard-js/scripts/dev.js.hbs} +0 -0
  57. /package/template/{standard-js → server-standard-js}/src/constants/index.js +0 -0
  58. /package/template/{standard-js → server-standard-js}/src/prompts/index.js +0 -0
  59. /package/template/{standard-js → server-standard-js}/src/resources/index.js +0 -0
  60. /package/template/{standard-js → server-standard-js}/src/tools/index.js +0 -0
  61. /package/template/{standard-js → server-standard-js}/src/tools/registerGetData.js +0 -0
  62. /package/template/{standard-js → server-standard-js}/src/utils/index.js +0 -0
  63. /package/template/{standard-ts/_env → server-standard-ts/.env.hbs} +0 -0
  64. /package/template/{standard-ts/_gitignore → server-standard-ts/.gitignore.hbs} +0 -0
  65. /package/template/{standard-ts/_nvmrc → server-standard-ts/.nvmrc.hbs} +0 -0
  66. /package/template/{standard-ts/scripts/build.js → server-standard-ts/scripts/build.js.hbs} +0 -0
  67. /package/template/{standard-ts/scripts/dev.js → server-standard-ts/scripts/dev.js.hbs} +0 -0
  68. /package/template/{standard-ts → server-standard-ts}/src/constants/index.ts +0 -0
  69. /package/template/{standard-ts → server-standard-ts}/src/prompts/index.ts +0 -0
  70. /package/template/{standard-ts → server-standard-ts}/src/resources/index.ts +0 -0
  71. /package/template/{standard-ts → server-standard-ts}/src/tools/index.ts +0 -0
  72. /package/template/{standard-ts → server-standard-ts}/src/tools/registerGetData.ts +0 -0
  73. /package/template/{standard-ts → server-standard-ts}/src/types/global.ts +0 -0
  74. /package/template/{standard-ts → server-standard-ts}/src/types/index.ts +0 -0
  75. /package/template/{standard-ts → server-standard-ts}/src/utils/index.ts +0 -0
package/dist/index.js CHANGED
@@ -1,15 +1,32 @@
1
1
  #!/usr/bin/env node
2
- import * as clack from "@clack/prompts";
3
- import pc from "picocolors";
4
2
  import { fileURLToPath } from "url";
5
3
  import { dirname, join, resolve } from "path";
6
- import { stat } from "fs/promises";
7
- import { createProject, installDependencies, sleep } from "@mcp-tool-kit/shared";
4
+ import * as clack from "@clack/prompts";
5
+ import pc from "picocolors";
6
+ import gradient from "gradient-string";
7
+ import { createProject, fileExists, installDependencies, sleep } from "@mcp-tool-kit/shared";
8
8
 
9
9
  //#region src/index.ts
10
10
  const __filename = fileURLToPath(import.meta.url);
11
11
  const __dirname = dirname(__filename);
12
- clack.intro(pc.inverse(" create-mcp-kit "));
12
+ clack.intro(gradient([
13
+ {
14
+ color: "#a855f7",
15
+ pos: 0
16
+ },
17
+ {
18
+ color: "#3b82f6",
19
+ pos: .4
20
+ },
21
+ {
22
+ color: "#06b6d4",
23
+ pos: .8
24
+ },
25
+ {
26
+ color: "#10b981",
27
+ pos: 1
28
+ }
29
+ ])("MCP Kit - The Modern Context Protocol Builder"));
13
30
  const group = await clack.group({
14
31
  type: () => clack.select({
15
32
  message: "Project type:",
@@ -37,33 +54,100 @@ const group = await clack.group({
37
54
  message: "Project template:",
38
55
  options: [{
39
56
  value: "standard",
40
- label: pc.magenta("Standard")
57
+ label: pc.magenta("Standard (recommended)")
58
+ }, {
59
+ value: "custom",
60
+ label: pc.blue("Custom")
41
61
  }]
42
62
  }),
63
+ transports: () => {
64
+ return clack.multiselect({
65
+ message: "Project Transport Type:",
66
+ required: true,
67
+ initialValues: ["stdio"],
68
+ options: [
69
+ {
70
+ value: "stdio",
71
+ label: pc.magenta("STDIO")
72
+ },
73
+ {
74
+ value: "streamable",
75
+ label: pc.blue("Streamable HTTP")
76
+ },
77
+ {
78
+ value: "sse",
79
+ label: pc.yellow("SSE")
80
+ }
81
+ ]
82
+ });
83
+ },
84
+ plugins: ({ results }) => {
85
+ if (results.template !== "custom") return Promise.resolve([
86
+ "github-action",
87
+ "vitest",
88
+ "inspector",
89
+ "style",
90
+ "commitlint",
91
+ "changelog"
92
+ ]);
93
+ return clack.multiselect({
94
+ message: "Project plugins:",
95
+ required: false,
96
+ options: [
97
+ {
98
+ value: "github-action",
99
+ label: pc.magenta("GitHub Action")
100
+ },
101
+ {
102
+ value: "vitest",
103
+ label: pc.green("Vitest")
104
+ },
105
+ {
106
+ value: "inspector",
107
+ label: pc.blue("Inspector")
108
+ },
109
+ {
110
+ value: "style",
111
+ label: pc.white("ESLint + Prettier + Lint-staged")
112
+ },
113
+ {
114
+ value: "commitlint",
115
+ label: pc.gray("Commitlint")
116
+ },
117
+ {
118
+ value: "changelog",
119
+ label: pc.blueBright("Changelog")
120
+ }
121
+ ]
122
+ });
123
+ },
43
124
  install: () => clack.confirm({ message: "Do you want to install dependencies?" })
44
125
  }, { onCancel: () => {
45
126
  clack.cancel("Operation cancelled.");
46
127
  process.exit(0);
47
128
  } });
48
- const templatePath = join(__dirname, "../template", `${group.template}-${group.language}`);
129
+ const templatePath = join(__dirname, "../template", `${group.type}-${group.template}-${group.language}`);
49
130
  const targetPath = resolve(process.cwd(), group.name);
50
- try {
51
- await stat(templatePath);
52
- } catch {
131
+ if (!await fileExists(templatePath)) {
53
132
  clack.log.error(`Template not found: ${templatePath}`);
54
133
  process.exit(1);
55
134
  }
56
- try {
57
- await stat(targetPath);
135
+ if (await fileExists(targetPath)) {
58
136
  clack.log.error(`Directory ${group.name} already exists`);
59
137
  process.exit(1);
60
- } catch {}
138
+ }
61
139
  {
62
140
  const createSpinner = clack.spinner();
63
141
  createSpinner.start("Creating project...");
64
142
  await sleep(100);
65
143
  try {
66
- await createProject(targetPath, templatePath, { projectName: group.name });
144
+ await createProject(targetPath, templatePath, {
145
+ projectName: group.name,
146
+ year: (/* @__PURE__ */ new Date()).getFullYear().toString(),
147
+ transports: group.transports,
148
+ plugins: group.plugins,
149
+ components: []
150
+ });
67
151
  } catch (error) {
68
152
  createSpinner.stop("Failed to create project");
69
153
  clack.log.error(error.message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-mcp-kit",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "create mcp tool kit",
5
5
  "type": "module",
6
6
  "author": "zhensherlock",
@@ -40,8 +40,10 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@clack/prompts": "^0.11.0",
43
+ "gradient-string": "^3.0.0",
44
+ "handlebars": "^4.7.8",
43
45
  "picocolors": "^1.1.1",
44
- "@mcp-tool-kit/shared": "^0.0.4"
46
+ "@mcp-tool-kit/shared": "^0.0.5"
45
47
  },
46
48
  "devDependencies": {
47
49
  "@modelcontextprotocol/sdk": "^1.17.1",
@@ -1,3 +1,4 @@
1
+ {{#if (includes plugins 'style')}}
1
2
  {
2
3
  "tabWidth": 2,
3
4
  "printWidth": 120,
@@ -9,3 +10,4 @@
9
10
  "jsxBracketSameLine": false,
10
11
  "arrowParens": "avoid"
11
12
  }
13
+ {{/if}}
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) {{YEAR}} {{PROJECT_NAME}}
3
+ Copyright (c) {{year}} {{projectName}}
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,3 +1,4 @@
1
+ {{#if (includes plugins 'github-action')}}
1
2
  name: build
2
3
 
3
4
  on:
@@ -7,7 +8,7 @@ on:
7
8
 
8
9
  jobs:
9
10
  build:
10
- if: github.repository == '{{PROJECT_NAME}}'
11
+ if: github.repository == '{{projectName}}'
11
12
  runs-on: ubuntu-latest
12
13
  steps:
13
14
  - name: Checkout
@@ -35,3 +36,4 @@ jobs:
35
36
 
36
37
  - name: Coveralls
37
38
  uses: coverallsapp/github-action@v2
39
+ {{/if}}
@@ -1,3 +1,4 @@
1
+ {{#if (includes plugins 'github-action')}}
1
2
  name: npm-publish
2
3
 
3
4
  on:
@@ -6,7 +7,7 @@ on:
6
7
 
7
8
  jobs:
8
9
  build:
9
- if: github.repository == '{{PROJECT_NAME}}'
10
+ if: github.repository == '{{projectName}}'
10
11
  runs-on: ubuntu-latest
11
12
  permissions:
12
13
  contents: read
@@ -37,3 +38,4 @@ jobs:
37
38
  run: npm publish --provenance --access public
38
39
  env:
39
40
  NODE_AUTH_TOKEN: ${{secrets.npm_token}}
41
+ {{/if}}
@@ -0,0 +1,3 @@
1
+ {{#if (includes plugins 'commitlint')}}
2
+ npx --no-install commitlint --edit $1
3
+ {{/if}}
@@ -0,0 +1,3 @@
1
+ {{#if (includes plugins 'style')}}
2
+ npx lint-staged
3
+ {{/if}}
@@ -1,3 +1,4 @@
1
+ {{#if (includes plugins 'changelog')}}
1
2
  import compareFunc from 'compare-func'
2
3
 
3
4
  export default {
@@ -85,3 +86,4 @@ export default {
85
86
  notesSort: compareFunc,
86
87
  },
87
88
  }
89
+ {{/if}}
@@ -1,3 +1,4 @@
1
+ {{#if (includes plugins 'commitlint')}}
1
2
  export default {
2
3
  extends: ['@commitlint/config-conventional'],
3
4
  rules: {
@@ -23,3 +24,4 @@ export default {
23
24
  'subject-case': [0],
24
25
  },
25
26
  }
27
+ {{/if}}
@@ -1,13 +1,18 @@
1
+ {{#if (includes plugins 'style')}}
1
2
  import importPlugin from 'eslint-plugin-import'
2
3
  import prettierPlugin from 'eslint-plugin-prettier'
3
4
  import globals from 'globals'
4
5
 
5
6
  export default [
6
7
  {
7
- ignores: ['**/build', '**/node_modules', '**/.*', '**/*.d.ts', '.husky/'],
8
+ ignores: ['**/build', '**/node_modules', '**/.*', '.husky/'],
8
9
  },
9
10
  {
11
+ {{#if (includes plugins 'vitest')}}
10
12
  files: ['src/**/*.js', 'tests/**/*.js'],
13
+ {{else}}
14
+ files: ['src/**/*.js'],
15
+ {{/if}}
11
16
  },
12
17
  {
13
18
  languageOptions: {
@@ -40,3 +45,4 @@ export default [
40
45
  },
41
46
  },
42
47
  ]
48
+ {{/if}}
@@ -12,6 +12,10 @@
12
12
  "@/*": ["./src/*"]
13
13
  }
14
14
  },
15
+ {{#if (includes plugins 'vitest')}}
15
16
  "include": ["src", "tests", "vitest.setup.js", "vitest.config.js"],
17
+ {{else}}
18
+ "include": ["src"],
19
+ {{/if}}
16
20
  "exclude": ["node_modules"]
17
21
  }
@@ -1,3 +1,5 @@
1
+ {{#if (includes plugins 'style')}}
1
2
  export default {
2
3
  'src/**/*.js': ['npx eslint'],
3
4
  }
5
+ {{/if}}
@@ -1,12 +1,12 @@
1
1
  {
2
- "name": "{{PROJECT_NAME}}",
2
+ "name": "{{projectName}}",
3
3
  "version": "0.0.0",
4
- "description": "{{PROJECT_NAME}}",
4
+ "description": "{{projectName}}",
5
5
  "author": "zhensherlock",
6
6
  "type": "module",
7
7
  "license": "MIT",
8
8
  "bin": {
9
- "{{PROJECT_NAME}}": "./build/index.js"
9
+ "{{projectName}}": "./build/index.js"
10
10
  },
11
11
  "files": [
12
12
  "build",
@@ -15,48 +15,83 @@
15
15
  ],
16
16
  "main": "build/index.js",
17
17
  "scripts": {
18
- "prepare": "husky",
18
+ {{#if (includes plugins 'style')}}
19
19
  "lint": "npx eslint \"src/**/*.js\"",
20
+ {{/if}}
20
21
  "build": "cross-env NODE_ENV=production node scripts/build.js",
22
+ {{#if (and (includes transports 'stdio') (or (includes transports 'streamable') (includes transports 'sse')))}}
21
23
  "dev": "npm run dev:stdio",
22
24
  "dev:stdio": "cross-env NODE_ENV=local node scripts/dev.js",
25
+ {{else if (includes transports 'web')}}
26
+ "dev": "npm run dev:stdio",
27
+ "dev:stdio": "cross-env NODE_ENV=local node scripts/dev.js",
28
+ {{else}}
29
+ "dev": "npm run dev:web",
23
30
  "dev:web": "cross-env NODE_ENV=local TRANSPORT=web node scripts/dev.js",
31
+ {{/if}}
32
+ {{#if (includes plugins 'vitest')}}
24
33
  "test": "vitest run",
25
34
  "coverage": "rimraf coverage && npm run test && c8 report --reporter=lcov --reporter=html",
26
- "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 -n changelog-option.js"
35
+ {{/if}}
36
+ {{#if (includes plugins 'changelog')}}
37
+ "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 -n changelog-option.js",
38
+ {{/if}}
39
+ "prepare": "husky"
27
40
  },
28
41
  "dependencies": {
29
42
  "@modelcontextprotocol/sdk": "^1.17.1",
30
- "cors": "^2.8.5",
31
43
  "dotenv": "^17.2.1",
44
+ {{#if (or (includes transports 'streamable') (includes transports 'sse'))}}
32
45
  "express": "^5.1.0",
33
46
  "nanoid": "^5.1.5",
34
- "node-fetch": "^3.3.2",
47
+ {{/if}}
35
48
  "yargs": "^17.7.2",
36
49
  "zod": "^3.25.76"
37
50
  },
38
51
  "devDependencies": {
52
+ {{#if (includes plugins 'commitlint')}}
39
53
  "@commitlint/cli": "^19.8.1",
40
54
  "@commitlint/config-conventional": "^19.8.1",
55
+ {{/if}}
56
+ {{#if (includes plugins 'inspector')}}
41
57
  "@modelcontextprotocol/inspector": "^0.16.2",
58
+ {{/if}}
59
+ {{#if (includes plugins 'vitest')}}
42
60
  "@vitest/coverage-v8": "^3.2.4",
43
61
  "c8": "^10.1.3",
62
+ {{/if}}
63
+ {{#if (includes plugins 'changelog')}}
44
64
  "compare-func": "^2.0.0",
65
+ {{/if}}
45
66
  "concurrently": "^9.2.0",
67
+ {{#if (includes plugins 'changelog')}}
46
68
  "conventional-changelog-angular": "^8.0.0",
47
69
  "conventional-changelog-cli": "^5.0.0",
70
+ {{/if}}
48
71
  "cross-env": "^10.0.0",
49
72
  "esbuild": "^0.25.8",
73
+ {{#if (includes plugins 'style')}}
50
74
  "eslint": "^9.32.0",
51
75
  "eslint-plugin-import": "^2.32.0",
52
76
  "eslint-plugin-prettier": "^5.5.3",
53
77
  "globals": "^16.3.0",
78
+ {{/if}}
54
79
  "husky": "^9.1.7",
80
+ {{#if (includes plugins 'style')}}
55
81
  "lint-staged": "^16.1.4",
82
+ {{/if}}
83
+ {{#if (includes plugins 'vitest')}}
56
84
  "nyc": "^17.1.0",
85
+ {{/if}}
86
+ {{#if (includes plugins 'style')}}
57
87
  "prettier": "^3.6.2",
58
- "rimraf": "^6.0.1",
88
+ {{/if}}
89
+ {{#if (includes plugins 'inspector')}}
59
90
  "tree-kill": "^1.2.2",
60
- "vitest": "^3.2.4"
91
+ {{/if}}
92
+ {{#if (includes plugins 'vitest')}}
93
+ "vitest": "^3.2.4",
94
+ {{/if}}
95
+ "rimraf": "^6.0.1"
61
96
  }
62
97
  }
@@ -1,16 +1,22 @@
1
1
  import path from 'path'
2
2
  import { fileURLToPath } from 'url'
3
3
  import { promises as fs } from 'fs'
4
+ {{#if (includes plugins 'inspector')}}
4
5
  import { spawn } from 'child_process'
6
+ {{/if}}
5
7
  import { rimraf } from 'rimraf'
8
+ {{#if (includes plugins 'inspector')}}
6
9
  import kill from 'tree-kill'
10
+ {{/if}}
7
11
 
8
12
  const __dirname = path.dirname(fileURLToPath(import.meta.url))
9
13
  const isProd = process.env.NODE_ENV === 'production'
10
14
  const isDev = process.env.NODE_ENV === 'local'
15
+ {{#if (includes plugins 'inspector')}}
11
16
  let inspectorProcess = null
12
17
  let webProcess = null
13
18
  let autoOpenBrowser = true
19
+ {{/if}}
14
20
 
15
21
  /** @type {import('esbuild').BuildOptions} */
16
22
  export const config = {
@@ -21,7 +27,7 @@ export const config = {
21
27
  sourcemap: isDev,
22
28
  minify: isProd,
23
29
  platform: 'node',
24
- external: ['yargs', 'node-fetch', 'cors', 'express', 'nanoid', 'zod', 'dotenv', '@modelcontextprotocol/sdk'],
30
+ external: ['yargs', 'express', 'nanoid', 'zod', 'dotenv', '@modelcontextprotocol/sdk'],
25
31
  alias: {
26
32
  '@': path.resolve(__dirname, '../src'),
27
33
  },
@@ -53,11 +59,10 @@ const after = async result => {
53
59
  } else {
54
60
  console.error('❌ Rebuild failed')
55
61
  }
56
-
62
+ {{#if (includes plugins 'inspector')}}
57
63
  console.log('🚀 Starting @modelcontextprotocol/inspector...')
58
64
  if (inspectorProcess) {
59
65
  kill(inspectorProcess.pid, 'SIGINT')
60
- // inspectorProcess.kill('SIGINT')
61
66
  }
62
67
  inspectorProcess = spawn('npx', ['@modelcontextprotocol/inspector', 'build/index.js'], {
63
68
  stdio: 'inherit',
@@ -78,5 +83,6 @@ const after = async result => {
78
83
  stdio: 'inherit',
79
84
  })
80
85
  }
86
+ {{/if}}
81
87
  }
82
88
  }
@@ -1,28 +1,39 @@
1
1
  #!/usr/bin/env node
2
2
  import yargs from 'yargs'
3
3
  import { hideBin } from 'yargs/helpers'
4
+ {{#if (and (includes transports 'stdio') (or (includes transports 'streamable') (includes transports 'sse')))}}
4
5
  import { startWebServer, startStdioServer } from './services/index.js'
6
+ {{else if (includes transports 'stdio')}}
7
+ import { startStdioServer } from './services/index.js'
8
+ {{else}}
9
+ import { startWebServer } from './services/index.js'
10
+ {{/if}}
5
11
  import { getOptions } from './utils/index.js'
6
12
  import 'dotenv/config'
7
13
  import pkg from '../package.json' with { type: 'json' }
8
14
 
9
- const name = 'node-mcp-server'
15
+ const name = '{{projectName}}'
10
16
 
11
17
  const argv = await yargs()
12
18
  .scriptName(name)
13
19
  .usage('$0 <command> [options]')
20
+ {{#if (includes transports 'stdio')}}
14
21
  .command(
15
22
  'stdio',
16
23
  'Start the server using the stdio transport protocol.',
17
24
  () => {},
18
25
  argv => startServer('stdio', argv),
19
26
  )
27
+ {{/if}}
28
+ {{#if (or (includes transports 'streamable') (includes transports 'sse'))}}
20
29
  .command(
21
30
  'web',
22
31
  'Start the web server transport protocol.',
23
32
  () => {},
24
33
  argv => startServer('web', argv),
25
34
  )
35
+ {{/if}}
36
+ {{#if (or (includes transports 'streamable') (includes transports 'sse'))}}
26
37
  .options({
27
38
  port: {
28
39
  describe: 'Specify the port for SSE or streamable transport (default: 8401)',
@@ -30,11 +41,16 @@ const argv = await yargs()
30
41
  default: process.env.PORT || '8401',
31
42
  },
32
43
  })
44
+ {{/if}}
33
45
  .help()
34
46
  .parse(hideBin(process.argv))
35
47
 
36
48
  if (!argv._[0]) {
49
+ {{#if (includes transports 'stdio')}}
37
50
  startServer('stdio', argv)
51
+ {{else}}
52
+ startServer('web', argv)
53
+ {{/if}}
38
54
  }
39
55
 
40
56
  async function startServer(mode, argv) {
@@ -42,9 +58,19 @@ async function startServer(mode, argv) {
42
58
  name,
43
59
  version: pkg.version,
44
60
  })
61
+ {{#if (and (includes transports 'stdio') (or (includes transports 'streamable') (includes transports 'sse')))}}
45
62
  if (mode === 'stdio') {
46
63
  startStdioServer(options).catch(console.error)
47
64
  } else if (mode === 'web') {
48
65
  startWebServer(options).catch(console.error)
49
66
  }
67
+ {{else if (includes transports 'stdio')}}
68
+ if (mode === 'stdio') {
69
+ startStdioServer(options).catch(console.error)
70
+ }
71
+ {{else}}
72
+ if (mode === 'web') {
73
+ startWebServer(options).catch(console.error)
74
+ }
75
+ {{/if}}
50
76
  }
@@ -2,8 +2,12 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
2
2
  import { registerTools } from '../tools/index.js'
3
3
  import { registerResources } from '../resources/index.js'
4
4
  import { registerPrompts } from '../prompts/index.js'
5
+ {{#if (includes transports 'stdio')}}
5
6
  import { stdioServer } from './stdio.js'
7
+ {{/if}}
8
+ {{#if (or (includes transports 'streamable') (includes transports 'sse'))}}
6
9
  import { webServer } from './web.js'
10
+ {{/if}}
7
11
 
8
12
  const createServer = options => {
9
13
  const server = new McpServer({
@@ -15,13 +19,17 @@ const createServer = options => {
15
19
  registerPrompts(server)
16
20
  return server
17
21
  }
22
+ {{#if (includes transports 'stdio')}}
18
23
 
19
24
  export async function startStdioServer(options) {
20
25
  const server = createServer(options)
21
26
  await stdioServer(server)
22
27
  }
28
+ {{/if}}
29
+ {{#if (or (includes transports 'streamable') (includes transports 'sse'))}}
23
30
 
24
31
  export async function startWebServer(options) {
25
32
  const server = createServer(options)
26
33
  await webServer(server, options)
27
34
  }
35
+ {{/if}}
@@ -1,6 +1,8 @@
1
+ {{#if (includes transports 'stdio')}}
1
2
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
2
3
 
3
4
  export async function stdioServer(server) {
4
5
  const transport = new StdioServerTransport()
5
6
  await server.connect(transport)
6
7
  }
8
+ {{/if}}
@@ -1,17 +1,30 @@
1
- import { nanoid } from 'nanoid'
1
+ {{#if (or (includes transports 'streamable') (includes transports 'sse'))}}
2
+ {{#if (includes transports 'streamable')}}
3
+ import { nanoid } from 'nanoid'
4
+ {{/if}}
2
5
  import express from 'express'
6
+ {{#if (includes transports 'streamable')}}
3
7
  import { isInitializeRequest } from '@modelcontextprotocol/sdk/types.js'
4
8
  import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js'
9
+ {{/if}}
10
+ {{#if (includes transports 'sse')}}
5
11
  import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js'
12
+ {{/if}}
6
13
 
7
14
  export async function webServer(server, options) {
8
15
  const app = express()
9
16
  app.use(express.json())
10
17
 
11
18
  const transports = {
19
+ {{#if (includes transports 'streamable')}}
12
20
  streamable: {},
21
+ {{/if}}
22
+ {{#if (includes transports 'sse')}}
13
23
  sse: {},
24
+ {{/if}}
14
25
  }
26
+ {{#if (includes transports 'streamable')}}
27
+
15
28
  app.post('/mcp', async (req, res) => {
16
29
  const sessionId = req.headers['mcp-session-id']
17
30
  let transport
@@ -61,6 +74,8 @@ export async function webServer(server, options) {
61
74
  app.get('/mcp', handleSessionRequest)
62
75
 
63
76
  app.delete('/mcp', handleSessionRequest)
77
+ {{/if}}
78
+ {{#if (includes transports 'sse')}}
64
79
 
65
80
  app.get('/sse', async (req, res) => {
66
81
  const transport = new SSEServerTransport('/messages', res)
@@ -83,6 +98,8 @@ export async function webServer(server, options) {
83
98
  }
84
99
  })
85
100
 
101
+ {{/if}}
86
102
  app.listen(options.port)
87
- console.log(`MCP server started on port ${options.port}. SSE endpoint: /sse, streamable endpoint: /mcp`)
103
+ console.log(`MCP server started on port ${options.port}.{{#if (includes transports 'sse')}} SSE endpoint: /sse{{/if}}{{#if (includes transports 'streamable')}} streamable endpoint: /mcp{{/if}}`)
88
104
  }
105
+ {{/if}}
@@ -1,3 +1,4 @@
1
+ {{#if (includes plugins 'vitest')}}
1
2
  import { describe, expect, test } from 'vitest'
2
3
 
3
4
  describe('echoPrompt', () => {
@@ -22,3 +23,4 @@ describe('echoPrompt', () => {
22
23
  })
23
24
  })
24
25
  })
26
+ {{/if}}
@@ -1,3 +1,4 @@
1
+ {{#if (includes plugins 'vitest')}}
1
2
  import { describe, expect, test } from 'vitest'
2
3
 
3
4
  describe('searchResource', () => {
@@ -16,3 +17,4 @@ describe('searchResource', () => {
16
17
  })
17
18
  })
18
19
  })
20
+ {{/if}}
@@ -1,3 +1,4 @@
1
+ {{#if (includes plugins 'vitest')}}
1
2
  import { describe, expect, test } from 'vitest'
2
3
 
3
4
  describe('getDataTool', () => {
@@ -40,3 +41,4 @@ describe('getDataTool', () => {
40
41
  })
41
42
  })
42
43
  })
44
+ {{/if}}
@@ -1,3 +1,4 @@
1
+ {{#if (includes plugins 'vitest')}}
1
2
  import { defineConfig } from 'vitest/config'
2
3
 
3
4
  export default defineConfig({
@@ -8,3 +9,4 @@ export default defineConfig({
8
9
  },
9
10
  },
10
11
  })
12
+ {{/if}}