anomalyco / anomalyco/opencode
"Unknown identifier query" in Code Mode with MCP tools
@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 havequeryas requiredstrparameter)
Steps to Reproduce
- Configure Graphiti MCP server in
opencode.json - Start OpenCode TUI/CLI with Code Mode
- Use a tool call referencing
search_nodesorsearch_memory_facts - 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
- #48912 —
search()discovery function unregistered - #45521 —
search()documented 3 ways, only baresearch(input)works - #41389 — Catalog-listed MCP tools fail
Unknown tooloutsideexecute - #46628 — MCP schemas bypass
tool.definitionhook
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.