# How to test an MCP server with OpenCode

> OpenCode called MCP servers more readily than Claude Code or Codex in our runs, largely because it has no built-in web search. SineFrame M3 runs OpenCode against your server and asserts on the tool calls it records, so you can test it alongside the agents that skip servers more often.

Facts last checked: 2026-11-17.

## Short answer

Run OpenCode against your server in a pytest test and assert on the recorded tool calls. With SineFrame M3:

1. Install the M3 CLI with uv tool install sf-m3-cli, then run m3 init and m3 setup.
2. Select the opencode harness and a provider-prefixed model, such as anthropic/, openai/ or opencode/.
3. Provide the matching key: ANTHROPIC\_API\_KEY, OPENAI\_API\_KEY or OPENCODE\_API\_KEY.
4. Assert on the recorded call with expect(result).to\_have\_tool\_call(...).
5. Pin the version with m3 test --runtime managed --harness opencode@VERSION=MODEL.

## How does M3 run OpenCode?

M3 drives OpenCode through a native adapter named opencode. It starts OpenCode’s server with opencode serve, creates a session, and connects your MCP server to it. Startup and session creation each have their own timeout, and the MCP timeout applies per server.

The managed runtime downloads the OpenCode version you name from its GitHub releases; on Linux, settings choose the C library and CPU variant. Settings from your own OpenCode installation are not copied into the test.

Pinning uses the same harness selector as the other agents: --runtime managed with opencode@VERSION=MODEL.

## Which credentials does OpenCode need?

M3 chooses the key from the model’s provider prefix: a model starting with opencode/ uses OPENCODE\_API\_KEY, openai/ uses OPENAI\_API\_KEY, and anthropic/ uses ANTHROPIC\_API\_KEY. Map a different source variable with credential\_env or --credential-env, and only the variables you map reach the agent.

## Why does OpenCode call MCP servers more often?

With the same model, Claude Haiku 5.5, OpenCode scored 82.0% across 21 MCP servers, against 65.4% for Claude Code. On servers that do something no agent has a built-in tool for, the agents were within a few points of each other. The difference was on servers that overlap a built-in tool: OpenCode 66.3%, Claude Code 34.5%.

In 1,239 trials OpenCode never called a built-in web search tool; its only web built-in was webfetch. For a question that needs a search, your MCP server is the only search it has, which is why it scored 96% on the Exa server while Claude Code and Codex scored 11%. On file and shell servers every agent has a built-in alternative, and OpenCode’s lead shrinks to between 8 and 37 points.

- 21 servers, same model: OpenCode 82.0%, Claude Code 65.4%.
- Should-call trials where OpenCode skipped the server: 16.1% (Claude Code 36.5%, Codex 44.5%).
- Exa search server: OpenCode 96%, Claude Code and Codex 11%.

## What should I know about OpenCode traces?

OpenCode returns a turn in one response, so a turn that times out has no messages or tool calls in its trace. Give agent tests a timeout with room to spare. Its observations are timestamped when M3 receives them rather than on the agent’s own clock.

Agent-driven elicitation is documented for Codex and Pi, not OpenCode, and m3 lint’s harness rules cover Claude Code and Codex. Test those paths through Codex or Pi.

## Frequently asked questions

### Is OpenCode better at using MCP servers than Claude Code?

With the same model it called servers more often in our runs, 82.0% against 65.4% across 21 servers, mostly because it has no built-in web search to fall back on. On servers no agent has a built-in alternative for, the two were close.

### Which models can I test OpenCode with?

Any model OpenCode supports, named with its provider prefix. M3 uses the prefix to decide which API key to pass: anthropic/, openai/, or opencode/.

## Related

- [How to test an MCP server](https://m3.sineframe.com/mcp-testing)
- [Test an MCP server with Claude Code](https://m3.sineframe.com/mcp-testing/claude-code)
- [Test an MCP server with Codex](https://m3.sineframe.com/mcp-testing/codex)
- [Research: same model, different agent on 21 MCP servers](https://m3.sineframe.com/blog/same-model-different-agent)
- [MCP agent usability leaderboard](https://m3.sineframe.com/leaderboard/)
- [Choose an agent harness](https://m3.sineframe.com/docs/guides/agents/harnesses)
