anomalyco / anomalyco/opencode

"Unknown identifier query" in Code Mode with MCP tools

Open
#49,115 0 comments 0 reactions 1 assignee View on GitHub

@nexxeln is already working on this.

Since Sep 15, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Bug Description

When calling MCP tools with a query parameter (e.g., search_nodes, search_memory_facts) from within OpenCode Code Mode, the JS interpreter throws:

Unknown identifier 'query'. (line 1, col 30)

Environment

  • OpenCode version: 2.0.3
  • MCP server: Graphiti MCP (running in Docker)
  • MCP tools: search_nodes, search_memory_facts (both have query as required str parameter)

Steps to Reproduce

  1. Configure Graphiti MCP server in opencode.json
  2. Start OpenCode TUI/CLI with Code Mode
  3. Use a tool call referencing search_nodes or search_memory_facts
  4. JS interpreter fails with "Unknown identifier 'query'"

Expected Behavior

The query parameter should be available as a JS variable in the Code Mode sandbox.

Actual Behavior

JS interpreter throws Unknown identifier 'query'. (line 1, col 30) — the parameter is not declared in the JS scope before code execution.

Related Issues

  • #48910 — Same version (2.0.3), same class of bug: MCP tool parameters not properly handled in Code Mode sandbox
  • #48912search() discovery function unregistered
  • #45521search() documented 3 ways, only bare search(input) works
  • #41389 — Catalog-listed MCP tools fail Unknown tool outside execute
  • #46628 — MCP schemas bypass tool.definition hook

Root Cause Hypothesis

The Code Mode JS executor wraps LLM-generated code in an async function but doesn't declare MCP tool parameters (like query) as JS variables before execution. The LLM generates code referencing query but the variable doesn't exist in scope, causing the "Unknown identifier" error from acorn parser.

This is likely the same class of bug as #48910 — sandbox scope injection for MCP parameters is incomplete.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.