fix(memory-mcp): accept the reserved _meta param on ping

tools/list and tools/call on main already admit `_meta` — MCP reserves it
for request metadata and a client may attach it to any request. ping still
refused every parameter, so a client that sends `_meta` on everything
(Codex does) got -32602 on its keepalive.

Rebased onto main and narrowed: when this branch was first written the same
gap existed on tools/list, which has since been fixed upstream. Only the
ping handler is left, so only the ping handler is touched.

Refs #2810
This commit is contained in:
Nguyen Thanh Dat
2026-09-10 15:01:03 -04:00
committed by haelyra
parent 013ed0a8e6
commit 380f4b35db
2 changed files with 32 additions and 2 deletions
+12 -2
View File
@@ -426,8 +426,18 @@ function createMemoryMcpService(options = {}) {
return jsonRpcError(message.id, -32002, 'Server is not initialized.');
}
if (message.method === 'ping') {
if (message.params && Object.keys(message.params).length > 0) {
return jsonRpcError(message.id, -32602, 'ping does not accept parameters.');
const params = message.params ?? {};
// `_meta` is reserved by MCP for request metadata (e.g. progressToken) and
// may ride on any request, which is why `tools/list` and `tools/call` below
// both admit it. `ping` rejected every parameter, so a client that attaches
// `_meta` to everything — Codex does — got -32602 on its keepalive. Present
// means it must be a metadata object; nothing else is accepted. (#2810)
if (
!isRecord(params)
|| (Object.prototype.hasOwnProperty.call(params, '_meta') && !isRecord(params._meta))
|| Object.keys(params).some(key => key !== '_meta')
) {
return jsonRpcError(message.id, -32602, 'ping accepts no parameters other than _meta.');
}
return jsonRpcResult(message.id, {});
}