feat(mcp): append server instructions to context (#32490)

Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
This commit is contained in:
4rcadia
2026-06-24 11:54:19 -05:00
committed by GitHub
co-authored by Aiden Cline
parent 2e909334c1
commit e8e83afbce
8 changed files with 269 additions and 36 deletions
@@ -13,6 +13,7 @@ import { TestInstance } from "../fixture/fixture"
interface MockClientState {
capabilities: { tools?: object; prompts?: object; resources?: object }
capabilitiesShouldThrow: boolean
instructions?: string
tools: Array<{ name: string; description?: string; inputSchema: object; outputSchema?: object }>
listToolsCalls: number
listPromptsCalls: number
@@ -188,6 +189,10 @@ void mock.module("@modelcontextprotocol/sdk/client/index.js", () => ({
return this._state?.capabilities
}
getInstructions() {
return this._state?.instructions
}
async listTools(params?: { cursor?: string }) {
if (this._state) this._state.listToolsCalls++
if (this._state?.listToolsShouldFail) {
@@ -347,6 +352,60 @@ it.instance(
{ config: { mcp: {} } },
)
it.instance(
"instructions() returns connected server instructions with tool names",
() =>
MCP.Service.use((mcp: MCPNS.Interface) =>
Effect.gen(function* () {
lastCreatedClientName = "guide-server"
const serverState = getOrCreateClientState("guide-server")
serverState.instructions = "Use lookup before mutate."
yield* mcp.add("guide-server", {
type: "local",
command: ["echo", "test"],
})
expect(yield* mcp.instructions()).toContainEqual({
name: "guide-server",
instructions: "Use lookup before mutate.",
tools: ["guide-server_test_tool"],
})
}),
),
{ config: { mcp: {} } },
)
it.instance(
"instructions() omits empty and disconnected server instructions",
() =>
MCP.Service.use((mcp: MCPNS.Interface) =>
Effect.gen(function* () {
lastCreatedClientName = "temporary-server"
getOrCreateClientState("temporary-server").instructions = "Temporary guidance."
yield* mcp.add("temporary-server", {
type: "local",
command: ["echo", "test"],
})
yield* mcp.disconnect("temporary-server")
lastCreatedClientName = "blank-server"
getOrCreateClientState("blank-server").instructions = " "
yield* mcp.add("blank-server", {
type: "local",
command: ["echo", "test"],
})
const instructions = yield* mcp.instructions()
expect(instructions.some((item) => item.name === "temporary-server")).toBe(false)
expect(instructions.some((item) => item.name === "blank-server")).toBe(false)
}),
),
{ config: { mcp: {} } },
)
it.instance(
"follows cursors when listing tools, prompts, and resources",
() =>