Skip to content

Commit fbe04de

Browse files
committed
refactor(mcp): simplify instruction markup
1 parent 43877bd commit fbe04de

3 files changed

Lines changed: 11 additions & 25 deletions

File tree

packages/opencode/src/session/system.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { AbsolutePath } from "@opencode-ai/core/schema"
2020
import { Location } from "@opencode-ai/core/location"
2121
import { LocationServiceMap } from "@opencode-ai/core/location-layer"
2222
import { Reference } from "@opencode-ai/core/reference"
23-
import { McpCatalog } from "@/mcp/catalog"
2423
import { MCP } from "@/mcp"
2524

2625
export function provider(model: Provider.Model) {
@@ -115,19 +114,13 @@ export const layer = Layer.effect(
115114
if (available.length === 0) return
116115

117116
return [
118-
"MCP servers may provide instructions for using their tools, prompts, and resources.",
119-
"Each entry applies to tools matching its tool prefix and to prompts and resources from that server.",
120-
"<mcp_server_instructions>",
117+
"<mcp_instructions>",
121118
...available.flatMap((item) => [
122-
" <mcp_server>",
123-
` <name>${item.name}</name>`,
124-
` <tool_prefix>mcp__${McpCatalog.sanitize(item.name)}__</tool_prefix>`,
125-
" <instructions>",
126-
...item.instructions.split("\n").map((line) => ` ${line}`),
127-
" </instructions>",
128-
" </mcp_server>",
119+
` <server name="${item.name}">`,
120+
...item.instructions.split("\n").map((line) => ` ${line}`),
121+
" </server>",
129122
]),
130-
"</mcp_server_instructions>",
123+
"</mcp_instructions>",
131124
].join("\n")
132125
}),
133126
})

packages/opencode/test/session/prompt.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,7 @@ withMcpInstructions.instance("loop includes MCP instructions in model system con
545545

546546
const hits = yield* llm.hits
547547
const body = JSON.stringify(hits[0]?.body)
548-
expect(body).toContain("<name>guide-server</name>")
549-
expect(body).toContain("<tool_prefix>mcp__guide-server__</tool_prefix>")
548+
expect(body).toContain('<server name=\\"guide-server\\">')
550549
expect(body).toContain("Use lookup before mutate.")
551550
yield* Fiber.interrupt(fiber)
552551
}),

packages/opencode/test/session/system.test.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,11 @@ describe("session.system", () => {
107107

108108
expect(output).toBe(
109109
[
110-
"MCP servers may provide instructions for using their tools, prompts, and resources.",
111-
"Each entry applies to tools matching its tool prefix and to prompts and resources from that server.",
112-
"<mcp_server_instructions>",
113-
" <mcp_server>",
114-
" <name>guide-server</name>",
115-
" <tool_prefix>mcp__guide-server__</tool_prefix>",
116-
" <instructions>",
117-
" Use lookup before mutate.",
118-
" </instructions>",
119-
" </mcp_server>",
120-
"</mcp_server_instructions>",
110+
"<mcp_instructions>",
111+
' <server name="guide-server">',
112+
" Use lookup before mutate.",
113+
" </server>",
114+
"</mcp_instructions>",
121115
].join("\n"),
122116
)
123117
}),

0 commit comments

Comments
 (0)