import { Plugin, Rpc } from "@opencode/plugin"; import { z } from "zod"; // Loaded only by the opt-in isolated smoke script, never by the Agent service. export default Plugin.define({ id: "tjwater.mcp-fixture", async setup(ctx) { await ctx.websearch.transform((editor) => { editor.add({ id: "fixture-search", name: "Isolated search fixture", execute: async ({ query }) => [ { url: "https://example.test/search-result", title: "Fixture result", content: query, time: {} }, ] }); }); // Materialize the native session toolbox, then stop before any model call. await ctx.session.hook("context", () => { throw new Error("MCP fixture stops before model request"); }); const evaluated: string[] = []; await ctx.permission.hook("evaluate", (event) => { evaluated.push(event.action); }); await ctx.rpc.register(Rpc.define({ id: "tjwater.mcp-fixture", events: {}, methods: { call: { input: z.object({ session_id: z.string(), tool: z.enum(["mcp_stdio_echo", "mcp_http_write", "mcp_tjwater_session_search", "mcp_tjwater_todoread", "mcp_tjwater_run_simulation", "websearch"]), value: z.string().optional(), arguments: z.record(z.string(), z.unknown()).optional() }), output: z.object({ content: z.unknown(), evaluated: z.array(z.string()), error: z.string().optional() }) }, }, }), { call: async (input, context) => { const tool = (await ctx.tool.list()).find((tool) => tool.id === input.tool); if (!tool) throw new Error("fixture tool missing"); try { const result = await tool.execute(input.arguments ?? { value: input.value }, { sessionID: input.session_id as never, id: "call-mcp-fixture" as never, messageID: "msg-mcp-fixture" as never, agent: "instruction" as never, signal: context.signal, progress: async () => {} }); return { content: result.content ?? [], evaluated }; } catch (error) { return { content: [], evaluated, error: String(error) }; } }, }); }, });