@eaperezc/mcpgen 0.1.0

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 ADDED
@@ -0,0 +1,328 @@
1
+ # mcpkit
2
+
3
+ A TypeScript framework for building MCP (Model Context Protocol) servers with excellent developer experience.
4
+
5
+ ## Features
6
+
7
+ - **Class-based API** - Define tools, resources, and prompts using clean class inheritance
8
+ - **Fluent Builder** - Alternative chainable API for simple servers
9
+ - **Built-in Testing** - In-memory test client for unit testing your MCP servers
10
+ - **Structured Logging** - Pino-based logging with correlation IDs
11
+ - **Type-safe** - Full TypeScript support with Zod schema validation
12
+ - **Production Ready** - Supports stdio and HTTP transports
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install mcpkit @modelcontextprotocol/sdk
18
+ # or
19
+ pnpm add mcpkit @modelcontextprotocol/sdk
20
+ ```
21
+
22
+ ## CLI - Scaffold New Projects
23
+
24
+ The fastest way to get started is using the CLI:
25
+
26
+ ```bash
27
+ # Install globally
28
+ npm install -g mcpkit
29
+
30
+ # Create a new project
31
+ mcpkit init my-mcp-server
32
+
33
+ # Create with HTTP transport
34
+ mcpkit init my-api --transport http
35
+
36
+ # Navigate and start
37
+ cd my-mcp-server
38
+ npm install
39
+ npm run dev
40
+ ```
41
+
42
+ ### Generate Components
43
+
44
+ ```bash
45
+ # Generate a new tool
46
+ mcpkit generate tool search-users
47
+
48
+ # Generate a new resource
49
+ mcpkit g resource database
50
+
51
+ # Generate a new prompt
52
+ mcpkit new prompt summarize
53
+ ```
54
+
55
+ ### CLI Commands
56
+
57
+ | Command | Description |
58
+ |---------|-------------|
59
+ | `mcpkit init <name>` | Create a new MCP server project |
60
+ | `mcpkit init <name> --transport http` | Create with HTTP transport |
61
+ | `mcpkit generate tool <name>` | Generate a new tool |
62
+ | `mcpkit generate resource <name>` | Generate a new resource |
63
+ | `mcpkit generate prompt <name>` | Generate a new prompt |
64
+
65
+ ## Quick Start
66
+
67
+ ### Class-based API (Recommended)
68
+
69
+ ```typescript
70
+ import { McpServer, BaseTool, BaseResource } from 'mcpkit';
71
+ import { z } from 'zod';
72
+
73
+ // Define a tool
74
+ class GreetTool extends BaseTool {
75
+ name = 'greet';
76
+ description = 'Greets a user by name';
77
+
78
+ schema = z.object({
79
+ name: z.string().describe('Name to greet'),
80
+ });
81
+
82
+ async execute(input: z.infer<typeof this.schema>) {
83
+ return { content: { greeting: `Hello, ${input.name}!` } };
84
+ }
85
+ }
86
+
87
+ // Define a resource
88
+ class ConfigResource extends BaseResource {
89
+ uri = 'config://app';
90
+ name = 'App Configuration';
91
+
92
+ async read() {
93
+ return { contents: [this.json({ version: '1.0.0' })] };
94
+ }
95
+ }
96
+
97
+ // Create and start server
98
+ const server = new McpServer({
99
+ name: 'my-server',
100
+ version: '1.0.0',
101
+ });
102
+
103
+ server.tool(new GreetTool());
104
+ server.resource(new ConfigResource());
105
+ server.start();
106
+ ```
107
+
108
+ ### Fluent Builder API
109
+
110
+ ```typescript
111
+ import { createServer } from 'mcpkit';
112
+ import { z } from 'zod';
113
+
114
+ const server = createServer({ name: 'my-server', version: '1.0.0' })
115
+ .tool('greet', {
116
+ description: 'Greets a user',
117
+ schema: z.object({ name: z.string() }),
118
+ handler: async ({ name }) => ({ content: `Hello, ${name}!` }),
119
+ })
120
+ .resource('config://app', {
121
+ name: 'App Config',
122
+ read: async () => ({ version: '1.0.0' }),
123
+ })
124
+ .build();
125
+
126
+ await server.start();
127
+ ```
128
+
129
+ ## Testing
130
+
131
+ mcpkit includes a built-in test client for unit testing your MCP servers:
132
+
133
+ ```typescript
134
+ import { describe, it, expect } from 'vitest';
135
+ import { createTestClient } from 'mcpkit/testing';
136
+ import { GreetTool } from './tools/GreetTool';
137
+
138
+ describe('GreetTool', () => {
139
+ it('should greet the user', async () => {
140
+ const client = createTestClient();
141
+ client.registerTool(new GreetTool());
142
+
143
+ const result = await client.callTool('greet', { name: 'Alice' });
144
+ expect(result.content).toEqual({ greeting: 'Hello, Alice!' });
145
+ });
146
+
147
+ it('should validate input', async () => {
148
+ const client = createTestClient();
149
+ client.registerTool(new GreetTool());
150
+
151
+ await expect(client.callTool('greet', {})).rejects.toThrow();
152
+ });
153
+ });
154
+ ```
155
+
156
+ ### Testing with Server Builder
157
+
158
+ ```typescript
159
+ import { TestClient } from 'mcpkit/testing';
160
+ import { createServer } from 'mcpkit';
161
+
162
+ const server = createServer({ name: 'test', version: '1.0.0' })
163
+ .tool('add', {
164
+ description: 'Adds numbers',
165
+ schema: z.object({ a: z.number(), b: z.number() }),
166
+ handler: async ({ a, b }) => ({ content: { sum: a + b } }),
167
+ })
168
+ .build();
169
+
170
+ const client = TestClient.fromServer(server);
171
+ const result = await client.callTool('add', { a: 2, b: 3 });
172
+ // result.content = { sum: 5 }
173
+ ```
174
+
175
+ ## API Reference
176
+
177
+ ### McpServer
178
+
179
+ ```typescript
180
+ const server = new McpServer({
181
+ name: string;
182
+ version: string;
183
+ description?: string;
184
+ transport?: 'stdio' | TransportConfig;
185
+ logging?: { level?: 'debug' | 'info' | 'warn' | 'error' };
186
+ });
187
+
188
+ // Register components
189
+ server.tool(tool: BaseTool);
190
+ server.resource(resource: BaseResource);
191
+ server.prompt(prompt: BasePrompt);
192
+
193
+ // Lifecycle
194
+ await server.start();
195
+ await server.stop();
196
+ ```
197
+
198
+ ### BaseTool
199
+
200
+ ```typescript
201
+ abstract class BaseTool<TSchema extends z.ZodType> {
202
+ abstract name: string;
203
+ abstract description: string;
204
+ abstract schema: TSchema;
205
+
206
+ abstract execute(input: z.infer<TSchema>): Promise<ToolResult>;
207
+ }
208
+ ```
209
+
210
+ ### BaseResource
211
+
212
+ ```typescript
213
+ abstract class BaseResource {
214
+ abstract uri: string;
215
+ abstract name: string;
216
+ description?: string;
217
+
218
+ abstract read(): Promise<ResourceResult>;
219
+
220
+ // Helpers
221
+ protected text(content: string): ResourceContent;
222
+ protected json(data: unknown): ResourceContent;
223
+ }
224
+ ```
225
+
226
+ ### BasePrompt
227
+
228
+ ```typescript
229
+ abstract class BasePrompt<TArgs extends z.ZodType> {
230
+ abstract name: string;
231
+ description?: string;
232
+ arguments?: TArgs;
233
+
234
+ abstract render(args: z.infer<TArgs>): Promise<PromptResult>;
235
+
236
+ // Helpers
237
+ protected user(content: string): PromptMessage;
238
+ protected assistant(content: string): PromptMessage;
239
+ }
240
+ ```
241
+
242
+ ## Project Structure
243
+
244
+ When building MCP servers with mcpkit, we recommend:
245
+
246
+ ```
247
+ my-mcp-server/
248
+ ├── src/
249
+ │ ├── tools/
250
+ │ │ ├── GreetTool.ts
251
+ │ │ └── index.ts
252
+ │ ├── resources/
253
+ │ │ ├── ConfigResource.ts
254
+ │ │ └── index.ts
255
+ │ ├── prompts/
256
+ │ │ └── index.ts
257
+ │ └── index.ts
258
+ ├── tests/
259
+ │ └── tools.test.ts
260
+ ├── package.json
261
+ └── tsconfig.json
262
+ ```
263
+
264
+ ## HTTP Transport
265
+
266
+ mcpkit supports HTTP transport for remote MCP servers:
267
+
268
+ ```typescript
269
+ import { McpServer } from 'mcpkit';
270
+
271
+ const server = new McpServer({
272
+ name: 'my-http-server',
273
+ version: '1.0.0',
274
+ transport: {
275
+ type: 'http',
276
+ port: 3000,
277
+ host: '0.0.0.0', // Optional, defaults to 0.0.0.0
278
+ basePath: '/mcp', // Optional, defaults to /mcp
279
+ cors: {
280
+ origin: ['https://myapp.com'],
281
+ credentials: true,
282
+ },
283
+ },
284
+ });
285
+
286
+ server.tool(new MyTool());
287
+ await server.start();
288
+
289
+ // Server is now running at http://0.0.0.0:3000/mcp
290
+ // Health check available at http://0.0.0.0:3000/health
291
+ ```
292
+
293
+ ### CORS Configuration
294
+
295
+ ```typescript
296
+ {
297
+ transport: {
298
+ type: 'http',
299
+ port: 3000,
300
+ cors: {
301
+ origin: '*', // or ['https://example.com']
302
+ methods: ['GET', 'POST', 'OPTIONS'],
303
+ allowedHeaders: ['Content-Type', 'Authorization'],
304
+ credentials: true,
305
+ maxAge: 86400,
306
+ },
307
+ },
308
+ }
309
+ ```
310
+
311
+ ## Roadmap
312
+
313
+ - [x] Core server implementation
314
+ - [x] Tools, Resources, Prompts
315
+ - [x] Stdio transport
316
+ - [x] HTTP transport (production-ready)
317
+ - [x] Testing utilities
318
+ - [x] Structured logging
319
+ - [x] CLI scaffolding (`mcpkit init`, `mcpkit generate`)
320
+ - [ ] SSE transport
321
+ - [ ] OAuth 2.1 authentication
322
+ - [ ] API key authentication
323
+ - [ ] Middleware system
324
+ - [ ] Auto-discovery
325
+
326
+ ## License
327
+
328
+ MIT