[FEATURE]: Improve MCP Tool Prioritization for GrepAI (Search-First Planning Mode) #9476

Open
opened 2026-02-16 18:12:32 -05:00 by yindo · 0 comments
Owner

Originally created by @electroheadfx on GitHub (Feb 16, 2026).

Originally assigned to: @thdxr on GitHub.

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Improve MCP Tool Prioritization for GrepAI (Search-First Planning Mode)

Summary

When integrating GrepAI via MCP in OpenCode, the agent correctly uses grepai_search on the first turn but progressively falls back to blob-based exploration in subsequent turns — even when:

  • AGENTS.md explicitly requires GrepAI as the primary search tool
  • grep and glob tools are disabled
  • The agent prompt enforces a grepai-first workflow

In contrast, Claude Code consistently uses GrepAI tools across the entire session without drifting to blob-based exploration.

This suggests OpenCode's planner is context-first, not tool-first, and does not persist tool priority across turns.


Expected Behavior

For code-related queries:

  1. Always start with grepai_search
  2. Use grepai_trace_* for call graph exploration
  3. Only use blob after grepai returns file paths
  4. Repeat this pattern consistently across turns

The behavior should not degrade after the first query.


Actual Behavior

Observed session pattern:

Turn 1:
→ grepai_search

Turn 2:
→ blob

Turn 3:
→ blob
→ blob

Even when AGENTS.md explicitly states:

You MUST use grepai as your PRIMARY tool for code exploration and search.


Environment

  • OpenCode: latest version
  • GrepAI installed and indexed
  • MCP server running via:
{
  "mcp": {
    "grepai": {
      "type": "local",
      "enabled": true,
      "command": ["grepai", "mcp-serve"]
    }
  }
}
  • Project type: pnpm monorepo (React + TanStack Start + Motion Canvas)

AGENTS.md Configuration

Generated via:

grepai agent-setup

Relevant section:

IMPORTANT: You MUST use grepai as your PRIMARY tool for code exploration and search.

Workflow defined in AGENTS.md:

  1. Start with grepai search
  2. Use grepai trace
  3. Use file read only after search
  4. Fallback to grep only if grepai fails

Agent Configuration (opencode.json)

{
  "mcp": {
    "grepai": {
      "type": "local",
      "enabled": true,
      "command": ["grepai", "mcp-serve"]
    }
  },
  "agent": {
    "main": {
      "tools": {
        "grep": false,
        "glob": false
      },
      "prompt": "Follow AGENTS.md strictly. For every code-related request, always start with grepai_search or grepai_trace tools. Do not explore the codebase using blob before grepai."
    }
  }
}

Tool Conflict Behavior

When grep is disabled, OpenCode logs:

invalid [tool=grep, error=Model tried to call unavailable tool 'grep']

The agent then switches to:

grepai_grepai_search

This indicates the planner still attempts to use grep first before adapting.


Comparison with Claude Code

With the same project and GrepAI MCP setup:

  • Claude always uses grepai_search first
  • No drift to blob-only exploration
  • No invalid tool attempts
  • Call graph queries reliably trigger grepai_trace_*

Claude appears to be tool-first rather than context-first.


Suspected Root Cause

OpenCode's planner appears to:

  • Prioritize already-loaded file context
  • Optimize for fewer tool calls
  • Reuse blob-based reads after first search
  • Treat AGENTS.md as advisory rather than enforceable

As a result, semantic search tools are effectively used only once per session.


Proposed Improvements

1. Tool Priority System

Allow explicit tool prioritization, e.g.:

{
  "toolPolicy": {
    "search": ["grepai_search"],
    "trace": ["grepai_trace_callers", "grepai_trace_callees"]
  }
}

or:

{
  "preferredTools": ["grepai_*"]
}

2. Search-First Planning Mode

Example:

{
  "planner": {
    "mode": "search-first"
  }
}

Behavior:

  • Every new user request triggers semantic search first
  • Context reuse is secondary
  • Prevents blob drift

3. Enforce AGENTS.md as Hard Constraint

Example:

{
  "agent": {
    "enforceAgentsMd": true
  }
}

This would elevate:

You MUST use grepai

to a planner-level rule rather than advisory context.


Why This Matters

Semantic search tools like GrepAI are:

  • More accurate for large monorepos
  • Designed for intent-based navigation
  • More efficient than exploratory blob reads

Current planner behavior reduces GrepAI to a first-turn-only tool, which undermines its usefulness.


Offer to Provide

I can provide:

  • Minimal reproduction repository
  • Full session logs (OpenCode vs Claude Code)
  • Additional configuration experiments
  • Planner trace outputs

Conclusion

OpenCode would benefit from:

  • Explicit tool prioritization
  • Search-first planning option
  • Stronger enforcement of agent constraints

This would significantly improve MCP-based semantic tooling integration.

Originally created by @electroheadfx on GitHub (Feb 16, 2026). Originally assigned to: @thdxr on GitHub. ### Feature hasn't been suggested before. - [x] I have verified this feature I'm about to request hasn't been suggested before. ### Describe the enhancement you want to request # Improve MCP Tool Prioritization for GrepAI (Search-First Planning Mode) ## Summary When integrating **GrepAI via MCP** in OpenCode, the agent correctly uses `grepai_search` on the first turn but progressively falls back to `blob`-based exploration in subsequent turns — even when: - `AGENTS.md` explicitly requires GrepAI as the primary search tool - `grep` and `glob` tools are disabled - The agent prompt enforces a grepai-first workflow In contrast, Claude Code consistently uses GrepAI tools across the entire session without drifting to blob-based exploration. This suggests OpenCode's planner is **context-first**, not **tool-first**, and does not persist tool priority across turns. --- ## Expected Behavior For code-related queries: 1. Always start with `grepai_search` 2. Use `grepai_trace_*` for call graph exploration 3. Only use `blob` after grepai returns file paths 4. Repeat this pattern consistently across turns The behavior should not degrade after the first query. --- ## Actual Behavior Observed session pattern: ``` Turn 1: → grepai_search Turn 2: → blob Turn 3: → blob → blob ``` Even when AGENTS.md explicitly states: > You MUST use grepai as your PRIMARY tool for code exploration and search. --- ## Environment - OpenCode: latest version - GrepAI installed and indexed - MCP server running via: ```json { "mcp": { "grepai": { "type": "local", "enabled": true, "command": ["grepai", "mcp-serve"] } } } ``` - Project type: pnpm monorepo (React + TanStack Start + Motion Canvas) --- ## AGENTS.md Configuration Generated via: ``` grepai agent-setup ``` Relevant section: ``` IMPORTANT: You MUST use grepai as your PRIMARY tool for code exploration and search. ``` Workflow defined in AGENTS.md: 1. Start with `grepai search` 2. Use `grepai trace` 3. Use file read only after search 4. Fallback to grep only if grepai fails --- ## Agent Configuration (opencode.json) ```json { "mcp": { "grepai": { "type": "local", "enabled": true, "command": ["grepai", "mcp-serve"] } }, "agent": { "main": { "tools": { "grep": false, "glob": false }, "prompt": "Follow AGENTS.md strictly. For every code-related request, always start with grepai_search or grepai_trace tools. Do not explore the codebase using blob before grepai." } } } ``` --- ## Tool Conflict Behavior When `grep` is disabled, OpenCode logs: ``` invalid [tool=grep, error=Model tried to call unavailable tool 'grep'] ``` The agent then switches to: ``` grepai_grepai_search ``` This indicates the planner still attempts to use grep first before adapting. --- ## Comparison with Claude Code With the same project and GrepAI MCP setup: - Claude always uses `grepai_search` first - No drift to blob-only exploration - No invalid tool attempts - Call graph queries reliably trigger `grepai_trace_*` Claude appears to be tool-first rather than context-first. --- ## Suspected Root Cause OpenCode's planner appears to: - Prioritize already-loaded file context - Optimize for fewer tool calls - Reuse blob-based reads after first search - Treat AGENTS.md as advisory rather than enforceable As a result, semantic search tools are effectively used only once per session. --- ## Proposed Improvements ### 1. Tool Priority System Allow explicit tool prioritization, e.g.: ```json { "toolPolicy": { "search": ["grepai_search"], "trace": ["grepai_trace_callers", "grepai_trace_callees"] } } ``` or: ```json { "preferredTools": ["grepai_*"] } ``` --- ### 2. Search-First Planning Mode Example: ```json { "planner": { "mode": "search-first" } } ``` Behavior: - Every new user request triggers semantic search first - Context reuse is secondary - Prevents blob drift --- ### 3. Enforce AGENTS.md as Hard Constraint Example: ```json { "agent": { "enforceAgentsMd": true } } ``` This would elevate: ``` You MUST use grepai ``` to a planner-level rule rather than advisory context. --- ## Why This Matters Semantic search tools like GrepAI are: - More accurate for large monorepos - Designed for intent-based navigation - More efficient than exploratory blob reads Current planner behavior reduces GrepAI to a first-turn-only tool, which undermines its usefulness. --- ## Offer to Provide I can provide: - Minimal reproduction repository - Full session logs (OpenCode vs Claude Code) - Additional configuration experiments - Planner trace outputs --- ## Conclusion OpenCode would benefit from: - Explicit tool prioritization - Search-first planning option - Stronger enforcement of agent constraints This would significantly improve MCP-based semantic tooling integration.
yindo added the discussion label 2026-02-16 18:12:32 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#9476