|
|
@@ -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
|
|
|
// ========================================================================
|