@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 +328 -0
- package/dist/cli/index.cjs +625 -0
- package/dist/cli/index.cjs.map +1 -0
- package/dist/cli/index.d.cts +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +623 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/index.cjs +1516 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +297 -0
- package/dist/index.d.ts +297 -0
- package/dist/index.js +1481 -0
- package/dist/index.js.map +1 -0
- package/dist/testing/index.cjs +1056 -0
- package/dist/testing/index.cjs.map +1 -0
- package/dist/testing/index.d.cts +183 -0
- package/dist/testing/index.d.ts +183 -0
- package/dist/testing/index.js +1049 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/types-B9yzEar_.d.cts +895 -0
- package/dist/types-B9yzEar_.d.ts +895 -0
- package/package.json +81 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { I as InlineToolDefinition, c as InlineResourceDefinition, d as InlinePromptDefinition, T as TransportConfig, e as AuthConfig, L as LogLevel, S as ServerHooks, M as McpServer, f as Logger, R as RequestContextData, A as AuthContext, g as Transport, H as HttpTransportConfig } from './types-B9yzEar_.js';
|
|
2
|
+
export { k as ApiKeyConfig, l as ApiKeyValidationResult, b as BasePrompt, a as BaseResource, B as BaseTool, U as ContextKey, Y as CorsConfig, K as LogEntry, Q as LogTransport, N as LoggerConfig, O as OAuthConfig, F as PromptArgumentMetadata, C as PromptDefinition, E as PromptHandler, z as PromptMessage, G as PromptMetadata, P as PromptRegistry, D as PromptResult, y as PromptRole, s as ResourceContent, t as ResourceDefinition, v as ResourceHandler, w as ResourceMetadata, r as ResourceRegistry, u as ResourceResult, x as ResourceTemplate, j as ServerCapabilities, h as ServerConfig, i as ServerInfo, X as SseTransportConfig, W as StdioTransportConfig, Z as TlsConfig, n as ToolDefinition, p as ToolHandler, q as ToolMetadata, m as ToolRegistry, o as ToolResult, V as TransportType, J as logger } from './types-B9yzEar_.js';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
export { z } from 'zod';
|
|
5
|
+
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
6
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Fluent builder for creating MCP servers
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const server = createServer({ name: 'my-server', version: '1.0.0' })
|
|
14
|
+
* .tool('greet', {
|
|
15
|
+
* description: 'Greets a user',
|
|
16
|
+
* schema: z.object({ name: z.string() }),
|
|
17
|
+
* handler: async ({ name }) => ({ content: `Hello, ${name}!` }),
|
|
18
|
+
* })
|
|
19
|
+
* .resource('config://app', {
|
|
20
|
+
* name: 'App Config',
|
|
21
|
+
* read: async () => ({ version: '1.0.0' }),
|
|
22
|
+
* })
|
|
23
|
+
* .withLogging({ level: 'debug' })
|
|
24
|
+
* .build();
|
|
25
|
+
*
|
|
26
|
+
* await server.start();
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
declare class ServerBuilder {
|
|
30
|
+
private config;
|
|
31
|
+
private tools;
|
|
32
|
+
private resources;
|
|
33
|
+
private prompts;
|
|
34
|
+
private hooks;
|
|
35
|
+
constructor(config: {
|
|
36
|
+
name: string;
|
|
37
|
+
version: string;
|
|
38
|
+
description?: string;
|
|
39
|
+
});
|
|
40
|
+
/**
|
|
41
|
+
* Add a tool using inline definition
|
|
42
|
+
*/
|
|
43
|
+
tool<TSchema extends z.ZodType>(name: string, definition: InlineToolDefinition<TSchema>): ServerBuilder;
|
|
44
|
+
/**
|
|
45
|
+
* Add a resource using inline definition
|
|
46
|
+
*/
|
|
47
|
+
resource(uri: string, definition: InlineResourceDefinition): ServerBuilder;
|
|
48
|
+
/**
|
|
49
|
+
* Add a prompt using inline definition
|
|
50
|
+
*/
|
|
51
|
+
prompt<TArgs extends z.ZodType>(name: string, definition: InlinePromptDefinition<TArgs>): ServerBuilder;
|
|
52
|
+
/**
|
|
53
|
+
* Configure transport
|
|
54
|
+
*/
|
|
55
|
+
withTransport(transport: 'stdio' | TransportConfig): ServerBuilder;
|
|
56
|
+
/**
|
|
57
|
+
* Configure authentication
|
|
58
|
+
*/
|
|
59
|
+
withAuth(auth: AuthConfig): ServerBuilder;
|
|
60
|
+
/**
|
|
61
|
+
* Configure logging
|
|
62
|
+
*/
|
|
63
|
+
withLogging(options: {
|
|
64
|
+
level?: LogLevel;
|
|
65
|
+
pretty?: boolean;
|
|
66
|
+
}): ServerBuilder;
|
|
67
|
+
/**
|
|
68
|
+
* Configure auto-discovery
|
|
69
|
+
*/
|
|
70
|
+
withDiscovery(options: {
|
|
71
|
+
enabled?: boolean;
|
|
72
|
+
directories?: {
|
|
73
|
+
tools?: string;
|
|
74
|
+
resources?: string;
|
|
75
|
+
prompts?: string;
|
|
76
|
+
};
|
|
77
|
+
}): ServerBuilder;
|
|
78
|
+
/**
|
|
79
|
+
* Add lifecycle hooks
|
|
80
|
+
*/
|
|
81
|
+
withHooks(hooks: ServerHooks): ServerBuilder;
|
|
82
|
+
/**
|
|
83
|
+
* Add a hook for before start
|
|
84
|
+
*/
|
|
85
|
+
onBeforeStart(fn: () => Promise<void> | void): ServerBuilder;
|
|
86
|
+
/**
|
|
87
|
+
* Add a hook for after start
|
|
88
|
+
*/
|
|
89
|
+
onAfterStart(fn: () => Promise<void> | void): ServerBuilder;
|
|
90
|
+
/**
|
|
91
|
+
* Add a hook for before stop
|
|
92
|
+
*/
|
|
93
|
+
onBeforeStop(fn: () => Promise<void> | void): ServerBuilder;
|
|
94
|
+
/**
|
|
95
|
+
* Add a hook for after stop
|
|
96
|
+
*/
|
|
97
|
+
onAfterStop(fn: () => Promise<void> | void): ServerBuilder;
|
|
98
|
+
/**
|
|
99
|
+
* Add an error handler
|
|
100
|
+
*/
|
|
101
|
+
onError(fn: (error: Error) => Promise<void> | void): ServerBuilder;
|
|
102
|
+
/**
|
|
103
|
+
* Build the server instance
|
|
104
|
+
*/
|
|
105
|
+
build(): McpServer;
|
|
106
|
+
/**
|
|
107
|
+
* Build and start the server
|
|
108
|
+
*/
|
|
109
|
+
start(): Promise<McpServer>;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Create a new server builder
|
|
113
|
+
*/
|
|
114
|
+
declare function createServer(config: {
|
|
115
|
+
name: string;
|
|
116
|
+
version: string;
|
|
117
|
+
description?: string;
|
|
118
|
+
}): ServerBuilder;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Create a new request context
|
|
122
|
+
*/
|
|
123
|
+
declare function createRequestContext(correlationId?: string, logger?: Logger): RequestContextData;
|
|
124
|
+
/**
|
|
125
|
+
* Run a function within a request context
|
|
126
|
+
*/
|
|
127
|
+
declare function runInRequestContext<T>(fn: () => T, context?: RequestContextData): T;
|
|
128
|
+
/**
|
|
129
|
+
* Run an async function within a request context
|
|
130
|
+
*/
|
|
131
|
+
declare function runInRequestContextAsync<T>(fn: () => Promise<T>, context?: RequestContextData): Promise<T>;
|
|
132
|
+
/**
|
|
133
|
+
* Get the current request context
|
|
134
|
+
* @returns The current context or undefined if not in a context
|
|
135
|
+
*/
|
|
136
|
+
declare function getRequestContext(): RequestContextData | undefined;
|
|
137
|
+
/**
|
|
138
|
+
* Get the current request context or throw if not in a context
|
|
139
|
+
*/
|
|
140
|
+
declare function requireRequestContext(): RequestContextData;
|
|
141
|
+
/**
|
|
142
|
+
* Get the correlation ID from current context
|
|
143
|
+
*/
|
|
144
|
+
declare function getCorrelationId(): string | undefined;
|
|
145
|
+
/**
|
|
146
|
+
* Get the logger from current context
|
|
147
|
+
*/
|
|
148
|
+
declare function getContextLogger(): Logger;
|
|
149
|
+
/**
|
|
150
|
+
* Set authentication context for current request
|
|
151
|
+
*/
|
|
152
|
+
declare function setAuthContext(auth: AuthContext): void;
|
|
153
|
+
/**
|
|
154
|
+
* Get authentication context from current request
|
|
155
|
+
*/
|
|
156
|
+
declare function getAuthContext(): AuthContext | undefined;
|
|
157
|
+
/**
|
|
158
|
+
* Set a custom value in the context
|
|
159
|
+
*/
|
|
160
|
+
declare function setContextValue<T>(key: string, value: T): void;
|
|
161
|
+
/**
|
|
162
|
+
* Get a custom value from the context
|
|
163
|
+
*/
|
|
164
|
+
declare function getContextValue<T>(key: string): T | undefined;
|
|
165
|
+
/**
|
|
166
|
+
* Get the request duration in milliseconds
|
|
167
|
+
*/
|
|
168
|
+
declare function getRequestDuration(): number | undefined;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Error codes for MCP operations
|
|
172
|
+
*/
|
|
173
|
+
declare enum McpErrorCode {
|
|
174
|
+
SERVER_NOT_INITIALIZED = "SERVER_NOT_INITIALIZED",
|
|
175
|
+
SERVER_ALREADY_RUNNING = "SERVER_ALREADY_RUNNING",
|
|
176
|
+
SERVER_SHUTDOWN_ERROR = "SERVER_SHUTDOWN_ERROR",
|
|
177
|
+
TOOL_NOT_FOUND = "TOOL_NOT_FOUND",
|
|
178
|
+
TOOL_EXECUTION_ERROR = "TOOL_EXECUTION_ERROR",
|
|
179
|
+
TOOL_VALIDATION_ERROR = "TOOL_VALIDATION_ERROR",
|
|
180
|
+
TOOL_ALREADY_REGISTERED = "TOOL_ALREADY_REGISTERED",
|
|
181
|
+
RESOURCE_NOT_FOUND = "RESOURCE_NOT_FOUND",
|
|
182
|
+
RESOURCE_READ_ERROR = "RESOURCE_READ_ERROR",
|
|
183
|
+
RESOURCE_ALREADY_REGISTERED = "RESOURCE_ALREADY_REGISTERED",
|
|
184
|
+
PROMPT_NOT_FOUND = "PROMPT_NOT_FOUND",
|
|
185
|
+
PROMPT_RENDER_ERROR = "PROMPT_RENDER_ERROR",
|
|
186
|
+
PROMPT_ALREADY_REGISTERED = "PROMPT_ALREADY_REGISTERED",
|
|
187
|
+
AUTH_INVALID_TOKEN = "AUTH_INVALID_TOKEN",
|
|
188
|
+
AUTH_TOKEN_EXPIRED = "AUTH_TOKEN_EXPIRED",
|
|
189
|
+
AUTH_INSUFFICIENT_SCOPE = "AUTH_INSUFFICIENT_SCOPE",
|
|
190
|
+
AUTH_MISSING_CREDENTIALS = "AUTH_MISSING_CREDENTIALS",
|
|
191
|
+
TRANSPORT_ERROR = "TRANSPORT_ERROR",
|
|
192
|
+
TRANSPORT_CONNECTION_CLOSED = "TRANSPORT_CONNECTION_CLOSED",
|
|
193
|
+
VALIDATION_ERROR = "VALIDATION_ERROR",
|
|
194
|
+
SCHEMA_ERROR = "SCHEMA_ERROR",
|
|
195
|
+
INTERNAL_ERROR = "INTERNAL_ERROR",
|
|
196
|
+
NOT_IMPLEMENTED = "NOT_IMPLEMENTED"
|
|
197
|
+
}
|
|
198
|
+
interface McpErrorOptions {
|
|
199
|
+
code: McpErrorCode;
|
|
200
|
+
message: string;
|
|
201
|
+
cause?: Error;
|
|
202
|
+
details?: Record<string, unknown>;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Base error class for all MCP-related errors
|
|
207
|
+
*/
|
|
208
|
+
declare class McpError extends Error {
|
|
209
|
+
readonly code: McpErrorCode;
|
|
210
|
+
readonly details?: Record<string, unknown>;
|
|
211
|
+
readonly timestamp: Date;
|
|
212
|
+
constructor(options: McpErrorOptions);
|
|
213
|
+
/**
|
|
214
|
+
* Convert error to a JSON-serializable object
|
|
215
|
+
*/
|
|
216
|
+
toJSON(): Record<string, unknown>;
|
|
217
|
+
/**
|
|
218
|
+
* Create an error for tool not found
|
|
219
|
+
*/
|
|
220
|
+
static toolNotFound(toolName: string): McpError;
|
|
221
|
+
/**
|
|
222
|
+
* Create an error for resource not found
|
|
223
|
+
*/
|
|
224
|
+
static resourceNotFound(uri: string): McpError;
|
|
225
|
+
/**
|
|
226
|
+
* Create an error for prompt not found
|
|
227
|
+
*/
|
|
228
|
+
static promptNotFound(promptName: string): McpError;
|
|
229
|
+
/**
|
|
230
|
+
* Create a validation error
|
|
231
|
+
*/
|
|
232
|
+
static validationError(message: string, details?: Record<string, unknown>): McpError;
|
|
233
|
+
/**
|
|
234
|
+
* Create an authentication error
|
|
235
|
+
*/
|
|
236
|
+
static authError(code: McpErrorCode.AUTH_INVALID_TOKEN | McpErrorCode.AUTH_TOKEN_EXPIRED | McpErrorCode.AUTH_INSUFFICIENT_SCOPE | McpErrorCode.AUTH_MISSING_CREDENTIALS, message: string): McpError;
|
|
237
|
+
/**
|
|
238
|
+
* Create an internal error
|
|
239
|
+
*/
|
|
240
|
+
static internal(message: string, cause?: Error): McpError;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* HTTP Transport for MCP servers
|
|
245
|
+
*
|
|
246
|
+
* Implements the MCP Streamable HTTP transport specification,
|
|
247
|
+
* supporting both SSE streaming and direct HTTP responses.
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```typescript
|
|
251
|
+
* const transport = new HttpTransport({
|
|
252
|
+
* type: 'http',
|
|
253
|
+
* port: 3000,
|
|
254
|
+
* cors: { origin: ['https://myapp.com'] },
|
|
255
|
+
* });
|
|
256
|
+
*
|
|
257
|
+
* await transport.start(mcpServer);
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
declare class HttpTransport implements Transport {
|
|
261
|
+
private config;
|
|
262
|
+
private logger;
|
|
263
|
+
private httpServer;
|
|
264
|
+
private mcpTransport;
|
|
265
|
+
private running;
|
|
266
|
+
constructor(config: HttpTransportConfig, logger?: Logger);
|
|
267
|
+
/**
|
|
268
|
+
* Start the HTTP transport
|
|
269
|
+
*/
|
|
270
|
+
start(mcpServer?: Server): Promise<void>;
|
|
271
|
+
/**
|
|
272
|
+
* Stop the HTTP transport
|
|
273
|
+
*/
|
|
274
|
+
stop(): Promise<void>;
|
|
275
|
+
/**
|
|
276
|
+
* Check if transport is running
|
|
277
|
+
*/
|
|
278
|
+
isRunning(): boolean;
|
|
279
|
+
/**
|
|
280
|
+
* Get the underlying MCP transport (for advanced use cases)
|
|
281
|
+
*/
|
|
282
|
+
getMcpTransport(): StreamableHTTPServerTransport | null;
|
|
283
|
+
/**
|
|
284
|
+
* Handle incoming HTTP request
|
|
285
|
+
*/
|
|
286
|
+
private handleRequest;
|
|
287
|
+
/**
|
|
288
|
+
* Set CORS headers on response
|
|
289
|
+
*/
|
|
290
|
+
private setCorsHeaders;
|
|
291
|
+
/**
|
|
292
|
+
* Parse request body as JSON
|
|
293
|
+
*/
|
|
294
|
+
private parseBody;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export { AuthConfig, AuthContext, HttpTransport, HttpTransportConfig, InlinePromptDefinition, InlineResourceDefinition, InlineToolDefinition, LogLevel, Logger, McpError, McpErrorCode, type McpErrorOptions, McpServer, RequestContextData, ServerBuilder, ServerHooks, Transport, TransportConfig, createRequestContext, createServer, getAuthContext, getContextLogger, getContextValue, getCorrelationId, getRequestContext, getRequestDuration, requireRequestContext, runInRequestContext, runInRequestContextAsync, setAuthContext, setContextValue };
|