fix(skill-mcp): pass workspace directory as cwd to stdio MCP processes
In OpenCode web multi-workspace mode, skill_mcp spawned stdio child processes inherited process.cwd() instead of the session's workspace directory. Pass toolContext.directory through SkillMcpClientInfo to StdioClientTransport's cwd parameter.
This commit is contained in:
@@ -60,6 +60,7 @@ export async function createStdioClient(params: SkillMcpClientConnectionParams):
|
|||||||
args,
|
args,
|
||||||
env: mergedEnv,
|
env: mergedEnv,
|
||||||
stderr: "ignore",
|
stderr: "ignore",
|
||||||
|
...(info.directory ? { cwd: info.directory } : {}),
|
||||||
})
|
})
|
||||||
|
|
||||||
const client: McpClient = stdioClientDependencies.createClient(
|
const client: McpClient = stdioClientDependencies.createClient(
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ export interface SkillMcpClientInfo {
|
|||||||
skillName: string
|
skillName: string
|
||||||
sessionID: string
|
sessionID: string
|
||||||
scope?: SkillScope | "local"
|
scope?: SkillScope | "local"
|
||||||
|
directory?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SkillMcpServerContext {
|
export interface SkillMcpServerContext {
|
||||||
|
|||||||
@@ -192,6 +192,32 @@ describe("skill_mcp tool", () => {
|
|||||||
{},
|
{},
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("passes toolContext.directory to the manager", async () => {
|
||||||
|
// given
|
||||||
|
loadedSkills = [
|
||||||
|
createMockSkillWithMcp("test-skill", {
|
||||||
|
"test-server": { command: "echo", args: ["test"] },
|
||||||
|
}),
|
||||||
|
]
|
||||||
|
const callToolSpy = spyOn(manager, "callTool").mockResolvedValue({ content: [] } as never)
|
||||||
|
const tool = createSkillMcpTool({
|
||||||
|
manager,
|
||||||
|
getLoadedSkills: () => loadedSkills,
|
||||||
|
getSessionID: () => "session-1",
|
||||||
|
})
|
||||||
|
|
||||||
|
// when
|
||||||
|
await tool.execute({ mcp_name: "test-server", tool_name: "some-tool" }, mockContext)
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect(callToolSpy).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({ directory: "/test" }),
|
||||||
|
expect.any(Object),
|
||||||
|
"some-tool",
|
||||||
|
{},
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -167,6 +167,7 @@ export function createSkillMcpTool(options: SkillMcpToolOptions): ToolDefinition
|
|||||||
skillName: found.skill.name,
|
skillName: found.skill.name,
|
||||||
sessionID,
|
sessionID,
|
||||||
scope: found.skill.scope,
|
scope: found.skill.scope,
|
||||||
|
directory: toolContext.directory,
|
||||||
}
|
}
|
||||||
|
|
||||||
const context: SkillMcpServerContext = {
|
const context: SkillMcpServerContext = {
|
||||||
|
|||||||
Reference in New Issue
Block a user