@mcp-weave/nestjs 0.2.0 → 0.3.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/dist/index.d.mts +125 -3
- package/dist/index.d.ts +125 -3
- package/dist/index.js +269 -45
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +256 -44
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ToolInputSchema, PromptArgument, McpParamMetadata, McpPromptMetadata, McpResourceMetadata, McpServerMetadata, McpToolMetadata } from '@mcp-weave/core';
|
|
2
2
|
export { METADATA_KEYS, McpParamMetadata, McpPromptMetadata, McpResourceMetadata, McpServerMetadata, McpToolMetadata, ScannedMetadata, extractMetadata } from '@mcp-weave/core';
|
|
3
|
+
import { IncomingMessage, ServerResponse, Server } from 'http';
|
|
3
4
|
import { Server as Server$1 } from '@modelcontextprotocol/sdk/server/index.js';
|
|
4
|
-
import { Server } from 'http';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Options for @McpServer decorator
|
|
@@ -205,6 +205,122 @@ declare function getPromptsMetadata(target: Function): McpPromptMetadata[];
|
|
|
205
205
|
*/
|
|
206
206
|
declare function getParamsMetadata(target: Function): McpParamMetadata[];
|
|
207
207
|
|
|
208
|
+
/**
|
|
209
|
+
* @mcp-weave/nestjs - Authentication Module
|
|
210
|
+
* Provides API key authentication and request tracking
|
|
211
|
+
*/
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* API Key configuration
|
|
215
|
+
*/
|
|
216
|
+
interface ApiKeyConfig {
|
|
217
|
+
/** The API key value */
|
|
218
|
+
key: string;
|
|
219
|
+
/** Human-readable name for the key (for logging) */
|
|
220
|
+
name?: string;
|
|
221
|
+
/** Optional metadata associated with this key */
|
|
222
|
+
metadata?: Record<string, unknown>;
|
|
223
|
+
/** Scopes/permissions for this key */
|
|
224
|
+
scopes?: string[];
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Authentication options for MCP servers
|
|
228
|
+
*/
|
|
229
|
+
interface McpAuthOptions {
|
|
230
|
+
/**
|
|
231
|
+
* Enable authentication (default: false)
|
|
232
|
+
*/
|
|
233
|
+
enabled?: boolean;
|
|
234
|
+
/**
|
|
235
|
+
* API keys allowed to access the server
|
|
236
|
+
* Can be a single key string, array of keys, or array of ApiKeyConfig objects
|
|
237
|
+
*/
|
|
238
|
+
apiKeys?: string | string[] | ApiKeyConfig[];
|
|
239
|
+
/**
|
|
240
|
+
* Header name for the API key (default: 'x-api-key')
|
|
241
|
+
*/
|
|
242
|
+
headerName?: string;
|
|
243
|
+
/**
|
|
244
|
+
* Query parameter name for the API key (default: 'api_key')
|
|
245
|
+
*/
|
|
246
|
+
queryParamName?: string;
|
|
247
|
+
/**
|
|
248
|
+
* Custom authentication function
|
|
249
|
+
* Return true to allow, false to deny, or an AuthResult object
|
|
250
|
+
*/
|
|
251
|
+
authenticate?: (token: string | undefined, request: IncomingMessage) => boolean | AuthResult | Promise<boolean | AuthResult>;
|
|
252
|
+
/**
|
|
253
|
+
* Called when authentication fails
|
|
254
|
+
*/
|
|
255
|
+
onAuthFailure?: (request: IncomingMessage, reason: string) => void;
|
|
256
|
+
/**
|
|
257
|
+
* Called when authentication succeeds
|
|
258
|
+
*/
|
|
259
|
+
onAuthSuccess?: (request: IncomingMessage, result: AuthResult) => void;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Result of authentication
|
|
263
|
+
*/
|
|
264
|
+
interface AuthResult {
|
|
265
|
+
/** Whether authentication succeeded */
|
|
266
|
+
success: boolean;
|
|
267
|
+
/** Client identifier (for tracking) */
|
|
268
|
+
clientId?: string;
|
|
269
|
+
/** Client name (for logging) */
|
|
270
|
+
clientName?: string;
|
|
271
|
+
/** Scopes/permissions granted */
|
|
272
|
+
scopes?: string[];
|
|
273
|
+
/** Additional metadata */
|
|
274
|
+
metadata?: Record<string, unknown>;
|
|
275
|
+
/** Error message if authentication failed */
|
|
276
|
+
error?: string;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Request context with authentication info
|
|
280
|
+
*/
|
|
281
|
+
interface AuthenticatedRequest {
|
|
282
|
+
/** The original request */
|
|
283
|
+
request: IncomingMessage;
|
|
284
|
+
/** Authentication result */
|
|
285
|
+
auth: AuthResult;
|
|
286
|
+
/** Request ID for tracking */
|
|
287
|
+
requestId: string;
|
|
288
|
+
/** Timestamp of the request */
|
|
289
|
+
timestamp: Date;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Normalize API keys configuration to ApiKeyConfig array
|
|
293
|
+
*/
|
|
294
|
+
declare function normalizeApiKeys(keys: string | string[] | ApiKeyConfig[] | undefined): ApiKeyConfig[];
|
|
295
|
+
/**
|
|
296
|
+
* Extract API key from request
|
|
297
|
+
*/
|
|
298
|
+
declare function extractApiKey(req: IncomingMessage, headerName?: string, queryParamName?: string): string | undefined;
|
|
299
|
+
/**
|
|
300
|
+
* Validate API key against configured keys
|
|
301
|
+
*/
|
|
302
|
+
declare function validateApiKey(token: string | undefined, apiKeys: ApiKeyConfig[]): AuthResult;
|
|
303
|
+
/**
|
|
304
|
+
* Hash a token for safe logging (shows first 4 and last 4 chars)
|
|
305
|
+
*/
|
|
306
|
+
declare function hashToken(token: string): string;
|
|
307
|
+
/**
|
|
308
|
+
* Generate a unique request ID
|
|
309
|
+
*/
|
|
310
|
+
declare function generateRequestId(): string;
|
|
311
|
+
/**
|
|
312
|
+
* Create an authentication middleware for HTTP requests
|
|
313
|
+
*/
|
|
314
|
+
declare function createAuthMiddleware(options?: McpAuthOptions): (req: IncomingMessage, res: ServerResponse) => Promise<AuthenticatedRequest | null>;
|
|
315
|
+
/**
|
|
316
|
+
* Send unauthorized response
|
|
317
|
+
*/
|
|
318
|
+
declare function sendUnauthorized(res: ServerResponse, message?: string, requestId?: string): void;
|
|
319
|
+
/**
|
|
320
|
+
* Generate a random API key
|
|
321
|
+
*/
|
|
322
|
+
declare function generateApiKey(prefix?: string): string;
|
|
323
|
+
|
|
208
324
|
/**
|
|
209
325
|
* Options for MCP runtime server
|
|
210
326
|
*/
|
|
@@ -221,6 +337,10 @@ interface McpRuntimeOptions {
|
|
|
221
337
|
* Endpoint path for SSE/WebSocket (default: '/sse' or '/ws')
|
|
222
338
|
*/
|
|
223
339
|
endpoint?: string;
|
|
340
|
+
/**
|
|
341
|
+
* Authentication options
|
|
342
|
+
*/
|
|
343
|
+
auth?: McpAuthOptions;
|
|
224
344
|
}
|
|
225
345
|
/**
|
|
226
346
|
* Runtime MCP server that wraps a decorated class
|
|
@@ -229,7 +349,9 @@ declare class McpRuntimeServer {
|
|
|
229
349
|
private server;
|
|
230
350
|
private instance;
|
|
231
351
|
private metadata;
|
|
232
|
-
|
|
352
|
+
private authOptions;
|
|
353
|
+
private authMiddleware;
|
|
354
|
+
constructor(target: Function, options?: McpRuntimeOptions);
|
|
233
355
|
private setupHandlers;
|
|
234
356
|
private setupToolHandlers;
|
|
235
357
|
private setupResourceHandlers;
|
|
@@ -284,4 +406,4 @@ declare function createMcpServer(target: Function, options?: McpRuntimeOptions):
|
|
|
284
406
|
|
|
285
407
|
declare const VERSION = "0.1.0";
|
|
286
408
|
|
|
287
|
-
export { McpInput, McpParam, McpPrompt, McpPromptArg, type McpPromptOptions, McpResource, type McpResourceOptions, type McpRuntimeOptions, McpRuntimeServer, McpServer, type McpServerOptions, McpTool, type McpToolOptions, VERSION, createMcpServer, getMcpServers, getParamsMetadata, getPromptsMetadata, getResourcesMetadata, getServerMetadata, getToolsMetadata, isMcpServer };
|
|
409
|
+
export { type ApiKeyConfig, type AuthResult, type AuthenticatedRequest, type McpAuthOptions, McpInput, McpParam, McpPrompt, McpPromptArg, type McpPromptOptions, McpResource, type McpResourceOptions, type McpRuntimeOptions, McpRuntimeServer, McpServer, type McpServerOptions, McpTool, type McpToolOptions, VERSION, createAuthMiddleware, createMcpServer, extractApiKey, generateApiKey, generateRequestId, getMcpServers, getParamsMetadata, getPromptsMetadata, getResourcesMetadata, getServerMetadata, getToolsMetadata, hashToken, isMcpServer, normalizeApiKeys, sendUnauthorized, validateApiKey };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ToolInputSchema, PromptArgument, McpParamMetadata, McpPromptMetadata, McpResourceMetadata, McpServerMetadata, McpToolMetadata } from '@mcp-weave/core';
|
|
2
2
|
export { METADATA_KEYS, McpParamMetadata, McpPromptMetadata, McpResourceMetadata, McpServerMetadata, McpToolMetadata, ScannedMetadata, extractMetadata } from '@mcp-weave/core';
|
|
3
|
+
import { IncomingMessage, ServerResponse, Server } from 'http';
|
|
3
4
|
import { Server as Server$1 } from '@modelcontextprotocol/sdk/server/index.js';
|
|
4
|
-
import { Server } from 'http';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Options for @McpServer decorator
|
|
@@ -205,6 +205,122 @@ declare function getPromptsMetadata(target: Function): McpPromptMetadata[];
|
|
|
205
205
|
*/
|
|
206
206
|
declare function getParamsMetadata(target: Function): McpParamMetadata[];
|
|
207
207
|
|
|
208
|
+
/**
|
|
209
|
+
* @mcp-weave/nestjs - Authentication Module
|
|
210
|
+
* Provides API key authentication and request tracking
|
|
211
|
+
*/
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* API Key configuration
|
|
215
|
+
*/
|
|
216
|
+
interface ApiKeyConfig {
|
|
217
|
+
/** The API key value */
|
|
218
|
+
key: string;
|
|
219
|
+
/** Human-readable name for the key (for logging) */
|
|
220
|
+
name?: string;
|
|
221
|
+
/** Optional metadata associated with this key */
|
|
222
|
+
metadata?: Record<string, unknown>;
|
|
223
|
+
/** Scopes/permissions for this key */
|
|
224
|
+
scopes?: string[];
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Authentication options for MCP servers
|
|
228
|
+
*/
|
|
229
|
+
interface McpAuthOptions {
|
|
230
|
+
/**
|
|
231
|
+
* Enable authentication (default: false)
|
|
232
|
+
*/
|
|
233
|
+
enabled?: boolean;
|
|
234
|
+
/**
|
|
235
|
+
* API keys allowed to access the server
|
|
236
|
+
* Can be a single key string, array of keys, or array of ApiKeyConfig objects
|
|
237
|
+
*/
|
|
238
|
+
apiKeys?: string | string[] | ApiKeyConfig[];
|
|
239
|
+
/**
|
|
240
|
+
* Header name for the API key (default: 'x-api-key')
|
|
241
|
+
*/
|
|
242
|
+
headerName?: string;
|
|
243
|
+
/**
|
|
244
|
+
* Query parameter name for the API key (default: 'api_key')
|
|
245
|
+
*/
|
|
246
|
+
queryParamName?: string;
|
|
247
|
+
/**
|
|
248
|
+
* Custom authentication function
|
|
249
|
+
* Return true to allow, false to deny, or an AuthResult object
|
|
250
|
+
*/
|
|
251
|
+
authenticate?: (token: string | undefined, request: IncomingMessage) => boolean | AuthResult | Promise<boolean | AuthResult>;
|
|
252
|
+
/**
|
|
253
|
+
* Called when authentication fails
|
|
254
|
+
*/
|
|
255
|
+
onAuthFailure?: (request: IncomingMessage, reason: string) => void;
|
|
256
|
+
/**
|
|
257
|
+
* Called when authentication succeeds
|
|
258
|
+
*/
|
|
259
|
+
onAuthSuccess?: (request: IncomingMessage, result: AuthResult) => void;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Result of authentication
|
|
263
|
+
*/
|
|
264
|
+
interface AuthResult {
|
|
265
|
+
/** Whether authentication succeeded */
|
|
266
|
+
success: boolean;
|
|
267
|
+
/** Client identifier (for tracking) */
|
|
268
|
+
clientId?: string;
|
|
269
|
+
/** Client name (for logging) */
|
|
270
|
+
clientName?: string;
|
|
271
|
+
/** Scopes/permissions granted */
|
|
272
|
+
scopes?: string[];
|
|
273
|
+
/** Additional metadata */
|
|
274
|
+
metadata?: Record<string, unknown>;
|
|
275
|
+
/** Error message if authentication failed */
|
|
276
|
+
error?: string;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Request context with authentication info
|
|
280
|
+
*/
|
|
281
|
+
interface AuthenticatedRequest {
|
|
282
|
+
/** The original request */
|
|
283
|
+
request: IncomingMessage;
|
|
284
|
+
/** Authentication result */
|
|
285
|
+
auth: AuthResult;
|
|
286
|
+
/** Request ID for tracking */
|
|
287
|
+
requestId: string;
|
|
288
|
+
/** Timestamp of the request */
|
|
289
|
+
timestamp: Date;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Normalize API keys configuration to ApiKeyConfig array
|
|
293
|
+
*/
|
|
294
|
+
declare function normalizeApiKeys(keys: string | string[] | ApiKeyConfig[] | undefined): ApiKeyConfig[];
|
|
295
|
+
/**
|
|
296
|
+
* Extract API key from request
|
|
297
|
+
*/
|
|
298
|
+
declare function extractApiKey(req: IncomingMessage, headerName?: string, queryParamName?: string): string | undefined;
|
|
299
|
+
/**
|
|
300
|
+
* Validate API key against configured keys
|
|
301
|
+
*/
|
|
302
|
+
declare function validateApiKey(token: string | undefined, apiKeys: ApiKeyConfig[]): AuthResult;
|
|
303
|
+
/**
|
|
304
|
+
* Hash a token for safe logging (shows first 4 and last 4 chars)
|
|
305
|
+
*/
|
|
306
|
+
declare function hashToken(token: string): string;
|
|
307
|
+
/**
|
|
308
|
+
* Generate a unique request ID
|
|
309
|
+
*/
|
|
310
|
+
declare function generateRequestId(): string;
|
|
311
|
+
/**
|
|
312
|
+
* Create an authentication middleware for HTTP requests
|
|
313
|
+
*/
|
|
314
|
+
declare function createAuthMiddleware(options?: McpAuthOptions): (req: IncomingMessage, res: ServerResponse) => Promise<AuthenticatedRequest | null>;
|
|
315
|
+
/**
|
|
316
|
+
* Send unauthorized response
|
|
317
|
+
*/
|
|
318
|
+
declare function sendUnauthorized(res: ServerResponse, message?: string, requestId?: string): void;
|
|
319
|
+
/**
|
|
320
|
+
* Generate a random API key
|
|
321
|
+
*/
|
|
322
|
+
declare function generateApiKey(prefix?: string): string;
|
|
323
|
+
|
|
208
324
|
/**
|
|
209
325
|
* Options for MCP runtime server
|
|
210
326
|
*/
|
|
@@ -221,6 +337,10 @@ interface McpRuntimeOptions {
|
|
|
221
337
|
* Endpoint path for SSE/WebSocket (default: '/sse' or '/ws')
|
|
222
338
|
*/
|
|
223
339
|
endpoint?: string;
|
|
340
|
+
/**
|
|
341
|
+
* Authentication options
|
|
342
|
+
*/
|
|
343
|
+
auth?: McpAuthOptions;
|
|
224
344
|
}
|
|
225
345
|
/**
|
|
226
346
|
* Runtime MCP server that wraps a decorated class
|
|
@@ -229,7 +349,9 @@ declare class McpRuntimeServer {
|
|
|
229
349
|
private server;
|
|
230
350
|
private instance;
|
|
231
351
|
private metadata;
|
|
232
|
-
|
|
352
|
+
private authOptions;
|
|
353
|
+
private authMiddleware;
|
|
354
|
+
constructor(target: Function, options?: McpRuntimeOptions);
|
|
233
355
|
private setupHandlers;
|
|
234
356
|
private setupToolHandlers;
|
|
235
357
|
private setupResourceHandlers;
|
|
@@ -284,4 +406,4 @@ declare function createMcpServer(target: Function, options?: McpRuntimeOptions):
|
|
|
284
406
|
|
|
285
407
|
declare const VERSION = "0.1.0";
|
|
286
408
|
|
|
287
|
-
export { McpInput, McpParam, McpPrompt, McpPromptArg, type McpPromptOptions, McpResource, type McpResourceOptions, type McpRuntimeOptions, McpRuntimeServer, McpServer, type McpServerOptions, McpTool, type McpToolOptions, VERSION, createMcpServer, getMcpServers, getParamsMetadata, getPromptsMetadata, getResourcesMetadata, getServerMetadata, getToolsMetadata, isMcpServer };
|
|
409
|
+
export { type ApiKeyConfig, type AuthResult, type AuthenticatedRequest, type McpAuthOptions, McpInput, McpParam, McpPrompt, McpPromptArg, type McpPromptOptions, McpResource, type McpResourceOptions, type McpRuntimeOptions, McpRuntimeServer, McpServer, type McpServerOptions, McpTool, type McpToolOptions, VERSION, createAuthMiddleware, createMcpServer, extractApiKey, generateApiKey, generateRequestId, getMcpServers, getParamsMetadata, getPromptsMetadata, getResourcesMetadata, getServerMetadata, getToolsMetadata, hashToken, isMcpServer, normalizeApiKeys, sendUnauthorized, validateApiKey };
|