An MCP tool worked before its server went down. Now the server is back, the agent can still name the tool, and its answer sounds right. Did OpenCode actually reach the replacement process? To verify an OpenCode MCP reconnect, ask for one fresh call and look for a value only the replacement process can return in that call’s tool result.
This walkthrough is for a developer who already uses the OpenCode V2 terminal interface with a configured, tool-capable model. You’ll run a disposable Python MCP server, make one successful call, stop the server long enough to see a call fail, and bring it back at the same URL with a different result. The original OpenCode conversation stays open. The fixture and expected observations are illustrative. The walkthrough was drafted from the linked documentation without executing it.
Use OpenCode v2.4.5 for the worked case. OpenCode published it on December 4, 2026, with behavior that retains tool listings through dropped connections and reconnects when a subsequent call needs the server. The release also removed the mcp_resilience flag. A tool name can therefore remain available to the model while its server is unreachable. OpenCode v2.4.5 release notes

Start a fixture you can stop independently
- Open two terminals in the network environment where the OpenCode backend will reach the fixture. Use a disposable directory outside an existing repository, with no project-specific instructions or source files. Put both terminals in that directory. Use the first for Python and the second for the OpenCode terminal interface. The terminal interface uses the project directory for the session, and the backend owns session and tool activity. A loopback address in a container or remote backend refers to that environment. OpenCode TUI and OpenCode troubleshooting
- Check
opencode --versionin the second terminal. Use the already configured model for this exercise. If you still need a working model and project setup, establish those before testing the call. A provider failure can end a turn before OpenCode attempts any MCP request. OpenCode troubleshooting and OpenCode Setup for V2 - Save the following as
server.pyin the disposable directory. You’ll need Python anduv. The example uses the documented FastMCP tool decorator, a Streamable HTTP listener, and a string result. MCP Python SDK v1 quick example and Building MCP Servers
import sys
from mcp.server.fastmcp import FastMCP
def main() -> None:
if len(sys.argv) != 2 or sys.argv[1] not in {"fixture-A", "fixture-B"}:
raise SystemExit("Usage: server.py fixture-A or server.py fixture-B")
marker = sys.argv[1]
server = FastMCP(
"Reconnect Fixture",
host="127.0.0.1",
port=8000,
stateless_http=True,
json_response=True,
)
@server.tool()
def health() -> str:
"""Return the current fixture process marker."""
print(f"health invoked: {marker}", flush=True)
return marker
server.run(transport="streamable-http")
if __name__ == "__main__":
main()
The function takes no arguments. The process captures the marker at startup and prints it each time the handler runs. A tool listing can describe health and its inputs without running the handler. This gives you something to check on both sides of the request. The handler reads no files and makes no external calls. Its foreground output gives you a direct record of which process entered the handler.
The server binds to loopback for this exercise. It uses the SDK’s stateless HTTP mode with JSON responses, keeping per-process MCP transport session state out of the example. The OpenCode conversation has its own history and remains open during the test. The SDK serves Streamable HTTP at /mcp by default. The server name, handler name and response type stay fixed across both runs. The launch argument changes the returned value without a source edit. Building MCP Servers
Start the baseline in the Python terminal and leave it in the foreground.
uv run --with 'mcp>=1.28,<2' server.py fixture-A
Wait for successful listener startup before launching OpenCode. The first run may install dependencies. If Python reports that port 8000 is in use, choose a free port and change both port=8000 in Python and :8000 in the configuration below before making the first call. Use that same port on both starts and record it in your notes. A dependency or bind error leaves the baseline unestablished. The SDK documents the uv run --with launch pattern and the v1 constraint. MCP Python SDK v1 quick example
Point the project at the fixture and capture a baseline
- Save the complete
opencode.jsoncbelow in the disposable directory. If the directory already has an OpenCode config, use a fresh disposable directory so you can paste the worked file as written. OpenCode searches parent directories for configuration, so use the distinctive server name in the example. OpenCode config - With Python running, start
opencodefrom the second terminal. Enter/mcpsand inspectreconnect_lab. Look for a connected server at baseline, then return to the composer without toggling the connection./mcpsshows MCP servers and provides connection controls. Record the status you actually see. OpenCode TUI and OpenCode MCP servers - Submit the supplied prompt. If your configuration asks for approval, check the requested action and allow the fixture tool for that call. Look for a new tool operation with the baseline result and the matching
health invoked: fixture-Aline in Python. Establish this baseline before stopping the fixture. OpenCode config and OpenCode MCP servers
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"servers": {
"reconnect_lab": {
"type": "remote",
"url": "http://127.0.0.1:8000/mcp",
"oauth": false,
"protocol": "legacy",
"codemode": false,
"timeout": {
"startup": 5000,
"catalog": 5000,
"execution": 10000
}
}
}
}
}
remote selects Streamable HTTP even though the server lives on your machine. OpenCode’s local type starts a child over stdio. Here, starting Python yourself gives you control over when the listener stops and when its replacement starts. This loopback fixture has no authentication, and the example sets oauth to false for this entry. Keep your normal authentication settings for real servers. legacy selects the classic initialize handshake and skips the newer revision probe for this v1 SDK example. OpenCode MCP servers
With codemode set to false, OpenCode exposes the tool directly. The documented server and tool name convention gives reconnect_lab_health, which identifies the action to request and inspect. The timeout values are milliseconds. Startup covers connection and initialization, catalog covers discovery, and execution covers calls. The supplied values give the small loopback fixture time to answer. Model response time and reconnect behavior can add time to the turn you see. OpenCode MCP servers
Make one fresh call to the MCP tool reconnect_lab_health with no arguments. Use only that tool. Report its returned value, or report that the call failed. Do not infer the value from conversation history, read files, or use the shell.
The prompt names the action and leaves the expected marker out. Use it unchanged in each phase. That way the requested action and arguments stay the same, and the later fixture-B value cannot come from the prompt itself. The model can still answer from history on a later turn or describe the tool without using it. Look for tool activity associated with the current prompt. If the interface shows only the assistant’s summary, preserve the server-side line and inspect the session export if needed.
Read the two baseline observations together. The Python line establishes that a handler entered with fixture-A, and the new tool operation establishes that OpenCode received the result. The connected row in /mcps tells you about the server connection. A line from a call made in a different client cannot establish a baseline for this conversation. If the first prompt produces only prose and Python stays quiet, resolve the invocation problem before introducing the outage.
Stop Python and observe the failed call
- Wait for the baseline turn to finish. Press Ctrl+C in the Python terminal and wait for it to return to the shell. Leave the OpenCode terminal interface on the same conversation. Keep the MCP entry enabled and leave the connection controls alone. The reconnect implementation clears retained tools on an explicit disconnect. OpenCode reconnect change
- Reopen
/mcpsfor a server-status observation without selecting a connection action. Record its server entry separately. Send the same prompt in the open conversation. If OpenCode shows an attempted operation namedreconnect_lab_healthwhile Python is down, record the name and the resulting failure. If the only visible evidence is the server row, mark the tool availability observation as unconfirmed. - Keep Python down until you have inspected the outage turn. Save the tool error as displayed. The exact text depends on when the transport notices the shutdown and when OpenCode tries to reconnect. If there was no attempted tool operation, record that the outage invocation is unconfirmed and repeat the prompt once while the listener is down.
The retained listing carries metadata from the last available tool catalog. The model can use that metadata to request a call even while the listener is down. A failed attempt with the tool name gives you two observations from the same turn. The operation shows that the model selected the tool, and its error shows that the attempted call did not produce a successful result. The assistant’s sentence about the outage can be an inference from conversation history. Read the tool operation for an error or look for the corresponding backend log activity. OpenCode reconnect change
Treat a missing attempt as its own outcome. If the second prompt also yields only prose, you can still bring the fixture back and check whether later tool execution works. Record the outage phase as unconfirmed, since the exercise did not establish what happened to an actual call during that interval. Starting the replacement before the outage invocation finishes also makes the sequence ambiguous. A late request could reach the replacement while you are still reviewing the earlier turn.
Restart on the same URL and verify fixture-B
- Start the replacement with the command below in the Python terminal. Wait for the listener to start successfully. Keep the same server name, endpoint and tool schema. With those held constant, the changed marker identifies which process handled the call.
- Send the same prompt in the original OpenCode session. Allow the named call if your configuration prompts. Check that Python prints
health invoked: fixture-Bafter this prompt, and inspect the successful tool result forfixture-B. If an immediate call fails after startup, allow the retained-tool retry delay to elapse before submitting a fresh call. The implementation discussion describes call-driven recovery with a backoff capped at 10 seconds for servers with retained tools. That cap applies to retry eligibility. The entire turn includes model and tool processing. Retained-tool and first-start retry behavior - Count the automatic reconnect as verified when a fresh invocation of
reconnect_lab_healthin the original conversation returnsfixture-Bafter the outage, with no manual connection action between the outage and recovery. If the handler logs a call and the tool operation shows an error, record receipt at Python and mark successful delivery as unconfirmed. If the assistant mentionsfixture-Bin prose, inspect the associated tool operation before accepting it as recovery evidence.
uv run --with 'mcp>=1.28,<2' server.py fixture-B
The following filled record shows the illustrative observations for the same case across all three phases. If your run differs, write down the actual error, result or missing evidence in place of the expected observation.
| Input | Action | Expected result |
|---|---|---|
task:mcp-reconnect-01 · 127.0.0.1:8000/mcp serving fixture-A |
Submit the supplied prompt for reconnect_lab_health from the disposable project. |
The tool result contains fixture-A and the Python terminal prints health invoked: fixture-A. |
task:mcp-reconnect-01 · Python stopped, same OpenCode session |
Inspect /mcps without changing status, then submit the supplied prompt again. Check the new operation for the tool name and record the invocation outcome separately. |
OpenCode can retain the tool name through the interruption. An attempted call while the listener stays down fails, with no new Python handler line. |
task:mcp-reconnect-01 · same endpoint now serving fixture-B |
Submit the supplied prompt in the original session after listener startup and any applicable backoff. | A fresh successful operation returns fixture-B and the replacement Python process prints health invoked: fixture-B. This passes the recovery check. |
Illustrative observations for the baseline, outage and replacement. The retained name can span all three phases. The new marker appears in a successful live result after the replacement handles the call. Based on OpenCode’s December 4, 2026 release notes.
A repeated fixture-A in the assistant’s answer is easy to misread because it was correct when the first process ran. If a fresh tool result itself contains fixture-A, verify that you’re reading the operation for the latest prompt, then check whether another listener or effective configuration points to the original marker. The fixture binds the marker once in main, so each successful handler run prints and returns the same string. If the replacement terminal shows fixture-B and the result you’re reading shows fixture-A, preserve both observations and check which operation produced each before changing any settings.
Find where the chain broke
| Observation | What to check next |
|---|---|
reconnect_lab is absent before the baseline |
Verify the TUI’s project directory and run opencode debug config from the fixture directory to list configuration sources. Inspect ancestors and .opencode files for overrides. |
| The server entry exists and an attempted call never reaches Python | Match the configured scheme, host, port and /mcp path against the running fixture. Check for a startup failure in Python and for an endpoint or handshake error in OpenCode’s server log. |
| The server appears connected and the model replies without an invocation | Verify the direct tool name, the selected model’s tool capability, and permissions governing reconnect_lab_health. Repeat with the exact prompt and review the new activity. |
| The baseline worked and the stopped phase failed | Restore the listener at the same URL and check for a fresh replacement result after any applicable backoff. |
| The replacement logs a call and OpenCode reports failure | Preserve the Python handler line and the matching OpenCode error. Investigate delivery before recording the call as successful. |
If the entry has never appeared in the right project, start at configuration. OpenCode searches upward, and discovered .opencode configs can override direct config files. For the same server name, a higher-precedence definition replaces the full server object. A small override can therefore point that name to a different URL or disable it. opencode debug config lists configuration sources. Use it to locate the files and inspect the actual server blocks. Run it from the directory used to launch this conversation so you examine the configuration for the same project. OpenCode config, OpenCode MCP servers and OpenCode CLI commands
If the entry loads and an attempted call produces no handler line, work outward from the listener. Compare the URL character by character, especially /mcp, the SDK’s Streamable HTTP route in this example. The same address must work from the OpenCode backend’s network environment. A listener on the wrong port can resemble a stopped process. A wrong path may accept the HTTP connection and still return a 404. The release says OpenCode drops servers it determines are gone, including URLs returning 404 or 410. Correct an endpoint error and re-establish the baseline before interpreting restart behavior. Building MCP Servers and OpenCode v2.4.5 release notes
For a stalled recovery, open another terminal and follow the installed build’s log. Leave the original terminals visible so you can match the time of a new prompt, the operation in OpenCode and any handler output in Python.
tail -f ~/.local/share/opencode/log/opencode.log
Look near the attempted call for role=server, the process run ID and relevant transport or tool activity. The documentation identifies those fields. Exact reconnect messages can vary with the failure. A provider error or permission rejection belongs to the model or approval stage. A refused connection after a successful baseline points toward the listener and its address. A handler line followed by an OpenCode error narrows the search to what happened after Python received the call. Press Ctrl+C in the log terminal when you’ve collected the relevant lines. OpenCode troubleshooting
If the terminal interface’s visible output is ambiguous, list sessions and export the disposable conversation. Substitute its actual ID for the example ID in the second line.
opencode session list
opencode session export ses_4f2a1c
Read the latest turn and look for the matching tool operation and result if present. The CLI documents JSON export without specifying a tool result field path in its command reference. Use the prompt and the tool name to locate the relevant part of the exported data. If it still yields no matching result, record the delivery check as inconclusive. For a report to others, use the documented --sanitize option and review what you share. OpenCode CLI commands
A fixture that was absent at first startup can leave the model with no tool to invoke. OpenCode has separate bounded retries for eligible first-start failures, triggered when the agent takes a step. A successful baseline establishes the retained-tool path used here. If the replacement still cannot be reached after you verify the URL and listener, connect it manually through /mcps and try the same read again. A fresh fixture-B result then verifies manual recovery. Record that intervention with the result so anyone reading the record knows what restored the connection. First-start retries and OpenCode MCP servers
If the disposable case works and your intended project still fails, compare the effective MCP entry and tool permissions in the two projects. For a broader backend problem, see OpenCode V2 background-service troubleshooting. For an independent test of the fixture, see MCP Inspector. Run an independent test outside the three recorded phases or note its time explicitly, since that call can produce the same handler line as OpenCode. The current OpenCode operation remains the evidence of delivery to the original conversation.
Remove the fixture and keep the recovery evidence
- Preserve the baseline result, the outage attempt and the replacement result if you need a record. Keep the matching Python lines and note whether you used manual reconnect. If you report the problem, include the version, the endpoint used for the fixture and the first phase that differed from the expected record. Keep the operation and handler output together so another reader can reconstruct the sequence. OpenCode troubleshooting and How to retain evidence for a fleet replay
- Stop the replacement from its foreground terminal with Ctrl+C. Remove the
reconnect_labentry from the project file. If the file was created solely for this exercise, remove that file andserver.pyfrom the disposable directory. OpenCode documents removing a server at the configuration scope where it was added. OpenCode MCP servers - If continuing to use the disposable project, run
opencode reloadafter the file change and verify the entry is gone with/mcpsonce the session has picked up the new configuration. OpenCode documents reload without a backend restart and says sessions pick up fresh services at the next step boundary. If the name persists, useopencode debug configto locate another definition. OpenCode CLI commands
When you apply the method to a tool you use, choose a read whose result you can tie to current server state, such as the version of a known test record. Pick a read that can safely be repeated during diagnosis. The new call’s returned value gives you a result to verify in the current turn, and the server log shows whether the intended process handled the request. For the vocabulary behind discovery and tool calls, see the Model Context Protocol explainer.
Sources
- OpenCode v2.4.5 release notes
- OpenCode pull request 67926 on reconnect and saved listings
- OpenCode pull request 67899 on first-start and retained-tool retries
- OpenCode MCP servers
- OpenCode CLI commands
- OpenCode troubleshooting
- MCP Python SDK v1 quick example
- Building MCP Servers
- OpenCode TUI
- OpenCode config

