Skip to content

Commit b2fd072

Browse files
BrainSlugs83Copilot
andcommitted
fix: graceful degradation on user mismatch
Instead of crashing (which copilot shows as 'Connection closed'), the proxy now catches startup errors, completes the MCP handshake, and returns the error message when tools are called. This way the AI sees the misconfiguration and can explain it to the user. Also uses PKG.version for MCP server version instead of hardcoded. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 408d041 commit b2fd072

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

index.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ function validateServer(pingResult) {
4242
if (!pingResult || !pingResult.ok) return null;
4343

4444
if (pingResult.user && pingResult.user !== EXPECTED_USER) {
45-
const msg = `[vector-memory] FATAL: Port ${PORT} is owned by user "${pingResult.user}" (expected "${EXPECTED_USER}"). ` +
46-
`Set VECTOR_MEMORY_PORT to a different port in your mcp-config.json.\n`;
47-
process.stderr.write(msg);
48-
process.exit(1);
45+
throw new Error(
46+
`Port ${PORT} is owned by user "${pingResult.user}" (expected "${EXPECTED_USER}"). ` +
47+
`Set VECTOR_MEMORY_PORT to a different port in your mcp-config.json.`
48+
);
4949
}
5050

5151
if (pingResult.version && pingResult.version !== PKG.version) {
@@ -142,11 +142,16 @@ function callServer(path, body) {
142142

143143
// --- Start: ensure server, then expose MCP tools ---
144144

145-
await ensureServer();
145+
let startupError = null;
146+
try {
147+
await ensureServer();
148+
} catch (err) {
149+
startupError = err.message;
150+
}
146151

147152
const server = new McpServer({
148153
name: "vector-memory",
149-
version: "1.0.0",
154+
version: PKG.version,
150155
});
151156

152157
server.tool(
@@ -164,6 +169,9 @@ server.tool(
164169
.describe("Max results to return (default 10)"),
165170
},
166171
async ({ query, limit }) => {
172+
if (startupError) {
173+
return { content: [{ type: "text", text: `⚠ vector-memory misconfigured: ${startupError}` }] };
174+
}
167175
try {
168176
const results = await callServer("/search", { query, limit });
169177

@@ -194,6 +202,9 @@ server.tool(
194202
"vector_search auto-indexes new content. Use this if the index seems stale or corrupted.",
195203
{},
196204
async () => {
205+
if (startupError) {
206+
return { content: [{ type: "text", text: `⚠ vector-memory misconfigured: ${startupError}` }] };
207+
}
197208
try {
198209
const result = await callServer("/reindex", {});
199210
if (result.error) {

0 commit comments

Comments
 (0)