Skip to content

MCP prompt commands fail with a misleading "MCP prompt not found" when required prompt arguments are omitted #52446

Done

Description

@cardin

Description

When an MCP server exposes prompts that declare required arguments, OpenCode registers them as slash commands. Running such a command without supplying its arguments always fails, and the failure is reported with a message that misdescribes the cause:

MCP prompt not found: <server>:<prompt>

The prompt is registered and does exist. What actually happens is that OpenCode substitutes empty strings for the omitted arguments, the MCP server rejects prompts/get with JSON-RPC -32602 Missing required prompt arguments, and OpenCode discards that error and surfaces "prompt not found" instead. OpenCode does not crash.

This is distinct from #36974 and #33564 — see "Relationship to other reports" below.

Plugins

None relevant to this report.

OpenCode version

v2.0.21

Steps to reproduce

  1. Configure an MCP server that exposes a prompt with at least one required argument.
  2. Start OpenCode; the prompt appears in the command palette as /server:prompt.
  3. Invoke it without arguments: /server:prompt.
  4. Session setup fails with Failed to set up session / MCP prompt not found: server:prompt.
  5. Invoke it with arguments: /server:prompt arg1 "arg two" → succeeds.

Screenshot and/or share link

Not included.

Operating System

Linux (WSL2)

Terminal

Windows Terminal

Expected behaviour

Surface the underlying server error (e.g. "missing required prompt arguments"), or request the required arguments before submitting, instead of sending empty values and then reporting "prompt not found".

Actual behaviour

A misleading MCP prompt not found toast during new-session setup, which sends users looking for installation or configuration problems that do not exist. No crash and no stack trace.

Relationship to other reports

Evidence

Raw JSON-RPC over stdio against the MCP server.

prompts/list (abridged):

{"jsonrpc":"2.0","id":2,"result":{"prompts":[{"name":"explore_codebase","arguments":[{"name":"project","required":true},{"name":"question","required":true}]}]}}

prompts/get with the empty strings OpenCode sends when no arguments are given:

{"jsonrpc":"2.0","id":2,"error":{"code":-32602,"message":"Missing required prompt arguments"}}

prompts/get with non-empty arguments returns the prompt messages successfully.

Root cause (v2.0.21)

packages/core/src/plugin/command.ts:

59:  execute: (input) =>
60:    Effect.gen(function* () {
61:      const args = parseArguments(input.prompt.text)
62:      const result = yield* mcp.prompt({
63:        server: prompt.server,
64:        name: prompt.name,
65:        args: Object.fromEntries(
66:          (prompt.arguments ?? []).map((argument, index) => [argument.name, args[index] ?? ""]),
67:        ),
68:      })
69:      if (!result) return yield* Effect.fail(new Error(`MCP prompt not found: ${prompt.server}:${prompt.name}`))

Missing positional arguments become "" (line 66), and a failed lookup is reported as "not found" (line 69).

packages/core/src/mcp/index.ts:

688:  prompt: Effect.fn("MCP.prompt")(function* (input) {
689:    const target = yield* requireServer(input.server)
...
692:    const result = yield* recovering(target.name, target.entry, target.entry.client, (connection) =>
693:      connection.prompt({ name: input.name, args: input.args }),
694:    ).pipe(Effect.orElseSucceed(() => undefined))
695:    if (!result) return undefined

The JSON-RPC error is collapsed to undefined (line 694), so the caller cannot distinguish "server rejected the request" from "prompt is not registered" and can only report "not found".

Suggested fixes

  1. Preserve the cause: don't collapse every MCP.prompt failure into undefined; propagate the error (or an error type distinguishing "server rejected" from "prompt not registered").
  2. Handle required arguments explicitly: when required arguments are missing, request them or refuse to run with an actionable message, instead of sending "".
  3. Minor: the palette entry gives no indication that arguments are required.

Workaround

Supply the positional arguments explicitly:

/server:prompt <arg1> "<arg2>"

Activity

  1. added
    needs:compliance
    and removed
    needs:compliance
    on Oct 1, 2026
  2. github-actions commented on Oct 1, 2026

    @github-actions
    Contributor

    Thanks for updating this issue. It now meets our issue-reporting guidelines.

  3. r266-tech commented on Oct 2, 2026

    @r266-tech
    Contributor

    Confirmed with a synthetic stdio MCP server through the real V2 client, Mcp.Service, and registered CommandPlugin callback. The relevant three source files at current v2 (2a01ed60b1) match the tested checkout (0f9f0a9ae3). No model call or user session was used.

    The server advertises greet(name required, style optional) and returns JSON-RPC -32602 for a missing/empty name:

    Call Raw McpClient Mcp.Service.prompt
    No arguments / empty name Missing required prompt arguments: name undefined
    Unknown prompt Unknown prompt undefined
    Valid name, optional argument omitted Success Success

    Invoking the actual registered /resources:greet callback with empty input returns exactly MCP prompt not found: resources:greet. The fixture passed with 13 assertions (bun test test/mcp.test.ts --test-name-pattern OSS52446).

    The error is lost in src/mcp/index.ts at recovering(...).pipe(Effect.orElseSucceed(() => undefined)); the command's if (!result) then turns every such failure into “not found.” Validating required arguments alone would leave other server failures misclassified. @kitlangton, I can provide the regression fixture alongside your existing work; I have not opened a competing PR.

    AI-assisted investigation.

  4. opencodejr commented on Oct 28, 2026

    @opencodejr
    Contributor

    Thanks for the detailed report. I can reproduce this on v2.0.21, and it still happens on the latest dev (891a020).

    Steps:

    • Use a stdio MCP server whose prompt explore_codebase has two required arguments. The server rejects empty values with -32602 Missing required prompt arguments.
    • In the TUI, run /demo:explore_codebase without arguments.
    • OpenCode shows Failed to set up session / MCP prompt not found: demo:explore_codebase, even though the prompt is registered and connected.

    The recording and screenshot below show this, and the script below reproduces it, including the mock server. As you described, the code still sends empty strings for missing arguments and turns the server's error into "not found". Until this is addressed, passing the arguments explicitly (/server:prompt <arg1> "<arg2>") avoids the error.

    recording.mp4

    Screenshot

    Reproduction script (drive.ts)
    import { Effect } from "effect"
    import { OpenCodeDriver } from "opencode-drive"
    import { writeFileSync } from "node:fs"
    
    // Minimal stdio MCP server exposing one prompt with two required arguments.
    const SERVER = '// Minimal stdio MCP server: one prompt with two required arguments; rejects empty values with -32602.\nimport readline from "node:readline"\nconst rl = readline.createInterface({ input: process.stdin })\nconst send = (m) => process.stdout.write(JSON.stringify(m) + "\\n")\nrl.on("line", (line) => {\n  let msg; try { msg = JSON.parse(line) } catch { return }\n  if (msg.id === undefined) return\n  const ok = (result) => send({ jsonrpc: "2.0", id: msg.id, result })\n  switch (msg.method) {\n    case "initialize":\n      return ok({ protocolVersion: msg.params?.protocolVersion ?? "2025-06-18", capabilities: { prompts: {}, tools: {} }, serverInfo: { name: "demo", version: "1.0.0" } })\n    case "tools/list": return ok({ tools: [] })\n    case "prompts/list":\n      return ok({ prompts: [{ name: "explore_codebase", description: "Explore a codebase", arguments: [{ name: "project", required: true }, { name: "question", required: true }] }] })\n    case "prompts/get": {\n      const a = msg.params?.arguments ?? {}\n      if (!a.project || !a.question) return send({ jsonrpc: "2.0", id: msg.id, error: { code: -32602, message: "Missing required prompt arguments" } })\n      return ok({ messages: [{ role: "user", content: { type: "text", text: `Explore ${a.project}: ${a.question}` } }] })\n    }\n    case "ping": return ok({})\n    default: return send({ jsonrpc: "2.0", id: msg.id, error: { code: -32601, message: "Method not found" } })\n  }\n})\n'
    const serverPath = "/tmp/opencode-52446-mcp.mjs"
    writeFileSync(serverPath, SERVER)
    
    export default OpenCodeDriver.use(
      {
        ...(process.env.OC_DEV ? { opencode: { dev: process.env.OC_DEV } } : {}),
        tui: { recording: true },
        project: { git: true },
        config: {
          mcp: { demo: { type: "local", command: ["node", serverPath] } },
        },
      },
      ({ ui, llm }) =>
        Effect.gen(function* () {
          yield* Effect.sleep("3 seconds")
          yield* ui.screenshot("home")
          // Without arguments: server rejects with -32602, OpenCode reports "MCP prompt not found"
          yield* ui.type("/demo:explore_codebase")
          yield* Effect.sleep("1 second")
          yield* ui.screenshot("typed")
          yield* ui.enter()
          yield* Effect.sleep("1 second")
          yield* ui.screenshot("after-enter-1")
          yield* ui.enter()
          yield* ui.waitFor("MCP prompt not found", { timeout: 20000 })
          yield* ui.screenshot("after-enter-2")
          yield* ui.screenshot("not-found")
          yield* Effect.sleep("3 seconds")
        }),
    )

    Run it with opencode-drive: opencode-drive run ./drive.ts. It drives opencode from your PATH; set OC_DEV to the path of an OpenCode checkout to run that from source instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions