MCP (Model Context Protocol) is an open protocol that describes how to connect external tools and data sources to the language model: a file system, documentation, task tracker, bug tracker or your own service. Instead of embedding each tool into the agent, you set up a separate MCP server, and the agent communicates with it according to the standard scheme.
OpenCode supports MCP out of the box: both local servers, which are launched by a child process, and remote ones, accessible via HTTP. An important point is that the entire MCP layer is implemented on the side of OpenCode itself, and not on the side of the model provider. Therefore, DeepSeek receives MCP tools as normal functions in the request, and does not need to know anything about the protocol itself.
In this post, I will look at how to add a local and remote server, how to get authorized, how not to drown in tokens, and what to consider when working with DeepSeek models.
What you need
To work you need three things:
- OpenCode installed. If the agent is not yet configured, I discussed the procedure for installing and connecting DeepSeek in a separate note.
- Node.js and npx. Necessary for local MCP servers, which are distributed as npm packages.
- Access keys. Only for those remote servers that require authorization. Public servers like Context7 work without a key, but with lower limits.
How it works
Servers are described in the OpenCode configuration in the mcp block. Each server has a unique name by which it can be mentioned in a request. Server tools are registered with this name prefix, so there are no conflicts between different servers.
After connecting, MCP tools become available to models along with the built-in ones: reading files, editing code and running commands. From DeepSeek’s point of view, these are ordinary functions that an agent can call – which is why the bundle works without any MCP support on the model API side.
Local server
The easiest way to get acquainted with the mechanism is the test server @modelcontextprotocol/server-everything. Let’s add it to the opencode.json file in the project root:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"mcp_everything": {
"type": "local",
"command": ["npx", "-y", "@modelcontextprotocol/server-everything"]
}
}
}
The command field is the server startup command and its arguments in the form of an array. After restarting OpenCode, the tools will appear in the session and can be asked for explicitly:
используй инструмент mcp_everything, чтобы сложить 3 и 4
The local server has several more useful fields. environment sets the process environment variables, cwd – the working directory, timeout – request timeout in milliseconds, and enabled allows you to temporarily disable the server without removing it from the configuration.
Remote server
Remote servers are more convenient: you don’t need to run anything locally, and they can be accessed via URL. A good example is Context7, which looks for up-to-date library documentation. It connects without a key:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"context7": {
"type": "remote",
"url": "https://mcp.context7.com/mcp"
}
}
}
If you have a free Context7 account, the key is raising the limits. Headers are transmitted through the headers block, and it is convenient to keep the key itself in an environment variable:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"context7": {
"type": "remote",
"url": "https://mcp.context7.com/mcp",
"headers": {
"CONTEXT7_API_KEY": "{env:CONTEXT7_API_KEY}"
}
}
}
}
The {env:NAME} construction substitutes the value of the environment variable when loading the configuration, so the key does not end up in the repository. Before starting the agent, the variable must be exported in the terminal.
Another useful public server is Grep by Vercel, search for code examples on GitHub:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"gh_grep": {
"type": "remote",
"url": "https://mcp.grep.app"
}
}
}
Authorization via OAuth
Some remote servers require OAuth. OpenCode can go through this scenario itself: it notices the 401 response, triggers the authorization and saves the tokens. For Sentry, just specify the server:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"sentry": {
"type": "remote",
"url": "https://mcp.sentry.dev/mcp",
"oauth": {}
}
}
}
After this, authorization can be started manually – the browser will open:
opencode mcp auth sentry
Service commands are also useful in everyday work. opencode mcp list shows servers and authorization status, opencode mcp logout deletes stored tokens, and opencode mcp debug checks network connectivity and OAuth discovery for a specific server. Tokens are stored locally in the file ~/.local/share/opencode/mcp-auth.json.
If the server does not use OAuth, but a regular API key, automatic authorization should be disabled, otherwise OpenCode will try to pass OAuth where it is not needed:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"my-api-key-server": {
"type": "remote",
"url": "https://mcp.example.com/mcp",
"oauth": false,
"headers": {
"Authorization": "Bearer {env:MY_API_KEY}"
}
}
}
}
Tool management
MCP tools consume context: each server adds descriptions of its functions to the request. Therefore, it is better to keep servers that are rarely needed turned off. This can be done globally through the tools block:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"my-mcp-foo": {
"type": "local",
"command": ["npx", "-y", "my-mcp-command-foo"]
},
"my-mcp-bar": {
"type": "local",
"command": ["npx", "-y", "my-mcp-command-bar"]
}
},
"tools": {
"my-mcp*": false
}
}
The my-mcp* template disables all tools whose name begins with this prefix. If there are many servers, it makes more sense to disable them globally and enable them locally for a specific agent:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"my-mcp": {
"type": "local",
"command": ["npx", "-y", "my-mcp-command"],
"enabled": true
}
},
"tools": {
"my-mcp*": false
},
"agent": {
"my-agent": {
"tools": {
"my-mcp*": true
}
}
}
}
DeepSeek Features
The connection with DeepSeek works because the models support calling functions, and the MCP tools for them look like ordinary functions. DeepSeek itself does not connect MCP servers and should not: the connection is handled by OpenCode.
What you should pay attention to:
- Selecting a model. For routine and small edits, deepseek-flash is sufficient. For tasks where you need to keep a lot of context in your head and carefully select a tool, it is better to give deepseek-v4-pro.
- Context size. Heavy servers like GitHub MCP add a lot of tokens and, together with a large project, easily hit the limit. Turn them on only for the duration of a specific task.
- Cost Tooling schemas are sent with each request, so the more servers included, the more expensive each iteration is. You pay the provider directly, so the extra servers are noticeable on your bill.
- Hints for the agent. It is safer not to rely on the ingenuity of the model, but to directly name the server in the request or write a rule in AGENTS.md.
An example of a rule for AGENTS.md, so that the agent itself accesses the required source:
Когда нужно посмотреть документацию библиотеки, используй инструменты context7.
Practical recipe
For everyday work, two servers are usually enough: Context7 for documentation and one narrow server for a specific task – for example, Sentry for analyzing errors or Grep for searching for code examples. It is better to keep the rest turned off and turn on as needed.
My procedure is as follows: I add the server to opencode.json, restart OpenCode, check the list through opencode mcp list, then ask a test question that explicitly mentions the server. If the tool is not called, I look towards opencode mcp debug and the timeout – a slow server may not have time to respond in the allotted 30 seconds.
What to pay attention to
A couple of practical points. MCP servers are trusted code: the local server runs on your machine with your rights, and you send request data to the remote one. Therefore, installing random servers from the Internet should be done with the same caution as any third-party CLI.
Keep keys and tokens in environment variables and do not commit to the repository. OpenCode stores OAuth tokens locally, but on a shared machine this is also worth considering: opencode mcp logout deletes them when access is no longer needed.
And one more thing: don’t turn on everything at once. MCP adds tools to context, and context is money and quality of response. Two or three really necessary servers work much better than ten connected just in case.
Links
https://opencode.ai/docs/mcp-servers/
https://opencode.ai/docs/config/
https://modelcontextprotocol.io/
https://github.com/upstash/context7
https://mcp.sentry.dev
https://mcp.grep.app
https://github.com/anomalyco/opencode
Sources
https://opencode.ai/docs/mcp-servers/
https://modelcontextprotocol.io/
https://api-docs.deepseek.com/
https://api-docs.deepseek.com/quick_start/agent_integrations/opencode
Leave a Reply