@mcp-tool-kit/shared 0.0.7 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +242 -50
- package/dist/handlebars/register.js +4 -9
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Create-MCP-Kit
|
|
2
2
|
A CLI tool to create MCP (Model Context Protocol) applications with ease.
|
|
3
3
|
|
|
4
4
|
[![][npm-release-shield]][npm-release-link]
|
|
@@ -12,6 +12,8 @@ A CLI tool to create MCP (Model Context Protocol) applications with ease.
|
|
|
12
12
|
- 📦 TypeScript support out of the box
|
|
13
13
|
- 🛠️ Built-in development tools
|
|
14
14
|
- 🔧 Configurable project templates
|
|
15
|
+
- 🌐 Multiple Transport Modes (stdio/streamable-http/sse)
|
|
16
|
+
- 📚 Comprehensive APIs
|
|
15
17
|
|
|
16
18
|
## Usage
|
|
17
19
|
|
|
@@ -31,85 +33,275 @@ or
|
|
|
31
33
|
pnpm create mcp-kit@latest
|
|
32
34
|
```
|
|
33
35
|
|
|
34
|
-
## Project
|
|
36
|
+
## Project Types
|
|
37
|
+
|
|
38
|
+
create-mcp-kit supports generating two types of projects:
|
|
39
|
+
|
|
40
|
+
### MCP Server
|
|
41
|
+
|
|
42
|
+
Create an MCP server that provides tools, resources, and prompts for MCP clients.
|
|
43
|
+
|
|
44
|
+
#### Server Project Structure
|
|
35
45
|
|
|
36
46
|
```text
|
|
37
|
-
The generated project will have the following structure:
|
|
47
|
+
The generated server project will have the following structure:
|
|
38
48
|
|
|
39
49
|
├── src/
|
|
40
50
|
│ ├── tools/ # MCP tools implementation
|
|
51
|
+
│ │ ├── index.ts # Tools registration
|
|
52
|
+
│ │ └── register*.ts # Individual tool implementations
|
|
41
53
|
│ ├── resources/ # MCP resources implementation
|
|
54
|
+
│ │ └── index.ts # Resources registration
|
|
42
55
|
│ ├── prompts/ # MCP prompts implementation
|
|
43
|
-
│
|
|
56
|
+
│ │ └── index.ts # Prompts registration
|
|
57
|
+
│ ├── services/ # Server implementations
|
|
58
|
+
│ │ ├── stdio.ts # STDIO transport implementation
|
|
59
|
+
│ │ └── web.ts # Streamable HTTP and SSE transport implementation
|
|
44
60
|
│ └── index.ts # Entry point
|
|
45
|
-
├── tests/ # Test files
|
|
61
|
+
├── tests/ # Test files (optional)
|
|
62
|
+
├── scripts/ # Build and development scripts
|
|
63
|
+
├── .github/ # GitHub Actions workflows (optional)
|
|
64
|
+
├── .husky/ # Git hooks (optional)
|
|
65
|
+
└── package.json
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
#### Server Development Scripts
|
|
69
|
+
|
|
70
|
+
- `npm run dev` - Start the development server in stdio mode
|
|
71
|
+
- `npm run dev:web` - Start the development server in web mode
|
|
72
|
+
- `npm run build` - Build the project
|
|
73
|
+
- `npm run test` - Run tests (if vitest plugin is selected)
|
|
74
|
+
- `npm run coverage` - Generate test coverage report (if vitest plugin is selected)
|
|
75
|
+
- `npm run lint` - Run linting (if style plugin is selected)
|
|
76
|
+
|
|
77
|
+
### MCP Client
|
|
78
|
+
|
|
79
|
+
Create an MCP client that connects to MCP servers and uses their tools, resources, and prompts.
|
|
80
|
+
|
|
81
|
+
#### Client Project Structure
|
|
82
|
+
|
|
83
|
+
```text
|
|
84
|
+
The generated client project will have the following structure:
|
|
85
|
+
|
|
86
|
+
├── src/
|
|
87
|
+
│ └── index.ts # Entry point with transport implementations
|
|
88
|
+
├── tests/ # Test files (optional)
|
|
46
89
|
├── scripts/ # Build and development scripts
|
|
47
|
-
├── .github/ # GitHub Actions workflows
|
|
90
|
+
├── .github/ # GitHub Actions workflows (optional)
|
|
91
|
+
├── .husky/ # Git hooks (optional)
|
|
48
92
|
└── package.json
|
|
49
93
|
```
|
|
50
94
|
|
|
51
|
-
|
|
95
|
+
#### Client Development Scripts
|
|
52
96
|
|
|
53
|
-
- npm run dev - Start the
|
|
54
|
-
- npm run
|
|
55
|
-
- npm run
|
|
56
|
-
- npm run
|
|
57
|
-
- npm run
|
|
97
|
+
- `npm run dev` - Start the client in development mode
|
|
98
|
+
- `npm run build` - Build the project
|
|
99
|
+
- `npm run test` - Run tests (if vitest plugin is selected)
|
|
100
|
+
- `npm run coverage` - Generate test coverage report (if vitest plugin is selected)
|
|
101
|
+
- `npm run lint` - Run linting (if style plugin is selected)
|
|
58
102
|
|
|
59
103
|
## Features
|
|
60
|
-
|
|
104
|
+
|
|
105
|
+
### MCP Server Features
|
|
106
|
+
|
|
107
|
+
#### Transport Modes
|
|
108
|
+
|
|
109
|
+
MCP Server supports three transport modes:
|
|
110
|
+
|
|
111
|
+
1. **STDIO**: Communication through standard input/output streams
|
|
112
|
+
2. **Streamable HTTP**: RESTful API with streaming capabilities
|
|
113
|
+
3. **SSE (Server-Sent Events)**: Real-time event streaming from server to client
|
|
114
|
+
|
|
115
|
+
#### MCP Tools
|
|
61
116
|
Implement custom tools that can be used by MCP clients:
|
|
62
117
|
|
|
63
118
|
```ts
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
119
|
+
// Full implementation example
|
|
120
|
+
import { z } from 'zod'
|
|
121
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
122
|
+
|
|
123
|
+
export default function register(server, options) {
|
|
124
|
+
server.registerTool(
|
|
125
|
+
'GetData',
|
|
126
|
+
{
|
|
127
|
+
title: 'Get Data',
|
|
128
|
+
description: 'Get Data',
|
|
129
|
+
inputSchema: {
|
|
130
|
+
keyword: z.string().describe('search keyword'),
|
|
131
|
+
},
|
|
71
132
|
},
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
133
|
+
async ({ keyword }) => {
|
|
134
|
+
const { success, data, message } = await getData(keyword, options)
|
|
135
|
+
return {
|
|
136
|
+
content: [
|
|
137
|
+
{
|
|
138
|
+
type: 'text',
|
|
139
|
+
text: success ? data : message,
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export const getData = async (keyword, options) => {
|
|
148
|
+
if (!keyword || keyword === 'error') {
|
|
149
|
+
return {
|
|
150
|
+
success: false,
|
|
151
|
+
message: 'Invalid keyword',
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
success: true,
|
|
157
|
+
data: `Data for ${keyword}`,
|
|
75
158
|
}
|
|
76
|
-
|
|
159
|
+
}
|
|
77
160
|
```
|
|
78
|
-
|
|
161
|
+
|
|
162
|
+
#### MCP Resources
|
|
79
163
|
Define resources that can be accessed by MCP clients:
|
|
80
164
|
|
|
81
165
|
```ts
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
166
|
+
// Full implementation example
|
|
167
|
+
import { type McpServer, ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
168
|
+
import type { OptionsType } from '@/types'
|
|
169
|
+
|
|
170
|
+
export const registerResources = (server: McpServer, options: OptionsType) => {
|
|
171
|
+
server.registerResource(
|
|
172
|
+
'search',
|
|
173
|
+
new ResourceTemplate('search://{keyword}', {
|
|
174
|
+
list: undefined,
|
|
175
|
+
}),
|
|
176
|
+
{
|
|
177
|
+
title: 'Search Resource',
|
|
178
|
+
description: 'Dynamic generate search resource',
|
|
179
|
+
},
|
|
180
|
+
async (uri, { keyword }) => {
|
|
181
|
+
return {
|
|
182
|
+
contents: [
|
|
183
|
+
{
|
|
184
|
+
uri: uri.href,
|
|
185
|
+
text: `search ${keyword}`,
|
|
186
|
+
},
|
|
187
|
+
],
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
)
|
|
191
|
+
}
|
|
95
192
|
```
|
|
96
|
-
|
|
193
|
+
|
|
194
|
+
#### MCP Prompts
|
|
97
195
|
Create reusable prompts for MCP clients:
|
|
98
196
|
|
|
99
197
|
```ts
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
198
|
+
// Full implementation example
|
|
199
|
+
import { z } from 'zod'
|
|
200
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
201
|
+
|
|
202
|
+
export const registerPrompts = (server: McpServer) => {
|
|
203
|
+
server.registerPrompt(
|
|
204
|
+
'echo',
|
|
205
|
+
{
|
|
206
|
+
title: 'Echo Prompt',
|
|
207
|
+
description: 'Creates a prompt to process a message.',
|
|
208
|
+
argsSchema: {
|
|
209
|
+
message: z.string(),
|
|
210
|
+
},
|
|
107
211
|
},
|
|
212
|
+
({ message }) => {
|
|
213
|
+
return {
|
|
214
|
+
messages: [
|
|
215
|
+
{
|
|
216
|
+
role: 'user',
|
|
217
|
+
content: {
|
|
218
|
+
type: 'text',
|
|
219
|
+
text: `Please process this message: ${message}`,
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
],
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
)
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### MCP Client Features
|
|
230
|
+
|
|
231
|
+
#### Multiple Transport Modes
|
|
232
|
+
Connect to MCP servers using different transport modes:
|
|
233
|
+
|
|
234
|
+
```ts
|
|
235
|
+
// Import the MCP client
|
|
236
|
+
import { McpClient } from '@modelcontextprotocol/sdk/client/mcp.js'
|
|
237
|
+
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/transports/stdio.js'
|
|
238
|
+
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/transports/streamable-http.js'
|
|
239
|
+
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/transports/sse.js'
|
|
240
|
+
|
|
241
|
+
// Create a new MCP client
|
|
242
|
+
const client = new McpClient()
|
|
243
|
+
|
|
244
|
+
// STDIO Transport
|
|
245
|
+
const stdioClientTransport = new StdioClientTransport({
|
|
246
|
+
command: 'npx',
|
|
247
|
+
args: ['-y', '@my-mcp-hub/node-mcp-server'],
|
|
248
|
+
env: process.env,
|
|
249
|
+
})
|
|
250
|
+
await client.connect(stdioClientTransport)
|
|
251
|
+
|
|
252
|
+
// Streamable HTTP Transport
|
|
253
|
+
const streamableBaseUrl = new URL('http://localhost:8401/mcp')
|
|
254
|
+
const streamableClientTransport = new StreamableHTTPClientTransport(streamableBaseUrl)
|
|
255
|
+
await client.connect(streamableClientTransport)
|
|
256
|
+
|
|
257
|
+
// SSE Transport
|
|
258
|
+
const sseBaseUrl = new URL('http://localhost:8401/sse')
|
|
259
|
+
const sseClientTransport = new SSEClientTransport(sseBaseUrl)
|
|
260
|
+
await client.connect(sseClientTransport)
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
#### Tool Calling
|
|
264
|
+
Call tools provided by MCP servers:
|
|
265
|
+
|
|
266
|
+
```ts
|
|
267
|
+
// List available tools
|
|
268
|
+
const tools = await client.listTools()
|
|
269
|
+
console.log(tools)
|
|
270
|
+
|
|
271
|
+
// Call a tool
|
|
272
|
+
const callResult = await client.callTool({
|
|
273
|
+
name: 'GetData',
|
|
274
|
+
arguments: {
|
|
275
|
+
keyword: 'Hello',
|
|
108
276
|
},
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
277
|
+
})
|
|
278
|
+
console.log(callResult.content)
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
#### Resource Access
|
|
282
|
+
Access resources provided by MCP servers:
|
|
283
|
+
|
|
284
|
+
```ts
|
|
285
|
+
// List available resources
|
|
286
|
+
const resources = await client.listResources()
|
|
287
|
+
console.log(resources)
|
|
288
|
+
|
|
289
|
+
// Get a resource
|
|
290
|
+
const resource = await client.getResource('search://example')
|
|
291
|
+
console.log(resource.contents)
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
#### Prompt Usage
|
|
295
|
+
Use prompts provided by MCP servers:
|
|
296
|
+
|
|
297
|
+
```ts
|
|
298
|
+
// List available prompts
|
|
299
|
+
const prompts = await client.listPrompts()
|
|
300
|
+
console.log(prompts)
|
|
301
|
+
|
|
302
|
+
// Use a prompt
|
|
303
|
+
const prompt = await client.getPrompt('echo', { message: 'Hello, world!' })
|
|
304
|
+
console.log(prompt.messages)
|
|
113
305
|
```
|
|
114
306
|
|
|
115
307
|
## Contributing
|
|
@@ -2,15 +2,10 @@ import Handlebars from "handlebars";
|
|
|
2
2
|
|
|
3
3
|
//#region src/handlebars/register.ts
|
|
4
4
|
function registerHandlebarsHelpers() {
|
|
5
|
-
Handlebars.registerHelper("includes",
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Handlebars.registerHelper("
|
|
9
|
-
return a && b;
|
|
10
|
-
});
|
|
11
|
-
Handlebars.registerHelper("or", function(a, b) {
|
|
12
|
-
return a || b;
|
|
13
|
-
});
|
|
5
|
+
Handlebars.registerHelper("includes", (array, value) => array && Array.isArray(array) && array.includes(value));
|
|
6
|
+
Handlebars.registerHelper("and", (a, b) => a && b);
|
|
7
|
+
Handlebars.registerHelper("or", (a, b) => a || b);
|
|
8
|
+
Handlebars.registerHelper("eq", (a, b) => a === b);
|
|
14
9
|
}
|
|
15
10
|
|
|
16
11
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcp-tool-kit/shared",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.9",
|
|
4
|
+
"description": "A CLI tool to create MCP (Model Context Protocol) applications with ease.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "zhensherlock",
|
|
7
7
|
"homepage": "https://github.com/my-mcp-hub/mcp-kit/tree/master/packages/shared#readme",
|
|
@@ -9,11 +9,16 @@
|
|
|
9
9
|
"mcp",
|
|
10
10
|
"mcp server",
|
|
11
11
|
"mcp client",
|
|
12
|
+
"mcp host",
|
|
12
13
|
"mcp kit",
|
|
13
14
|
"mcp tool kit",
|
|
15
|
+
"mcp cli",
|
|
16
|
+
"cli",
|
|
17
|
+
"cli tool",
|
|
14
18
|
"create mcp",
|
|
15
19
|
"create mcp server",
|
|
16
20
|
"create mcp client",
|
|
21
|
+
"create mcp host",
|
|
17
22
|
"modelcontextprotocol",
|
|
18
23
|
"typescript"
|
|
19
24
|
],
|