feat(mcp): append server instructions to context (#32490)
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import { NamedError } from "@opencode-ai/core/util/error"
|
||||
import { Skill } from "../../src/skill"
|
||||
import { Permission } from "../../src/permission"
|
||||
import { SystemPrompt } from "../../src/session/system"
|
||||
import { MCP } from "../../src/mcp"
|
||||
import { LocationServiceMap } from "@opencode-ai/core/location-layer"
|
||||
import { testEffect } from "../lib/effect"
|
||||
|
||||
@@ -44,6 +45,23 @@ const build: Agent.Info = {
|
||||
const it = testEffect(
|
||||
SystemPrompt.layer.pipe(
|
||||
Layer.provide(LocationServiceMap.layer),
|
||||
Layer.provide(
|
||||
Layer.mock(MCP.Service, {
|
||||
instructions: () =>
|
||||
Effect.succeed([
|
||||
{
|
||||
name: "guide-server",
|
||||
instructions: "Use lookup before mutate.",
|
||||
tools: [],
|
||||
},
|
||||
{
|
||||
name: "tool-server",
|
||||
instructions: "Prefer search before update.",
|
||||
tools: ["tool-server_search", "tool-server_update"],
|
||||
},
|
||||
]),
|
||||
}),
|
||||
),
|
||||
Layer.provide(
|
||||
Layer.succeed(
|
||||
Skill.Service,
|
||||
@@ -83,4 +101,41 @@ describe("session.system", () => {
|
||||
expect(output).not.toContain("manual-skill")
|
||||
}),
|
||||
)
|
||||
|
||||
it.effect("MCP output includes connected server instructions", () =>
|
||||
Effect.gen(function* () {
|
||||
const prompt = yield* SystemPrompt.Service
|
||||
const output = yield* prompt.mcp(build)
|
||||
|
||||
expect(output).toBe(
|
||||
[
|
||||
"<mcp_instructions>",
|
||||
' <server name="guide-server">',
|
||||
" Use lookup before mutate.",
|
||||
" </server>",
|
||||
' <server name="tool-server">',
|
||||
" Prefer search before update.",
|
||||
" </server>",
|
||||
"</mcp_instructions>",
|
||||
].join("\n"),
|
||||
)
|
||||
}),
|
||||
)
|
||||
|
||||
it.effect("MCP output omits servers when all advertised tools are denied", () =>
|
||||
Effect.gen(function* () {
|
||||
const prompt = yield* SystemPrompt.Service
|
||||
const output = yield* prompt.mcp(build, Permission.fromConfig({ "tool-server_*": "deny" }))
|
||||
|
||||
expect(output).toBe(
|
||||
[
|
||||
"<mcp_instructions>",
|
||||
' <server name="guide-server">',
|
||||
" Use lookup before mutate.",
|
||||
" </server>",
|
||||
"</mcp_instructions>",
|
||||
].join("\n"),
|
||||
)
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user