@memnexus-ai/cli 1.7.45 → 1.7.46
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/commands/mcp.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/commands/mcp.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMpC,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAU1D"}
|
package/dist/commands/mcp.js
CHANGED
|
@@ -41,9 +41,13 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
41
41
|
return result;
|
|
42
42
|
};
|
|
43
43
|
})();
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
44
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
48
|
exports.registerMcpCommands = registerMcpCommands;
|
|
46
49
|
const config_1 = require("../lib/config");
|
|
50
|
+
const package_json_1 = __importDefault(require("../../package.json"));
|
|
47
51
|
const DEFAULT_MCP_URL = 'https://mcp.memnexus.ai/mcp';
|
|
48
52
|
function registerMcpCommands(program) {
|
|
49
53
|
const mcp = program.command('mcp').description('MCP bridge commands');
|
|
@@ -55,6 +59,22 @@ function registerMcpCommands(program) {
|
|
|
55
59
|
await serve(opts.url);
|
|
56
60
|
});
|
|
57
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Format an error with its cause chain for diagnostic logging.
|
|
64
|
+
* Node.js fetch errors (undici) put the real error in `error.cause`.
|
|
65
|
+
*/
|
|
66
|
+
function formatError(err) {
|
|
67
|
+
if (!(err instanceof Error))
|
|
68
|
+
return String(err);
|
|
69
|
+
let msg = err.message;
|
|
70
|
+
const cause = err.cause;
|
|
71
|
+
if (cause instanceof Error) {
|
|
72
|
+
msg += ` — ${cause.message}`;
|
|
73
|
+
if ('code' in cause)
|
|
74
|
+
msg += ` (${cause.code})`;
|
|
75
|
+
}
|
|
76
|
+
return msg;
|
|
77
|
+
}
|
|
58
78
|
async function serve(mcpUrl) {
|
|
59
79
|
// Resolve API key
|
|
60
80
|
const apiKey = config_1.config.getApiKey();
|
|
@@ -68,38 +88,75 @@ async function serve(mcpUrl) {
|
|
|
68
88
|
// unless this command is actually invoked.
|
|
69
89
|
const { StdioServerTransport } = await Promise.resolve().then(() => __importStar(require('@modelcontextprotocol/sdk/server/stdio.js')));
|
|
70
90
|
const { StreamableHTTPClientTransport } = await Promise.resolve().then(() => __importStar(require('@modelcontextprotocol/sdk/client/streamableHttp.js')));
|
|
91
|
+
// Build the X-MX-Client analytics header value
|
|
92
|
+
const agentInfo = config_1.config.detectAIAgent();
|
|
93
|
+
const agentName = agentInfo.detected ? agentInfo.agent : 'mcp-bridge';
|
|
94
|
+
const mxClient = [
|
|
95
|
+
`mx-cli/${package_json_1.default.version}`,
|
|
96
|
+
`os=${process.platform}`,
|
|
97
|
+
`node=${process.version}`,
|
|
98
|
+
`agent=${agentName}`,
|
|
99
|
+
].join(' ');
|
|
100
|
+
// Custom fetch wrapper that adds our headers non-destructively.
|
|
101
|
+
// The global fetch (index.ts) is monkey-patched to inject X-MX-Client,
|
|
102
|
+
// but that wrapper creates new Headers(init?.headers) which can lose
|
|
103
|
+
// headers when the SDK passes them on a Request object or omits init.
|
|
104
|
+
// This wrapper preserves existing headers and only adds missing ones.
|
|
105
|
+
const mcpFetch = (input, init) => {
|
|
106
|
+
const headers = new Headers(init?.headers);
|
|
107
|
+
// Also copy headers from Request object if input is a Request
|
|
108
|
+
if (input instanceof Request) {
|
|
109
|
+
input.headers.forEach((value, key) => {
|
|
110
|
+
if (!headers.has(key))
|
|
111
|
+
headers.set(key, value);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
if (!headers.has('Authorization')) {
|
|
115
|
+
headers.set('Authorization', `Bearer ${apiKey}`);
|
|
116
|
+
}
|
|
117
|
+
if (!headers.has('X-MX-Client')) {
|
|
118
|
+
headers.set('X-MX-Client', mxClient);
|
|
119
|
+
}
|
|
120
|
+
return globalThis.fetch(input, { ...init, headers });
|
|
121
|
+
};
|
|
71
122
|
// stdio side — reads JSON-RPC from the agent on stdin, writes to stdout
|
|
72
123
|
const stdio = new StdioServerTransport();
|
|
73
|
-
// HTTP side — connects to the remote MCP server with auth
|
|
124
|
+
// HTTP side — connects to the remote MCP server with auth + analytics headers
|
|
74
125
|
const http = new StreamableHTTPClientTransport(new URL(mcpUrl), {
|
|
75
126
|
requestInit: {
|
|
76
127
|
headers: {
|
|
77
128
|
Authorization: `Bearer ${apiKey}`,
|
|
129
|
+
'X-MX-Client': mxClient,
|
|
78
130
|
},
|
|
79
131
|
},
|
|
132
|
+
fetch: mcpFetch,
|
|
80
133
|
});
|
|
81
134
|
// Wire the two transports together as a raw message pipe:
|
|
82
135
|
// Agent stdin → stdio.onmessage → http.send() → HTTP server
|
|
83
136
|
// HTTP server → http.onmessage → stdio.send() → Agent stdout
|
|
84
137
|
stdio.onmessage = (message) => {
|
|
85
138
|
http.send(message).catch((err) => {
|
|
86
|
-
log(`Error forwarding to server: ${err
|
|
139
|
+
log(`Error forwarding to server: ${formatError(err)}`);
|
|
87
140
|
});
|
|
88
141
|
};
|
|
89
142
|
http.onmessage = (message) => {
|
|
90
143
|
stdio.send(message).catch((err) => {
|
|
91
|
-
log(`Error forwarding to agent: ${err
|
|
144
|
+
log(`Error forwarding to agent: ${formatError(err)}`);
|
|
92
145
|
});
|
|
93
146
|
};
|
|
94
147
|
// Error handlers
|
|
95
148
|
stdio.onerror = (error) => {
|
|
96
|
-
log(`stdio error: ${error
|
|
149
|
+
log(`stdio error: ${formatError(error)}`);
|
|
97
150
|
};
|
|
98
151
|
http.onerror = (error) => {
|
|
99
|
-
log(`HTTP error: ${error
|
|
152
|
+
log(`HTTP error: ${formatError(error)}`);
|
|
100
153
|
};
|
|
101
154
|
// Close handlers — shut down both sides when either closes
|
|
155
|
+
let shuttingDown = false;
|
|
102
156
|
const shutdown = async () => {
|
|
157
|
+
if (shuttingDown)
|
|
158
|
+
return;
|
|
159
|
+
shuttingDown = true;
|
|
103
160
|
log('Shutting down...');
|
|
104
161
|
await Promise.allSettled([stdio.close(), http.close()]);
|
|
105
162
|
process.exit(0);
|
|
@@ -119,7 +176,7 @@ async function serve(mcpUrl) {
|
|
|
119
176
|
log('Bridge active');
|
|
120
177
|
}
|
|
121
178
|
catch (err) {
|
|
122
|
-
log(`Failed to start: ${err
|
|
179
|
+
log(`Failed to start: ${formatError(err)}`);
|
|
123
180
|
process.exit(1);
|
|
124
181
|
}
|
|
125
182
|
}
|
package/dist/commands/mcp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../src/commands/mcp.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG
|
|
1
|
+
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../src/commands/mcp.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQH,kDAUC;AAfD,0CAAuC;AACvC,sEAA6C;AAE7C,MAAM,eAAe,GAAG,6BAA6B,CAAC;AAEtD,SAAgB,mBAAmB,CAAC,OAAgB;IAClD,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,qBAAqB,CAAC,CAAC;IAEtE,GAAG;SACA,OAAO,CAAC,OAAO,CAAC;SAChB,WAAW,CAAC,iDAAiD,CAAC;SAC9D,MAAM,CAAC,aAAa,EAAE,gBAAgB,EAAE,OAAO,CAAC,G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