MCP & LSP

OpenCode extends external capabilities via MCP (Model Context Protocol) and gets live language diagnostics via LSP (Language Server Protocol).


MCP Overview

MCP lets the agent call databases, browsers, Slack, custom APIs, etc., without baking that logic into OpenCode itself.

Config locations:

  • Global: mcp in ~/.config/opencode/opencode.json
  • Project: project root opencode.json

Configure MCP Servers

stdio (local process)

{
  "mcp": {
    "filesystem": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/allowed"]
    }
  }
}

SSE / HTTP (remote)

{
  "mcp": {
    "my-api": {
      "type": "sse",
      "url": "https://mcp.example.com/sse"
    }
  }
}

Use /connect in TUI for Providers interactively; MCP is usually maintained in config files.


MCP and Permissions

MCP tool names often include a server prefix. Control via permission:

{
  "permission": {
    "mcp": {
      "*": "ask",
      "filesystem_*": "allow"
    }
  }
}

Security:

  • Enable only MCP servers the project needs
  • Default write/network MCP to ask
  • Review MCP server source and scope

Common MCP Use Cases

ScenarioMCP example
Doc searchInternal wiki / Notion MCP
DatabasePostgres MCP (read-only account)
BrowserPlaywright / Puppeteer MCP
DesignFigma MCP

Explore subagent + read-only MCP avoids Build accidentally writing to production systems.


LSP Integration

OpenCode can connect language servers and surface diagnostics (errors, warnings) after edits so the agent can self-correct.

Enable

opencode.json:

{
  "lsp": {
    "typescript": {
      "command": "typescript-language-server",
      "args": ["--stdio"]
    },
    "python": {
      "command": "pyright-langserver",
      "args": ["--stdio"]
    }
  }
}

Install the corresponding LSP binaries on your machine.

With the agent

  1. Agent edits foo.ts
  2. LSP returns type errors
  3. Agent reads diagnostics and fixes

More reliable than the model guessing types alone.

LSP permission

permission.lsp controls LSP tool access; usually allow by default.


MCP vs LSP

MCPLSP
ProtocolModel Context ProtocolLanguage Server Protocol
Typical useExternal systems, browser, DBLanguage diagnostics, completion
Configmcp blocklsp block
Provided byCommunity/custom serversLanguage/community LSP

Both can run together—they complement each other.


Troubleshooting

SymptomCheck
MCP tools missingJSON syntax, type/command
MCP fails to startRun command+args manually in terminal
No LSP diagnosticswhich typescript-language-server, project tsconfig
Constant permission promptsSet common read-only MCP to allow

Next Steps