OpenCode
Use Memtro from OpenCode as its model and tool server, or run OpenCode as Memtro's agent engine with your organisation's memory behind it.
There are two ways to put OpenCode and Memtro together. Pick the one that matches what you want.
1. Memtro's tools inside OpenCode (MCP)
Give your OpenCode sessions Memtro's memory and your connected systems as tools.
- Create a personal API key on Dashboard → Profile → API keys — it acts as you, with your memory, connections and permissions.
- Add Memtro as a remote MCP server in
opencode.json(project or global):
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"memtro": {
"type": "remote",
"url": "https://platform.memtro.com/api/mcp",
"enabled": true,
"headers": { "Authorization": "Bearer sk-memtro-..." }
}
}
}
- Start OpenCode. The tools appear as
memtro_memtro_search,memtro_hubspot_search, and so on (OpenCode prefixes MCP tools with the server name; OpenCode v2 may expose them through its code-modeexecutetool instead).
Try: "Use memtro to find who owns the billing migration and when it launches." or "Look up Help Scout ticket 2450 through memtro and check the customer in HubSpot."
2. Memtro as a model provider in OpenCode
Route OpenCode's own model calls through Memtro, so every session gets memory injected and facts extracted. OpenCode supports custom OpenAI-compatible providers:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"memtro": {
"npm": "@ai-sdk/openai-compatible",
"name": "Memtro",
"options": {
"baseURL": "https://platform.memtro.com/v1",
"apiKey": "sk-memtro-..."
},
"models": {
"auto:chat": {
"name": "Memtro auto (one reply)",
"limit": { "context": 200000, "output": 32000 }
},
"auto:agent": {
"name": "Memtro auto (multi-step agent)",
"limit": { "context": 200000, "output": 32000 }
}
}
}
},
"model": "memtro/auto:chat"
}
OpenCode's own tools (files, bash) keep working because OpenCode executes them; Memtro only sees the conversation and adds its memory. Memtro's server tools are not used in this mode unless you also add the MCP server from section 1.
The two details that are not optional
auto:chat, not auto. OpenCode runs an agent loop of its own. A plain auto means whatever your organisation set as its default mode, and if that is agent then every OpenCode turn starts a Memtro investigation inside OpenCode's loop — an agent running an agent. It is not an error and nothing reports it; it is a reply that takes minutes instead of seconds. :chat pins one reply per request and ignores the default. :agent forces the other way, for when you do want the investigation.
limit, always. OpenCode decides when to compact a session by comparing the tokens used against the model's context window, and for a custom provider it only knows that window if you declare it. Leave limit out and it has nothing to pace against, so it compacts again and again — which looks like Memtro losing the thread and is really OpenCode being told nothing about the model. Set context to the smallest window on your routing ladder; 200,000 suits a Claude or GPT-5 ladder, and if auto can reach something smaller, use that number instead.
Both together, because they compound: agent mode also streams its progress back as reasoning_content, OpenCode keeps that in the session, and a session that grows by a few thousand tokens of narration every turn reaches the compaction threshold that much sooner.
Troubleshooting
- The session compacts over and over:
limitis missing from the model inopencode.json, so OpenCode has no context window to pace against. See section 2. - Every reply takes minutes: the model id has no
:chatand your organisation's default mode isagent, so OpenCode's loop is driving Memtro's. See section 2, or change the default on Dashboard → Routing. - 401 from the MCP server: the header must be exactly
Authorization: Bearer sk-memtro-…; keys are shown once when created. - No connector tools: connect the system on Dashboard → Connections first; MCP only exposes connections you (or your organisation) have.
- Tools missing in OpenCode v2: look for the
executecode-mode tool; MCP tools are callable from there.