mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-19 17:01:37 +03:00
fix(core): accept numeric MCP timeouts (#55851)
Co-authored-by: dajiaohuang <mikewushuwen@outlook.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
3485a7b366
commit
a448d5b987
@@ -257,6 +257,7 @@ function normalizeMcp(input: Record<string, unknown>, encoded: Record<string, un
|
||||
["experimental", "mcp_timeout"],
|
||||
diagnostics,
|
||||
)
|
||||
// V1 never applied this to connecting, unlike a per-server timeout.
|
||||
if (value !== undefined) {
|
||||
timeout.catalog = value
|
||||
timeout.execution = value
|
||||
@@ -272,13 +273,18 @@ function normalizeMcp(input: Record<string, unknown>, encoded: Record<string, un
|
||||
return
|
||||
}
|
||||
if (name === "servers" && !isDirectLegacyMcp(value)) {
|
||||
Object.entries(decodeMap(value, ConfigMCP.Server, path, diagnostics, decodeEncoded)).forEach(
|
||||
([key, server]) => setOwn(nativeServers, key, server),
|
||||
)
|
||||
Object.entries(
|
||||
decodeMap(expandServerTimeouts(value), ConfigMCP.Server, path, diagnostics, decodeEncoded),
|
||||
).forEach(([key, server]) => setOwn(nativeServers, key, server))
|
||||
return
|
||||
}
|
||||
if (name === "timeout" && !isDirectLegacyMcp(value)) {
|
||||
normalizeMcpTimeout(value, timeout, path, diagnostics)
|
||||
normalizeMcpTimeout(
|
||||
typeof value === "number" ? ConfigMigrateV1.migrateMcpTimeout(value) : value,
|
||||
timeout,
|
||||
path,
|
||||
diagnostics,
|
||||
)
|
||||
return
|
||||
}
|
||||
const server = decodeValue(ConfigMCPV1.Info, value, path, diagnostics)
|
||||
@@ -298,6 +304,19 @@ function normalizeMcp(input: Record<string, unknown>, encoded: Record<string, un
|
||||
}
|
||||
}
|
||||
|
||||
// Native servers accept the V1 bare-number timeout so one V1-shaped field does not drop the whole server.
|
||||
function expandServerTimeouts(value: unknown) {
|
||||
if (!isRecord(value)) return value
|
||||
return Object.fromEntries(
|
||||
Object.entries(value).map(([name, server]) => [
|
||||
name,
|
||||
isRecord(server) && typeof server.timeout === "number"
|
||||
? { ...server, timeout: ConfigMigrateV1.migrateMcpTimeout(server.timeout) }
|
||||
: server,
|
||||
]),
|
||||
)
|
||||
}
|
||||
|
||||
function normalizeMcpTimeout(
|
||||
value: unknown,
|
||||
timeout: Record<string, unknown>,
|
||||
|
||||
@@ -76,6 +76,11 @@ export function modelSelection(input?: string, variant?: string) {
|
||||
}
|
||||
}
|
||||
|
||||
// V1 had a single MCP timeout, so a bare number bounds every phase.
|
||||
export function migrateMcpTimeout(timeout: number) {
|
||||
return { startup: timeout, catalog: timeout, execution: timeout }
|
||||
}
|
||||
|
||||
export function migrateMcp(info: ConfigMCPV1.Info) {
|
||||
const disabled = info.enabled === undefined ? undefined : !info.enabled
|
||||
if (info.type === "local")
|
||||
@@ -85,7 +90,7 @@ export function migrateMcp(info: ConfigMCPV1.Info) {
|
||||
cwd: info.cwd,
|
||||
environment: info.environment,
|
||||
disabled,
|
||||
timeout: info.timeout === undefined ? undefined : { catalog: info.timeout, execution: info.timeout },
|
||||
timeout: info.timeout === undefined ? undefined : migrateMcpTimeout(info.timeout),
|
||||
}
|
||||
return {
|
||||
type: info.type,
|
||||
@@ -99,7 +104,7 @@ export function migrateMcp(info: ConfigMCPV1.Info) {
|
||||
redirect_uri: info.oauth.redirectUri,
|
||||
},
|
||||
disabled,
|
||||
timeout: info.timeout === undefined ? undefined : { catalog: info.timeout, execution: info.timeout },
|
||||
timeout: info.timeout === undefined ? undefined : migrateMcpTimeout(info.timeout),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1823,13 +1823,13 @@ describe("Config", () => {
|
||||
type: "local",
|
||||
command: ["node", "server.js"],
|
||||
disabled: true,
|
||||
timeout: { catalog: 10000, execution: 10000 },
|
||||
timeout: { startup: 10000, catalog: 10000, execution: 10000 },
|
||||
},
|
||||
remote: {
|
||||
type: "remote",
|
||||
url: "https://mcp.example.com",
|
||||
oauth: { client_id: "client", callback_port: 19876 },
|
||||
timeout: { catalog: 20000, execution: 20000 },
|
||||
timeout: { startup: 20000, catalog: 20000, execution: 20000 },
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
@@ -420,6 +420,35 @@ describe("ConfigNormalize", () => {
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
test("expands numeric MCP timeouts to every phase", () => {
|
||||
const result = normalized({
|
||||
mcp: {
|
||||
timeout: 4000,
|
||||
servers: {
|
||||
local: { type: "local", command: ["local"], timeout: 6000 },
|
||||
remote: { type: "remote", url: "https://remote.example.com", timeout: 8000 },
|
||||
structured: { type: "local", command: ["structured"], timeout: { catalog: 9000 } },
|
||||
invalid: { type: "local", command: ["invalid"], timeout: -1 },
|
||||
},
|
||||
},
|
||||
})
|
||||
expect(result.encoded.mcp).toEqual({
|
||||
timeout: { startup: 4000, catalog: 4000, execution: 4000 },
|
||||
servers: {
|
||||
local: { type: "local", command: ["local"], timeout: { startup: 6000, catalog: 6000, execution: 6000 } },
|
||||
remote: {
|
||||
type: "remote",
|
||||
url: "https://remote.example.com",
|
||||
timeout: { startup: 8000, catalog: 8000, execution: 8000 },
|
||||
},
|
||||
structured: { type: "local", command: ["structured"], timeout: { catalog: 9000 } },
|
||||
},
|
||||
})
|
||||
expect(result.diagnostics.map((item) => [item.kind, item.path])).toEqual([
|
||||
["invalid", ["mcp", "servers", "invalid"]],
|
||||
])
|
||||
})
|
||||
|
||||
test("uses raw MCP discriminators for reserved server names", () => {
|
||||
const result = normalized({
|
||||
mcp: {
|
||||
|
||||
Reference in New Issue
Block a user