@leanmcp/core 0.3.18 → 0.4.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.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
2
+ import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
2
3
 
3
4
  /**
4
5
  * Simple configurable logger for LeanMCP SDK
@@ -58,6 +59,43 @@ declare class Logger {
58
59
  }
59
60
  declare const defaultLogger: Logger;
60
61
 
62
+ /**
63
+ * Session data stored in persistent storage (e.g., DynamoDB)
64
+ */
65
+ interface SessionData {
66
+ sessionId: string;
67
+ createdAt: Date;
68
+ updatedAt: Date;
69
+ ttl?: number;
70
+ data?: Record<string, any>;
71
+ }
72
+ /**
73
+ * Interface for session storage backends
74
+ * Implementations can use DynamoDB, Redis, or other persistent stores
75
+ */
76
+ interface ISessionStore {
77
+ /**
78
+ * Check if a session exists in the store
79
+ */
80
+ sessionExists(sessionId: string): Promise<boolean>;
81
+ /**
82
+ * Create a new session in the store
83
+ */
84
+ createSession(sessionId: string, data?: Record<string, any>): Promise<void>;
85
+ /**
86
+ * Get session data from the store
87
+ */
88
+ getSession(sessionId: string): Promise<SessionData | null>;
89
+ /**
90
+ * Update session data in the store
91
+ */
92
+ updateSession(sessionId: string, data: Partial<SessionData>): Promise<void>;
93
+ /**
94
+ * Delete a session from the store
95
+ */
96
+ deleteSession(sessionId: string): Promise<void>;
97
+ }
98
+
61
99
  interface HTTPServerOptions {
62
100
  port?: number;
63
101
  cors?: boolean | {
@@ -71,6 +109,8 @@ interface HTTPServerOptions {
71
109
  dashboard?: boolean;
72
110
  /** OAuth/Auth configuration (MCP authorization spec) */
73
111
  auth?: HTTPServerAuthOptions;
112
+ /** Session store for stateful mode (enables session persistence across Lambda container recycling) */
113
+ sessionStore?: ISessionStore;
74
114
  }
75
115
  /**
76
116
  * OAuth/Auth configuration for MCP server
@@ -530,6 +570,127 @@ declare function createProtectedResourceMetadata(options: {
530
570
  documentationUrl?: string;
531
571
  }): ProtectedResourceMetadata;
532
572
 
573
+ interface LeanMCPSessionProviderOptions {
574
+ tableName?: string;
575
+ region?: string;
576
+ ttlSeconds?: number;
577
+ logging?: boolean;
578
+ sessionStore?: ISessionStore;
579
+ }
580
+ /**
581
+ * Drop-in replacement for Map<string, StreamableHTTPServerTransport>
582
+ * Provides automatic session persistence for Lambda deployments
583
+ *
584
+ * @example
585
+ * // Before: const transports = new Map<string, StreamableHTTPServerTransport>();
586
+ * // After: const sessions = new LeanMCPSessionProvider();
587
+ *
588
+ * // Then use sessions.get(), sessions.set(), sessions.getOrRecreate()
589
+ */
590
+ declare class LeanMCPSessionProvider {
591
+ private transports;
592
+ private sessionStore;
593
+ constructor(options?: LeanMCPSessionProviderOptions);
594
+ /**
595
+ * Get transport from memory
596
+ */
597
+ get(sessionId: string): StreamableHTTPServerTransport | undefined;
598
+ /**
599
+ * Check if session exists (memory or DynamoDB)
600
+ */
601
+ has(sessionId: string): Promise<boolean>;
602
+ /**
603
+ * Store transport and create session in DynamoDB
604
+ */
605
+ set(sessionId: string, transport: StreamableHTTPServerTransport): Promise<void>;
606
+ /**
607
+ * Delete transport and session
608
+ */
609
+ delete(sessionId: string): Promise<void>;
610
+ /**
611
+ * Get or recreate transport for a session
612
+ * This is the key method for Lambda support - handles container recycling
613
+ *
614
+ * @param sessionId - Session ID to get or recreate
615
+ * @param serverFactory - Factory function to create fresh MCP server instances
616
+ * @param transportOptions - Optional callbacks for transport lifecycle events
617
+ * @returns Transport instance or null if session doesn't exist
618
+ */
619
+ getOrRecreate(sessionId: string, serverFactory: () => Server | Promise<Server>, transportOptions?: {
620
+ onsessioninitialized?: (sid: string) => void;
621
+ onclose?: () => void;
622
+ }): Promise<StreamableHTTPServerTransport | null>;
623
+ /**
624
+ * Get session data from DynamoDB
625
+ */
626
+ getSessionData(sessionId: string): Promise<Record<string, any> | null>;
627
+ /**
628
+ * Update session data in DynamoDB
629
+ */
630
+ updateSessionData(sessionId: string, data: Record<string, any>): Promise<void>;
631
+ /**
632
+ * Get number of in-memory transports
633
+ */
634
+ get size(): number;
635
+ /**
636
+ * Get all session IDs in memory
637
+ */
638
+ keys(): IterableIterator<string>;
639
+ /**
640
+ * Get all transports in memory
641
+ */
642
+ values(): IterableIterator<StreamableHTTPServerTransport>;
643
+ /**
644
+ * Iterate over all sessions in memory
645
+ */
646
+ entries(): IterableIterator<[string, StreamableHTTPServerTransport]>;
647
+ /**
648
+ * Clear all in-memory transports (does not affect DynamoDB)
649
+ */
650
+ clear(): void;
651
+ }
652
+
653
+ declare const DEFAULT_TABLE_NAME = "leanmcp-sessions";
654
+ declare const DEFAULT_TTL_SECONDS = 86400;
655
+ interface DynamoDBSessionStoreOptions {
656
+ tableName?: string;
657
+ region?: string;
658
+ ttlSeconds?: number;
659
+ logging?: boolean;
660
+ }
661
+ /**
662
+ * DynamoDB-backed session store for stateful Lambda MCP servers
663
+ * Automatically handles session persistence across Lambda container recycling
664
+ */
665
+ declare class DynamoDBSessionStore implements ISessionStore {
666
+ private client;
667
+ private tableName;
668
+ private ttlSeconds;
669
+ private logger;
670
+ constructor(options?: DynamoDBSessionStoreOptions);
671
+ /**
672
+ * Check if a session exists in DynamoDB
673
+ */
674
+ sessionExists(sessionId: string): Promise<boolean>;
675
+ /**
676
+ * Create a new session in DynamoDB
677
+ */
678
+ createSession(sessionId: string, data?: Record<string, any>): Promise<void>;
679
+ /**
680
+ * Get session data from DynamoDB
681
+ */
682
+ getSession(sessionId: string): Promise<SessionData | null>;
683
+ /**
684
+ * Update session data in DynamoDB
685
+ * Automatically refreshes TTL on each update
686
+ */
687
+ updateSession(sessionId: string, updates: Partial<SessionData>): Promise<void>;
688
+ /**
689
+ * Delete a session from DynamoDB
690
+ */
691
+ deleteSession(sessionId: string): Promise<void>;
692
+ }
693
+
533
694
  interface MCPServerOptions {
534
695
  servicesDir: string;
535
696
  port?: number;
@@ -673,16 +834,10 @@ declare class MCPServer {
673
834
  method: string;
674
835
  params?: {
675
836
  [x: string]: unknown;
676
- task?: {
677
- [x: string]: unknown;
678
- ttl?: number | null | undefined;
679
- pollInterval?: number | undefined;
680
- } | undefined;
681
837
  _meta?: {
682
838
  [x: string]: unknown;
683
839
  progressToken?: string | number | undefined;
684
840
  "io.modelcontextprotocol/related-task"?: {
685
- [x: string]: unknown;
686
841
  taskId: string;
687
842
  } | undefined;
688
843
  } | undefined;
@@ -693,8 +848,8 @@ declare class MCPServer {
693
848
  [x: string]: unknown;
694
849
  _meta?: {
695
850
  [x: string]: unknown;
851
+ progressToken?: string | number | undefined;
696
852
  "io.modelcontextprotocol/related-task"?: {
697
- [x: string]: unknown;
698
853
  taskId: string;
699
854
  } | undefined;
700
855
  } | undefined;
@@ -703,8 +858,8 @@ declare class MCPServer {
703
858
  [x: string]: unknown;
704
859
  _meta?: {
705
860
  [x: string]: unknown;
861
+ progressToken?: string | number | undefined;
706
862
  "io.modelcontextprotocol/related-task"?: {
707
- [x: string]: unknown;
708
863
  taskId: string;
709
864
  } | undefined;
710
865
  } | undefined;
@@ -734,16 +889,10 @@ declare class MCPServerRuntime {
734
889
  method: string;
735
890
  params?: {
736
891
  [x: string]: unknown;
737
- task?: {
738
- [x: string]: unknown;
739
- ttl?: number | null | undefined;
740
- pollInterval?: number | undefined;
741
- } | undefined;
742
892
  _meta?: {
743
893
  [x: string]: unknown;
744
894
  progressToken?: string | number | undefined;
745
895
  "io.modelcontextprotocol/related-task"?: {
746
- [x: string]: unknown;
747
896
  taskId: string;
748
897
  } | undefined;
749
898
  } | undefined;
@@ -754,8 +903,8 @@ declare class MCPServerRuntime {
754
903
  [x: string]: unknown;
755
904
  _meta?: {
756
905
  [x: string]: unknown;
906
+ progressToken?: string | number | undefined;
757
907
  "io.modelcontextprotocol/related-task"?: {
758
- [x: string]: unknown;
759
908
  taskId: string;
760
909
  } | undefined;
761
910
  } | undefined;
@@ -764,8 +913,8 @@ declare class MCPServerRuntime {
764
913
  [x: string]: unknown;
765
914
  _meta?: {
766
915
  [x: string]: unknown;
916
+ progressToken?: string | number | undefined;
767
917
  "io.modelcontextprotocol/related-task"?: {
768
- [x: string]: unknown;
769
918
  taskId: string;
770
919
  } | undefined;
771
920
  } | undefined;
@@ -779,4 +928,4 @@ declare class MCPServerRuntime {
779
928
  */
780
929
  declare function startMCPServer(options: MCPServerOptions): Promise<MCPServerRuntime>;
781
930
 
782
- export { Auth, type AuthErrorOptions, type AuthErrorResult, type AuthOptions, Deprecated, type HTTPServerAuthOptions, type HTTPServerInput, type HTTPServerOptions, LogLevel, type LogPayload, Logger, type LoggerHandler, type LoggerOptions, MCPServer, type MCPServerConstructorOptions, type MCPServerFactory, type MCPServerOptions, MCPServerRuntime, Optional, Prompt, type PromptOptions, type ProtectedResourceMetadata, Render, Resource, type ResourceOptions, SchemaConstraint, type SecurityScheme, Tool, type ToolOptions, UI, UserEnvs, classToJsonSchema, classToJsonSchemaWithConstraints, createAuthError, createHTTPServer, createProtectedResourceMetadata, defaultLogger, extractBearerToken, getDecoratedMethods, getMethodMetadata, isAuthError, startMCPServer, validateNonEmpty, validatePath, validatePort, validateServiceName, validateUrl };
931
+ export { Auth, type AuthErrorOptions, type AuthErrorResult, type AuthOptions, DEFAULT_TABLE_NAME, DEFAULT_TTL_SECONDS, Deprecated, DynamoDBSessionStore, type HTTPServerAuthOptions, type HTTPServerInput, type HTTPServerOptions, type ISessionStore, LeanMCPSessionProvider, type LeanMCPSessionProviderOptions, LogLevel, type LogPayload, Logger, type LoggerHandler, type LoggerOptions, MCPServer, type MCPServerConstructorOptions, type MCPServerFactory, type MCPServerOptions, MCPServerRuntime, Optional, Prompt, type PromptOptions, type ProtectedResourceMetadata, Render, Resource, type ResourceOptions, SchemaConstraint, type SecurityScheme, type SessionData, Tool, type ToolOptions, UI, UserEnvs, classToJsonSchema, classToJsonSchemaWithConstraints, createAuthError, createHTTPServer, createProtectedResourceMetadata, defaultLogger, extractBearerToken, getDecoratedMethods, getMethodMetadata, isAuthError, startMCPServer, validateNonEmpty, validatePath, validatePort, validateServiceName, validateUrl };