fix(mcp): apply timeouts to prompts and resources (#31612)
This commit is contained in:
parent
954d618790
commit
174ab58343
2 changed files with 52 additions and 8 deletions
|
|
@ -13,6 +13,8 @@ interface MockClientState {
|
|||
listToolsCalls: number
|
||||
listPromptsCalls: number
|
||||
listResourcesCalls: number
|
||||
getPromptTimeout?: number
|
||||
readResourceTimeout?: number
|
||||
requestCalls: number
|
||||
listToolsShouldFail: boolean
|
||||
listToolsError: string
|
||||
|
|
@ -206,6 +208,16 @@ void mock.module("@modelcontextprotocol/sdk/client/index.js", () => ({
|
|||
return { resources: this._state?.resources ?? [] }
|
||||
}
|
||||
|
||||
async getPrompt(_params: unknown, options?: { timeout?: number }) {
|
||||
if (this._state) this._state.getPromptTimeout = options?.timeout
|
||||
return { messages: [] }
|
||||
}
|
||||
|
||||
async readResource(params: { uri: string }, options?: { timeout?: number }) {
|
||||
if (this._state) this._state.readResourceTimeout = options?.timeout
|
||||
return { contents: [{ uri: params.uri, text: "test" }] }
|
||||
}
|
||||
|
||||
async close() {
|
||||
if (this._state) this._state.closed = true
|
||||
}
|
||||
|
|
@ -758,6 +770,29 @@ it.instance(
|
|||
},
|
||||
)
|
||||
|
||||
it.instance(
|
||||
"uses per-server timeouts for prompt and resource requests",
|
||||
() =>
|
||||
MCP.Service.use((mcp: MCPNS.Interface) =>
|
||||
Effect.gen(function* () {
|
||||
lastCreatedClientName = "timeout-server"
|
||||
const serverState = getOrCreateClientState("timeout-server")
|
||||
|
||||
yield* mcp.add("timeout-server", {
|
||||
type: "local",
|
||||
command: ["echo", "test"],
|
||||
timeout: 2500,
|
||||
})
|
||||
yield* mcp.getPrompt("timeout-server", "test")
|
||||
yield* mcp.readResource("timeout-server", "test://resource")
|
||||
|
||||
expect(serverState.getPromptTimeout).toBe(2500)
|
||||
expect(serverState.readResourceTimeout).toBe(2500)
|
||||
}),
|
||||
),
|
||||
{ config: { mcp: {}, experimental: { mcp_timeout: 5000 } } },
|
||||
)
|
||||
|
||||
it.instance(
|
||||
"resource-only servers connect without listing tools",
|
||||
() =>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue