Skip to content

[Bug] MCP prompt arguments receive literal $1/$2 placeholders instead of user input — type validation fails #33564

Closed

Description

@michael-conrad

Description

This error fires at startup, not on interactive use. When opencode discovers an MCP server that exposes prompts with typed arguments (e.g. precision: int), it calls prompts/get during initialization to resolve prompt templates for command registration. The $1/$2 placeholders are sent as literal argument values during this startup probe, and the MCP server's typed argument validation rejects them.

Example error from mcp-mathematics at startup:

MCP error 0: Could not convert argument 'precision' with value '$2' to expected type int
MCP error 0: Could not convert argument 'batch_size' with value '$1' to expected type int
failed to getPrompt

The prompts/get JSON payload confirms the literal placeholder is being sent:

{
    "method": "prompts/get",
    "params": {
        "name": "scientific_calculation",
        "arguments": {
            "precision": "$2",
            "calc_type": "general",
            "show_steps": false
        }
    }
}

This was previously reported in #9776 (auto-closed due to inactivity) and confirmed by another user in #9776 (comment) who captured the same "$1" in the prompts/get payload.

The root cause is in packages/opencode/src/command/index.ts lines 100-112. The get template() function maps prompt arguments to $N placeholders but never substitutes them against actual user-provided command arguments before calling mcp.getPrompt().

Plugins

None

OpenCode version

1.14.33

Steps to reproduce

  1. Configure an MCP server that exposes prompts with typed arguments (e.g. mcp-mathematics via uvx mcp-mathematics)
  2. Start opencode
  3. The error appears in the startup log automatically — no user interaction required

Screenshot and/or share link

N/A

Operating System

Ubuntu 24.04.4 LTS, Linux 6.8.0-124-generic x86_64

Terminal

WezTerm

Full startup log

2026-06-24T00:38:58.314570Z  INFO sidecar: opencode_lib::cli: ERROR 2026-06-24T00:38:58 +1350ms service=mcp clientName=math promptName=scientific_calculation error=MCP error 0: Could not convert argument 'precision' with value '$2' to expected type typing.Annotated[int, 'Decimal precision for results']. Error: 1 validation error for int
2026-06-24T00:38:58.314591Z  INFO sidecar: opencode_lib::cli:   Input should be a valid integer, unable to parse string as an integer [type=int_parsing, input_value='$2', input_type=str]
2026-06-24T00:38:58.314595Z  INFO sidecar: opencode_lib::cli:     For further information visit https://errors.pydantic.dev/2.13/v/int_parsing failed to getPrompt
2026-06-24T00:38:58.314908Z  INFO sidecar: opencode_lib::cli: ERROR 2026-06-24T00:38:58 +0ms service=mcp clientName=math promptName=batch_calculation error=MCP error 0: Could not convert argument 'batch_size' with value '$1' to expected type typing.Annotated[int, 'Number of calculations to process']. Error: 1 validation error for int
2026-06-24T00:38:58.314927Z  INFO sidecar: opencode_lib::cli:   Input should be a valid integer, unable to parse string as an integer [type=int_parsing, input_value='$1', input_type=str]
2026-06-24T00:38:58.314933Z  INFO sidecar: opencode_lib::cli:     For further information visit https://errors.pydantic.dev/2.13/v/int_parsing failed to getPrompt
2026-06-24T00:38:58.487985Z  INFO sidecar: opencode_lib::cli: ERROR 2026-06-24T00:38:58 +173ms service=server error=Session not found failed
2026-06-24T00:38:59.379392Z  INFO sidecar: opencode_lib::cli: ERROR 2026-06-24T00:38:59 +892ms service=server error=NotFoundError failed
2026-06-24T00:39:06.830627Z  INFO sidecar: opencode_lib::cli: ERROR 2026-06-24T00:39:06 +7451ms service=file.watcher dir=/home/muksihs cause=TimeoutError: TimeoutError
2026-06-24T00:39:06.830645Z  INFO sidecar: opencode_lib::cli:     at orElse (/$bunfs/root/chunk-y3yhj99w.js:25:15739)
2026-06-24T00:39:06.830648Z  INFO sidecar: opencode_lib::cli:     at runLoop (/$bunfs/root/chunk-y3yhj99w.js:25:2045)
2026-06-24T00:39:06.830651Z  INFO sidecar: opencode_lib::cli:     at evaluate (/$bunfs/root/chunk-y3yhj99w.js:25:1435)
2026-06-24T00:39:06.830653Z  INFO sidecar: opencode_lib::cli:     at <anonymous> (/$bunfs/root/chunk-y3yhj99w.js:25:5589)
2026-06-24T00:39:06.830656Z  INFO sidecar: opencode_lib::cli:     at FileWatcher.state (/$bunfs/root/chunk-aan3zwa9.js:7:67961)
2026-06-24T00:39:06.830659Z  INFO sidecar: opencode_lib::cli:     at FileWatcher.state (definition) (/$bunfs/root/chunk-14sjmzy6.js:444:5415)
2026-06-24T00:39:06.830661Z  INFO sidecar: opencode_lib::cli:     at FileWatcher.init (/$bunfs/root/chunk-14sjmzy6.js:2722:9592)
2026-06-24T00:39:06.830664Z  INFO sidecar: opencode_lib::cli:     at FileWatcher.init (definition) (/$bunfs/root/chunk-14sjmzy6.js:444:6981)
2026-06-24T00:39:06.830667Z  INFO sidecar: opencode_lib::cli:     at InstanceBootstrap.init (/$bunfs/root/chunk-14sjmzy6.js:2722:9613)
2026-06-24T00:39:06.830670Z  INFO sidecar: opencode_lib::cli:     at InstanceBootstrap (/$bunfs/root/chunk-14sjmzy6.js:2722:9779)
2026-06-24T00:39:06.830674Z  INFO sidecar: opencode_lib::cli:     at InstanceStore.boot (/$bunfs/root/chunk-aan3zwa9.js:18:5242)
2026-06-24T00:39:06.830677Z  INFO sidecar: opencode_lib::cli:     at InstanceStore.load (/$bunfs/root/chunk-aan3zwa9.js:18:6366) failed to subscribe
2026-06-24T00:39:07.095955Z  INFO sidecar: opencode_lib::cli: ERROR 2026-06-24T00:39:07 +265ms service=file.watcher dir=/home/muksihs/git/opencode-config cause=TimeoutError: TimeoutError
2026-06-24T00:39:07.095979Z  INFO sidecar: opencode_lib::cli:     at orElse (/$bunfs/root/chunk-y3yhj99w.js:25:15739)
2026-06-24T00:39:07.095984Z  INFO sidecar: opencode_lib::cli:     at runLoop (/$bunfs/root/chunk-y3yhj99w.js:25:2045)
2026-06-24T00:39:07.095990Z  INFO sidecar: opencode_lib::cli:     at evaluate (/$bunfs/root/chunk-y3yhj99w.js:25:1435)
2026-06-24T00:39:07.095994Z  INFO sidecar: opencode_lib::cli:     at <anonymous> (/$bunfs/root/chunk-y3yhj99w.js:25:5589)
2026-06-24T00:39:07.095999Z  INFO sidecar: opencode_lib::cli:     at FileWatcher.state (/$bunfs/root/chunk-aan3zwa9.js:7:67961)
2026-06-24T00:39:07.096004Z  INFO sidecar: opencode_lib::cli:     at FileWatcher.state (definition) (/$bunfs/root/chunk-14sjmzy6.js:444:5415)
2026-06-24T00:39:07.096010Z  INFO sidecar: opencode_lib::cli:     at FileWatcher.init (/$bunfs/root/chunk-14sjmzy6.js:2722:9592)
2026-06-24T00:39:07.096016Z  INFO sidecar: opencode_lib::cli:     at FileWatcher.init (definition) (/$bunfs/root/chunk-14sjmzy6.js:444:6981)
2026-06-24T00:39:07.096021Z  INFO sidecar: opencode_lib::cli:     at InstanceBootstrap.init (/$bunfs/root/chunk-14sjmzy6.js:2722:9613)
2026-06-24T00:39:07.096027Z  INFO sidecar: opencode_lib::cli:     at InstanceBootstrap (/$bunfs/root/chunk-14sjmzy6.js:2722:9779)
2026-06-24T00:39:07.096032Z  INFO sidecar: opencode_lib::cli:     at InstanceStore.boot (/$bunfs/root/chunk-aan3zwa9.js:18:5242)
2026-06-24T00:39:07.096038Z  INFO sidecar: opencode_lib::cli:     at InstanceStore.load (/$bunfs/root/chunk-aan3zwa9.js:18:6366) failed to subscribe
2026-06-24T00:39:17.098010Z  INFO sidecar: opencode_lib::cli: ERROR 2026-06-24T00:39:17 +10002ms service=file.watcher dir=/home/muksihs/git/opencode-config/.git cause=TimeoutError: TimeoutError
2026-06-24T00:39:17.098031Z  INFO sidecar: opencode_lib::cli:     at orElse (/$bunfs/root/chunk-y3yhj99w.js:25:15739)
2026-06-24T00:39:17.098034Z  INFO sidecar: opencode_lib::cli:     at runLoop (/$bunfs/root/chunk-y3yhj99w.js:25:2045)
2026-06-24T00:39:17.098037Z  INFO sidecar: opencode_lib::cli:     at evaluate (/$bunfs/root/chunk-y3yhj99w.js:25:1435)
2026-06-24T00:39:17.098039Z  INFO sidecar: opencode_lib::cli:     at <anonymous> (/$bunfs/root/chunk-y3yhj99w.js:25:5589)
2026-06-24T00:39:17.098042Z  INFO sidecar: opencode_lib::cli:     at FileWatcher.state (/$bunfs/root/chunk-aan3zwa9.js:7:67961)
2026-06-24T00:39:17.098045Z  INFO sidecar: opencode_lib::cli:     at FileWatcher.state (definition) (/$bunfs/root/chunk-14sjmzy6.js:444:5415)
2026-06-24T00:39:17.098048Z  INFO sidecar: opencode_lib::cli:     at FileWatcher.init (/$bunfs/root/chunk-14sjmzy6.js:2722:9592)
2026-06-24T00:39:17.098051Z  INFO sidecar: opencode_lib::cli:     at FileWatcher.init (definition) (/$bunfs/root/chunk-14sjmzy6.js:444:6981)
2026-06-24T00:39:17.098054Z  INFO sidecar: opencode_lib::cli:     at InstanceBootstrap.init (/$bunfs/root/chunk-14sjmzy6.js:2722:9613)
2026-06-24T00:39:17.098057Z  INFO sidecar: opencode_lib::cli:     at InstanceBootstrap (/$bunfs/root/chunk-14sjmzy6.js:2722:9779)
2026-06-24T00:39:17.098060Z  INFO sidecar: opencode_lib::cli:     at InstanceStore.boot (/$bunfs/root/chunk-aan3zwa9.js:18:5242)
2026-06-24T00:39:17.098066Z  INFO sidecar: opencode_lib::cli:     at InstanceStore.load (/$bunfs/root/chunk-aan3zwa9.js:18:6366) failed to subscribe
2026-06-24T00:39:32.143253Z  INFO opencode_lib: Received Exit
2026-06-24T00:39:32.143269Z  INFO opencode_lib: Killed server

Activity

  1. koch-c commented on Aug 13, 2026

    @koch-c

    I have also experienced that opencode passes $1, $2, $X... literals to MCP prompts when they are fetched with prompts/get. The MCP server logs the passed arguments as $X and it seems it never receives the actual parameter values given by the user.

  2. neriousy commented on Oct 1, 2026

    @neriousy
    Member

    In OpenCode v2, MCP prompts are only listed at startup; prompts/get isn't called then. It runs when you invoke the prompt as a command, using the arguments parsed from what you typed (missing ones are sent as empty strings). Literal $1/$2 placeholders are no longer sent.

    Changed in the v2 MCP command rewrite (#34849).

    Closing as completed. If something doesn't work on v2, please open a new issue.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions