create-mcp-kit 0.0.1
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/LICENSE +21 -0
- package/README.md +125 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/package.json +62 -0
- package/template/standard-ts/LICENSE +21 -0
- package/template/standard-ts/_env +1 -0
- package/template/standard-ts/_github/workflows/build.yml +34 -0
- package/template/standard-ts/_github/workflows/npm-publish.yml +36 -0
- package/template/standard-ts/_gitignore +112 -0
- package/template/standard-ts/_husky/commit-msg +1 -0
- package/template/standard-ts/_husky/pre-commit +1 -0
- package/template/standard-ts/_nvmrc +1 -0
- package/template/standard-ts/_prettierrc +11 -0
- package/template/standard-ts/changelog-option.js +87 -0
- package/template/standard-ts/commitlint.config.js +27 -0
- package/template/standard-ts/eslint.config.js +49 -0
- package/template/standard-ts/lint-staged.config.js +3 -0
- package/template/standard-ts/package.json +70 -0
- package/template/standard-ts/scripts/base.js +82 -0
- package/template/standard-ts/scripts/build.js +4 -0
- package/template/standard-ts/scripts/dev.js +7 -0
- package/template/standard-ts/src/constants/index.ts +1 -0
- package/template/standard-ts/src/index.ts +50 -0
- package/template/standard-ts/src/prompts/index.ts +28 -0
- package/template/standard-ts/src/resources/index.ts +25 -0
- package/template/standard-ts/src/services/index.ts +28 -0
- package/template/standard-ts/src/services/stdio.ts +7 -0
- package/template/standard-ts/src/services/web.ts +90 -0
- package/template/standard-ts/src/tools/index.ts +7 -0
- package/template/standard-ts/src/tools/registerGetData.ts +40 -0
- package/template/standard-ts/src/types/global.ts +5 -0
- package/template/standard-ts/src/types/index.ts +1 -0
- package/template/standard-ts/src/utils/index.ts +16 -0
- package/template/standard-ts/tests/prompts/index.test.ts +24 -0
- package/template/standard-ts/tests/resources/index.test.ts +18 -0
- package/template/standard-ts/tests/tools/index.test.ts +42 -0
- package/template/standard-ts/tests/vitest-global.d.ts +5 -0
- package/template/standard-ts/tsconfig.json +17 -0
- package/template/standard-ts/vitest.config.ts +10 -0
- package/template/standard-ts/vitest.setup.ts +25 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Watermark Design
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# create-mcp-kit
|
|
2
|
+
A CLI tool to create MCP (Model Context Protocol) applications with ease.
|
|
3
|
+
|
|
4
|
+
## Features
|
|
5
|
+
- 🚀 Quick project scaffolding
|
|
6
|
+
- 📦 TypeScript support out of the box
|
|
7
|
+
- 🛠️ Built-in development tools
|
|
8
|
+
- 🔧 Configurable project templates
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm create mcp-kit@latest
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
or
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
yarn create mcp-kit@latest
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
or
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pnpm create mcp-kit@latest
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Project Structure
|
|
29
|
+
|
|
30
|
+
```text
|
|
31
|
+
The generated project will have the following structure:
|
|
32
|
+
|
|
33
|
+
├── src/
|
|
34
|
+
│ ├── tools/ # MCP tools implementation
|
|
35
|
+
│ ├── resources/ # MCP resources implementation
|
|
36
|
+
│ ├── prompts/ # MCP prompts implementation
|
|
37
|
+
│ ├── services/ # Server implementations (stdio/web)
|
|
38
|
+
│ └── index.ts # Entry point
|
|
39
|
+
├── tests/ # Test files
|
|
40
|
+
├── scripts/ # Build and development scripts
|
|
41
|
+
├── .github/ # GitHub Actions workflows
|
|
42
|
+
└── package.json
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Development Scripts
|
|
46
|
+
|
|
47
|
+
- npm run dev - Start the development server in stdio mode
|
|
48
|
+
- npm run dev:web - Start the development server in web mode
|
|
49
|
+
- npm run build - Build the project
|
|
50
|
+
- npm run test - Run tests
|
|
51
|
+
- npm run coverage - Generate test coverage report
|
|
52
|
+
|
|
53
|
+
## Features
|
|
54
|
+
### MCP Tools
|
|
55
|
+
Implement custom tools that can be used by MCP clients:
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
server.registerTool(
|
|
59
|
+
'GetData',
|
|
60
|
+
{
|
|
61
|
+
title: 'Get Data',
|
|
62
|
+
description: 'Get Data',
|
|
63
|
+
inputSchema: {
|
|
64
|
+
keyword: z.string().describe('search keyword'),
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
async ({ keyword }) => {
|
|
68
|
+
// Your implementation
|
|
69
|
+
}
|
|
70
|
+
)
|
|
71
|
+
```
|
|
72
|
+
### MCP Resources
|
|
73
|
+
Define resources that can be accessed by MCP clients:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
server.registerResource(
|
|
77
|
+
'search',
|
|
78
|
+
new ResourceTemplate('search://{keyword}', {
|
|
79
|
+
list: undefined,
|
|
80
|
+
}),
|
|
81
|
+
{
|
|
82
|
+
title: 'Search Resource',
|
|
83
|
+
description: 'Dynamic generate search resource',
|
|
84
|
+
},
|
|
85
|
+
async (uri, { keyword }) => {
|
|
86
|
+
// Your implementation
|
|
87
|
+
}
|
|
88
|
+
)
|
|
89
|
+
```
|
|
90
|
+
### MCP Prompts
|
|
91
|
+
Create reusable prompts for MCP clients:
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
server.registerPrompt(
|
|
95
|
+
'echo',
|
|
96
|
+
{
|
|
97
|
+
title: 'Echo Prompt',
|
|
98
|
+
description: 'Creates a prompt to process a message.',
|
|
99
|
+
argsSchema: {
|
|
100
|
+
message: z.string(),
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
({ message }) => {
|
|
104
|
+
// Your implementation
|
|
105
|
+
}
|
|
106
|
+
)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Contributing
|
|
110
|
+
|
|
111
|
+
Feel free to dive in! [Open an issue](https://github.com/my-mcp-hub/mcp-kit/issues/new/choose) or submit PRs.
|
|
112
|
+
|
|
113
|
+
Standard Readme follows the [Contributor Covenant](http://contributor-covenant.org/version/1/3/0/) Code of Conduct.
|
|
114
|
+
|
|
115
|
+
### Contributors
|
|
116
|
+
|
|
117
|
+
This project exists thanks to all the people who contribute.
|
|
118
|
+
|
|
119
|
+
<a href="https://github.com/my-mcp-hub/mcp-kit/graphs/contributors">
|
|
120
|
+
<img src="https://contrib.rocks/image?repo=my-mcp-hub/mcp-kit" />
|
|
121
|
+
</a>
|
|
122
|
+
|
|
123
|
+
## License
|
|
124
|
+
|
|
125
|
+
[MIT](LICENSE) © MichaelSun
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import*as e from"@clack/prompts";import t from"picocolors";import{fileURLToPath as r}from"url";import a,{dirname as n,join as o,resolve as s}from"path";import{cp as i,mkdir as c,readFile as p,readdir as l,rename as m,stat as g,writeFile as u}from"fs/promises";import{setTimeout as d}from"timers/promises";import{spawn as f}from"child_process";const w=n(r(import.meta.url));e.intro(t.inverse(" create-mcp-kit "));const y=await e.group({type:()=>e.select({message:"Project type:",options:[{value:"server",label:t.magenta("MCP Server")}]}),name:({results:t})=>e.text({message:"Project name:",defaultValue:`mcp-${t.type}-starter`,placeholder:`mcp-${t.type}-starter`}),language:()=>e.select({message:"Project language:",options:[{value:"ts",label:t.magenta("TypeScript")}]}),template:()=>e.select({message:"Project template:",options:[{value:"standard",label:t.magenta("Standard")}]}),install:()=>e.confirm({message:"Do you want to install dependencies?"})},{onCancel:()=>{e.cancel("Operation cancelled."),process.exit(0)}}),v=o(w,"../template",`${y.template}-${y.language}`),j=s(process.cwd(),y.name);try{await g(v)}catch{e.log.error(`Template not found: ${v}`),process.exit(1)}try{await g(j),e.log.error(`Directory ${y.name} already exists`),process.exit(1)}catch{}{const r=e.spinner();r.start("Creating project..."),await d(100);try{await async function(e,t,r){await c(e,{recursive:!0}),await i(t,e,{recursive:!0}),await async function(e){const t={_env:".env",_gitignore:".gitignore",_git:".git",_nvmrc:".nvmrc",_prettierrc:".prettierrc",_husky:".husky",_github:".github"},r=await l(e,{recursive:!0});for(const n of r)n in t&&await m(a.join(e,n),a.join(e,t[n]))}(e),await async function(e,t){const r={"{{PROJECT_NAME}}":t.projectName,"{{YEAR}}":(new Date).getFullYear().toString()},n=await l(e,{recursive:!0});for(const t of n){const n=a.join(e,t);if(!(await g(n)).isDirectory())for(const[e,t]of Object.entries(r)){const r=await p(n,"utf-8"),a=new RegExp(e,"g"),o=r.replace(a,t);await u(n,o,"utf-8")}}}(e,r)}(j,v,{projectName:y.name})}catch(t){r.stop("Failed to create project"),e.log.error(t.message),process.exit(1)}r.stop(t.green("Project created!"))}if(y.install){const r=e.spinner();r.start("Installing dependencies..."),await($=j,new Promise((e,t)=>{const r=f("npm",["install"],{cwd:$,stdio:"pipe"});r.on("close",r=>{0===r?e():t(new Error(`npm install failed with code ${r}`))}),r.on("error",t)})),r.stop(t.green("Dependencies installed!"))}var $;e.outro(`\n${t.green("✓")} Project created successfully!\n\n${t.cyan("Next steps:")}\n ${t.dim("cd")} ${y.name}\n ${t.dim("npm install")}\n ${t.dim("npm run dev")}\n\nEnjoy coding! 🎉\n `);
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,iBAEhC,SAAU,IACR,EAAM,OAAO,CACX,QAAS,oBACT,QAAS,CACP,CAAE,MAAO,KAAM,MAAO,EAAG,QAAQ,kBAIvC,SAAU,IACR,EAAM,OAAO,CACX,QAAS,oBACT,QAAS,CACP,CAAE,MAAO,WAAY,MAAO,EAAG,QAAQ,gBAI7C,QAAS,IACP,EAAM,QAAQ,CACZ,QAAS,0CAGf,CACE,SAAU,KACR,EAAM,OAAO,wBACb,QAAQ,KAAK,MAKb,EAAe,EAAK,EAAW,cAAe,GAAG,EAAM,YAAY,EAAM,YACzE,EAAa,EAAQ,QAAQ,MAAO,EAAM,MAEhD,UACQ,EAAK,EACZ,CAAA,MACC,EAAM,IAAI,MAAM,uBAAuB,KACvC,QAAQ,KAAK,EACd,CAED,UACQ,EAAK,GACX,EAAM,IAAI,MAAM,aAAa,EAAM,uBACnC,QAAQ,KAAK,EACd,CAAA,MAAS,CAEV,CACE,MAAM,EAAgB,EAAM,UAC5B,EAAc,MAAM,6BACd,EAAM,KACZ,yBD9E8ZA,EAAE,EAAEC,SAAS,EAAED,EAAE,CAAC,WAAA,UAAqB,EAAE,EAAEA,EAAE,CAAC,WAAA,UAAqB,eAAeA,GAAG,MAAM,EAAE,CAAC,KAAK,OAAO,WAAW,aAAa,KAAK,OAAO,OAAO,SAAS,YAAY,cAAc,OAAO,SAAS,QAAQ,WAAW,QAAQ,EAAEA,EAAE,CAAC,WAAA,IAAe,IAAI,MAAM,KAAK,EAAE,KAAK,SAAS,EAAE,EAAE,KAAKA,EAAE,GAAG,EAAE,KAAKA,EAAE,EAAE,IAAK,CAAjP,CAAkPA,SAAS,eAAeA,EAAE,GAAG,MAAM,EAAE,CAAC,mBAAmB,EAAE,YAAY,YAAW,IAAK,MAAM,cAAc,YAAY,QAAQ,EAAEA,EAAE,CAAC,WAAA,IAAe,IAAI,MAAME,KAAK,EAAE,CAAC,MAAM,EAAE,EAAE,KAAKF,EAAEE,GAAG,WAAW,EAAE,IAAI,cAAc,IAAI,MAAMF,EAAEE,KAAK,OAAO,QAAQ,GAAG,CAAC,MAAMC,QAAQ,EAAE,EAAE,SAASC,EAAE,IAAI,OAAOJ,EAAE,KAAK,EAAE,EAAE,QAAQI,EAAEF,SAAS,EAAE,EAAE,EAAE,QAAS,CAAC,CAAC,CAA1U,CAA2UF,EAAEC,EAAG,CC+EpiC,CAAc,EAAY,EAAc,CAC5C,YAAa,EAAM,MAEtB,CAAA,MAAQ,GACP,EAAc,KAAK,4BACnB,EAAM,IAAI,MAAO,EAAgB,SACjC,QAAQ,KAAK,EACd,CACD,EAAc,KAAK,EAAG,MAAM,oBAC7B,CAED,GAAI,EAAM,QAAS,CACjB,MAAM,EAAU,EAAM,UACtB,EAAQ,MAAM,oCD5F8MD,EC6FlM,ED7F4M,IAAI,QAAQ,CAAC,EAAE,KAAK,MAAM,EAAE,EAAE,MAAM,CAAC,WAAW,CAAC,IAAIA,EAAE,MAAM,SAAS,EAAE,GAAG,QAAQ,IAAI,IAAIA,EAAE,IAAI,EAAE,IAAI,MAAM,gCAAgCA,QAAQ,EAAE,GAAG,QAAQ,MC8FxY,EAAQ,KAAK,EAAG,MAAM,2BACvB,CD/FkN,IAAWA,ECiG9N,EAAM,MAAM,KACV,EAAG,MAAM,yCAET,EAAG,KAAK,qBACN,EAAG,IAAI,SAAS,EAAM,WACtB,EAAG,IAAI,qBACP,EAAG,IAAI"}
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-mcp-kit",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "create mcp tool kit",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"author": "zhensherlock",
|
|
7
|
+
"homepage": "https://github.com/my-mcp-hub/mcp-kit/tree/master/packages/create#readme",
|
|
8
|
+
"bin": {
|
|
9
|
+
"create-mcp-kit": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"mcp",
|
|
13
|
+
"mcp server",
|
|
14
|
+
"mcp client",
|
|
15
|
+
"mcp kit",
|
|
16
|
+
"mcp tool kit",
|
|
17
|
+
"create mcp",
|
|
18
|
+
"create mcp server",
|
|
19
|
+
"create mcp client",
|
|
20
|
+
"modelcontextprotocol",
|
|
21
|
+
"typescript"
|
|
22
|
+
],
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"registry": "https://registry.npmjs.org/",
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"template",
|
|
31
|
+
"LICENSE",
|
|
32
|
+
"README.md"
|
|
33
|
+
],
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/my-mcp-hub/mcp-kit.git"
|
|
37
|
+
},
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/my-mcp-hub/mcp-kit/issues"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@clack/prompts": "^0.11.0",
|
|
43
|
+
"picocolors": "^1.1.1",
|
|
44
|
+
"@mcp-tool-kit/shared": "^0.0.2"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@modelcontextprotocol/sdk": "^1.17.0",
|
|
48
|
+
"@types/express": "^5.0.3",
|
|
49
|
+
"@types/yargs": "^17.0.33",
|
|
50
|
+
"express": "^5.1.0",
|
|
51
|
+
"nanoid": "^5.1.5",
|
|
52
|
+
"yargs": "^17.7.2",
|
|
53
|
+
"zod": "^3.25.76"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"clean:dist": "rimraf dist",
|
|
57
|
+
"build:types": "tsc --noEmit",
|
|
58
|
+
"build": "npm run clean:dist && npm run build:types && rolldown -c rolldown.config.ts",
|
|
59
|
+
"dev": "rolldown -c rolldown.config.ts --watch",
|
|
60
|
+
"start": "node ./dist/index.js"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) {{YEAR}} {{PROJECT_NAME}}
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
PORT=8401
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
name: build
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
build:
|
|
10
|
+
if: github.repository == '{{PROJECT_NAME}}'
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- name: Checkout
|
|
14
|
+
uses: actions/checkout@v4
|
|
15
|
+
with:
|
|
16
|
+
fetch-depth: 0
|
|
17
|
+
|
|
18
|
+
- name: Install Node
|
|
19
|
+
uses: actions/setup-node@v4
|
|
20
|
+
with:
|
|
21
|
+
node-version: 22
|
|
22
|
+
cache: npm
|
|
23
|
+
|
|
24
|
+
- name: Install Package
|
|
25
|
+
run: npm i
|
|
26
|
+
|
|
27
|
+
- name: Build Package
|
|
28
|
+
run: npm run build
|
|
29
|
+
|
|
30
|
+
- name: Test Package
|
|
31
|
+
run: npm run coverage
|
|
32
|
+
|
|
33
|
+
- name: Coveralls
|
|
34
|
+
uses: coverallsapp/github-action@v2
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
name: npm-publish
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [created]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
build:
|
|
9
|
+
if: github.repository == '{{PROJECT_NAME}}'
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
permissions:
|
|
12
|
+
contents: read
|
|
13
|
+
id-token: write
|
|
14
|
+
steps:
|
|
15
|
+
- name: Checkout
|
|
16
|
+
uses: actions/checkout@v4
|
|
17
|
+
with:
|
|
18
|
+
fetch-depth: 0
|
|
19
|
+
|
|
20
|
+
- name: Install Node
|
|
21
|
+
uses: actions/setup-node@v4
|
|
22
|
+
with:
|
|
23
|
+
node-version: 22
|
|
24
|
+
registry-url: https://registry.npmjs.org/
|
|
25
|
+
cache: npm
|
|
26
|
+
|
|
27
|
+
- name: Install Package
|
|
28
|
+
run: npm i
|
|
29
|
+
|
|
30
|
+
- name: Build Package
|
|
31
|
+
run: npm run build
|
|
32
|
+
|
|
33
|
+
- name: Publish NPM Package
|
|
34
|
+
run: npm publish --provenance --access public
|
|
35
|
+
env:
|
|
36
|
+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
.DS_Store
|
|
2
|
+
.idea/
|
|
3
|
+
# Logs
|
|
4
|
+
logs
|
|
5
|
+
*.log
|
|
6
|
+
npm-debug.log*
|
|
7
|
+
yarn-debug.log*
|
|
8
|
+
yarn-error.log*
|
|
9
|
+
lerna-debug.log*
|
|
10
|
+
|
|
11
|
+
# Diagnostic reports (https://nodejs.org/api/report.html)
|
|
12
|
+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
|
13
|
+
|
|
14
|
+
# Runtime data
|
|
15
|
+
pids
|
|
16
|
+
*.pid
|
|
17
|
+
*.seed
|
|
18
|
+
*.pid.lock
|
|
19
|
+
|
|
20
|
+
# Directory for instrumented libs generated by jscoverage/JSCover
|
|
21
|
+
lib-cov
|
|
22
|
+
|
|
23
|
+
# Coverage directory used by tools like istanbul
|
|
24
|
+
coverage
|
|
25
|
+
*.lcov
|
|
26
|
+
|
|
27
|
+
# nyc test coverage
|
|
28
|
+
.nyc_output
|
|
29
|
+
|
|
30
|
+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
|
31
|
+
.grunt
|
|
32
|
+
|
|
33
|
+
# Bower dependency directory (https://bower.io/)
|
|
34
|
+
bower_components
|
|
35
|
+
|
|
36
|
+
# node-waf configuration
|
|
37
|
+
.lock-wscript
|
|
38
|
+
|
|
39
|
+
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
|
40
|
+
build/Release
|
|
41
|
+
|
|
42
|
+
# Dependency directories
|
|
43
|
+
node_modules/
|
|
44
|
+
jspm_packages/
|
|
45
|
+
|
|
46
|
+
# TypeScript v1 declaration files
|
|
47
|
+
typings/
|
|
48
|
+
|
|
49
|
+
# TypeScript cache
|
|
50
|
+
*.tsbuildinfo
|
|
51
|
+
|
|
52
|
+
# Optional npm cache directory
|
|
53
|
+
.npm
|
|
54
|
+
|
|
55
|
+
# Optional eslint cache
|
|
56
|
+
.eslintcache
|
|
57
|
+
|
|
58
|
+
# Microbundle cache
|
|
59
|
+
.rpt2_cache/
|
|
60
|
+
.rts2_cache_cjs/
|
|
61
|
+
.rts2_cache_es/
|
|
62
|
+
.rts2_cache_umd/
|
|
63
|
+
|
|
64
|
+
# Optional REPL history
|
|
65
|
+
.node_repl_history
|
|
66
|
+
|
|
67
|
+
# Output of 'npm pack'
|
|
68
|
+
*.tgz
|
|
69
|
+
|
|
70
|
+
# Yarn Integrity file
|
|
71
|
+
.yarn-integrity
|
|
72
|
+
|
|
73
|
+
# dotenv environment variables file
|
|
74
|
+
#.env
|
|
75
|
+
.env.test
|
|
76
|
+
|
|
77
|
+
# parcel-bundler cache (https://parceljs.org/)
|
|
78
|
+
.cache
|
|
79
|
+
|
|
80
|
+
# Next.js build output
|
|
81
|
+
.next
|
|
82
|
+
|
|
83
|
+
# Nuxt.js build / generate output
|
|
84
|
+
.nuxt
|
|
85
|
+
dist
|
|
86
|
+
|
|
87
|
+
# Gatsby files
|
|
88
|
+
.cache/
|
|
89
|
+
# Comment in the public line in if your project uses Gatsby and *not* Next.js
|
|
90
|
+
# https://nextjs.org/blog/next-9-1#public-directory-support
|
|
91
|
+
# public
|
|
92
|
+
|
|
93
|
+
# vuepress build output
|
|
94
|
+
.vuepress/dist
|
|
95
|
+
|
|
96
|
+
# Serverless directories
|
|
97
|
+
.serverless/
|
|
98
|
+
|
|
99
|
+
# FuseBox cache
|
|
100
|
+
.fusebox/
|
|
101
|
+
|
|
102
|
+
# DynamoDB Local files
|
|
103
|
+
.dynamodb/
|
|
104
|
+
|
|
105
|
+
# TernJS port file
|
|
106
|
+
.tern-port
|
|
107
|
+
|
|
108
|
+
/docs/.vitepress/cache/
|
|
109
|
+
|
|
110
|
+
stats.html
|
|
111
|
+
|
|
112
|
+
build/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
npx --no-install commitlint --edit $1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
npx lint-staged
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
v22
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import compareFunc from 'compare-func'
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
writerOpts: {
|
|
5
|
+
transform: (commit, context) => {
|
|
6
|
+
let discard = true
|
|
7
|
+
const issues = []
|
|
8
|
+
|
|
9
|
+
const newCommit = {
|
|
10
|
+
...commit,
|
|
11
|
+
notes: commit.notes.map(note => ({
|
|
12
|
+
...note,
|
|
13
|
+
title: 'BREAKING CHANGES',
|
|
14
|
+
})),
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (newCommit.notes.length > 0) {
|
|
18
|
+
discard = false
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const typeMap = {
|
|
22
|
+
feat: '✨ Features | 新功能',
|
|
23
|
+
fix: '🐛 Bug Fixes | Bug 修复',
|
|
24
|
+
perf: '⚡ Performance Improvements | 性能优化',
|
|
25
|
+
revert: '⏪ Reverts | 回退',
|
|
26
|
+
refactor: '♻ Code Refactoring | 代码重构',
|
|
27
|
+
test: '✅ Tests | 测试',
|
|
28
|
+
build: '👷 Build System | 构建',
|
|
29
|
+
chore: '🎫 Chores | 其他更新',
|
|
30
|
+
style: '💄 Styles | 风格',
|
|
31
|
+
ci: '🔧 Continuous Integration | CI 配置',
|
|
32
|
+
docs: '📝 Documentation | 文档',
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (typeMap[newCommit.type]) {
|
|
36
|
+
newCommit.type = typeMap[newCommit.type]
|
|
37
|
+
} else if (newCommit.type === 'revert' || newCommit.revert) {
|
|
38
|
+
newCommit.type = typeMap['revert']
|
|
39
|
+
} else if (discard) {
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (newCommit.scope === '*') {
|
|
44
|
+
newCommit.scope = ''
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (typeof newCommit.hash === 'string') {
|
|
48
|
+
newCommit.shortHash = newCommit.hash.substring(0, 7)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (typeof newCommit.subject === 'string') {
|
|
52
|
+
let url = context.repository ? `${context.host}/${context.owner}/${context.repository}` : context.repoUrl
|
|
53
|
+
|
|
54
|
+
if (url) {
|
|
55
|
+
url = `${url}/issues/`
|
|
56
|
+
newCommit.subject = newCommit.subject.replace(/#([0-9]+)/g, (_, issue) => {
|
|
57
|
+
issues.push(issue)
|
|
58
|
+
return `[#${issue}](${url}${issue})`
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (context.host) {
|
|
63
|
+
newCommit.subject = newCommit.subject.replace(/\B@([a-z0-9](?:-?[a-z0-9/]){0,38})/g, (_, username) => {
|
|
64
|
+
if (username.includes('/')) {
|
|
65
|
+
return `@${username}`
|
|
66
|
+
}
|
|
67
|
+
return `[@${username}](${context.host}/${username})`
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
newCommit.references = newCommit.references.filter(reference => {
|
|
73
|
+
if (issues.indexOf(reference.issue) === -1) {
|
|
74
|
+
return true
|
|
75
|
+
}
|
|
76
|
+
return false
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
return newCommit
|
|
80
|
+
},
|
|
81
|
+
groupBy: 'type',
|
|
82
|
+
commitGroupsSort: 'title',
|
|
83
|
+
commitsSort: ['scope', 'subject'],
|
|
84
|
+
noteGroupsSort: 'title',
|
|
85
|
+
notesSort: compareFunc,
|
|
86
|
+
},
|
|
87
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
extends: ['@commitlint/config-conventional'],
|
|
3
|
+
rules: {
|
|
4
|
+
// type 类型定义,表示 git 提交的 type 必须在以下类型范围内
|
|
5
|
+
'type-enum': [
|
|
6
|
+
2,
|
|
7
|
+
'always',
|
|
8
|
+
[
|
|
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', // 发版
|
|
22
|
+
],
|
|
23
|
+
],
|
|
24
|
+
// subject 大小写不做校验
|
|
25
|
+
'subject-case': [0],
|
|
26
|
+
},
|
|
27
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import tsParser from '@typescript-eslint/parser'
|
|
2
|
+
import tsPlugin from '@typescript-eslint/eslint-plugin'
|
|
3
|
+
import importPlugin from 'eslint-plugin-import'
|
|
4
|
+
import prettierPlugin from 'eslint-plugin-prettier'
|
|
5
|
+
import globals from 'globals'
|
|
6
|
+
|
|
7
|
+
export default [
|
|
8
|
+
{
|
|
9
|
+
ignores: ['**/build', '**/node_modules', '**/.*', '**/*.d.ts', '.husky/'],
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
files: ['src/**/*.{js,ts}', 'tests/**/*.{js,ts}'],
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
languageOptions: {
|
|
16
|
+
parser: tsParser,
|
|
17
|
+
parserOptions: {
|
|
18
|
+
ecmaVersion: 'latest',
|
|
19
|
+
sourceType: 'module',
|
|
20
|
+
},
|
|
21
|
+
globals: {
|
|
22
|
+
...globals.es2022,
|
|
23
|
+
...globals.node,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
plugins: {
|
|
27
|
+
'@typescript-eslint': tsPlugin,
|
|
28
|
+
import: importPlugin,
|
|
29
|
+
prettier: prettierPlugin,
|
|
30
|
+
},
|
|
31
|
+
rules: {
|
|
32
|
+
'prettier/prettier': 'error',
|
|
33
|
+
'no-console': 'off',
|
|
34
|
+
semi: ['warn', 'never'],
|
|
35
|
+
quotes: ['warn', 'single'],
|
|
36
|
+
'no-unused-vars': 'off',
|
|
37
|
+
'@typescript-eslint/no-unused-vars': 'warn',
|
|
38
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
39
|
+
'@typescript-eslint/no-unused-expressions': ['error', { allowShortCircuit: true, allowTernary: true }],
|
|
40
|
+
},
|
|
41
|
+
settings: {
|
|
42
|
+
'import/resolver': {
|
|
43
|
+
node: {
|
|
44
|
+
extensions: ['.js', '.ts'],
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
]
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{PROJECT_NAME}}",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "{{PROJECT_NAME}}",
|
|
5
|
+
"author": "zhensherlock",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"bin": {
|
|
9
|
+
"{{PROJECT_NAME}}": "./build/index.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"build",
|
|
13
|
+
"LICENSE",
|
|
14
|
+
"README.md"
|
|
15
|
+
],
|
|
16
|
+
"main": "build/index.js",
|
|
17
|
+
"scripts": {
|
|
18
|
+
"prepare": "husky",
|
|
19
|
+
"lint": "npx eslint \"src/**/*.{ts,js}\"",
|
|
20
|
+
"build": "tsc --noEmit && cross-env NODE_ENV=production node scripts/build.js",
|
|
21
|
+
"dev": "npm run dev:stdio",
|
|
22
|
+
"dev:stdio": "cross-env NODE_ENV=local concurrently \"tsc --noEmit --watch\" \"node scripts/dev.js\"",
|
|
23
|
+
"dev:web": "cross-env NODE_ENV=local TRANSPORT=web concurrently \"tsc --noEmit --watch\" \"node scripts/dev.js\"",
|
|
24
|
+
"test": "vitest run",
|
|
25
|
+
"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"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@modelcontextprotocol/sdk": "^1.17.0",
|
|
30
|
+
"cors": "^2.8.5",
|
|
31
|
+
"dotenv": "^17.2.1",
|
|
32
|
+
"express": "^5.1.0",
|
|
33
|
+
"nanoid": "^5.1.5",
|
|
34
|
+
"node-fetch": "^3.3.2",
|
|
35
|
+
"yargs": "^17.7.2",
|
|
36
|
+
"zod": "^3.25.76"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@commitlint/cli": "^19.8.1",
|
|
40
|
+
"@commitlint/config-conventional": "^19.8.1",
|
|
41
|
+
"@modelcontextprotocol/inspector": "^0.16.2",
|
|
42
|
+
"@types/cors": "^2.8.19",
|
|
43
|
+
"@types/express": "^5.0.3",
|
|
44
|
+
"@types/node-fetch": "^2.6.12",
|
|
45
|
+
"@types/yargs": "^17.0.33",
|
|
46
|
+
"@typescript-eslint/eslint-plugin": "^8.38.0",
|
|
47
|
+
"@typescript-eslint/parser": "^8.38.0",
|
|
48
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
49
|
+
"c8": "^10.1.3",
|
|
50
|
+
"compare-func": "^2.0.0",
|
|
51
|
+
"concurrently": "^9.2.0",
|
|
52
|
+
"conventional-changelog-angular": "^8.0.0",
|
|
53
|
+
"conventional-changelog-cli": "^5.0.0",
|
|
54
|
+
"cross-env": "^7.0.3",
|
|
55
|
+
"esbuild": "^0.25.8",
|
|
56
|
+
"eslint": "^9.32.0",
|
|
57
|
+
"eslint-plugin-import": "^2.32.0",
|
|
58
|
+
"eslint-plugin-prettier": "^5.5.3",
|
|
59
|
+
"globals": "^16.3.0",
|
|
60
|
+
"husky": "^9.1.7",
|
|
61
|
+
"lint-staged": "^16.1.2",
|
|
62
|
+
"nyc": "^17.1.0",
|
|
63
|
+
"prettier": "^3.6.2",
|
|
64
|
+
"rimraf": "^6.0.1",
|
|
65
|
+
"tree-kill": "^1.2.2",
|
|
66
|
+
"tsx": "^4.20.3",
|
|
67
|
+
"typescript": "^5.8.3",
|
|
68
|
+
"vitest": "^3.2.4"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -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.ts')],
|
|
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 @@
|
|
|
1
|
+
export const MagicSeparator = '###MAGIC###'
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import yargs, { type ArgumentsCamelCase } from 'yargs'
|
|
3
|
+
import { hideBin } from 'yargs/helpers'
|
|
4
|
+
import { startWebServer, startStdioServer } from './services'
|
|
5
|
+
import { getOptions } from './utils'
|
|
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: string, argv: ArgumentsCamelCase) {
|
|
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,28 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
3
|
+
|
|
4
|
+
export const registerPrompts = (server: McpServer) => {
|
|
5
|
+
server.registerPrompt(
|
|
6
|
+
'echo',
|
|
7
|
+
{
|
|
8
|
+
title: 'Echo Prompt',
|
|
9
|
+
description: 'Creates a prompt to process a message.',
|
|
10
|
+
argsSchema: {
|
|
11
|
+
message: z.string(),
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
({ message }) => {
|
|
15
|
+
return {
|
|
16
|
+
messages: [
|
|
17
|
+
{
|
|
18
|
+
role: 'user',
|
|
19
|
+
content: {
|
|
20
|
+
type: 'text',
|
|
21
|
+
text: `Please process this message: ${message}`,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
)
|
|
28
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { McpServer, ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
2
|
+
import type { OptionsType } from '@/types'
|
|
3
|
+
|
|
4
|
+
export const registerResources = (server: McpServer, options: OptionsType) => {
|
|
5
|
+
server.registerResource(
|
|
6
|
+
'search',
|
|
7
|
+
new ResourceTemplate('search://{keyword}', {
|
|
8
|
+
list: undefined,
|
|
9
|
+
}),
|
|
10
|
+
{
|
|
11
|
+
title: 'Search Resource',
|
|
12
|
+
description: 'Dynamic generate search resource',
|
|
13
|
+
},
|
|
14
|
+
async (uri, { keyword }) => {
|
|
15
|
+
return {
|
|
16
|
+
contents: [
|
|
17
|
+
{
|
|
18
|
+
uri: uri.href,
|
|
19
|
+
text: `search ${keyword}`,
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
)
|
|
25
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
2
|
+
import { registerTools } from '@/tools'
|
|
3
|
+
import { registerResources } from '@/resources'
|
|
4
|
+
import { registerPrompts } from '@/prompts'
|
|
5
|
+
import { stdioServer } from './stdio'
|
|
6
|
+
import { webServer } from './web'
|
|
7
|
+
import type { OptionsType } from '@/types'
|
|
8
|
+
|
|
9
|
+
const createServer = (options: OptionsType) => {
|
|
10
|
+
const server = new McpServer({
|
|
11
|
+
name: options.name,
|
|
12
|
+
version: options.version,
|
|
13
|
+
})
|
|
14
|
+
registerTools(server, options)
|
|
15
|
+
registerResources(server, options)
|
|
16
|
+
registerPrompts(server)
|
|
17
|
+
return server
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function startStdioServer(options: OptionsType) {
|
|
21
|
+
const server = createServer(options)
|
|
22
|
+
await stdioServer(server)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function startWebServer(options: OptionsType) {
|
|
26
|
+
const server = createServer(options)
|
|
27
|
+
await webServer(server, options)
|
|
28
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
2
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
3
|
+
|
|
4
|
+
export async function stdioServer(server: McpServer) {
|
|
5
|
+
const transport = new StdioServerTransport()
|
|
6
|
+
await server.connect(transport)
|
|
7
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { nanoid } from 'nanoid'
|
|
2
|
+
import express from 'express'
|
|
3
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
4
|
+
import { isInitializeRequest } from '@modelcontextprotocol/sdk/types.js'
|
|
5
|
+
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js'
|
|
6
|
+
import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js'
|
|
7
|
+
import type { OptionsType } from '@/types'
|
|
8
|
+
|
|
9
|
+
export async function webServer(server: McpServer, options: OptionsType) {
|
|
10
|
+
const app = express()
|
|
11
|
+
app.use(express.json())
|
|
12
|
+
|
|
13
|
+
const transports = {
|
|
14
|
+
streamable: {} as Record<string, StreamableHTTPServerTransport>,
|
|
15
|
+
sse: {} as Record<string, SSEServerTransport>,
|
|
16
|
+
}
|
|
17
|
+
app.post('/mcp', async (req, res) => {
|
|
18
|
+
const sessionId = req.headers['mcp-session-id'] as string | undefined
|
|
19
|
+
let transport: StreamableHTTPServerTransport
|
|
20
|
+
|
|
21
|
+
if (sessionId && transports.streamable[sessionId]) {
|
|
22
|
+
transport = transports.streamable[sessionId]
|
|
23
|
+
} else if (!sessionId && isInitializeRequest(req.body)) {
|
|
24
|
+
transport = new StreamableHTTPServerTransport({
|
|
25
|
+
sessionIdGenerator: () => nanoid(),
|
|
26
|
+
onsessioninitialized: sessionId => {
|
|
27
|
+
transports.streamable[sessionId] = transport
|
|
28
|
+
},
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
transport.onclose = () => {
|
|
32
|
+
if (transport.sessionId) {
|
|
33
|
+
delete transports.streamable[transport.sessionId]
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
await server.connect(transport)
|
|
37
|
+
} else {
|
|
38
|
+
res.status(400).json({
|
|
39
|
+
jsonrpc: '2.0',
|
|
40
|
+
error: {
|
|
41
|
+
code: -32000,
|
|
42
|
+
message: 'Bad Request: No valid session ID provided',
|
|
43
|
+
},
|
|
44
|
+
id: null,
|
|
45
|
+
})
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
await transport.handleRequest(req, res, req.body)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
const handleSessionRequest = async (req: express.Request, res: express.Response) => {
|
|
53
|
+
const sessionId = req.headers['mcp-session-id'] as string | undefined
|
|
54
|
+
if (!sessionId || !transports.streamable[sessionId]) {
|
|
55
|
+
res.status(400).send('Invalid or missing session ID')
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const transport = transports.streamable[sessionId]
|
|
60
|
+
await transport.handleRequest(req, res)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
app.get('/mcp', handleSessionRequest)
|
|
64
|
+
|
|
65
|
+
app.delete('/mcp', handleSessionRequest)
|
|
66
|
+
|
|
67
|
+
app.get('/sse', async (req, res) => {
|
|
68
|
+
const transport = new SSEServerTransport('/messages', res)
|
|
69
|
+
transports.sse[transport.sessionId] = transport
|
|
70
|
+
|
|
71
|
+
res.on('close', () => {
|
|
72
|
+
delete transports.sse[transport.sessionId]
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
await server.connect(transport)
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
app.post('/messages', async (req, res) => {
|
|
79
|
+
const sessionId = req.query.sessionId as string
|
|
80
|
+
const transport = transports.sse[sessionId]
|
|
81
|
+
if (transport) {
|
|
82
|
+
await transport.handlePostMessage(req, res, req.body)
|
|
83
|
+
} else {
|
|
84
|
+
res.status(400).send('No transport found for sessionId')
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
app.listen(options.port)
|
|
89
|
+
console.log(`MCP server started on port ${options.port}. SSE endpoint: /sse, streamable endpoint: /mcp`)
|
|
90
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import registerGetData from './registerGetData'
|
|
2
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
3
|
+
import type { OptionsType } from '@/types'
|
|
4
|
+
|
|
5
|
+
export const registerTools = (server: McpServer, options: OptionsType) => {
|
|
6
|
+
registerGetData(server, options)
|
|
7
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
3
|
+
import type { OptionsType } from '@/types'
|
|
4
|
+
|
|
5
|
+
export default function register(server: McpServer, options: OptionsType) {
|
|
6
|
+
server.registerTool(
|
|
7
|
+
'GetData',
|
|
8
|
+
{
|
|
9
|
+
title: 'Get Data',
|
|
10
|
+
description: 'Get Data',
|
|
11
|
+
inputSchema: {
|
|
12
|
+
keyword: z.string().describe('search keyword'),
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
async ({ keyword }) => {
|
|
16
|
+
const { success, data, message } = await getData(keyword, options)
|
|
17
|
+
return {
|
|
18
|
+
content: [
|
|
19
|
+
{
|
|
20
|
+
type: 'text',
|
|
21
|
+
text: success ? data! : message!,
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const getData = async (keyword: string, options: OptionsType) => {
|
|
30
|
+
if (!keyword || keyword === 'error') {
|
|
31
|
+
return {
|
|
32
|
+
success: false,
|
|
33
|
+
message: 'not found',
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
success: true,
|
|
38
|
+
data: `keyword: ${keyword};`,
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './global'
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ArgumentsCamelCase } from 'yargs'
|
|
2
|
+
import type { OptionsType } from '@/types'
|
|
3
|
+
|
|
4
|
+
export function getOptions(
|
|
5
|
+
argv: ArgumentsCamelCase,
|
|
6
|
+
pkg: {
|
|
7
|
+
name: string
|
|
8
|
+
version: string
|
|
9
|
+
},
|
|
10
|
+
) {
|
|
11
|
+
return {
|
|
12
|
+
name: pkg.name,
|
|
13
|
+
version: pkg.version,
|
|
14
|
+
port: argv.port,
|
|
15
|
+
} as OptionsType
|
|
16
|
+
}
|
|
@@ -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,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"outDir": "./build",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"paths": {
|
|
12
|
+
"@/*": ["./src/*"]
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"include": ["src", "tests", "vitest.setup.ts", "vitest.config.ts"],
|
|
16
|
+
"exclude": ["node_modules"]
|
|
17
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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: [
|
|
8
|
+
'--merge-async',
|
|
9
|
+
'--reporter=lcov',
|
|
10
|
+
'--reporter=text',
|
|
11
|
+
'tsx',
|
|
12
|
+
'./src/index.ts'
|
|
13
|
+
],
|
|
14
|
+
env: {
|
|
15
|
+
...process.env as Record<string, string>,
|
|
16
|
+
NODE_V8_COVERAGE: './coverage/tmp',
|
|
17
|
+
},
|
|
18
|
+
})
|
|
19
|
+
const client = new Client({
|
|
20
|
+
name: 'test-mcp-client',
|
|
21
|
+
version: '1.0.0',
|
|
22
|
+
})
|
|
23
|
+
await client.connect(serverParams)
|
|
24
|
+
|
|
25
|
+
global.client = client
|