@amar_528/mcp-bridge 2.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 HIVE-MIND Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,187 @@
1
+ # @hivemind/mcp-bridge
2
+
3
+ **Sovereign EU MCP Bridge for Claude Desktop and Cursor**
4
+
5
+ Connect your AI IDE to GDPR-compliant, sovereign European memory storage with a single command.
6
+
7
+ ```bash
8
+ npx @hivemind/mcp-bridge
9
+ ```
10
+
11
+ ## Features
12
+
13
+ - **Sovereign EU Storage**: All data resides in Hetzner Cloud (Falkenstein, Germany)
14
+ - **GDPR Compliant**: No data residency concerns for European enterprises
15
+ - **Semantic Search**: Powered by Qdrant vector database with automatic embedding
16
+ - **Triple-Operator System**: Memories support Updates/Extends/Derives relationships
17
+ - **Zero Configuration**: Works with `npx` - no installation required
18
+
19
+ ## Quick Start
20
+
21
+ ### Claude Desktop Configuration
22
+
23
+ Add this to your `claude_desktop_config.json`:
24
+
25
+ ```json
26
+ {
27
+ "mcpServers": {
28
+ "hivemind": {
29
+ "command": "npx",
30
+ "args": ["-y", "@hivemind/mcp-bridge"],
31
+ "env": {
32
+ "HIVEMIND_API_URL": "https://hivemind.davinciai.eu",
33
+ "HIVEMIND_API_KEY": "hm_master_key_99228811",
34
+ "HIVEMIND_USER_ID": "00000000-0000-4000-8000-000000000001"
35
+ }
36
+ }
37
+ }
38
+ }
39
+ ```
40
+
41
+ ### Cursor IDE Configuration
42
+
43
+ Add this to your `.cursor/settings.json`:
44
+
45
+ ```json
46
+ {
47
+ "mcpServers": {
48
+ "hivemind": {
49
+ "command": "npx",
50
+ "args": ["-y", "@hivemind/mcp-bridge"],
51
+ "env": {
52
+ "HIVEMIND_API_URL": "https://hivemind.davinciai.eu",
53
+ "HIVEMIND_API_KEY": "hm_master_key_99228811"
54
+ }
55
+ }
56
+ }
57
+ }
58
+ ```
59
+
60
+ ## Available Tools
61
+
62
+ Once connected, you have access to these MCP tools:
63
+
64
+ | Tool | Description |
65
+ |------|-------------|
66
+ | `save_memory` | Save text, code, or data to sovereign storage |
67
+ | `recall` | Search memories with semantic ranking |
68
+ | `list_memories` | List all memories with filters |
69
+ | `get_memory` | Retrieve a specific memory by ID |
70
+ | `delete_memory` | Delete a memory |
71
+ | `get_context` | Get contextual information |
72
+ | `search_memories` | Hybrid search across memories |
73
+ | `traverse_graph` | Navigate memory relationships |
74
+
75
+ ## Usage Examples
76
+
77
+ ### Save a Memory
78
+
79
+ ```
80
+ Save this code snippet:
81
+
82
+ const greet = (name) => `Hello, ${name}!`;
83
+
84
+ Tags: javascript, utility, greeting
85
+ Project: my-app
86
+ ```
87
+
88
+ ### Search Memories
89
+
90
+ ```
91
+ Find memories about authentication patterns
92
+ ```
93
+
94
+ ### Recall Context
95
+
96
+ ```
97
+ What do I know about the user preferences API?
98
+ ```
99
+
100
+ ## Environment Variables
101
+
102
+ | Variable | Required | Description |
103
+ |----------|----------|-------------|
104
+ | `HIVEMIND_API_URL` | Yes | HIVE-MIND API endpoint URL |
105
+ | `HIVEMIND_API_KEY` | Yes | Authentication API key |
106
+ | `HIVEMIND_USER_ID` | No | User identifier (auto-generated if not set) |
107
+
108
+ ## Local Development Mode
109
+
110
+ For testing against a local HIVE-MIND server:
111
+
112
+ ```bash
113
+ npx @hivemind/mcp-bridge local --url http://localhost:3000
114
+ ```
115
+
116
+ ## Command Line Options
117
+
118
+ ```
119
+ USAGE:
120
+ npx @hivemind/mcp-bridge [mode] [options]
121
+
122
+ MODES:
123
+ hosted Connect to hosted HIVE-MIND API (default)
124
+ local Connect to local development server
125
+
126
+ OPTIONS:
127
+ --url <url> API URL (overrides env var)
128
+ --api-key <key> API key (overrides env var)
129
+ --user-id <id> User ID (overrides env var)
130
+ --verbose, -v Enable verbose logging
131
+ --version Show version number
132
+ --help, -h Show help message
133
+ ```
134
+
135
+ ## Architecture
136
+
137
+ ```
138
+ ┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
139
+ │ Claude Desktop │────▶│ MCP Bridge │────▶│ HIVE-MIND API │
140
+ │ (MCP Client) │ │ (npx @hivemind) │ │ (Hetzner EU) │
141
+ └─────────────────┘ └──────────────────┘ └─────────────────┘
142
+
143
+ ┌──────────────────────────────┼──────────────┐
144
+ │ │ │
145
+ ▼ ▼ ▼
146
+ ┌─────────────────┐ ┌─────────────────┐ │
147
+ │ PostgreSQL │ │ Qdrant Cloud │ │
148
+ │ (Metadata) │ │ (Vectors) │ │
149
+ └─────────────────┘ └─────────────────┘ │
150
+
151
+ ┌─────────────────┐
152
+ │ Hetzner │
153
+ │ Embeddings │
154
+ │ (all-MiniLM) │
155
+ └─────────────────┘
156
+ ```
157
+
158
+ ## Data Residency
159
+
160
+ All data is stored in the European Union:
161
+
162
+ - **PostgreSQL**: Hetzner Cloud (Falkenstein, Germany)
163
+ - **Qdrant Cloud**: AWS Frankfurt (EU region)
164
+ - **Embeddings**: Hetzner Cloud (Falkenstein, Germany)
165
+
166
+ This ensures GDPR compliance for European enterprises with strict data residency requirements.
167
+
168
+ ## Comparison with Supermemory
169
+
170
+ | Feature | HIVE-MIND | Supermemory |
171
+ |---------|-----------|-------------|
172
+ | Data Residency | EU (Hetzner) | US (Cloudflare) |
173
+ | GDPR Compliance | Yes | Limited |
174
+ | Infrastructure | Sovereign EU | US-centric |
175
+ | Target Market | European enterprises | Global |
176
+
177
+ ## License
178
+
179
+ MIT License - See [LICENSE](LICENSE) file.
180
+
181
+ ## Repository
182
+
183
+ https://github.com/hivemind/mcp-bridge
184
+
185
+ ## Support
186
+
187
+ For issues or questions, please open an issue on GitHub.
package/dist/cli.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * HIVE-MIND MCP Bridge CLI
4
+ * Bridges local MCP clients to hosted HIVE-MIND MCP service
5
+ *
6
+ * Usage:
7
+ * npx @hivemind/mcp-bridge hosted - Connect to hosted EU backend
8
+ * npx @hivemind/mcp-bridge local - Connect to local development server
9
+ * npx @hivemind/mcp-bridge - Defaults to hosted mode
10
+ *
11
+ * Environment Variables (hosted mode):
12
+ * HIVEMIND_API_URL - HIVE-MIND API URL (required for hosted)
13
+ * HIVEMIND_API_KEY - API key for authentication (required for hosted)
14
+ * HIVEMIND_USER_ID - User identifier (optional, defaults to UUID)
15
+ *
16
+ * Environment Variables (local mode):
17
+ * HIVEMIND_LOCAL_URL - Local server URL (default: http://localhost:3000)
18
+ */
19
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,311 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * HIVE-MIND MCP Bridge CLI
4
+ * Bridges local MCP clients to hosted HIVE-MIND MCP service
5
+ *
6
+ * Usage:
7
+ * npx @hivemind/mcp-bridge hosted - Connect to hosted EU backend
8
+ * npx @hivemind/mcp-bridge local - Connect to local development server
9
+ * npx @hivemind/mcp-bridge - Defaults to hosted mode
10
+ *
11
+ * Environment Variables (hosted mode):
12
+ * HIVEMIND_API_URL - HIVE-MIND API URL (required for hosted)
13
+ * HIVEMIND_API_KEY - API key for authentication (required for hosted)
14
+ * HIVEMIND_USER_ID - User identifier (optional, defaults to UUID)
15
+ *
16
+ * Environment Variables (local mode):
17
+ * HIVEMIND_LOCAL_URL - Local server URL (default: http://localhost:3000)
18
+ */
19
+ import { readFileSync } from 'fs';
20
+ import { fileURLToPath } from 'url';
21
+ import { dirname, join } from 'path';
22
+ // Get package version
23
+ const __dirname = dirname(fileURLToPath(import.meta.url));
24
+ let packageVersion = '2.0.0';
25
+ try {
26
+ const pkg = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf-8'));
27
+ packageVersion = pkg.version;
28
+ }
29
+ catch {
30
+ // Ignore if package.json not found
31
+ }
32
+ function parseArgs() {
33
+ const args = process.argv.slice(2);
34
+ const config = {};
35
+ for (let i = 0; i < args.length; i++) {
36
+ const arg = args[i];
37
+ switch (arg) {
38
+ case 'hosted':
39
+ case '--hosted':
40
+ config.mode = 'hosted';
41
+ break;
42
+ case 'local':
43
+ case '--local':
44
+ config.mode = 'local';
45
+ break;
46
+ case '--url':
47
+ config.apiUrl = args[++i];
48
+ break;
49
+ case '--api-key':
50
+ config.apiKey = args[++i];
51
+ break;
52
+ case '--user-id':
53
+ config.userId = args[++i];
54
+ break;
55
+ case '-v':
56
+ case '--verbose':
57
+ config.verbose = true;
58
+ break;
59
+ case '--version':
60
+ console.log(`@hivemind/mcp-bridge v${packageVersion}`);
61
+ process.exit(0);
62
+ case '--help':
63
+ case '-h':
64
+ printHelp();
65
+ process.exit(0);
66
+ }
67
+ }
68
+ return config;
69
+ }
70
+ function printHelp() {
71
+ console.log(`
72
+ HIVE-MIND MCP Bridge v${packageVersion}
73
+ Connect Claude Desktop/Cursor to sovereign EU memory storage
74
+
75
+ USAGE:
76
+ npx @hivemind/mcp-bridge [mode] [options]
77
+
78
+ MODES:
79
+ hosted Connect to hosted HIVE-MIND API (default)
80
+ local Connect to local development server
81
+
82
+ OPTIONS:
83
+ --url <url> API URL (overrides env var)
84
+ --api-key <key> API key (overrides env var)
85
+ --user-id <id> User ID (overrides env var)
86
+ --verbose, -v Enable verbose logging
87
+ --version Show version number
88
+ --help, -h Show this help message
89
+
90
+ ENVIRONMENT VARIABLES:
91
+ HIVEMIND_API_URL API URL for hosted mode
92
+ HIVEMIND_API_KEY API key for authentication
93
+ HIVEMIND_USER_ID User identifier (UUID)
94
+ HIVEMIND_LOCAL_URL Local server URL (default: http://localhost:3000)
95
+
96
+ EXAMPLES:
97
+ # Use with Claude Desktop (configured in claude_desktop_config.json)
98
+ {
99
+ "mcpServers": {
100
+ "hivemind": {
101
+ "command": "npx",
102
+ "args": ["-y", "@hivemind/mcp-bridge", "hosted"],
103
+ "env": {
104
+ "HIVEMIND_API_URL": "https://hivemind.davinciai.eu",
105
+ "HIVEMIND_API_KEY": "hm_master_key_...",
106
+ "HIVEMIND_USER_ID": "00000000-0000-4000-8000-000000000001"
107
+ }
108
+ }
109
+ }
110
+ }
111
+
112
+ # Local development
113
+ npx @hivemind/mcp-bridge local --url http://localhost:3000
114
+
115
+ MORE INFO:
116
+ https://github.com/hivemind/mcp-bridge
117
+ `);
118
+ }
119
+ function loadConfig() {
120
+ const cliConfig = parseArgs();
121
+ const mode = cliConfig.mode || 'hosted';
122
+ const verbose = cliConfig.verbose || false;
123
+ if (mode === 'hosted') {
124
+ const apiUrl = cliConfig.apiUrl || process.env.HIVEMIND_API_URL;
125
+ const apiKey = cliConfig.apiKey || process.env.HIVEMIND_API_KEY;
126
+ const userId = cliConfig.userId || process.env.HIVEMIND_USER_ID || generateUserId();
127
+ if (!apiUrl || !apiKey) {
128
+ console.error('ERROR: Hosted mode requires HIVEMIND_API_URL and HIVEMIND_API_KEY');
129
+ console.error('');
130
+ console.error('Set environment variables:');
131
+ console.error(' export HIVEMIND_API_URL="https://hivemind.davinciai.eu"');
132
+ console.error(' export HIVEMIND_API_KEY="hm_master_key_..."');
133
+ console.error('');
134
+ console.error('Or configure in claude_desktop_config.json:');
135
+ console.error(' "env": {');
136
+ console.error(' "HIVEMIND_API_URL": "...",');
137
+ console.error(' "HIVEMIND_API_KEY": "..."');
138
+ console.error(' }');
139
+ process.exit(1);
140
+ }
141
+ return { mode, apiUrl, apiKey, userId, verbose };
142
+ }
143
+ else {
144
+ // Local mode
145
+ const apiUrl = cliConfig.apiUrl || process.env.HIVEMIND_LOCAL_URL || 'http://localhost:3000';
146
+ const apiKey = cliConfig.apiKey || process.env.HIVEMIND_API_KEY || 'hm_master_key_99228811';
147
+ const userId = cliConfig.userId || '00000000-0000-4000-8000-000000000001';
148
+ return { mode, apiUrl, apiKey, userId, verbose };
149
+ }
150
+ }
151
+ function generateUserId() {
152
+ // Generate a stable user ID based on hostname for local development
153
+ const hostname = require('os').hostname();
154
+ const hash = require('crypto').createHash('md5').update(hostname).digest('hex');
155
+ return `${hash.slice(0, 8)}-${hash.slice(8, 12)}-${hash.slice(12, 16)}-${hash.slice(16, 20)}-${hash.slice(20, 32)}`;
156
+ }
157
+ // ============================================================================
158
+ // MCP Bridge Implementation
159
+ // ============================================================================
160
+ async function runHostedBridge(config) {
161
+ log(config, `Starting HIVE-MIND MCP Bridge v${packageVersion}`);
162
+ log(config, `Mode: HOSTED`);
163
+ log(config, `API URL: ${config.apiUrl}`);
164
+ log(config, `User ID: ${config.userId}`);
165
+ // Fetch MCP configuration from hosted service
166
+ log(config, 'Fetching MCP configuration...');
167
+ try {
168
+ const response = await fetch(`${config.apiUrl}/api/mcp/servers/${config.userId}`, {
169
+ headers: {
170
+ 'X-API-Key': config.apiKey,
171
+ 'X-User-Id': config.userId
172
+ }
173
+ });
174
+ if (!response.ok) {
175
+ console.error(`Failed to connect to HIVE-MIND: ${response.status} ${response.statusText}`);
176
+ console.error('');
177
+ console.error('Troubleshooting:');
178
+ console.error(' 1. Check HIVEMIND_API_URL is correct');
179
+ console.error(' 2. Check HIVEMIND_API_KEY is valid');
180
+ console.error(' 3. Verify the server is running');
181
+ process.exit(1);
182
+ }
183
+ const serverConfig = await response.json();
184
+ log(config, `Connected! Server: ${serverConfig.mcp.serverInfo.name} v${serverConfig.mcp.serverInfo.version}`);
185
+ log(config, `Available tools: ${serverConfig.tools.length}`);
186
+ if (config.verbose) {
187
+ serverConfig.tools.forEach(tool => {
188
+ log(config, ` - ${tool.name}: ${tool.description}`);
189
+ });
190
+ }
191
+ // Start stdio bridge - handle incoming MCP messages
192
+ process.stdin.on('data', async (data) => {
193
+ try {
194
+ const message = JSON.parse(data.toString());
195
+ await handleMessage(message, config, serverConfig);
196
+ }
197
+ catch (error) {
198
+ log(config, `Error parsing message: ${error.message}`);
199
+ sendError(null, -32700, 'Parse error: Invalid JSON');
200
+ }
201
+ });
202
+ // Keep process alive
203
+ setInterval(() => { }, 1000);
204
+ }
205
+ catch (error) {
206
+ console.error(`Connection error: ${error.message}`);
207
+ process.exit(1);
208
+ }
209
+ }
210
+ async function handleMessage(message, config, serverConfig) {
211
+ const { method, id, params } = message;
212
+ switch (method) {
213
+ case 'initialize':
214
+ sendResponse(id, { result: serverConfig.mcp });
215
+ break;
216
+ case 'tools/list':
217
+ sendResponse(id, { result: { tools: serverConfig.tools } });
218
+ break;
219
+ case 'tools/call': {
220
+ const toolParams = params;
221
+ const toolName = toolParams?.name;
222
+ const toolArgs = toolParams?.arguments;
223
+ log(config, `Tool call: ${toolName}`);
224
+ if (config.verbose) {
225
+ log(config, ` Arguments: ${JSON.stringify(toolArgs, null, 2)}`);
226
+ }
227
+ try {
228
+ // Proxy tool call to hosted service
229
+ const response = await fetch(`${config.apiUrl}/api/mcp/rpc`, {
230
+ method: 'POST',
231
+ headers: {
232
+ 'Content-Type': 'application/json',
233
+ 'Authorization': `Bearer ${config.apiKey}`,
234
+ 'X-User-Id': config.userId
235
+ },
236
+ body: JSON.stringify({
237
+ jsonrpc: '2.0',
238
+ id,
239
+ method: 'tools/call',
240
+ params: {
241
+ name: toolName,
242
+ arguments: toolArgs
243
+ }
244
+ })
245
+ });
246
+ const resultData = await response.json();
247
+ if (config.verbose) {
248
+ log(config, ` Response: ${JSON.stringify(resultData)}`);
249
+ }
250
+ console.log(JSON.stringify(resultData));
251
+ }
252
+ catch (error) {
253
+ sendError(id, -32603, `Tool call failed: ${error.message}`);
254
+ }
255
+ break;
256
+ }
257
+ case 'ping':
258
+ sendResponse(id, { result: {} });
259
+ break;
260
+ default:
261
+ sendError(id, -32601, `Method not found: ${method}`);
262
+ }
263
+ }
264
+ function sendResponse(id, response) {
265
+ console.log(JSON.stringify({
266
+ jsonrpc: '2.0',
267
+ id,
268
+ ...response
269
+ }));
270
+ }
271
+ function sendError(id, code, message) {
272
+ console.log(JSON.stringify({
273
+ jsonrpc: '2.0',
274
+ id,
275
+ error: { code, message }
276
+ }));
277
+ }
278
+ function log(config, message) {
279
+ if (config.verbose || !config.mode) {
280
+ console.error(`[HIVE-MIND Bridge] ${message}`);
281
+ }
282
+ }
283
+ async function runLocalBridge(config) {
284
+ log(config, `Starting HIVE-MIND MCP Bridge v${packageVersion}`);
285
+ log(config, `Mode: LOCAL`);
286
+ log(config, `Local URL: ${config.apiUrl}`);
287
+ // For local mode, we proxy to a local HIVEMIND server
288
+ console.error(`[HIVE-MIND Bridge] Local mode connects to ${config.apiUrl}`);
289
+ console.error(`[HIVE-MIND Bridge] This mode is for development only`);
290
+ // Same implementation as hosted, but with local URL
291
+ await runHostedBridge(config);
292
+ }
293
+ // ============================================================================
294
+ // Main Entry Point
295
+ // ============================================================================
296
+ async function main() {
297
+ try {
298
+ const config = loadConfig();
299
+ if (config.mode === 'hosted') {
300
+ await runHostedBridge(config);
301
+ }
302
+ else {
303
+ await runLocalBridge(config);
304
+ }
305
+ }
306
+ catch (error) {
307
+ console.error(`Fatal error: ${error.message}`);
308
+ process.exit(1);
309
+ }
310
+ }
311
+ main().catch(console.error);
@@ -0,0 +1,178 @@
1
+ /**
2
+ * HIVE-MIND MCP Server with Zod Validation
3
+ * Implements the "Supermemory" tool pattern for strict input validation
4
+ * Ensures all memory operations follow the Normalized Memory Schema
5
+ */
6
+ import { z } from 'zod';
7
+ /**
8
+ * Memory content schema - accepts text, code, or structured data
9
+ */
10
+ export declare const MemoryContentSchema: z.ZodString;
11
+ /**
12
+ * Tags schema - optional array of strings for categorization
13
+ */
14
+ export declare const MemoryTagsSchema: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
15
+ /**
16
+ * Project identifier schema - defaults to 'antigravity' for backward compatibility
17
+ */
18
+ export declare const ProjectSchema: z.ZodDefault<z.ZodString>;
19
+ /**
20
+ * User identifier schema - UUID format preferred
21
+ */
22
+ export declare const UserIdSchema: z.ZodString;
23
+ /**
24
+ * Memory priority schema - for importance ranking
25
+ */
26
+ export declare const PrioritySchema: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
27
+ /**
28
+ * Relationship type for triple-operator system
29
+ */
30
+ export declare const RelationshipTypeSchema: z.ZodOptional<z.ZodEnum<["updates", "extends", "derives"]>>;
31
+ /**
32
+ * Complete memory input schema - combines all fields
33
+ */
34
+ export declare const SaveMemoryInputSchema: z.ZodObject<{
35
+ content: z.ZodString;
36
+ tags: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
37
+ project: z.ZodDefault<z.ZodString>;
38
+ userId: z.ZodOptional<z.ZodString>;
39
+ priority: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
40
+ relationship: z.ZodOptional<z.ZodObject<{
41
+ type: z.ZodOptional<z.ZodEnum<["updates", "extends", "derives"]>>;
42
+ targetId: z.ZodOptional<z.ZodString>;
43
+ }, "strip", z.ZodTypeAny, {
44
+ type?: "updates" | "extends" | "derives" | undefined;
45
+ targetId?: string | undefined;
46
+ }, {
47
+ type?: "updates" | "extends" | "derives" | undefined;
48
+ targetId?: string | undefined;
49
+ }>>;
50
+ }, "strip", z.ZodTypeAny, {
51
+ content: string;
52
+ tags: string[];
53
+ project: string;
54
+ userId?: string | undefined;
55
+ priority?: number | undefined;
56
+ relationship?: {
57
+ type?: "updates" | "extends" | "derives" | undefined;
58
+ targetId?: string | undefined;
59
+ } | undefined;
60
+ }, {
61
+ content: string;
62
+ userId?: string | undefined;
63
+ tags?: string[] | undefined;
64
+ project?: string | undefined;
65
+ priority?: number | undefined;
66
+ relationship?: {
67
+ type?: "updates" | "extends" | "derives" | undefined;
68
+ targetId?: string | undefined;
69
+ } | undefined;
70
+ }>;
71
+ export type SaveMemoryInput = z.infer<typeof SaveMemoryInputSchema>;
72
+ export type MemoryTags = z.infer<typeof MemoryTagsSchema>;
73
+ export type RelationshipType = z.infer<typeof RelationshipTypeSchema>;
74
+ /**
75
+ * Validate and parse memory input with detailed error messages
76
+ */
77
+ export declare function validateMemoryInput(input: unknown): {
78
+ success: true;
79
+ data: SaveMemoryInput;
80
+ } | {
81
+ success: false;
82
+ error: string;
83
+ details?: Record<string, string[]>;
84
+ };
85
+ /**
86
+ * Normalize memory content (trim, clean, standardize)
87
+ */
88
+ export declare function normalizeMemoryContent(content: string): string;
89
+ /**
90
+ * Generate normalized tags (lowercase, trimmed, deduplicated)
91
+ */
92
+ export declare function normalizeTags(tags?: string[]): string[];
93
+ /**
94
+ * Result type for memory operations
95
+ */
96
+ export interface MemoryOperationResult {
97
+ success: boolean;
98
+ memoryId?: string;
99
+ message: string;
100
+ metadata?: {
101
+ vectorStored?: boolean;
102
+ relationshipDetected?: boolean;
103
+ relationshipType?: RelationshipType;
104
+ };
105
+ }
106
+ /**
107
+ * Handler function type for save_memory tool
108
+ */
109
+ export type SaveMemoryHandler = (input: SaveMemoryInput) => Promise<MemoryOperationResult>;
110
+ /**
111
+ * Create a configured save_memory tool handler
112
+ *
113
+ * @param hivemindApiUrl - The HIVE-MIND API URL
114
+ * @param hivemindApiKey - The API key for authentication
115
+ * @returns Handler function for MCP tool
116
+ */
117
+ export declare function createSaveMemoryHandler(hivemindApiUrl: string, hivemindApiKey: string): SaveMemoryHandler;
118
+ /**
119
+ * Tool definition for registration with MCP server
120
+ *
121
+ * Usage:
122
+ * ```typescript
123
+ * const server = new McpServer({ name: "HIVE-MIND", version: "2.0.0" });
124
+ *
125
+ * server.tool(
126
+ * MEMORY_TOOL_DEFINITION.name,
127
+ * MEMORY_TOOL_DEFINITION.inputSchema,
128
+ * MEMORY_TOOL_DEFINITION.handler
129
+ * );
130
+ * ```
131
+ */
132
+ export declare const MEMORY_TOOL_DEFINITION: {
133
+ name: string;
134
+ description: string;
135
+ inputSchema: {
136
+ readonly type: "object";
137
+ readonly properties: {
138
+ readonly content: {
139
+ readonly type: "string";
140
+ readonly description: "The text, code, or data to remember (max 50,000 chars)";
141
+ };
142
+ readonly tags: {
143
+ readonly type: "array";
144
+ readonly items: {
145
+ readonly type: "string";
146
+ };
147
+ readonly description: "Category tags for organizing memories (max 20)";
148
+ };
149
+ readonly project: {
150
+ readonly type: "string";
151
+ readonly description: "Project context (default: \"antigravity\")";
152
+ };
153
+ readonly priority: {
154
+ readonly type: "number";
155
+ readonly minimum: 0;
156
+ readonly maximum: 10;
157
+ readonly description: "Importance priority 0-10 (default: 5)";
158
+ };
159
+ readonly relationship: {
160
+ readonly type: "object";
161
+ readonly properties: {
162
+ readonly type: {
163
+ readonly type: "string";
164
+ readonly enum: readonly ["updates", "extends", "derives"];
165
+ readonly description: "Relationship to existing memory";
166
+ };
167
+ readonly targetId: {
168
+ readonly type: "string";
169
+ readonly format: "uuid";
170
+ readonly description: "ID of related memory";
171
+ };
172
+ };
173
+ readonly description: "Triple-operator relationship (Updates/Extends/Derives)";
174
+ };
175
+ };
176
+ readonly required: readonly ["content"];
177
+ };
178
+ };
package/dist/server.js ADDED
@@ -0,0 +1,231 @@
1
+ /**
2
+ * HIVE-MIND MCP Server with Zod Validation
3
+ * Implements the "Supermemory" tool pattern for strict input validation
4
+ * Ensures all memory operations follow the Normalized Memory Schema
5
+ */
6
+ import { z } from 'zod';
7
+ // ============================================================================
8
+ // Schema Definitions (Normalized Memory Schema)
9
+ // ============================================================================
10
+ /**
11
+ * Memory content schema - accepts text, code, or structured data
12
+ */
13
+ export const MemoryContentSchema = z.string()
14
+ .min(1, "Memory content cannot be empty")
15
+ .max(50000, "Memory content exceeds maximum length of 50,000 characters")
16
+ .describe("The text, code, or data to remember");
17
+ /**
18
+ * Tags schema - optional array of strings for categorization
19
+ */
20
+ export const MemoryTagsSchema = z.array(z.string())
21
+ .max(20, "Maximum 20 tags allowed")
22
+ .optional()
23
+ .default([])
24
+ .describe("Category tags for organizing memories");
25
+ /**
26
+ * Project identifier schema - defaults to 'antigravity' for backward compatibility
27
+ */
28
+ export const ProjectSchema = z.string()
29
+ .min(1, "Project name cannot be empty")
30
+ .default("antigravity")
31
+ .describe("Project context for the memory");
32
+ /**
33
+ * User identifier schema - UUID format preferred
34
+ */
35
+ export const UserIdSchema = z.string()
36
+ .uuid("Invalid UUID format")
37
+ .describe("User who owns this memory");
38
+ /**
39
+ * Memory priority schema - for importance ranking
40
+ */
41
+ export const PrioritySchema = z.number()
42
+ .min(0)
43
+ .max(10)
44
+ .default(5)
45
+ .optional()
46
+ .describe("Importance priority (0-10, default 5)");
47
+ /**
48
+ * Relationship type for triple-operator system
49
+ */
50
+ export const RelationshipTypeSchema = z.enum(['updates', 'extends', 'derives'])
51
+ .optional()
52
+ .describe("Relationship to existing memories (triple-operator system)");
53
+ /**
54
+ * Complete memory input schema - combines all fields
55
+ */
56
+ export const SaveMemoryInputSchema = z.object({
57
+ content: MemoryContentSchema,
58
+ tags: MemoryTagsSchema,
59
+ project: ProjectSchema,
60
+ userId: UserIdSchema.optional(),
61
+ priority: PrioritySchema,
62
+ relationship: z.object({
63
+ type: RelationshipTypeSchema,
64
+ targetId: z.string().uuid().optional()
65
+ }).optional()
66
+ });
67
+ // ============================================================================
68
+ // Input Validation Helpers
69
+ // ============================================================================
70
+ /**
71
+ * Validate and parse memory input with detailed error messages
72
+ */
73
+ export function validateMemoryInput(input) {
74
+ const result = SaveMemoryInputSchema.safeParse(input);
75
+ if (result.success) {
76
+ return { success: true, data: result.data };
77
+ }
78
+ const details = {};
79
+ result.error.errors.forEach(err => {
80
+ const path = err.path.join('.') || 'root';
81
+ if (!details[path])
82
+ details[path] = [];
83
+ details[path].push(err.message);
84
+ });
85
+ return {
86
+ success: false,
87
+ error: result.error.message,
88
+ details
89
+ };
90
+ }
91
+ /**
92
+ * Normalize memory content (trim, clean, standardize)
93
+ */
94
+ export function normalizeMemoryContent(content) {
95
+ return content
96
+ .trim()
97
+ .replace(/\r\n/g, '\n') // Normalize line endings
98
+ .replace(/\s+$/gm, '') // Remove trailing whitespace
99
+ .replace(/^\s*\n/gm, '\n'); // Remove leading whitespace on lines
100
+ }
101
+ /**
102
+ * Generate normalized tags (lowercase, trimmed, deduplicated)
103
+ */
104
+ export function normalizeTags(tags) {
105
+ if (!tags || tags.length === 0)
106
+ return [];
107
+ return Array.from(new Set(tags
108
+ .map(tag => tag.toLowerCase().trim())
109
+ .filter(tag => tag.length > 0)));
110
+ }
111
+ /**
112
+ * Create a configured save_memory tool handler
113
+ *
114
+ * @param hivemindApiUrl - The HIVE-MIND API URL
115
+ * @param hivemindApiKey - The API key for authentication
116
+ * @returns Handler function for MCP tool
117
+ */
118
+ export function createSaveMemoryHandler(hivemindApiUrl, hivemindApiKey) {
119
+ return async (input) => {
120
+ try {
121
+ // Normalize input
122
+ const normalizedContent = normalizeMemoryContent(input.content);
123
+ const normalizedTags = normalizeTags(input.tags);
124
+ // Prepare payload for HIVE-MIND API
125
+ const payload = {
126
+ content: normalizedContent,
127
+ tags: normalizedTags,
128
+ project: input.project,
129
+ priority: input.priority,
130
+ relationship: input.relationship
131
+ };
132
+ // Send to sovereign EU backend
133
+ const response = await fetch(`${hivemindApiUrl}/api/memories`, {
134
+ method: 'POST',
135
+ headers: {
136
+ 'Content-Type': 'application/json',
137
+ 'Authorization': `Bearer ${hivemindApiKey}`,
138
+ 'X-Data-Residency': 'EU' // GDPR compliance header
139
+ },
140
+ body: JSON.stringify(payload)
141
+ });
142
+ if (!response.ok) {
143
+ const errorBody = await response.text();
144
+ throw new Error(`API error: ${response.status} - ${errorBody}`);
145
+ }
146
+ const result = await response.json();
147
+ return {
148
+ success: true,
149
+ memoryId: result.id,
150
+ message: "Memory secured in HIVE-MIND sovereign storage",
151
+ metadata: {
152
+ vectorStored: result.vectorStored ?? true,
153
+ relationshipDetected: !!result.relationship,
154
+ relationshipType: result.relationship?.type
155
+ }
156
+ };
157
+ }
158
+ catch (error) {
159
+ return {
160
+ success: false,
161
+ message: `Failed to save memory: ${error.message}`,
162
+ metadata: {
163
+ vectorStored: false,
164
+ relationshipDetected: false
165
+ }
166
+ };
167
+ }
168
+ };
169
+ }
170
+ // ============================================================================
171
+ // MCP Tool Definition (for direct use with @modelcontextprotocol/sdk)
172
+ // ============================================================================
173
+ /**
174
+ * Tool definition for registration with MCP server
175
+ *
176
+ * Usage:
177
+ * ```typescript
178
+ * const server = new McpServer({ name: "HIVE-MIND", version: "2.0.0" });
179
+ *
180
+ * server.tool(
181
+ * MEMORY_TOOL_DEFINITION.name,
182
+ * MEMORY_TOOL_DEFINITION.inputSchema,
183
+ * MEMORY_TOOL_DEFINITION.handler
184
+ * );
185
+ * ```
186
+ */
187
+ export const MEMORY_TOOL_DEFINITION = {
188
+ name: 'save_memory',
189
+ description: 'Save a memory to HIVE-MIND sovereign EU storage. Supports text, code, and structured data with automatic semantic indexing.',
190
+ inputSchema: {
191
+ type: 'object',
192
+ properties: {
193
+ content: {
194
+ type: 'string',
195
+ description: 'The text, code, or data to remember (max 50,000 chars)'
196
+ },
197
+ tags: {
198
+ type: 'array',
199
+ items: { type: 'string' },
200
+ description: 'Category tags for organizing memories (max 20)'
201
+ },
202
+ project: {
203
+ type: 'string',
204
+ description: 'Project context (default: "antigravity")'
205
+ },
206
+ priority: {
207
+ type: 'number',
208
+ minimum: 0,
209
+ maximum: 10,
210
+ description: 'Importance priority 0-10 (default: 5)'
211
+ },
212
+ relationship: {
213
+ type: 'object',
214
+ properties: {
215
+ type: {
216
+ type: 'string',
217
+ enum: ['updates', 'extends', 'derives'],
218
+ description: 'Relationship to existing memory'
219
+ },
220
+ targetId: {
221
+ type: 'string',
222
+ format: 'uuid',
223
+ description: 'ID of related memory'
224
+ }
225
+ },
226
+ description: 'Triple-operator relationship (Updates/Extends/Derives)'
227
+ }
228
+ },
229
+ required: ['content']
230
+ }
231
+ };
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@amar_528/mcp-bridge",
3
+ "version": "2.0.0",
4
+ "description": "Sovereign EU MCP Bridge - Connect Claude Desktop/Cursor to HIVE-MIND hosted MCP service with GDPR-compliant data residency",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "bin": {
9
+ "hivemind-mcp-bridge": "./dist/cli.js",
10
+ "hivemind-mcp": "./dist/cli.js"
11
+ },
12
+ "files": [
13
+ "dist",
14
+ "README.md",
15
+ "LICENSE"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsc",
19
+ "dev": "tsc --watch",
20
+ "start": "node dist/cli.js",
21
+ "prepublishOnly": "npm run build",
22
+ "clean": "rm -rf dist"
23
+ },
24
+ "keywords": [
25
+ "hivemind",
26
+ "mcp",
27
+ "model-context-protocol",
28
+ "claude",
29
+ "cursor",
30
+ "ai",
31
+ "memory",
32
+ "gdpr",
33
+ "sovereign",
34
+ "europe"
35
+ ],
36
+ "author": "HIVE-MIND Team",
37
+ "license": "MIT",
38
+ "homepage": "https://github.com/hivemind/mcp-bridge#readme",
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "https://github.com/hivemind/mcp-bridge.git"
42
+ },
43
+ "bugs": {
44
+ "url": "https://github.com/hivemind/mcp-bridge/issues"
45
+ },
46
+ "dependencies": {
47
+ "@modelcontextprotocol/sdk": "^1.0.0",
48
+ "zod": "^3.25.76"
49
+ },
50
+ "devDependencies": {
51
+ "@types/node": "^20.0.0",
52
+ "typescript": "^5.0.0"
53
+ },
54
+ "engines": {
55
+ "node": ">=18"
56
+ },
57
+ "peerDependencies": {
58
+ "node-fetch": "^3.3.2"
59
+ }
60
+ }