Defines Model Context Protocol (MCP) server configurations and integrations for the OpenCode plugin. This module provides built-in MCP servers for web search, code search, and documentation lookup, enabling agents to access external tools and resources via the MCP standard.
The src/mcp/ directory implements a modular MCP configuration system with the following architecture:
types.ts): Core type system for MCP configurations (RemoteMcpConfig, LocalMcpConfig, McpConfig)index.ts): Centralized creation and management of MCP configurations with user-configurable overrides| Type | Purpose | Example Use Case |
|---|---|---|
| RemoteMcpConfig | Connects to hosted MCP servers via URL | Web search, documentation lookup |
| LocalMcpConfig | Spawns local processes as MCP servers | Custom tool integrations |
websearch (websearch.ts)
context7 (context7.ts)
gh_grep (grep-app.ts)
Plugin loads → createBuiltinMcps() called with disabledMcps list and optional websearchConfig
↓
Filters built-in MCP list to exclude disabled servers
↓
Creates RemoteMcpConfig instances for each enabled server
↓
Overrides websearch config if custom websearchConfig provided
↓
Returns record of McpConfig objects to main plugin
Configuration phase (at plugin initialization):
createBuiltinMcps() is called from src/index.tsIntegration phase (during agent execution):
Primary consumer: src/index.ts - Main plugin entry point
createBuiltinMcps() during plugin initializationConfiguration layer: src/config/ - Provides McpName type and WebsearchConfig schema
Environment variables:
EXA_API_KEY - API key for Exa web search providerTAVILY_API_KEY - API key for Tavily web search providerCONTEXT7_API_KEY - API key for Context7 documentation lookupType system: Shares McpName type with src/config/ to avoid duplication
RemoteMcpConfig, LocalMcpConfig, McpConfig from types.tscreateBuiltinMcps() from index.tswebsearch, context7, gh_grep constantsThe system supports runtime configuration overrides:
// In user configuration (e.g., ~/.config/opencode/oh-my-opencode-slim.json)
{
"mcp": {
"disabled": ["websearch"],
"websearch": {
"provider": "tavily"
}
}
}
This allows users to:
index.test.ts validates MCP creation and filtering logicIntegration tests: MCP servers are tested via integration with OpenCode's MCP runtime
Configuration tests: Schema validation ensures user configurations match expected types