feat(httpapi): bridge mcp control endpoints (#24403)

This commit is contained in:
Kit Langton
2026-04-25 19:16:19 -04:00
committed by GitHub
parent 58c65874ba
commit a14c22d4e9
5 changed files with 294 additions and 32 deletions

View File

@@ -11,12 +11,13 @@ void Log.init({ print: false })
const context = Context.empty() as Context.Context<unknown>
function request(route: string, directory: string) {
function request(route: string, directory: string, init?: RequestInit) {
const headers = new Headers(init?.headers)
headers.set("x-opencode-directory", directory)
return ExperimentalHttpApiServer.webHandler().handler(
new Request(`http://localhost${route}`, {
headers: {
"x-opencode-directory": directory,
},
...init,
headers,
}),
context,
)
@@ -45,4 +46,41 @@ describe("mcp HttpApi", () => {
expect(response.status).toBe(200)
expect(await response.json()).toEqual({ demo: { status: "disabled" } })
})
test("serves add, connect, and disconnect endpoints", async () => {
await using tmp = await tmpdir({
config: {
mcp: {
demo: {
type: "local",
command: ["echo", "demo"],
enabled: false,
},
},
},
})
const added = await request(McpPaths.status, tmp.path, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
name: "added",
config: {
type: "local",
command: ["echo", "added"],
enabled: false,
},
}),
})
expect(added.status).toBe(200)
expect(await added.json()).toMatchObject({ added: { status: "disabled" } })
const connected = await request("/mcp/demo/connect", tmp.path, { method: "POST" })
expect(connected.status).toBe(200)
expect(await connected.json()).toBe(true)
const disconnected = await request("/mcp/demo/disconnect", tmp.path, { method: "POST" })
expect(disconnected.status).toBe(200)
expect(await disconnected.json()).toBe(true)
})
})