Browse Source

Fix: Add API key support in MCP server headers (v1.0.8)

Reza Febryan 2 months ago
parent
commit
702ec20a91
2 changed files with 19 additions and 4 deletions
  1. 18 3
      mcp-server/index.js
  2. 1 1
      mcp-server/package.json

+ 18 - 3
mcp-server/index.js

@@ -74,8 +74,9 @@ try {
   // Silent error handling
 }
 
-// Cognio API base URL
+// Cognio API base URL and API Key
 const COGNIO_API_URL = process.env.COGNIO_API_URL || "http://localhost:8080";
+const COGNIO_API_KEY = process.env.COGNIO_API_KEY;
 
 // Active project state (persists during MCP session)
 let activeProject = null;
@@ -90,6 +91,11 @@ async function cognioRequest(endpoint, method = "GET", body = null) {
     },
   };
 
+  // Add API key if provided
+  if (COGNIO_API_KEY) {
+    options.headers["X-API-Key"] = COGNIO_API_KEY;
+  }
+
   if (body) {
     options.body = JSON.stringify(body);
   }
@@ -508,9 +514,18 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
         if (args.project) params.append("project", args.project);
         params.append("format", format);
 
-        const response = await fetch(`${API_BASE}/memory/export?${params}`, {
+        const url = `${COGNIO_API_URL}/memory/export?${params}`;
+        const options = {
           method: "GET",
-        });
+          headers: {},
+        };
+
+        // Add API key if provided
+        if (COGNIO_API_KEY) {
+          options.headers["X-API-Key"] = COGNIO_API_KEY;
+        }
+
+        const response = await fetch(url, options);
 
         if (!response.ok) {
           throw new Error(`Export failed: ${response.statusText}`);

+ 1 - 1
mcp-server/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@0xrelogic/cognio-mcp",
-  "version": "1.0.7",
+  "version": "1.0.8",
   "description": "MCP server for Cognio semantic memory",
   "type": "module",
   "main": "index.js",