@ecommaps/mcp 1.0.8 → 1.0.10
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/cli.js +33 -8
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -72,14 +72,14 @@ function normalizeResponsePayload(rawBody, contentType) {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
async function postRpc(mcpUrl, apiKey, rpcPayload) {
|
|
75
|
+
async function postRpc(mcpUrl, apiKey, rpcPayload, protocolVersion) {
|
|
76
76
|
const response = await fetch(mcpUrl, {
|
|
77
77
|
method: 'POST',
|
|
78
78
|
headers: {
|
|
79
79
|
Authorization: `Bearer ${apiKey}`,
|
|
80
80
|
'Content-Type': 'application/json',
|
|
81
81
|
Accept: 'application/json, text/event-stream',
|
|
82
|
-
'MCP-Protocol-Version': '2025-06-18',
|
|
82
|
+
'MCP-Protocol-Version': protocolVersion || '2025-06-18',
|
|
83
83
|
},
|
|
84
84
|
body: JSON.stringify(rpcPayload),
|
|
85
85
|
});
|
|
@@ -93,6 +93,11 @@ async function postRpc(mcpUrl, apiKey, rpcPayload) {
|
|
|
93
93
|
|
|
94
94
|
const payload = normalizeResponsePayload(rawBody, contentType);
|
|
95
95
|
if (payload === null) {
|
|
96
|
+
const isNotification = !Object.prototype.hasOwnProperty.call(rpcPayload ?? {}, 'id');
|
|
97
|
+
if (isNotification) {
|
|
98
|
+
// JSON-RPC notifications legitimately have no response body.
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
96
101
|
throw new Error('MCP response was empty.');
|
|
97
102
|
}
|
|
98
103
|
|
|
@@ -123,6 +128,7 @@ async function main() {
|
|
|
123
128
|
});
|
|
124
129
|
|
|
125
130
|
let queue = Promise.resolve();
|
|
131
|
+
let negotiatedProtocolVersion = '2025-06-18';
|
|
126
132
|
|
|
127
133
|
rl.on('line', (line) => {
|
|
128
134
|
const trimmed = line.trim();
|
|
@@ -149,16 +155,35 @@ async function main() {
|
|
|
149
155
|
}
|
|
150
156
|
}
|
|
151
157
|
|
|
152
|
-
const
|
|
153
|
-
|
|
158
|
+
const requestedVersion =
|
|
159
|
+
payload?.method === 'initialize' && typeof payload?.params?.protocolVersion === 'string'
|
|
160
|
+
? payload.params.protocolVersion
|
|
161
|
+
: negotiatedProtocolVersion;
|
|
162
|
+
|
|
163
|
+
const result = await postRpc(mcpUrl, apiKey, payload, requestedVersion);
|
|
164
|
+
if (
|
|
165
|
+
payload?.method === 'initialize' &&
|
|
166
|
+
result &&
|
|
167
|
+
typeof result === 'object' &&
|
|
168
|
+
result.result &&
|
|
169
|
+
typeof result.result.protocolVersion === 'string'
|
|
170
|
+
) {
|
|
171
|
+
negotiatedProtocolVersion = result.result.protocolVersion;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (result !== null) {
|
|
175
|
+
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
176
|
+
}
|
|
154
177
|
} catch (error) {
|
|
155
178
|
const message = error && error.message ? error.message : String(error);
|
|
156
179
|
console.error(message);
|
|
157
180
|
// Best-effort JSON-RPC error response so MCP clients stay synchronized.
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
181
|
+
// Notifications do not expect responses.
|
|
182
|
+
if (payload && Object.prototype.hasOwnProperty.call(payload, 'id')) {
|
|
183
|
+
process.stdout.write(
|
|
184
|
+
`${JSON.stringify({ jsonrpc: '2.0', id: payload.id, error: { code: -32000, message } })}\n`
|
|
185
|
+
);
|
|
186
|
+
}
|
|
162
187
|
}
|
|
163
188
|
});
|
|
164
189
|
});
|