Skip to content

[BUG] MCP tools connected but not exposed to agent #33027

Description

@userX570

Description

[BUG] MCP tools connected but not exposed to agent

Description

MCP server pdfrag connects successfully and exposes 6 tools via tools/list, but the tools do not appear in the agent's available tool list. The server is working correctly (responds to MCP protocol, tools are valid), but something in the opencode pipeline isn't passing those tools to the agent.

Steps to Reproduce

  1. Create a custom MCP server (Python, stdio transport)
  2. Register in ~/.config/opencode/opencode.json:
    "mcp": {
      "pdfrag": {
        "type": "local",
        "command": "/Library/Frameworks/Python.framework/Versions/3.14/bin/pdfrag-mcp"
      }
    }
  3. Run opencode mcp list → shows "connected" with green checkmark
  4. Start opencode session → tools NOT available to agent

Expected Behavior

MCP tools should be available as first-class tools in the agent session after successful connection.

Actual Behavior

  • Server connects successfully
  • opencode mcp list shows "connected"
  • MCP protocol handshake works (initialize, tools/list returns 6 valid tools)
  • Tools do NOT appear in agent's available tool list
  • Agent cannot call MCP tools

Investigation

  1. Server works correctly: Verified with Python MCP client - server responds to initialize, tools/list, and tool calls
  2. Server format matches working servers: Compared with token-optimizer and lean-ctx servers - same structure, capabilities, and tool definitions
  3. No error logs: opencode logs show no errors related to pdfrag
  4. opencode binary is compiled: Cannot inspect source directly, but binary analysis shows MCP tool registration code exists

Similar Issue

Found similar issue on hermes-agent: #41625 - "MCP tools discovered but not exposed to agent in TUI mode"

The suspected cause there is a race condition in the TUI startup path with a timeout that's too short for MCP discovery.

Environment

  • OpenCode version: 1.17.8
  • OS: macOS (darwin)
  • Python: 3.14
  • MCP transport: stdio (local subprocess)

Workaround

Use CLI or Python direct calls:

python3 pdf_rag.py query "question"

Request

Please investigate why MCP tools are not being exposed to the agent despite successful connection. This may be related to:

  • Race condition in tool discovery (similar to hermes-agent #41625)
  • Tool filtering logic
  • Agent tool context initialization

Plugins

No response

OpenCode version

No response

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

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