feat(opencode): support cwd on local MCP servers (#30676)

Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
This commit is contained in:
Grant Martin 2026-06-11 16:05:45 -05:00 committed by GitHub
commit 7e7ad37736
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 46 additions and 11 deletions

View file

@ -1,8 +1,10 @@
import path from "node:path"
import { expect, mock, beforeEach } from "bun:test"
import { ToolListChangedNotificationSchema } from "@modelcontextprotocol/sdk/types.js"
import { Cause, Effect, Exit } from "effect"
import type { MCP as MCPNS } from "../../src/mcp/index"
import { testEffect } from "../lib/effect"
import { TestInstance } from "../fixture/fixture"
// --- Mock infrastructure ---
@ -48,6 +50,8 @@ let connectError = "Mock transport cannot connect"
let clientCreateCount = 0
// Tracks how many times transport.close() is called across all mock transports
let transportCloseCount = 0
// Captures the opts passed to each MockStdioTransport, keyed by lastCreatedClientName
const stdioOptsByName = new Map<string, any>()
function getOrCreateClientState(name?: string): MockClientState {
const key = name ?? "default"
@ -82,8 +86,9 @@ function getOrCreateClientState(name?: string): MockClientState {
class MockStdioTransport {
stderr: null = null
pid = 12345
// oxlint-disable-next-line no-useless-constructor
constructor(_opts: any) {}
constructor(opts: any) {
if (lastCreatedClientName) stdioOptsByName.set(lastCreatedClientName, opts)
}
async start() {
if (connectShouldHang) return new Promise<void>(() => {}) // never resolves
if (connectShouldFail) throw new Error(connectError)
@ -246,6 +251,20 @@ function statusName(status: Record<string, MCPNS.Status> | MCPNS.Status, server:
return status[server]?.status
}
it.instance(
"local mcp cwd resolves relative paths against instance directory",
() =>
MCP.Service.use((mcp: MCPNS.Interface) =>
Effect.gen(function* () {
const { directory } = yield* TestInstance
lastCreatedClientName = "rel-cwd"
yield* mcp.add("rel-cwd", { type: "local", command: ["echo", "test"], cwd: "plugins/sub" })
expect(stdioOptsByName.get("rel-cwd")?.cwd).toBe(path.resolve(directory, "plugins/sub"))
}),
),
{ config: { mcp: {} } },
)
// ========================================================================
// Test: tools() are cached after connect
// ========================================================================