create-mcp-kit 0.0.1 → 0.0.3

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 (45) hide show
  1. package/README.md +17 -0
  2. package/dist/index.js +89 -2
  3. package/package.json +5 -5
  4. package/template/standard-js/LICENSE +21 -0
  5. package/template/standard-js/_env +1 -0
  6. package/template/standard-js/_github/workflows/build.yml +37 -0
  7. package/template/standard-js/_github/workflows/npm-publish.yml +39 -0
  8. package/template/standard-js/_gitignore +112 -0
  9. package/template/standard-js/_husky/commit-msg +1 -0
  10. package/template/standard-js/_husky/pre-commit +1 -0
  11. package/template/standard-js/_nvmrc +1 -0
  12. package/template/standard-js/_prettierrc +11 -0
  13. package/template/standard-js/changelog-option.js +87 -0
  14. package/template/standard-js/commitlint.config.js +25 -0
  15. package/template/standard-js/eslint.config.js +42 -0
  16. package/template/standard-js/jsconfig.json +17 -0
  17. package/template/standard-js/lint-staged.config.js +3 -0
  18. package/template/standard-js/package.json +62 -0
  19. package/template/standard-js/scripts/base.js +82 -0
  20. package/template/standard-js/scripts/build.js +4 -0
  21. package/template/standard-js/scripts/dev.js +7 -0
  22. package/template/standard-js/src/constants/index.js +1 -0
  23. package/template/standard-js/src/index.js +50 -0
  24. package/template/standard-js/src/prompts/index.js +27 -0
  25. package/template/standard-js/src/resources/index.js +24 -0
  26. package/template/standard-js/src/services/index.js +27 -0
  27. package/template/standard-js/src/services/stdio.js +6 -0
  28. package/template/standard-js/src/services/web.js +88 -0
  29. package/template/standard-js/src/tools/index.js +5 -0
  30. package/template/standard-js/src/tools/registerGetData.js +38 -0
  31. package/template/standard-js/src/utils/index.js +7 -0
  32. package/template/standard-js/tests/prompts/index.test.js +24 -0
  33. package/template/standard-js/tests/resources/index.test.js +18 -0
  34. package/template/standard-js/tests/tools/index.test.js +42 -0
  35. package/template/standard-js/vitest.config.js +10 -0
  36. package/template/standard-js/vitest.setup.js +19 -0
  37. package/template/standard-ts/_github/workflows/build.yml +3 -0
  38. package/template/standard-ts/_github/workflows/npm-publish.yml +3 -0
  39. package/template/standard-ts/commitlint.config.js +13 -15
  40. package/template/standard-ts/package.json +4 -4
  41. package/template/standard-ts/src/prompts/index.ts +1 -1
  42. package/template/standard-ts/src/resources/index.ts +1 -1
  43. package/template/standard-ts/src/services/web.ts +1 -1
  44. package/template/standard-ts/vitest.setup.ts +1 -1
  45. package/dist/index.js.map +0 -1
@@ -0,0 +1,82 @@
1
+ import path from 'path'
2
+ import { fileURLToPath } from 'url'
3
+ import { promises as fs } from 'fs'
4
+ import { spawn } from 'child_process'
5
+ import { rimraf } from 'rimraf'
6
+ import kill from 'tree-kill'
7
+
8
+ const __dirname = path.dirname(fileURLToPath(import.meta.url))
9
+ const isProd = process.env.NODE_ENV === 'production'
10
+ const isDev = process.env.NODE_ENV === 'local'
11
+ let inspectorProcess = null
12
+ let webProcess = null
13
+ let autoOpenBrowser = true
14
+
15
+ /** @type {import('esbuild').BuildOptions} */
16
+ export const config = {
17
+ entryPoints: [path.resolve(__dirname, '../src/index.js')],
18
+ outfile: path.resolve(__dirname, '../build/index.js'),
19
+ format: 'esm',
20
+ bundle: true,
21
+ sourcemap: isDev,
22
+ minify: isProd,
23
+ platform: 'node',
24
+ external: ['yargs', 'node-fetch', 'cors', 'express', 'nanoid', 'zod', 'dotenv', '@modelcontextprotocol/sdk'],
25
+ alias: {
26
+ '@': path.resolve(__dirname, '../src'),
27
+ },
28
+ plugins: [
29
+ {
30
+ name: 'build-plugin',
31
+ setup(build) {
32
+ build.onStart(async result => {
33
+ await before(result)
34
+ })
35
+ build.onEnd(async result => {
36
+ await after(result)
37
+ })
38
+ },
39
+ },
40
+ ],
41
+ }
42
+
43
+ const before = async () => {
44
+ await rimraf('build')
45
+ }
46
+
47
+ const after = async result => {
48
+ await fs.chmod('build/index.js', 0o755)
49
+ console.log('✅ chmod 755 build/index.js done')
50
+ if (isDev) {
51
+ if (result.errors.length === 0) {
52
+ console.log('✅ Rebuild succeeded')
53
+ } else {
54
+ console.error('❌ Rebuild failed')
55
+ }
56
+
57
+ console.log('🚀 Starting @modelcontextprotocol/inspector...')
58
+ if (inspectorProcess) {
59
+ kill(inspectorProcess.pid, 'SIGINT')
60
+ // inspectorProcess.kill('SIGINT')
61
+ }
62
+ inspectorProcess = spawn('npx', ['@modelcontextprotocol/inspector', 'build/index.js'], {
63
+ stdio: 'inherit',
64
+ shell: true,
65
+ env: {
66
+ ...process.env,
67
+ DANGEROUSLY_OMIT_AUTH: true,
68
+ MCP_AUTO_OPEN_ENABLED: autoOpenBrowser,
69
+ },
70
+ })
71
+ autoOpenBrowser = false
72
+
73
+ if (process.env.TRANSPORT === 'web') {
74
+ if (webProcess) {
75
+ webProcess.kill('SIGINT')
76
+ }
77
+ webProcess = spawn('node', ['build/index.js', 'web'], {
78
+ stdio: 'inherit',
79
+ })
80
+ }
81
+ }
82
+ }
@@ -0,0 +1,4 @@
1
+ import esbuild from 'esbuild'
2
+ import { config } from './base.js'
3
+
4
+ esbuild.build(config).catch(() => process.exit(1))
@@ -0,0 +1,7 @@
1
+ import { context } from 'esbuild'
2
+ import { config } from './base.js'
3
+
4
+ const ctx = await context(config)
5
+ await ctx.watch()
6
+
7
+ console.log('🔍 Watching for changes...')
@@ -0,0 +1 @@
1
+ export const MagicSeparator = '###MAGIC###'
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env node
2
+ import yargs from 'yargs'
3
+ import { hideBin } from 'yargs/helpers'
4
+ import { startWebServer, startStdioServer } from './services/index.js'
5
+ import { getOptions } from './utils/index.js'
6
+ import 'dotenv/config'
7
+ import pkg from '../package.json' with { type: 'json' }
8
+
9
+ const name = 'node-mcp-server'
10
+
11
+ const argv = await yargs()
12
+ .scriptName(name)
13
+ .usage('$0 <command> [options]')
14
+ .command(
15
+ 'stdio',
16
+ 'Start the server using the stdio transport protocol.',
17
+ () => {},
18
+ argv => startServer('stdio', argv),
19
+ )
20
+ .command(
21
+ 'web',
22
+ 'Start the web server transport protocol.',
23
+ () => {},
24
+ argv => startServer('web', argv),
25
+ )
26
+ .options({
27
+ port: {
28
+ describe: 'Specify the port for SSE or streamable transport (default: 8401)',
29
+ type: 'string',
30
+ default: process.env.PORT || '8401',
31
+ },
32
+ })
33
+ .help()
34
+ .parse(hideBin(process.argv))
35
+
36
+ if (!argv._[0]) {
37
+ startServer('stdio', argv)
38
+ }
39
+
40
+ async function startServer(mode, argv) {
41
+ const options = getOptions(argv, {
42
+ name,
43
+ version: pkg.version,
44
+ })
45
+ if (mode === 'stdio') {
46
+ startStdioServer(options).catch(console.error)
47
+ } else if (mode === 'web') {
48
+ startWebServer(options).catch(console.error)
49
+ }
50
+ }
@@ -0,0 +1,27 @@
1
+ import { z } from 'zod'
2
+
3
+ export const registerPrompts = server => {
4
+ server.registerPrompt(
5
+ 'echo',
6
+ {
7
+ title: 'Echo Prompt',
8
+ description: 'Creates a prompt to process a message.',
9
+ argsSchema: {
10
+ message: z.string(),
11
+ },
12
+ },
13
+ ({ message }) => {
14
+ return {
15
+ messages: [
16
+ {
17
+ role: 'user',
18
+ content: {
19
+ type: 'text',
20
+ text: `Please process this message: ${message}`,
21
+ },
22
+ },
23
+ ],
24
+ }
25
+ },
26
+ )
27
+ }
@@ -0,0 +1,24 @@
1
+ import { ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js'
2
+
3
+ export const registerResources = (server, options) => {
4
+ server.registerResource(
5
+ 'search',
6
+ new ResourceTemplate('search://{keyword}', {
7
+ list: undefined,
8
+ }),
9
+ {
10
+ title: 'Search Resource',
11
+ description: 'Dynamic generate search resource',
12
+ },
13
+ async (uri, { keyword }) => {
14
+ return {
15
+ contents: [
16
+ {
17
+ uri: uri.href,
18
+ text: `search ${keyword}`,
19
+ },
20
+ ],
21
+ }
22
+ },
23
+ )
24
+ }
@@ -0,0 +1,27 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
2
+ import { registerTools } from '../tools/index.js'
3
+ import { registerResources } from '../resources/index.js'
4
+ import { registerPrompts } from '../prompts/index.js'
5
+ import { stdioServer } from './stdio.js'
6
+ import { webServer } from './web.js'
7
+
8
+ const createServer = options => {
9
+ const server = new McpServer({
10
+ name: options.name,
11
+ version: options.version,
12
+ })
13
+ registerTools(server, options)
14
+ registerResources(server, options)
15
+ registerPrompts(server)
16
+ return server
17
+ }
18
+
19
+ export async function startStdioServer(options) {
20
+ const server = createServer(options)
21
+ await stdioServer(server)
22
+ }
23
+
24
+ export async function startWebServer(options) {
25
+ const server = createServer(options)
26
+ await webServer(server, options)
27
+ }
@@ -0,0 +1,6 @@
1
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
2
+
3
+ export async function stdioServer(server) {
4
+ const transport = new StdioServerTransport()
5
+ await server.connect(transport)
6
+ }
@@ -0,0 +1,88 @@
1
+ import { nanoid } from 'nanoid'
2
+ import express from 'express'
3
+ import { isInitializeRequest } from '@modelcontextprotocol/sdk/types.js'
4
+ import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js'
5
+ import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js'
6
+
7
+ export async function webServer(server, options) {
8
+ const app = express()
9
+ app.use(express.json())
10
+
11
+ const transports = {
12
+ streamable: {},
13
+ sse: {},
14
+ }
15
+ app.post('/mcp', async (req, res) => {
16
+ const sessionId = req.headers['mcp-session-id']
17
+ let transport
18
+
19
+ if (sessionId && transports.streamable[sessionId]) {
20
+ transport = transports.streamable[sessionId]
21
+ } else if (!sessionId && isInitializeRequest(req.body)) {
22
+ transport = new StreamableHTTPServerTransport({
23
+ sessionIdGenerator: () => nanoid(),
24
+ onsessioninitialized: sessionId => {
25
+ transports.streamable[sessionId] = transport
26
+ },
27
+ })
28
+
29
+ transport.onclose = () => {
30
+ if (transport.sessionId) {
31
+ delete transports.streamable[transport.sessionId]
32
+ }
33
+ }
34
+ await server.connect(transport)
35
+ } else {
36
+ res.status(400).json({
37
+ jsonrpc: '2.0',
38
+ error: {
39
+ code: -32000,
40
+ message: 'Bad Request: No valid session ID provided',
41
+ },
42
+ id: null,
43
+ })
44
+ return
45
+ }
46
+
47
+ await transport.handleRequest(req, res, req.body)
48
+ })
49
+
50
+ const handleSessionRequest = async (req, res) => {
51
+ const sessionId = req.headers['mcp-session-id']
52
+ if (!sessionId || !transports.streamable[sessionId]) {
53
+ res.status(400).send('Invalid or missing session ID')
54
+ return
55
+ }
56
+
57
+ const transport = transports.streamable[sessionId]
58
+ await transport.handleRequest(req, res)
59
+ }
60
+
61
+ app.get('/mcp', handleSessionRequest)
62
+
63
+ app.delete('/mcp', handleSessionRequest)
64
+
65
+ app.get('/sse', async (req, res) => {
66
+ const transport = new SSEServerTransport('/messages', res)
67
+ transports.sse[transport.sessionId] = transport
68
+
69
+ res.on('close', () => {
70
+ delete transports.sse[transport.sessionId]
71
+ })
72
+
73
+ await server.connect(transport)
74
+ })
75
+
76
+ app.post('/messages', async (req, res) => {
77
+ const sessionId = req.query.sessionId
78
+ const transport = transports.sse[sessionId]
79
+ if (transport) {
80
+ await transport.handlePostMessage(req, res, req.body)
81
+ } else {
82
+ res.status(400).send('No transport found for sessionId')
83
+ }
84
+ })
85
+
86
+ app.listen(options.port)
87
+ console.log(`MCP server started on port ${options.port}. SSE endpoint: /sse, streamable endpoint: /mcp`)
88
+ }
@@ -0,0 +1,5 @@
1
+ import registerGetData from './registerGetData.js'
2
+
3
+ export const registerTools = (server, options) => {
4
+ registerGetData(server, options)
5
+ }
@@ -0,0 +1,38 @@
1
+ import { z } from 'zod'
2
+
3
+ export default function register(server, options) {
4
+ server.registerTool(
5
+ 'GetData',
6
+ {
7
+ title: 'Get Data',
8
+ description: 'Get Data',
9
+ inputSchema: {
10
+ keyword: z.string().describe('search keyword'),
11
+ },
12
+ },
13
+ async ({ keyword }) => {
14
+ const { success, data, message } = await getData(keyword, options)
15
+ return {
16
+ content: [
17
+ {
18
+ type: 'text',
19
+ text: success ? data : message,
20
+ },
21
+ ],
22
+ }
23
+ },
24
+ )
25
+ }
26
+
27
+ export const getData = async (keyword, options) => {
28
+ if (!keyword || keyword === 'error') {
29
+ return {
30
+ success: false,
31
+ message: 'not found',
32
+ }
33
+ }
34
+ return {
35
+ success: true,
36
+ data: `keyword: ${keyword};`,
37
+ }
38
+ }
@@ -0,0 +1,7 @@
1
+ export function getOptions(argv, pkg) {
2
+ return {
3
+ name: pkg.name,
4
+ version: pkg.version,
5
+ port: argv.port,
6
+ }
7
+ }
@@ -0,0 +1,24 @@
1
+ import { describe, expect, test } from 'vitest'
2
+
3
+ describe('echoPrompt', () => {
4
+ test('should return correct prompt content for a valid argument', async () => {
5
+ expect(
6
+ await global.client.getPrompt({
7
+ name: 'echo',
8
+ arguments: {
9
+ message: 'hello',
10
+ },
11
+ }),
12
+ ).toStrictEqual({
13
+ messages: [
14
+ {
15
+ role: 'user',
16
+ content: {
17
+ type: 'text',
18
+ text: 'Please process this message: hello',
19
+ },
20
+ },
21
+ ],
22
+ })
23
+ })
24
+ })
@@ -0,0 +1,18 @@
1
+ import { describe, expect, test } from 'vitest'
2
+
3
+ describe('searchResource', () => {
4
+ test('should return correct resource content for a valid URI', async () => {
5
+ expect(
6
+ await global.client.readResource({
7
+ uri: 'search://hello',
8
+ }),
9
+ ).toStrictEqual({
10
+ contents: [
11
+ {
12
+ uri: 'search://hello',
13
+ text: 'search hello',
14
+ },
15
+ ],
16
+ })
17
+ })
18
+ })
@@ -0,0 +1,42 @@
1
+ import { describe, expect, test } from 'vitest'
2
+
3
+ describe('getDataTool', () => {
4
+ test('returns data for a valid input', async () => {
5
+ expect(
6
+ await global.client.callTool({
7
+ name: 'GetData',
8
+ arguments: {
9
+ keyword: 'test',
10
+ },
11
+ }),
12
+ ).toStrictEqual({
13
+ content: [{ type: 'text', text: 'keyword: test;' }],
14
+ })
15
+ })
16
+
17
+ test('returns a "not found" response for an unrecognized input', async () => {
18
+ expect(
19
+ await global.client.callTool({
20
+ name: 'GetData',
21
+ arguments: {
22
+ keyword: 'error',
23
+ },
24
+ }),
25
+ ).toStrictEqual({
26
+ content: [{ type: 'text', text: 'not found' }],
27
+ })
28
+ })
29
+
30
+ test('returns a "not found" response for empty input', async () => {
31
+ expect(
32
+ await global.client.callTool({
33
+ name: 'GetData',
34
+ arguments: {
35
+ keyword: '',
36
+ },
37
+ }),
38
+ ).toStrictEqual({
39
+ content: [{ type: 'text', text: 'not found' }],
40
+ })
41
+ })
42
+ })
@@ -0,0 +1,10 @@
1
+ import { defineConfig } from 'vitest/config'
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ setupFiles: ['./vitest.setup.js'],
6
+ coverage: {
7
+ include: ['src/**/*.js'],
8
+ },
9
+ },
10
+ })
@@ -0,0 +1,19 @@
1
+ import 'dotenv/config'
2
+ import { Client } from '@modelcontextprotocol/sdk/client/index.js'
3
+ import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'
4
+
5
+ const serverParams = new StdioClientTransport({
6
+ command: 'nyc',
7
+ args: ['--merge-async', '--reporter=lcov', '--reporter=text', 'node', './src/index.js'],
8
+ env: {
9
+ ...process.env,
10
+ NODE_V8_COVERAGE: './coverage/tmp',
11
+ },
12
+ })
13
+ const client = new Client({
14
+ name: 'test-mcp-client',
15
+ version: '1.0.0',
16
+ })
17
+ await client.connect(serverParams)
18
+
19
+ global.client = client
@@ -24,6 +24,9 @@ jobs:
24
24
  - name: Install Package
25
25
  run: npm i
26
26
 
27
+ - name: Lint
28
+ run: npm run lint
29
+
27
30
  - name: Build Package
28
31
  run: npm run build
29
32
 
@@ -27,6 +27,9 @@ jobs:
27
27
  - name: Install Package
28
28
  run: npm i
29
29
 
30
+ - name: Lint
31
+ run: npm run lint
32
+
30
33
  - name: Build Package
31
34
  run: npm run build
32
35
 
@@ -1,27 +1,25 @@
1
1
  export default {
2
2
  extends: ['@commitlint/config-conventional'],
3
3
  rules: {
4
- // type 类型定义,表示 git 提交的 type 必须在以下类型范围内
5
4
  'type-enum': [
6
5
  2,
7
6
  'always',
8
7
  [
9
- 'feat', // 新功能
10
- 'fix', // 修复
11
- 'docs', // 文档变更
12
- 'style', // 代码格式
13
- 'refactor', // 重构
14
- 'perf', // 性能优化
15
- 'test', // 增加测试
16
- 'build', // 构建
17
- 'ci', // CI配置
18
- 'chore', // 构建过程或辅助工具的变动
19
- 'revert', // 回退
20
- 'build', // 打包
21
- 'release', // 发版
8
+ 'feat',
9
+ 'fix',
10
+ 'docs',
11
+ 'style',
12
+ 'refactor',
13
+ 'perf',
14
+ 'test',
15
+ 'build',
16
+ 'ci',
17
+ 'chore',
18
+ 'revert',
19
+ 'build',
20
+ 'release',
22
21
  ],
23
22
  ],
24
- // subject 大小写不做校验
25
23
  'subject-case': [0],
26
24
  },
27
25
  }
@@ -26,7 +26,7 @@
26
26
  "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 -n changelog-option.js"
27
27
  },
28
28
  "dependencies": {
29
- "@modelcontextprotocol/sdk": "^1.17.0",
29
+ "@modelcontextprotocol/sdk": "^1.17.1",
30
30
  "cors": "^2.8.5",
31
31
  "dotenv": "^17.2.1",
32
32
  "express": "^5.1.0",
@@ -41,7 +41,7 @@
41
41
  "@modelcontextprotocol/inspector": "^0.16.2",
42
42
  "@types/cors": "^2.8.19",
43
43
  "@types/express": "^5.0.3",
44
- "@types/node-fetch": "^2.6.12",
44
+ "@types/node-fetch": "^2.6.13",
45
45
  "@types/yargs": "^17.0.33",
46
46
  "@typescript-eslint/eslint-plugin": "^8.38.0",
47
47
  "@typescript-eslint/parser": "^8.38.0",
@@ -51,14 +51,14 @@
51
51
  "concurrently": "^9.2.0",
52
52
  "conventional-changelog-angular": "^8.0.0",
53
53
  "conventional-changelog-cli": "^5.0.0",
54
- "cross-env": "^7.0.3",
54
+ "cross-env": "^10.0.0",
55
55
  "esbuild": "^0.25.8",
56
56
  "eslint": "^9.32.0",
57
57
  "eslint-plugin-import": "^2.32.0",
58
58
  "eslint-plugin-prettier": "^5.5.3",
59
59
  "globals": "^16.3.0",
60
60
  "husky": "^9.1.7",
61
- "lint-staged": "^16.1.2",
61
+ "lint-staged": "^16.1.4",
62
62
  "nyc": "^17.1.0",
63
63
  "prettier": "^3.6.2",
64
64
  "rimraf": "^6.0.1",
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod'
2
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
2
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
3
3
 
4
4
  export const registerPrompts = (server: McpServer) => {
5
5
  server.registerPrompt(
@@ -1,4 +1,4 @@
1
- import { McpServer, ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js'
1
+ import { type McpServer, ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js'
2
2
  import type { OptionsType } from '@/types'
3
3
 
4
4
  export const registerResources = (server: McpServer, options: OptionsType) => {
@@ -1,9 +1,9 @@
1
1
  import { nanoid } from 'nanoid'
2
2
  import express from 'express'
3
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
4
3
  import { isInitializeRequest } from '@modelcontextprotocol/sdk/types.js'
5
4
  import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js'
6
5
  import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js'
6
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
7
7
  import type { OptionsType } from '@/types'
8
8
 
9
9
  export async function webServer(server: McpServer, options: OptionsType) {
@@ -9,7 +9,7 @@ const serverParams = new StdioClientTransport({
9
9
  '--reporter=lcov',
10
10
  '--reporter=text',
11
11
  'tsx',
12
- './src/index.ts'
12
+ './src/index.ts',
13
13
  ],
14
14
  env: {
15
15
  ...process.env as Record<string, string>,
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":["t","m","i","r","n"],"sources":["../../shared/dist/projectSetup.js","../src/index.ts"],"sourcesContent":["import{setTimeout as t}from\"timers/promises\";import{cp as i,mkdir as r,readFile as o,readdir as e,rename as n,stat as s,writeFile as a}from\"fs/promises\";import c from\"path\";import{spawn as f}from\"child_process\";function m(t){return new Promise((i,r)=>{const o=f(\"npm\",[\"install\"],{cwd:t,stdio:\"pipe\"});o.on(\"close\",t=>{0===t?i():r(new Error(`npm install failed with code ${t}`))}),o.on(\"error\",r)})}async function p(t,f,m){await r(t,{recursive:!0}),await i(f,t,{recursive:!0}),await async function(t){const i={_env:\".env\",_gitignore:\".gitignore\",_git:\".git\",_nvmrc:\".nvmrc\",_prettierrc:\".prettierrc\",_husky:\".husky\",_github:\".github\"},r=await e(t,{recursive:!0});for(const o of r)o in i&&await n(c.join(t,o),c.join(t,i[o]))}(t),await async function(t,i){const r={\"{{PROJECT_NAME}}\":i.projectName,\"{{YEAR}}\":(new Date).getFullYear().toString()},n=await e(t,{recursive:!0});for(const i of n){const e=c.join(t,i);if(!(await s(e)).isDirectory())for(const[t,i]of Object.entries(r)){const r=await o(e,\"utf-8\"),n=new RegExp(t,\"g\"),s=r.replace(n,i);await a(e,s,\"utf-8\")}}}(t,m)}export{p as createProject,m as installDependencies,t as sleep};\n//# sourceMappingURL=projectSetup.js.map","#!/usr/bin/env node\nimport * as clack from '@clack/prompts'\nimport pc from 'picocolors'\nimport { fileURLToPath } from 'url'\nimport { dirname, join, resolve } from 'path'\nimport { stat } from 'fs/promises'\nimport { sleep, createProject, installDependencies } from '@mcp-tool-kit/shared'\n\nconst __filename = fileURLToPath(import.meta.url)\nconst __dirname = dirname(__filename)\nclack.intro(pc.inverse(' create-mcp-kit '))\n\nconst group = await clack.group(\n {\n type: () =>\n clack.select({\n message: 'Project type:',\n options: [\n { value: 'server', label: pc.magenta('MCP Server') },\n // { value: 'client', label: pc.blue('MCP Client') },\n // { value: 'host', label: pc.green('MCP Host') },\n ],\n }),\n name: ({ results }) =>\n clack.text({\n message: 'Project name:',\n defaultValue: `mcp-${results.type}-starter`,\n placeholder: `mcp-${results.type}-starter`,\n }),\n language: () =>\n clack.select({\n message: 'Project language:',\n options: [\n { value: 'ts', label: pc.magenta('TypeScript') },\n // { value: 'js', label: pc.blue('JavaScript') },\n ],\n }),\n template: () =>\n clack.select({\n message: 'Project template:',\n options: [\n { value: 'standard', label: pc.magenta('Standard') },\n // { value: 'custom', label: pc.blue('Custom') },\n ],\n }),\n install: () =>\n clack.confirm({\n message: 'Do you want to install dependencies?',\n }),\n },\n {\n onCancel: () => {\n clack.cancel('Operation cancelled.')\n process.exit(0)\n },\n },\n)\n\nconst templatePath = join(__dirname, '../template', `${group.template}-${group.language}`)\nconst targetPath = resolve(process.cwd(), group.name as string)\n\ntry {\n await stat(templatePath)\n} catch {\n clack.log.error(`Template not found: ${templatePath}`)\n process.exit(1)\n}\n\ntry {\n await stat(targetPath)\n clack.log.error(`Directory ${group.name} already exists`)\n process.exit(1)\n} catch {}\n\n{\n const createSpinner = clack.spinner()\n createSpinner.start('Creating project...')\n await sleep(100)\n try {\n await createProject(targetPath, templatePath, {\n projectName: group.name as string,\n })\n } catch (error) {\n createSpinner.stop('Failed to create project')\n clack.log.error((error as Error).message)\n process.exit(1)\n }\n createSpinner.stop(pc.green('Project created!'))\n}\n\nif (group.install) {\n const spinner = clack.spinner()\n spinner.start('Installing dependencies...')\n await installDependencies(targetPath)\n spinner.stop(pc.green('Dependencies installed!'))\n}\n\nclack.outro(`\n${pc.green('✓')} Project created successfully!\n\n${pc.cyan('Next steps:')}\n ${pc.dim('cd')} ${group.name}\n ${pc.dim('npm install')}\n ${pc.dim('npm run dev')}\n\nEnjoy coding! 🎉\n `)\n"],"mappings":";uVCQA,MACM,EAAY,EADC,cAA0B,MAE7C,EAAM,MAAM,EAAG,QAAQ,qBAEvB,MAAM,QAAc,EAAM,MACxB,CACE,KAAM,IACJ,EAAM,OAAO,CACX,QAAS,gBACT,QAAS,CACP,CAAE,MAAO,SAAU,MAAO,EAAG,QAAQ,kBAK3C,KAAM,EAAG,aACP,EAAM,KAAK,CACT,QAAS,gBACT,aAAc,OAAO,EAAQ,eAC7B,YAAa,OAAO,EAAQ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