@prmichaelsen/remember-mcp 0.2.0 → 0.2.1
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/server-factory.d.ts +2 -0
- package/dist/server-factory.js +33 -1
- package/package.json +1 -1
- package/src/server-factory.ts +52 -5
package/dist/server-factory.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export interface ServerOptions {
|
|
|
13
13
|
* This factory function is compatible with mcp-auth wrapping pattern.
|
|
14
14
|
* It creates isolated server instances with no shared state.
|
|
15
15
|
*
|
|
16
|
+
* Note: Databases (Weaviate + Firestore) are initialized once globally on first call.
|
|
17
|
+
*
|
|
16
18
|
* @param accessToken - User's access token (reserved for future external APIs)
|
|
17
19
|
* @param userId - User identifier for scoping operations
|
|
18
20
|
* @param options - Optional server configuration
|
package/dist/server-factory.js
CHANGED
|
@@ -630,6 +630,10 @@ var logger = {
|
|
|
630
630
|
}
|
|
631
631
|
};
|
|
632
632
|
|
|
633
|
+
// src/server-factory.ts
|
|
634
|
+
init_client();
|
|
635
|
+
init_init();
|
|
636
|
+
|
|
633
637
|
// src/weaviate/schema.ts
|
|
634
638
|
init_client();
|
|
635
639
|
import weaviate2 from "weaviate-client";
|
|
@@ -2657,6 +2661,31 @@ async function handleDeleteRelationship(args, userId) {
|
|
|
2657
2661
|
}
|
|
2658
2662
|
|
|
2659
2663
|
// src/server-factory.ts
|
|
2664
|
+
var databasesInitialized = false;
|
|
2665
|
+
var initializationPromise = null;
|
|
2666
|
+
async function ensureDatabasesInitialized() {
|
|
2667
|
+
if (databasesInitialized) {
|
|
2668
|
+
return;
|
|
2669
|
+
}
|
|
2670
|
+
if (initializationPromise) {
|
|
2671
|
+
return initializationPromise;
|
|
2672
|
+
}
|
|
2673
|
+
initializationPromise = (async () => {
|
|
2674
|
+
try {
|
|
2675
|
+
logger.info("Initializing databases...");
|
|
2676
|
+
await initWeaviateClient();
|
|
2677
|
+
initFirestore();
|
|
2678
|
+
databasesInitialized = true;
|
|
2679
|
+
logger.info("Databases initialized successfully");
|
|
2680
|
+
} catch (error) {
|
|
2681
|
+
logger.error("Database initialization failed:", error);
|
|
2682
|
+
throw error;
|
|
2683
|
+
} finally {
|
|
2684
|
+
initializationPromise = null;
|
|
2685
|
+
}
|
|
2686
|
+
})();
|
|
2687
|
+
return initializationPromise;
|
|
2688
|
+
}
|
|
2660
2689
|
function createServer(accessToken, userId, options = {}) {
|
|
2661
2690
|
if (!accessToken) {
|
|
2662
2691
|
throw new Error("accessToken is required");
|
|
@@ -2665,10 +2694,13 @@ function createServer(accessToken, userId, options = {}) {
|
|
|
2665
2694
|
throw new Error("userId is required");
|
|
2666
2695
|
}
|
|
2667
2696
|
logger.debug("Creating server instance", { userId });
|
|
2697
|
+
ensureDatabasesInitialized().catch((error) => {
|
|
2698
|
+
logger.error("Failed to initialize databases:", error);
|
|
2699
|
+
});
|
|
2668
2700
|
const server = new Server(
|
|
2669
2701
|
{
|
|
2670
2702
|
name: options.name || "remember-mcp",
|
|
2671
|
-
version: options.version || "0.
|
|
2703
|
+
version: options.version || "0.2.0"
|
|
2672
2704
|
},
|
|
2673
2705
|
{
|
|
2674
2706
|
capabilities: {
|
package/package.json
CHANGED
package/src/server-factory.ts
CHANGED
|
@@ -11,6 +11,8 @@ import {
|
|
|
11
11
|
McpError,
|
|
12
12
|
} from '@modelcontextprotocol/sdk/types.js';
|
|
13
13
|
import { logger } from './utils/logger.js';
|
|
14
|
+
import { initWeaviateClient } from './weaviate/client.js';
|
|
15
|
+
import { initFirestore } from './firestore/init.js';
|
|
14
16
|
|
|
15
17
|
// Import memory tools
|
|
16
18
|
import { createMemoryTool, handleCreateMemory } from './tools/create-memory.js';
|
|
@@ -31,24 +33,62 @@ export interface ServerOptions {
|
|
|
31
33
|
version?: string;
|
|
32
34
|
}
|
|
33
35
|
|
|
36
|
+
// Global initialization flag to ensure databases are initialized once
|
|
37
|
+
let databasesInitialized = false;
|
|
38
|
+
let initializationPromise: Promise<void> | null = null;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Initialize databases (called once globally)
|
|
42
|
+
*/
|
|
43
|
+
async function ensureDatabasesInitialized(): Promise<void> {
|
|
44
|
+
if (databasesInitialized) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// If initialization is in progress, wait for it
|
|
49
|
+
if (initializationPromise) {
|
|
50
|
+
return initializationPromise;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Start initialization
|
|
54
|
+
initializationPromise = (async () => {
|
|
55
|
+
try {
|
|
56
|
+
logger.info('Initializing databases...');
|
|
57
|
+
await initWeaviateClient();
|
|
58
|
+
initFirestore();
|
|
59
|
+
databasesInitialized = true;
|
|
60
|
+
logger.info('Databases initialized successfully');
|
|
61
|
+
} catch (error) {
|
|
62
|
+
logger.error('Database initialization failed:', error);
|
|
63
|
+
throw error;
|
|
64
|
+
} finally {
|
|
65
|
+
initializationPromise = null;
|
|
66
|
+
}
|
|
67
|
+
})();
|
|
68
|
+
|
|
69
|
+
return initializationPromise;
|
|
70
|
+
}
|
|
71
|
+
|
|
34
72
|
/**
|
|
35
73
|
* Create a server instance for a specific user/tenant
|
|
36
|
-
*
|
|
74
|
+
*
|
|
37
75
|
* This factory function is compatible with mcp-auth wrapping pattern.
|
|
38
76
|
* It creates isolated server instances with no shared state.
|
|
39
|
-
*
|
|
77
|
+
*
|
|
78
|
+
* Note: Databases (Weaviate + Firestore) are initialized once globally on first call.
|
|
79
|
+
*
|
|
40
80
|
* @param accessToken - User's access token (reserved for future external APIs)
|
|
41
81
|
* @param userId - User identifier for scoping operations
|
|
42
82
|
* @param options - Optional server configuration
|
|
43
83
|
* @returns Configured MCP Server instance (not connected to transport)
|
|
44
|
-
*
|
|
84
|
+
*
|
|
45
85
|
* @example
|
|
46
86
|
* ```typescript
|
|
47
87
|
* // Direct usage
|
|
48
88
|
* const server = createServer('token', 'user123');
|
|
49
89
|
* const transport = new StdioServerTransport();
|
|
50
90
|
* await server.connect(transport);
|
|
51
|
-
*
|
|
91
|
+
*
|
|
52
92
|
* // With mcp-auth
|
|
53
93
|
* import { wrapServer } from '@prmichaelsen/mcp-auth';
|
|
54
94
|
* const wrapped = wrapServer({
|
|
@@ -75,11 +115,18 @@ export function createServer(
|
|
|
75
115
|
|
|
76
116
|
logger.debug('Creating server instance', { userId });
|
|
77
117
|
|
|
118
|
+
// Ensure databases are initialized (happens once globally)
|
|
119
|
+
// Note: This is synchronous to match the Server return type
|
|
120
|
+
// The actual initialization happens on first tool call
|
|
121
|
+
ensureDatabasesInitialized().catch(error => {
|
|
122
|
+
logger.error('Failed to initialize databases:', error);
|
|
123
|
+
});
|
|
124
|
+
|
|
78
125
|
// Create MCP server
|
|
79
126
|
const server = new Server(
|
|
80
127
|
{
|
|
81
128
|
name: options.name || 'remember-mcp',
|
|
82
|
-
version: options.version || '0.
|
|
129
|
+
version: options.version || '0.2.0',
|
|
83
130
|
},
|
|
84
131
|
{
|
|
85
132
|
capabilities: {
|