opencode-raven icon indicating copy to clipboard operation
opencode-raven copied to clipboard

[FEATURE] Add lazy / skill-scoped MCP mode to avoid global MCP schema context bloat

Open jan23456789 opened this issue 6 months ago • 2 comments

Raven already works very well as a context firewall for noisy tool and MCP results. However, the current architecture still registers bundled MCP servers globally through configInput.mcp, which means OpenCode still loads enabled MCP tool schemas into the main session.

This is also mentioned in Raven's README as a current limitation: Raven saves context from tool calls and raw results, but it cannot hide initial MCP schemas from the main model until OpenCode supports agent-scoped MCP visibility.

I would like to propose an additional "lazy MCP" mode inspired by Oh My OpenAgent's skill-embedded MCP pattern.

Problem

Current Raven behavior:

  • Raven registers bundled MCPs such as Context7, Exa, and Grep.app globally.
  • Raven then routes those MCP calls through raven_seek.
  • This prevents noisy MCP results from entering the main session.
  • But the MCP tool schemas are still loaded into the main session because the MCPs are globally enabled.

This is especially problematic when adding more MCPs. Raven becomes more powerful, but every additional MCP can increase initial context/tool-schema overhead even when the MCP is never used.

Proposed solution

Add an optional lazy / skill-scoped MCP mode where Raven does not register bundled MCPs globally.

Instead of exposing each MCP's individual tool schemas to OpenCode, Raven would expose only a small generic tool, for example:

raven_mcp({
  server: "context7",
  operation: "tool" | "resource" | "prompt",
  name: "resolve-library-id",
  arguments: { ... }
})

In this mode:

  • The main agent only sees raven_seek.
  • The Raven agent sees raven_seek disabled to avoid recursion, as today.
  • Raven internally uses raven_mcp or an equivalent MCP manager to connect to configured MCP servers only when needed.
  • MCP clients are created lazily and scoped by session/server, e.g. ${sessionID}:${serverName} or ${sessionID}:raven:${serverName}.
  • MCP schemas are discovered only inside the Raven session, not in the main session.
  • Raven returns only compact findings back to the main agent, same as today.

Example configuration

{
  "enabled": true,
  "mcpMode": "lazy",
  "allowBundledMCPServers": false,
  "lazyMcpServers": {
    "context7": {
      "type": "remote",
      "url": "https://mcp.context7.com/mcp",
      "description": "Library/framework documentation lookup"
    },
    "exa": {
      "type": "remote",
      "url": "https://mcp.exa.ai/mcp",
      "headers": {
        "x-api-key": "{env:EXA_API_KEY}"
      },
      "description": "Web search and page fetch"
    },
    "grep_app": {
      "type": "remote",
      "url": "https://mcp.grep.app",
      "description": "Public GitHub code search"
    }
  }
}

Implementation idea

The existing Raven architecture already has most of the pieces:

  • raven_seek creates a child Raven session.
  • tool.execute.before blocks routed tools for non-Raven agents.
  • Raven has a dedicated agent with its own prompt and permissions.
  • Raven already tracks sessions and context saved.

The missing part is a lazy MCP manager similar to Oh My OpenAgent's skill-embedded MCP design:

  1. Do not inject bundled MCPs into configInput.mcp when mcpMode === "lazy".
  2. Register a generic raven_mcp tool.
  3. Keep a map of MCP clients keyed by Raven session and server name.
  4. On first use, connect to the remote or stdio MCP server.
  5. Discover tools/resources/prompts inside the Raven session.
  6. Execute the requested operation.
  7. Return the raw MCP output only to Raven, which then summarizes it for the main agent.

Why this matters

This would make Raven scale better for MCP-heavy setups:

  • No global MCP schema context bloat.
  • Users can add more MCPs without making every main session heavier.
  • Raven remains the single controlled context firewall.
  • MCP outputs and MCP schemas both stay outside the main agent unless actually needed.
  • It aligns well with the idea of "tools only when needed".

Backward compatibility

The current behavior could remain the default:

{
  "mcpMode": "global"
}

The new behavior would be opt-in:

{
  "mcpMode": "lazy"
}

Existing users would not be affected.

Possible future extension

This could later support skill-like grouping:

{
  "lazyMcpGroups": {
    "docs": ["context7"],
    "web": ["exa"],
    "code-search": ["grep_app"]
  }
}

Then Raven could expose a small capability catalog in its prompt instead of full MCP schemas.

Acceptance criteria

  • Raven can run with bundled MCPs disabled globally.
  • raven_seek still works for docs, web, and GitHub/code search tasks.
  • MCP clients are created only when Raven actually needs them.
  • The main agent does not receive individual MCP tool schemas for lazy MCPs.
  • Existing global MCP routing continues to work unchanged when mcpMode is not set or set to "global".

jan23456789 avatar Jun 02 '26 11:06 jan23456789

Great suggestion the initial heavy load of mcps is excessive specially if you have a lot of mcps, this is the natural next step to make Raven more useful, my only concern is if blocking the initial load will affect the performance of the model using these mcps if not done correctly. I will be taking a look at this and see how feasible and update Raven if possible. Thank you for the write up, very usefull.

evilayman avatar Jun 02 '26 12:06 evilayman

Your Crazy, thanks!

jan23456789 avatar Jun 04 '26 16:06 jan23456789