Skip to content

"Unknown identifier query" in Code Mode with MCP tools #49115

Closed as not planned
Closed as not planned

Description

@lehcode

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

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.

Activity

  1. opencodejr commented on Oct 28, 2026

    @opencodejr

    Thanks for the report, @lehcode!

    The Unknown identifier '<name>' error comes from Code Mode's JavaScript interpreter. It's thrown when the program reads a variable that was never declared, the same as a ReferenceError in normal JS. Code Mode doesn't put tool parameters in scope as variables. They're passed as an object argument, for example:

    const result = await tools.graphiti.search_nodes({ query: "something" })

    So if the model wrote something like search_nodes({ query }) without declaring query first, this error is expected. If the code passed query correctly and still failed, that would be a real bug in the interpreter. To tell which it is, could you share:

    • The exact code the model passed to the execute tool when the error happened. You can copy it from the expanded tool call in the TUI or from the session export. Column 30 of line 1 should point at the query in question.
    • The provider and model you were using.
    • Whether it still happens on the latest v2 release (2.0.3 is fairly old; v2.2.x is current).

    You can reply here with the details or edit the issue. If you edit it, please also leave a comment saying you've updated it so we know you're done.

    I didn't find an existing report of this exact error. #48910, which you linked, is on the same version but is a different problem: MCP tool results come back as null.

  2. rekram1-node commented on Oct 29, 2026

    @rekram1-node
    Contributor

    This is the program referencing a variable it never declared: tool inputs are passed as an object, e.g. await tools.graphiti.search_nodes({ query: "..." }), not as variables in scope. The error points at the line that used query, which is the expected behavior, so I'm closing this.

  3. opencodejr commented on Oct 31, 2026

    @opencodejr

    We haven't heard back, so I'm closing this issue for now as not planned.

    We were waiting for the exact code the model passed to the execute tool, plus the provider and model. Without them we can't tell whether the model used an undeclared query variable (expected behaviour: tool parameters go in an object argument such as search_nodes({ query: "..." })) or the interpreter mishandled valid code.

    If this still happens on a current v2 release, please comment here with that code and we can reopen. Thanks, @lehcode!

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions