@leanmcp/core 0.3.2 → 0.3.4

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 CHANGED
@@ -8,11 +8,6 @@ interface PromptOptions {
8
8
  description?: string;
9
9
  inputClass?: any;
10
10
  }
11
- interface ResourceOptions {
12
- description?: string;
13
- mimeType?: string;
14
- inputClass?: any;
15
- }
16
11
  /**
17
12
  * Marks a method as an MCP tool (callable function)
18
13
  * - Tool name is automatically derived from function name
@@ -57,10 +52,21 @@ declare function Tool(options?: ToolOptions): MethodDecorator;
57
52
  * }
58
53
  */
59
54
  declare function Prompt(options?: PromptOptions): MethodDecorator;
55
+ interface ResourceOptions {
56
+ description?: string;
57
+ mimeType?: string;
58
+ inputClass?: any;
59
+ }
60
+ interface ResourceOptions {
61
+ description?: string;
62
+ mimeType?: string;
63
+ inputClass?: any;
64
+ uri?: string;
65
+ }
60
66
  /**
61
67
  * Marks a method as an MCP resource (data source/endpoint)
62
- * - Resource URI is automatically derived from function name (e.g., "myservice://functionName")
63
- * - Can be customized with description, mimeType, and input schema
68
+ * - Resource URI defaults to ui://classname/methodname (for ext-apps compatibility)
69
+ * - Can be customized with explicit uri option
64
70
  *
65
71
  * @example
66
72
  * class ResourceInput {
@@ -74,8 +80,7 @@ declare function Prompt(options?: PromptOptions): MethodDecorator;
74
80
  * inputClass: ResourceInput
75
81
  * })
76
82
  * getStats(args: ResourceInput) {
77
- * // Resource URI will be: "servicename://getStats"
78
- * return { stats: '...' };
83
+ * // Resource URI will be: "ui://servicename/getStats"
79
84
  * }
80
85
  */
81
86
  declare function Resource(options?: ResourceOptions): MethodDecorator;
@@ -193,14 +198,41 @@ interface LoggerOptions {
193
198
  level?: LogLevel;
194
199
  prefix?: string;
195
200
  timestamps?: boolean;
201
+ /**
202
+ * Enable or disable ANSI colors. Defaults to true.
203
+ */
204
+ colorize?: boolean;
205
+ /**
206
+ * Provide additional metadata context (e.g. module name)
207
+ */
208
+ context?: string;
209
+ /**
210
+ * Optional third-party handlers (PostHog, Sentry, etc.)
211
+ * They receive the structured payload for easy integration.
212
+ */
213
+ handlers?: LoggerHandler[];
196
214
  }
215
+ interface LogPayload {
216
+ level: LogLevel;
217
+ levelLabel: string;
218
+ message: string;
219
+ args: any[];
220
+ prefix?: string;
221
+ context?: string;
222
+ timestamp: string;
223
+ }
224
+ type LoggerHandler = (payload: LogPayload) => void;
197
225
  declare class Logger {
198
226
  private level;
199
227
  private prefix;
200
228
  private timestamps;
229
+ private colorize;
230
+ private context?;
231
+ private handlers;
201
232
  constructor(options?: LoggerOptions);
202
233
  private format;
203
234
  private shouldLog;
235
+ private emit;
204
236
  debug(message: string, ...args: any[]): void;
205
237
  info(message: string, ...args: any[]): void;
206
238
  warn(message: string, ...args: any[]): void;
@@ -219,6 +251,7 @@ interface HTTPServerOptions {
219
251
  logging?: boolean;
220
252
  logger?: Logger;
221
253
  sessionTimeout?: number;
254
+ stateless?: boolean;
222
255
  }
223
256
  interface MCPServerFactory {
224
257
  (): Server | Promise<Server>;
@@ -334,6 +367,7 @@ interface MCPServerConstructorOptions {
334
367
  credentials?: boolean;
335
368
  };
336
369
  sessionTimeout?: number;
370
+ stateless?: boolean;
337
371
  }
338
372
  interface RegisteredTool {
339
373
  name: string;
@@ -342,6 +376,7 @@ interface RegisteredTool {
342
376
  method: Function;
343
377
  instance: any;
344
378
  propertyKey: string;
379
+ _meta?: Record<string, unknown>;
345
380
  }
346
381
  interface RegisteredPrompt {
347
382
  name: string;
@@ -426,6 +461,11 @@ declare class MCPServer {
426
461
  * Register a service instance with decorated methods
427
462
  */
428
463
  registerService(instance: any): void;
464
+ /**
465
+ * Load UI manifest and auto-register resources for pre-built @UIApp components.
466
+ * The manifest is generated by `leanmcp dev` or `leanmcp start` commands.
467
+ */
468
+ private loadUIManifest;
429
469
  /**
430
470
  * Get the underlying MCP SDK Server instance
431
471
  * Attaches waitForInit method for HTTP server initialization
@@ -434,18 +474,9 @@ declare class MCPServer {
434
474
  method: string;
435
475
  params?: {
436
476
  [x: string]: unknown;
437
- task?: {
438
- [x: string]: unknown;
439
- ttl?: number | null | undefined;
440
- pollInterval?: number | undefined;
441
- } | undefined;
442
477
  _meta?: {
443
478
  [x: string]: unknown;
444
479
  progressToken?: string | number | undefined;
445
- "io.modelcontextprotocol/related-task"?: {
446
- [x: string]: unknown;
447
- taskId: string;
448
- } | undefined;
449
480
  } | undefined;
450
481
  } | undefined;
451
482
  }, {
@@ -454,20 +485,12 @@ declare class MCPServer {
454
485
  [x: string]: unknown;
455
486
  _meta?: {
456
487
  [x: string]: unknown;
457
- "io.modelcontextprotocol/related-task"?: {
458
- [x: string]: unknown;
459
- taskId: string;
460
- } | undefined;
461
488
  } | undefined;
462
489
  } | undefined;
463
490
  }, {
464
491
  [x: string]: unknown;
465
492
  _meta?: {
466
493
  [x: string]: unknown;
467
- "io.modelcontextprotocol/related-task"?: {
468
- [x: string]: unknown;
469
- taskId: string;
470
- } | undefined;
471
494
  } | undefined;
472
495
  }>;
473
496
  }
@@ -486,18 +509,9 @@ declare class MCPServerRuntime {
486
509
  method: string;
487
510
  params?: {
488
511
  [x: string]: unknown;
489
- task?: {
490
- [x: string]: unknown;
491
- ttl?: number | null | undefined;
492
- pollInterval?: number | undefined;
493
- } | undefined;
494
512
  _meta?: {
495
513
  [x: string]: unknown;
496
514
  progressToken?: string | number | undefined;
497
- "io.modelcontextprotocol/related-task"?: {
498
- [x: string]: unknown;
499
- taskId: string;
500
- } | undefined;
501
515
  } | undefined;
502
516
  } | undefined;
503
517
  }, {
@@ -506,20 +520,12 @@ declare class MCPServerRuntime {
506
520
  [x: string]: unknown;
507
521
  _meta?: {
508
522
  [x: string]: unknown;
509
- "io.modelcontextprotocol/related-task"?: {
510
- [x: string]: unknown;
511
- taskId: string;
512
- } | undefined;
513
523
  } | undefined;
514
524
  } | undefined;
515
525
  }, {
516
526
  [x: string]: unknown;
517
527
  _meta?: {
518
528
  [x: string]: unknown;
519
- "io.modelcontextprotocol/related-task"?: {
520
- [x: string]: unknown;
521
- taskId: string;
522
- } | undefined;
523
529
  } | undefined;
524
530
  }>;
525
531
  getTools(): RegisteredTool[];
@@ -531,4 +537,4 @@ declare class MCPServerRuntime {
531
537
  */
532
538
  declare function startMCPServer(options: MCPServerOptions): Promise<MCPServerRuntime>;
533
539
 
534
- export { Auth, type AuthOptions, Deprecated, type HTTPServerInput, type HTTPServerOptions, LogLevel, Logger, type LoggerOptions, MCPServer, type MCPServerConstructorOptions, type MCPServerFactory, type MCPServerOptions, MCPServerRuntime, Optional, Prompt, type PromptOptions, Render, Resource, type ResourceOptions, SchemaConstraint, Tool, type ToolOptions, UI, UserEnvs, classToJsonSchema, classToJsonSchemaWithConstraints, createHTTPServer, defaultLogger, getDecoratedMethods, getMethodMetadata, startMCPServer, validateNonEmpty, validatePath, validatePort, validateServiceName, validateUrl };
540
+ export { Auth, type AuthOptions, Deprecated, type HTTPServerInput, type HTTPServerOptions, LogLevel, type LogPayload, Logger, type LoggerHandler, type LoggerOptions, MCPServer, type MCPServerConstructorOptions, type MCPServerFactory, type MCPServerOptions, MCPServerRuntime, Optional, Prompt, type PromptOptions, Render, Resource, type ResourceOptions, SchemaConstraint, Tool, type ToolOptions, UI, UserEnvs, classToJsonSchema, classToJsonSchemaWithConstraints, createHTTPServer, defaultLogger, getDecoratedMethods, getMethodMetadata, startMCPServer, validateNonEmpty, validatePath, validatePort, validateServiceName, validateUrl };
package/dist/index.d.ts CHANGED
@@ -8,11 +8,6 @@ interface PromptOptions {
8
8
  description?: string;
9
9
  inputClass?: any;
10
10
  }
11
- interface ResourceOptions {
12
- description?: string;
13
- mimeType?: string;
14
- inputClass?: any;
15
- }
16
11
  /**
17
12
  * Marks a method as an MCP tool (callable function)
18
13
  * - Tool name is automatically derived from function name
@@ -57,10 +52,21 @@ declare function Tool(options?: ToolOptions): MethodDecorator;
57
52
  * }
58
53
  */
59
54
  declare function Prompt(options?: PromptOptions): MethodDecorator;
55
+ interface ResourceOptions {
56
+ description?: string;
57
+ mimeType?: string;
58
+ inputClass?: any;
59
+ }
60
+ interface ResourceOptions {
61
+ description?: string;
62
+ mimeType?: string;
63
+ inputClass?: any;
64
+ uri?: string;
65
+ }
60
66
  /**
61
67
  * Marks a method as an MCP resource (data source/endpoint)
62
- * - Resource URI is automatically derived from function name (e.g., "myservice://functionName")
63
- * - Can be customized with description, mimeType, and input schema
68
+ * - Resource URI defaults to ui://classname/methodname (for ext-apps compatibility)
69
+ * - Can be customized with explicit uri option
64
70
  *
65
71
  * @example
66
72
  * class ResourceInput {
@@ -74,8 +80,7 @@ declare function Prompt(options?: PromptOptions): MethodDecorator;
74
80
  * inputClass: ResourceInput
75
81
  * })
76
82
  * getStats(args: ResourceInput) {
77
- * // Resource URI will be: "servicename://getStats"
78
- * return { stats: '...' };
83
+ * // Resource URI will be: "ui://servicename/getStats"
79
84
  * }
80
85
  */
81
86
  declare function Resource(options?: ResourceOptions): MethodDecorator;
@@ -193,14 +198,41 @@ interface LoggerOptions {
193
198
  level?: LogLevel;
194
199
  prefix?: string;
195
200
  timestamps?: boolean;
201
+ /**
202
+ * Enable or disable ANSI colors. Defaults to true.
203
+ */
204
+ colorize?: boolean;
205
+ /**
206
+ * Provide additional metadata context (e.g. module name)
207
+ */
208
+ context?: string;
209
+ /**
210
+ * Optional third-party handlers (PostHog, Sentry, etc.)
211
+ * They receive the structured payload for easy integration.
212
+ */
213
+ handlers?: LoggerHandler[];
196
214
  }
215
+ interface LogPayload {
216
+ level: LogLevel;
217
+ levelLabel: string;
218
+ message: string;
219
+ args: any[];
220
+ prefix?: string;
221
+ context?: string;
222
+ timestamp: string;
223
+ }
224
+ type LoggerHandler = (payload: LogPayload) => void;
197
225
  declare class Logger {
198
226
  private level;
199
227
  private prefix;
200
228
  private timestamps;
229
+ private colorize;
230
+ private context?;
231
+ private handlers;
201
232
  constructor(options?: LoggerOptions);
202
233
  private format;
203
234
  private shouldLog;
235
+ private emit;
204
236
  debug(message: string, ...args: any[]): void;
205
237
  info(message: string, ...args: any[]): void;
206
238
  warn(message: string, ...args: any[]): void;
@@ -219,6 +251,7 @@ interface HTTPServerOptions {
219
251
  logging?: boolean;
220
252
  logger?: Logger;
221
253
  sessionTimeout?: number;
254
+ stateless?: boolean;
222
255
  }
223
256
  interface MCPServerFactory {
224
257
  (): Server | Promise<Server>;
@@ -334,6 +367,7 @@ interface MCPServerConstructorOptions {
334
367
  credentials?: boolean;
335
368
  };
336
369
  sessionTimeout?: number;
370
+ stateless?: boolean;
337
371
  }
338
372
  interface RegisteredTool {
339
373
  name: string;
@@ -342,6 +376,7 @@ interface RegisteredTool {
342
376
  method: Function;
343
377
  instance: any;
344
378
  propertyKey: string;
379
+ _meta?: Record<string, unknown>;
345
380
  }
346
381
  interface RegisteredPrompt {
347
382
  name: string;
@@ -426,6 +461,11 @@ declare class MCPServer {
426
461
  * Register a service instance with decorated methods
427
462
  */
428
463
  registerService(instance: any): void;
464
+ /**
465
+ * Load UI manifest and auto-register resources for pre-built @UIApp components.
466
+ * The manifest is generated by `leanmcp dev` or `leanmcp start` commands.
467
+ */
468
+ private loadUIManifest;
429
469
  /**
430
470
  * Get the underlying MCP SDK Server instance
431
471
  * Attaches waitForInit method for HTTP server initialization
@@ -434,18 +474,9 @@ declare class MCPServer {
434
474
  method: string;
435
475
  params?: {
436
476
  [x: string]: unknown;
437
- task?: {
438
- [x: string]: unknown;
439
- ttl?: number | null | undefined;
440
- pollInterval?: number | undefined;
441
- } | undefined;
442
477
  _meta?: {
443
478
  [x: string]: unknown;
444
479
  progressToken?: string | number | undefined;
445
- "io.modelcontextprotocol/related-task"?: {
446
- [x: string]: unknown;
447
- taskId: string;
448
- } | undefined;
449
480
  } | undefined;
450
481
  } | undefined;
451
482
  }, {
@@ -454,20 +485,12 @@ declare class MCPServer {
454
485
  [x: string]: unknown;
455
486
  _meta?: {
456
487
  [x: string]: unknown;
457
- "io.modelcontextprotocol/related-task"?: {
458
- [x: string]: unknown;
459
- taskId: string;
460
- } | undefined;
461
488
  } | undefined;
462
489
  } | undefined;
463
490
  }, {
464
491
  [x: string]: unknown;
465
492
  _meta?: {
466
493
  [x: string]: unknown;
467
- "io.modelcontextprotocol/related-task"?: {
468
- [x: string]: unknown;
469
- taskId: string;
470
- } | undefined;
471
494
  } | undefined;
472
495
  }>;
473
496
  }
@@ -486,18 +509,9 @@ declare class MCPServerRuntime {
486
509
  method: string;
487
510
  params?: {
488
511
  [x: string]: unknown;
489
- task?: {
490
- [x: string]: unknown;
491
- ttl?: number | null | undefined;
492
- pollInterval?: number | undefined;
493
- } | undefined;
494
512
  _meta?: {
495
513
  [x: string]: unknown;
496
514
  progressToken?: string | number | undefined;
497
- "io.modelcontextprotocol/related-task"?: {
498
- [x: string]: unknown;
499
- taskId: string;
500
- } | undefined;
501
515
  } | undefined;
502
516
  } | undefined;
503
517
  }, {
@@ -506,20 +520,12 @@ declare class MCPServerRuntime {
506
520
  [x: string]: unknown;
507
521
  _meta?: {
508
522
  [x: string]: unknown;
509
- "io.modelcontextprotocol/related-task"?: {
510
- [x: string]: unknown;
511
- taskId: string;
512
- } | undefined;
513
523
  } | undefined;
514
524
  } | undefined;
515
525
  }, {
516
526
  [x: string]: unknown;
517
527
  _meta?: {
518
528
  [x: string]: unknown;
519
- "io.modelcontextprotocol/related-task"?: {
520
- [x: string]: unknown;
521
- taskId: string;
522
- } | undefined;
523
529
  } | undefined;
524
530
  }>;
525
531
  getTools(): RegisteredTool[];
@@ -531,4 +537,4 @@ declare class MCPServerRuntime {
531
537
  */
532
538
  declare function startMCPServer(options: MCPServerOptions): Promise<MCPServerRuntime>;
533
539
 
534
- export { Auth, type AuthOptions, Deprecated, type HTTPServerInput, type HTTPServerOptions, LogLevel, Logger, type LoggerOptions, MCPServer, type MCPServerConstructorOptions, type MCPServerFactory, type MCPServerOptions, MCPServerRuntime, Optional, Prompt, type PromptOptions, Render, Resource, type ResourceOptions, SchemaConstraint, Tool, type ToolOptions, UI, UserEnvs, classToJsonSchema, classToJsonSchemaWithConstraints, createHTTPServer, defaultLogger, getDecoratedMethods, getMethodMetadata, startMCPServer, validateNonEmpty, validatePath, validatePort, validateServiceName, validateUrl };
540
+ export { Auth, type AuthOptions, Deprecated, type HTTPServerInput, type HTTPServerOptions, LogLevel, type LogPayload, Logger, type LoggerHandler, type LoggerOptions, MCPServer, type MCPServerConstructorOptions, type MCPServerFactory, type MCPServerOptions, MCPServerRuntime, Optional, Prompt, type PromptOptions, Render, Resource, type ResourceOptions, SchemaConstraint, Tool, type ToolOptions, UI, UserEnvs, classToJsonSchema, classToJsonSchemaWithConstraints, createHTTPServer, defaultLogger, getDecoratedMethods, getMethodMetadata, startMCPServer, validateNonEmpty, validatePath, validatePort, validateServiceName, validateUrl };