Skip to content

[Feature] Lazy-load MCP tool definitions to reduce token overhead #35376

Description

@jijoyo

Problem

When multiple MCP servers are connected, ALL tool definitions from ALL servers are injected into the system prompt of EVERY conversation.

With 9 MCP servers connected (project-tools, supabase, agent-browser, chrome-devtools, playwright, memory, context7, sequential-thinking, fetch), this results in ~40,000-70,000 tokens of tool definitions loaded upfront — even if the user only needs 2-3 tools.

Users paying per-token to LLM providers (Anthropic, OpenAI, etc.) bear this cost on every single message.

Current behavior

  • 9 MCP servers = ~250+ tool definitions
  • Each tool definition = 50-200 tokens
  • Total overhead: ~40-70k tokens per conversation
  • User pays for ALL tools in EVERY message, even unused ones

Proposed solutions

  1. Lazy tool loading — Only inject tool definitions when context suggests they are needed (e.g., if user mentions "deploy", load Supabase tools)
  2. Tool profiles — Let users configure preset profiles (e.g., "dev", "deploy", "debug") with only relevant MCP servers
  3. Tiered loading — Load essential tools (project-tools, bash, read, write) by default, load others on-demand via a /tools command

Impact

  • Reduces token cost by 30-50k tokens per conversation
  • No behavior change for users who want all tools available
  • Better UX for cost-conscious users

Environment

  • OpenCode version: latest
  • OS: Windows
  • MCP servers: 9 connected

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