mcp-server-optimization-guide
MCP Server Optimization Guide
Strategic guide for managing MCP servers in OpenCode to optimize context usage and performance.
Architecture Overview
Two-tier MCP system:
| Type | Manager | Config Location | Use Case |
|---|---|---|---|
| Docker MCP | Docker Desktop | ~/.docker/mcp/ | Official/community servers (Brave, Obsidian, Hostinger) |
| Custom MCP | OpenCode | ~/.config/opencode/opencode.json | Personal/project-specific servers |
Current MCP Servers
Docker MCP (Official)
| Server | Tools | Cost | Primary Use |
|---|---|---|---|
| Brave Search | 6 | Free (2000/mo) | Web search during coding sessions |
| Obsidian | 12 | Free | Vault integration, article management |
| Hostinger API | 113 | Paid | VPS deployment and management |
Custom MCP (Personal)
| Server | Tools | Purpose | Status |
|---|---|---|---|
| theslyprofessor | 23 | Unified productivity server | ✅ Core |
| registry | 6 | Cross-session task persistence | ✅ Core |
| opencode-sessions | 3 | Session history access | ✅ Core |
| zellij | ~6 | Multi-pane terminal awareness | ✅ Active |
| outlook-sqlite | ~8 | Email workflow integration | ⚠️ Situational |
| google-drive | ~10 | Cloud file management | ❌ Disabled (OAuth) |
theslyprofessor Server Deep Dive
Tool Categories (23 total):
- Routing (2):
route_context,list_projects - Vault Management (2):
create_article,generate_frontmatter - Outlook (2):
get_flagged_emails,email_to_article - Context (3):
morning_review,hil_status,daily_tasks - Vault Search (2):
search_vault,get_article - ARF Framework (5):
find_context,refresh_arf_catalog,get_context_stats,get_context_tree,get_context_path - Chezmoi (3):
chezmoi_edit_config,chezmoi_search_configs,chezmoi_preview_diff - Server Management (1):
restart_mcp_server
Performance Features:
- Parallel execution in
morning_review(HIL + emails + tasks) - Smart caching for ARF routing (5-min cache, checksum validation)
- Performance logging to
/tmp/theslyprofessor-perf.log
Optimization Strategy
Always Enable (Core Functionality)
json{ "opencode-sessions": { "enabled": true }, "registry": { "enabled": true }, "theslyprofessor": { "enabled": true }, "MCP_DOCKER": { "enabled": true } }
Rationale:
opencode-sessions→ Session continuity across chatsregistry→ Persistent task management (Convex-backed)theslyprofessor→ 23 productivity tools (vault, email, ARF, chezmoi)MCP_DOCKER→ Enables Brave search and Obsidian integration
Situational Enable
| Server | Enable When | Disable When |
|---|---|---|
| zellij | Multi-pane workflows | Single-pane terminal work |
| outlook-sqlite | Email processing sessions | Coding-focused work |
| Brave Search | Research-heavy tasks | Implementation-only sessions |
| Obsidian | Article creation (ma) | Non-vault work |
| Hostinger | VPS deployment | All other times (113 tools!) |
Always Disable
json{ "google-drive": { "enabled": false } }
Reason: Requires OAuth setup, not yet configured
Context Budget Management
Token cost by server:
| Server | Tools | Approx Context Cost |
|---|---|---|
| Hostinger | 113 | ~15K tokens (schemas) |
| theslyprofessor | 23 | ~8K tokens |
| Obsidian | 12 | ~4K tokens |
| outlook-sqlite | 8 | ~3K tokens |
| Brave Search | 6 | ~2K tokens |
| registry | 6 | ~2K tokens |
Model-specific recommendations:
| Model | Max Servers | Recommended Set |
|---|---|---|
| Big Pickle (FREE) | 3-4 | registry, sessions, theslyprofessor |
| Grok Code Fast (FREE) | 4-5 | + zellij, Brave |
| Claude Haiku 3.5 | 6-7 | + Obsidian, outlook-sqlite |
| Gemini 3 Pro | 6-8 | + Obsidian, outlook-sqlite |
| Claude Sonnet 4.5 | All | Enable everything (but $$$) |
Brave Search Rate Limits
CRITICAL: Brave Free AI plan = 1 req/sec, 2000/month
Best practices:
- NEVER call
brave_web_searchin parallel - Wait 2+ seconds between searches
- Batch queries in separate messages
- Monitor quota with usage tracking
Example (correct):
bash# Sequential with delays brave_web_search "query 1" sleep 2 brave_web_search "query 2"
MCP_DOCKER Integration
How it works:
- OpenCode starts
docker mcp gateway runautomatically - Gateway connects to Docker MCP servers
- Tools become available in OpenCode session
- Gateway must remain running (OpenCode manages this)
Troubleshooting:
bash# Check gateway status ps aux | grep "docker mcp gateway" # View gateway logs tail -f /tmp/docker-mcp-gateway.log # Verify servers enabled docker mcp server list
When to Enable/Disable Servers
Session Start Checklist
Ask yourself:
- Am I working in the vault? → Enable Obsidian
- Do I need to research? → Enable Brave Search
- Am I processing emails? → Enable outlook-sqlite
- Multi-pane terminal work? → Enable zellij
- Deploying to VPS? → Enable Hostinger (temporarily)
Mid-Session Changes
Enable server:
- Edit
~/.config/opencode/opencode.json - Set
"enabled": true - Reload OpenCode (Ctrl+R or restart)
Disable server:
- Set
"enabled": false - Reload OpenCode
Performance Monitoring
Check theslyprofessor performance:
bashtail -f /tmp/theslyprofessor-perf.log
Metrics to watch:
morning_review: <200ms typicalsearch_vault: <100ms for 10 resultsfind_context(ARF): <50ms with cache
Slow operations (expected):
refresh_arf_catalog: 500-1000ms (scans all AGENTS.md files)get_flagged_emails: 200-400ms (SQLite query)
Configuration File Reference
Location: ~/.config/opencode/opencode.json
Template for custom server:
json{ "mcp": { "my-server": { "type": "local", "command": ["bun", "/path/to/index.ts"], "environment": { "API_KEY": "{env:MY_API_KEY}" }, "enabled": true } } }
Cost Awareness
Free tier models (Big Pickle, Grok Code Fast):
- Minimize server count (3-4 max)
- Disable Hostinger (113 tools = huge context)
- Focus on essential tools
Paid models (Claude Sonnet 4.5):
- $3/1M input tokens, $15/1M output tokens
- 113 tools from Hostinger ≈ 15K tokens ≈ $0.045 per message
- Reserve for complex tasks, switch to free models for routine work
Recommended Configurations
Minimal (Free Models)
json{ "registry": true, "opencode-sessions": true, "theslyprofessor": true, "MCP_DOCKER": false }
Standard (Most Sessions)
json{ "registry": true, "opencode-sessions": true, "theslyprofessor": true, "zellij": true, "MCP_DOCKER": true, // Brave + Obsidian "hostinger-mcp-server": false }
Full Power (Complex Tasks)
json{ "registry": true, "opencode-sessions": true, "theslyprofessor": true, "zellij": true, "outlook-sqlite": true, "MCP_DOCKER": true, "hostinger-mcp-server": true // Only for deployment }
Anthropic's Advanced Tool Use (Nov 2025)
Anthropic released three beta features that address MCP context issues:
Tool Search Tool
Problem: 58 tools from 5 MCP servers = ~55K tokens before conversation starts.
Solution: defer_loading: true on tools. Claude discovers tools on-demand via search.
Results:
- 85% token reduction (77K → 8.7K)
- Opus 4: 49% → 74% accuracy
- Opus 4.5: 79.5% → 88.1% accuracy
json{ "tools": [ {"type": "tool_search_tool_regex_20251119", "name": "tool_search_tool_regex"}, { "name": "github.createPullRequest", "defer_loading": true // Only loaded when searched for } ] }
Programmatic Tool Calling
Problem: Each tool call = full inference pass. Intermediate results pollute context.
Solution: Claude writes Python code to orchestrate tools. Results processed in sandbox, only final output enters context.
Results:
- 37% token reduction (43K → 27K on complex tasks)
- Parallel execution eliminates round-trips
- Knowledge retrieval: 25.6% → 28.5%
python# Claude writes orchestration code team = await get_team_members("engineering") expenses = await asyncio.gather(*[ get_expenses(m["id"], "Q3") for m in team ]) # Only final summary enters context, not 2000+ expense records
Tool Use Examples
Problem: JSON schemas define structure, not usage patterns.
Solution: Provide concrete examples showing format conventions, parameter correlations.
Results: 72% → 90% accuracy on complex parameter handling
json{ "name": "create_ticket", "input_schema": {...}, "input_examples": [ {"title": "Critical bug", "priority": "critical", "escalation": {...}}, {"title": "Feature request", "labels": ["feature-request"]}, {"title": "Internal task"} // Minimal example ] }
When to Use Each
| Feature | Use When | Skip When |
|---|---|---|
| Tool Search | >10 tools, >10K tokens in definitions | <10 tools, all frequently used |
| Programmatic Calling | Multi-step workflows, large data filtering | Single tool calls, need all intermediate results |
| Tool Examples | Complex nested structures, domain conventions | Simple single-parameter tools |
Implications for Our Setup
Current approach (good):
- Selective enabling of MCP servers per task type
- Consolidated tools in theslyprofessor server
- Performance monitoring
Future optimizations:
- Add
defer_loading: truefor Hostinger's 113 tools - Use Tool Search Tool when total tools >25
- Add input_examples for complex tools like
create_article
Theo's Criticism of MCP (Context)
Theo (t3.gg) has discussed concerns about MCP servers consuming context window. Key points:
- Tool definitions eat tokens - Each tool's JSON schema is injected into context
- Similar tools confuse models - 20+ similar tools → wrong tool selection
- Cognitive overload - Studies show LLMs struggle with 10-20+ tools
Our mitigations:
- Only enable needed servers per session
- Consolidate related tools (theslyprofessor has 23 tools, not 23 servers)
- Use descriptive, distinct tool names
- Monitor context usage with
/contextcommand
Anthropic's response: The Tool Search Tool and defer_loading directly address these concerns by keeping tools out of context until needed.
See Also
- OpenCode Configuration
- Task Registry Architecture
- ARF (Agents Router Framework)
- Zellij Multi-Pane Workflows
- MCP vs Claude Skills - Choosing the Right Extension Model
- Anthropic: Advanced Tool Use