@mcp-tool-kit/shared 0.0.8 → 0.0.10

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 (2) hide show
  1. package/README.md +246 -54
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # create-mcp-kit
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 Structure
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
45
+
46
+ ```text
47
+ The generated server project will have the following structure:
48
+
49
+ ├── src/
50
+ │ ├── tools/ # MCP tools implementation
51
+ │ │ ├── index.ts # Tools registration
52
+ │ │ └── register*.ts # Individual tool implementations
53
+ │ ├── resources/ # MCP resources implementation
54
+ │ │ └── index.ts # Resources registration
55
+ │ ├── prompts/ # MCP prompts implementation
56
+ │ │ └── index.ts # Prompts registration
57
+ │ ├── services/ # Server implementations
58
+ │ │ ├── stdio.ts # STDIO transport implementation
59
+ │ │ └── web.ts # Streamable HTTP and SSE transport implementation
60
+ │ └── index.ts # Entry point
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
35
82
 
36
83
  ```text
37
- The generated project will have the following structure:
84
+ The generated client project will have the following structure:
38
85
 
39
86
  ├── src/
40
- ├── tools/ # MCP tools implementation
41
- ├── resources/ # MCP resources implementation
42
- │ ├── prompts/ # MCP prompts implementation
43
- │ ├── services/ # Server implementations (stdio/web)
44
- │ └── index.ts # Entry point
45
- ├── tests/ # Test files
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
- ## Development Scripts
95
+ #### Client Development Scripts
52
96
 
53
- - npm run dev - Start the development server in stdio mode
54
- - npm run dev:web - Start the development server in web mode
55
- - npm run build - Build the project
56
- - npm run test - Run tests
57
- - npm run coverage - Generate test coverage report
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
- ### MCP Tools
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
- server.registerTool(
65
- 'GetData',
66
- {
67
- title: 'Get Data',
68
- description: 'Get Data',
69
- inputSchema: {
70
- keyword: z.string().describe('search keyword'),
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
- async ({ keyword }) => {
74
- // Your implementation
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
- ### MCP Resources
161
+
162
+ #### MCP Resources
79
163
  Define resources that can be accessed by MCP clients:
80
164
 
81
165
  ```ts
82
- server.registerResource(
83
- 'search',
84
- new ResourceTemplate('search://{keyword}', {
85
- list: undefined,
86
- }),
87
- {
88
- title: 'Search Resource',
89
- description: 'Dynamic generate search resource',
90
- },
91
- async (uri, { keyword }) => {
92
- // Your implementation
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
- ### MCP Prompts
193
+
194
+ #### MCP Prompts
97
195
  Create reusable prompts for MCP clients:
98
196
 
99
197
  ```ts
100
- server.registerPrompt(
101
- 'echo',
102
- {
103
- title: 'Echo Prompt',
104
- description: 'Creates a prompt to process a message.',
105
- argsSchema: {
106
- message: z.string(),
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
- ({ message }) => {
110
- // Your implementation
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcp-tool-kit/shared",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "A CLI tool to create MCP (Model Context Protocol) applications with ease.",
5
5
  "type": "module",
6
6
  "author": "zhensherlock",