Model Context Protocol (MCP) is an open standard that enables AI assistants like OpenCode to interact with external tools, databases, and services.
On this page
Introduction
Model Context Protocol was developed by Anthropic and donated to the Linux Foundation.
Anthropic donate in December 2025 the Model Context Protocol to the Linux Foundation’s new Agentic AI Foundation, where it will join goose by Block and AGENTS.md by OpenAI as founding projects. Bringing these and future projects under the AAIF will foster innovation across the agentic AI ecosystem and ensure these foundational technologies remain neutral, open, and community-driven.
MCP is as a universal, open standard for connecting AI applications to external systems.
Since then, MCP has achieved incredible adoption:
-
Across the ecosystem: There are now more than 10,000 active public MCP servers, covering everything from developer tools to Fortune 500 deployments;
-
Across platforms: MCP has been adopted by ChatGPT, Cursor, Gemini, Microsoft Copilot, Visual Studio Code, and other popular AI products;
-
Across infrastructure: Enterprise-grade infrastructure now exists with deployment support for MCP from providers including AWS, Cloudflare, Google Cloud, and Microsoft Azure.
You can add external tools to OpenCode using the Model Context Protocol, or MCP. OpenCode supports both local and remote servers.
Once added, MCP tools are automatically available to the LLM alongside built-in tools.
MCP Server
Why Use MCP Servers?
- Extended Capabilities: Query databases, manage files, automate browsers, and more
- Standardized Integration: One protocol for all tools, no custom integrations needed
- Security First: Sandboxed execution with explicit permissions
- Growing Ecosystem: 1,200+ servers available from official and community sources
Caveats
When you use an MCP server, it adds to the context. This can quickly add up if you have a lot of tools. So we recommend being careful with which MCP servers you use.
MCP servers add to your context, so you want to be careful with which ones you enable.
Certain MCP servers, like the GitHub MCP server, tend to add a lot of tokens and can easily exceed the context limit.
Registry
MCP now has an official, community-driven Registry for discovering available MCP servers.
Yhe November 25th spec release introduced many new features, including asynchronous operations, statelessness, server identity, and official extensions. There are also official SDKs (Software Development Kits) for MCP in all major programming languages with 97M+ monthly SDK downloads across Python and TypeScript.
Installing MCP Servers
Configuration File
OpenCode uses a configuration file to manage MCP servers.
Create or edit ~/.config/opencode/config.toml:
[mcp]enabled = true
[mcp.servers.filesystem]command = "npx"args = ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/allowed/directory"]
[mcp.servers.github]command = "npx"args = ["-y", "@modelcontextprotocol/server-github"]env = { GITHUB_PERSONAL_ACCESS_TOKEN = "ghp_your_token_here" }Project-Level Configuration
For project-specific servers, create .opencode.json in your project root:
{ "mcpServers": { "postgres": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-postgres", "postgresql://localhost/mydb"] }, "memory": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-memory"] } }}Official Reference Servers
These are maintained by the MCP team and are the most reliable options:
Filesystem Server
Access and manage files in specified directories.
[mcp.servers.filesystem]command = "npx"args = ["-y", "@modelcontextprotocol/server-filesystem", "/Users/me/projects"]Exercises
uv init codeopencode code/initSQLite — Query a Local Database with Natural Language
In this exercise you will connect OpenCode to a local SQLite database and explore and manipulate data using plain English.
Tell opencode to use the SQLite MCP server:
Add the SQLite MCP server to project configurationopencode will create a new file ~/.config/opencode/opencode.jsonc
{ "$schema": "https://opencode.ai/config.json", "mcp": { "sqlite": { "type": "local", "command": ["uvx", "mcp-server-sqlite", "--db-path", "db.sqlite"], "enabled": true } }}and will respond with a message like this:
Created
opencode.jsonwith the SQLite MCP server configured. It uses uvx (consistent with the project’s uv-based toolchain) to runmcp-server-sqlite, pointing atdb.sqlitein the project root. The--db-pathvalue can be changed to any path you prefer. To use it in a prompt, reference it by name, e.g.: use the sqlite tool to show all tables in the database
Tell OpenCode: “create a db.sqlite database”
And refine wiht: “create a student table with some sample data”
TODO
- Create a small demo database to work with:
sqlite3 ~/demo.db "CREATE TABLE students (id INTEGER PRIMARY KEY, name TEXT, grade INTEGER); INSERT INTO students VALUES (1, 'Alice', 90), (2, 'Bob', 75), (3, 'Carol', 88);"ask it to describe the database:
use sqlite to describe the schema of the database- Ask it to query the data in plain English:
use sqlite to find all students with a grade above 80- Ask it to add a new record:
use sqlite to add a student named "David" with a grade of 95Then confirm the insert:
use sqlite to show all students sorted by grade descending- Try a more open-ended question:
use sqlite to find the average grade and tell me which students are above averageReflection
- How accurately did OpenCode translate your natural language requests into SQL?
- Did it make any mistakes? How did you catch them?
- What are the risks of letting an AI write and execute database queries directly?
GitLab — Triage and Fix an Issue with OpenCode
In this exercise you will connect OpenCode to a real GitLab project through CI/CD and let it explain and fix an issue automatically.
Prerequisites
- A GitLab account with at least one project
- An OpenCode auth JSON (generated after running
/connectin the TUI)
Steps
-
In your GitLab project, go to Settings > CI/CD > Variables and add a new File type variable named
OPENCODE_AUTH_JSON. Paste the contents of~/.local/share/opencode/auth.jsonas the value. Mark it as Masked and hidden. -
Create or edit
.gitlab-ci.ymlat the root of your project and include the community component:
include: - component: $CI_SERVER_FQDN/nagyv/gitlab-opencode/opencode@2 inputs: config_dir: ${CI_PROJECT_DIR}/opencode-config auth_json: $OPENCODE_AUTH_JSON message: "Explain the project structure and suggest improvements."-
Push the change and watch the pipeline run. Check the job log to see OpenCode’s output.
-
Create a new issue in your GitLab project describing a small bug or missing feature. Then add a comment:
@opencode explain this issue- After OpenCode replies, add another comment:
@opencode fix this- OpenCode will create a new branch and open a merge request. Review the MR: Does the proposed change make sense? What would you change?
Reflection
- What surprised you about how OpenCode interpreted the issue?
- Would you merge the MR as-is, or would you edit it first? Why?
Cloudflare — Deploy and Connect a Remote MCP Server
In this exercise you will create your own remote MCP server running on Cloudflare Workers and connect OpenCode to it.
Prerequisites
- A Cloudflare account (free tier is fine)
- Node.js and npm installed
Steps
- Scaffold a new MCP server project using the Cloudflare template:
npm create cloudflare@latest -- my-mcp-server --template=cloudflare/ai/demos/remote-mcp-authlesscd my-mcp-server- Start the development server locally:
npm startNote the port in the output (usually 8788). The MCP endpoint is at http://localhost:8788/mcp.
- In a separate terminal, run the MCP inspector to explore your server:
npx @modelcontextprotocol/inspector@latestOpen the inspector in your browser, enter http://localhost:8788/mcp, click Connect, then List Tools. You should see the tools exposed by the example server.
- Add your local server to OpenCode’s configuration. Create or edit
~/.config/opencode/opencode.jsonc:
{ "$schema": "https://opencode.ai/config.json", "mcp": { "my-mcp": { "type": "remote", "url": "http://localhost:8788/mcp", "enabled": true } }}- Start OpenCode and ask it to use one of your MCP tools:
use the my-mcp tool to list available tools- Once it works locally, deploy to Cloudflare Workers:
npx wrangler@latest deployThe server will be live at https://my-mcp-server.<your-account>.workers.dev/mcp. Update your OpenCode config to point to the remote URL.
Reflection
- What tools does the example server expose? What would you add for your own projects?
- How does a remote MCP server differ from a local one in terms of latency and availability?