OpenCode Plugin CLI provides full support for MCP servers, allowing plugins to integrate with external services.
MCP (Model Context Protocol) is a protocol that enables Claude Code plugins to:
- Connect to external services (databases, APIs, file systems)
- Provide structured tool access within Claude Code
- Bundle MCP servers with plugins for automatic setup
Execute local MCP servers as child processes.
Configuration (.mcp.json):
{
"my-server": {
"command": "node",
"args": ["${CLAUDE_PLUGIN_ROOT}/server.js"],
"env": {
"LOG_LEVEL": "debug"
}
}
}Use cases:
- File system access
- Local database connections
- Custom MCP servers
- NPM-packaged MCP servers
Connect to hosted MCP servers via HTTP.
Configuration:
{
"my-api": {
"type": "http",
"url": "https://api.example.com/mcp"
}
}Use cases:
- Cloud services
- REST APIs
- Remote databases
Connect to MCP servers using Server-Sent Events.
Configuration:
{
"my-sse-server": {
"type": "sse",
"url": "https://sse.example.com/events"
}
}Connect to MCP servers via WebSocket.
Configuration:
{
"my-ws-server": {
"type": "websocket",
"url": "wss://ws.example.com/mcp"
}
}Create .mcp.json at plugin root. Two formats are supported:
{
"my-database": {
"command": "${CLAUDE_PLUGIN_ROOT}/servers/db-server",
"args": ["--config", "${CLAUDE_PLUGIN_ROOT}/config.json"]
},
"my-api": {
"type": "http",
"url": "https://api.example.com/mcp"
}
}{
"mcpServers": {
"my-database": {
"command": "${CLAUDE_PLUGIN_ROOT}/servers/db-server",
"args": ["--config", "${CLAUDE_PLUGIN_ROOT}/config.json"]
}
}
}Both formats work identically. The direct format is the Claude Code standard.
Add mcpServers field to plugin.json:
{
"name": "my-plugin",
"version": "1.0.0",
"mcpServers": {
"my-server": {
"command": "node",
"args": ["${CLAUDE_PLUGIN_ROOT}/server.js"]
}
}
}Note: Both .mcp.json and inline mcpServers are merged when installing a plugin.
OpenCode Plugin CLI automatically substitutes variables in MCP configurations:
${CLAUDE_PLUGIN_ROOT}- Path to the plugin directory${PLUGIN_NAME}- Name of the plugin${PLUGIN_VERSION}- Version of the plugin
Example:
{
"my-server": {
"command": "${CLAUDE_PLUGIN_ROOT}/bin/server",
"args": ["--port", "8080"],
"env": {
"PLUGIN_ROOT": "${CLAUDE_PLUGIN_ROOT}",
"PLUGIN_NAME": "${PLUGIN_NAME}",
"PLUGIN_VERSION": "${PLUGIN_VERSION}"
}
}
}Variables are substituted in:
commandfieldargsarrayurlfieldenvvalues
opencode-plugin mcp listOutput:
Installed MCP Servers:
NAME TYPE COMMAND/URL
github.github http https://api.githubcopilot.com/mcp/
plugin-a.database stdio /path/to/plugin/servers/db-server
Total: 2 MCP server(s)
opencode-plugin mcp show github.githubOutput:
MCP Server: github.github
Type: http
URL: https://api.githubcopilot.com/mcp/
Environment Variables:
Authorization=Bearer ${GITHUB_PERSONAL_ACCESS_TOKEN}
MCP servers are installed automatically when you install a plugin:
# Install plugin with MCP servers
opencode-plugin plugin install github
# Output:
✓ Successfully installed plugin: github
From marketplace: anthropics/claude-plugins-official
Cache: ~/.opencode-plugin-cli/cache/anthropics/claude-plugins-official/github/latest
Skills: 0, Commands: 0, Agents: 0
MCP Servers: 1 # ← MCP servers installedThe MCP configuration is merged into ~/.config/opencode/.mcp.json.
When you remove a plugin, its MCP servers are also removed:
opencode-plugin plugin remove github
# Output:
✓ Removed MCP servers: github.github
✓ Successfully removed plugin: github (0 symlinks removed)If multiple plugins define MCP servers with the same name, OpenCode Plugin CLI prefixes them with the plugin name:
plugin-a.database
plugin-b.database
This ensures no conflicts between plugins.
.mcp.json:
{
"github": {
"type": "http",
"url": "https://api.githubcopilot.com/mcp/",
"headers": {
"Authorization": "Bearer ${GITHUB_PERSONAL_ACCESS_TOKEN}"
}
}
}.mcp.json:
{
"playwright": {
"command": "npx",
"args": ["@playwright/mcp@latest"]
}
}.mcp.json:
{
"custom-tools": {
"command": "${CLAUDE_PLUGIN_ROOT}/bin/server",
"args": ["--verbose"],
"env": {
"LOG_LEVEL": "info"
}
}
}For MCP servers that require OAuth or complex authentication:
- Environment Variables: Use
${VAR_NAME}syntax - Configuration Files: Bundle config files in plugin
- Interactive Setup: Plugin can prompt for credentials on first use
Example:
{
"github": {
"command": "${CLAUDE_PLUGIN_ROOT}/servers/github-mcp",
"env": {
"GITHUB_TOKEN": "${GITHUB_TOKEN}",
"GITHUB_ORG": "${GITHUB_ORG:-myorg}"
}
}
}Prefer separate .mcp.json for clarity and maintainability.
Use descriptive names that include the service:
{
"postgres-main": {...},
"github-api": {...}
}Document required environment variables in plugin README.
Test MCP servers locally before packaging with plugin.
If MCP servers have versions, track them in plugin.json.
- Check
.mcp.jsonorplugin.jsonsyntax - Verify
${CLAUDE_PLUGIN_ROOT}paths are correct - Run
opencode-plugin mcp listto see installed servers
- Check command path exists
- Verify environment variables are set
- Check MCP server logs
MCP servers are automatically prefixed with plugin name to avoid conflicts.