fix(mcp): carry requestIdFormat through MCP config discovery

The option was only present on the transport-facing `MCPServerConfig`, so a
value written in `.omp/mcp.json` or a standalone `.mcp.json` never reached the
transports: discovery normalizes config into the canonical `MCPServer` shape and
`convertToLegacyConfig()` rebuilds the transport config from it, and neither step
knew about the field. Setting `"number"` in the documented config path silently
kept the snowflake-string default, which is the hang the option exists to avoid.

Wire it through the same four places `timeout` already uses: the canonical
`MCPServer` shape, the two OMP-native loaders (with validate-and-warn on an
unrecognized value), and the legacy conversion. Foreign-format providers are
untouched, since the key is OMP-specific.

Also point the `MCPServerConfigBase` doc comment at `RequestIdAllocator` rather
than a helper name that never existed.
This commit is contained in:
Jérémy Marchand
2026-07-30 21:53:28 +02:00
parent fa9aa68218
commit 3cb6e5df9c
6 changed files with 113 additions and 1 deletions
@@ -0,0 +1,79 @@
/**
* `requestIdFormat` must survive the documented config path.
*
* The option is only useful if a value written in config actually reaches the
* transport: discovery parses config into the canonical `MCPServer` shape and
* `convertToLegacyConfig()` turns that back into the `MCPServerConfig` the
* transports read. A field missing from either step silently degrades to the
* snowflake-string default, which is the hang the option exists to avoid.
*
* Both OMP-native loaders are covered: `.omp/mcp.json` (native provider) and a
* standalone project-root `.mcp.json` (mcp-json provider).
*/
import { afterEach, beforeEach, expect, test } from "bun:test";
import * as fs from "node:fs/promises";
import * as os from "node:os";
import * as path from "node:path";
import { clearCache as clearFsCache } from "@oh-my-pi/pi-coding-agent/capability/fs";
import { loadAllMCPConfigs } from "@oh-my-pi/pi-coding-agent/mcp/config";
import { getConfigRootDir, removeWithRetries, setAgentDir } from "@oh-my-pi/pi-utils";
const originalAgentDirEnv = process.env.PI_CODING_AGENT_DIR;
const fallbackAgentDir = path.join(getConfigRootDir(), "agent");
let tempAgentDir = "";
let tempCwd = "";
beforeEach(async () => {
tempAgentDir = await fs.mkdtemp(path.join(os.tmpdir(), "omp-mcp-reqid-agent-"));
tempCwd = await fs.mkdtemp(path.join(os.tmpdir(), "omp-mcp-reqid-cwd-"));
setAgentDir(tempAgentDir);
clearFsCache();
});
afterEach(async () => {
if (originalAgentDirEnv) {
setAgentDir(originalAgentDirEnv);
} else {
setAgentDir(fallbackAgentDir);
delete process.env.PI_CODING_AGENT_DIR;
}
clearFsCache();
await removeWithRetries(tempAgentDir);
await removeWithRetries(tempCwd);
});
async function loadFrom(file: string, mcpServers: Record<string, unknown>) {
await Bun.write(path.join(tempCwd, file), JSON.stringify({ mcpServers }));
clearFsCache();
const { configs } = await loadAllMCPConfigs(tempCwd);
return configs;
}
test("requestIdFormat from .omp/mcp.json reaches the transport config", async () => {
const configs = await loadFrom(path.join(".omp", "mcp.json"), {
xcode: { type: "stdio", command: "/usr/bin/xcrun", args: ["mcpbridge"], requestIdFormat: "number" },
plain: { type: "stdio", command: "/bin/echo" },
});
expect(configs.xcode?.requestIdFormat).toBe("number");
// Unset stays unset so the allocator keeps its snowflake-string default.
expect(configs.plain?.requestIdFormat).toBeUndefined();
});
test("requestIdFormat from a standalone .mcp.json reaches the transport config", async () => {
const configs = await loadFrom(".mcp.json", {
xcode: { type: "stdio", command: "/usr/bin/xcrun", args: ["mcpbridge"], requestIdFormat: "number" },
});
expect(configs.xcode?.requestIdFormat).toBe("number");
});
test("an unrecognized requestIdFormat is dropped rather than passed through", async () => {
const configs = await loadFrom(path.join(".omp", "mcp.json"), {
bogus: { type: "stdio", command: "/bin/echo", requestIdFormat: "integer" },
});
expect(configs.bogus).toBeDefined();
expect(configs.bogus?.requestIdFormat).toBeUndefined();
});