opencode icon indicating copy to clipboard operation
opencode copied to clipboard

mcp: remote servers with >61 tools are silently truncated

Open noejunior299 opened this issue 1 week ago • 9 comments

Summary

Remote MCP servers exposing more than 61 tools are silently capped by OpenCode: only the first 61 tools appear in the tool catalog, and any additional tool is reported as Unknown tool even though the server advertises it via tools/list. This makes tools added after the initial handshake unusable, with no error or warning beyond the connection log line mcp connected tools=61.

Environment

  • opencode version: v2.3.2
  • OS: Linux 7.0.0-43-generic (linux x64)
  • Terminal: TERM=xterm-256color, COLORTERM=truecolor (TERM_PROGRAM unset)
  • Shell: /usr/bin/fish
  • Install/channel: latest (release)
  • Active plugins: none found in ~/.config/opencode/opencode.json

Reproduction

  1. Configure a remote MCP server in ~/.config/opencode/opencode.json (e.g. opencode mcp add organify --global --url https://…/mcp).
  2. Authenticate via /mcps.
  3. Connect an MCP server that exposes more than 61 tools (verified with servers exposing 62 and 79 tools).
  4. Try to call one of the tools beyond the 61st (e.g. list_workspaces).

Expected Behavior

All tools returned by the MCP server's tools/list should be available in the tool catalog and callable via tools.<server>.<name>.

Actual Behavior

Exactly 61 tools are exposed. search({ namespace: "<server>" }) returns 61 items; calling the 62nd tool fails with:

Unknown tool 'organify.list_workspaces'. Did you mean tools.organify.list_workspace_teams?

The service log reports mcp connected … tools=61, while a direct JSON-RPC tools/list call against the same endpoint returns 62 tools including list_workspaces. Reproduced consistently across:

  • TUI restart,
  • full opencode service restart (new run id),
  • MCP config removal + re-add + fresh OAuth authorization,
  • a second MCP entry with a different name pointing at the same URL.

The public endpoint was also verified at the server level: nginx proxies to the correct container, the running binary contains the tool, and a direct tools/list returns TOOL COUNT: 62.

Additional Context

No config option for a tool limit was found in https://opencode.ai/config.json; the only MCP-specific tuning appears to be mcp_timeout. Searches of opencode-ai/opencode issues for mcp max tools, mcp tools truncated, too many tools mcp, mcp tool count, mcp tools missing found no existing report.

Workaround: none found for exposing the additional tools in this version; the MCP server itself is healthy and tools within the first 61 work normally.

noejunior299 avatar Nov 22 '26 17:11 noejunior299

Thanks for the detailed report and for checking the server side so carefully.

In the MCP code I read, I did not find a limit on the number of tools. The tools=N in the mcp connected log line counts the tools that were kept after each one is checked, and a tool can be left out in two ways:

  • OpenCode skips a listed tool whose inputSchema is not an object, or whose inputSchema.type is something other than "object". It logs a skipping invalid MCP tool warning for each one it skips.
  • The MCP SDK that OpenCode uses also leaves out tools with an invalid x-mcp-header declaration, and prints [mcp-sdk] excluding tool '<name>' from tools/list: invalid x-mcp-header declaration — <reason>.

So list_workspaces may have been dropped because of how it is defined, not because of its position in the list. Could you share:

  1. Any skipping invalid MCP tool or [mcp-sdk] excluding tool lines from around the connection. The log is at ~/.local/share/opencode/log/opencode.log (opencode debug paths log prints the folder), e.g. grep -E 'skipping invalid MCP tool|excluding tool' ~/.local/share/opencode/log/opencode.log.
  2. The raw tools/list entry for list_workspaces, and how it differs from a tool that works (for example list_workspace_teams). Please remove anything private first.
  3. For the server with 79 tools: did OpenCode also show exactly 61, and which tools were missing?

You can reply here with the details, or edit the issue. If you edit it, please also leave a comment saying you've updated it, so we know when you're done.

Related issues I found, ordered by likelihood (I don't think either one is the same problem):

  • #64117: tools a server announces later through notifications/tools/list_changed never become callable. Your tools stay missing after a restart and a fresh connection, so this is probably a different cause.
  • #52420: tool names that differ only in characters normalized to _ collide, so one replaces the other.

opencodejr[bot] avatar Nov 22 '26 17:11 opencodejr[bot]

Thanks for the quick reply. I re-checked both points you asked for.

1. Skip/exclusion warnings — none found

grep -E 'skipping invalid MCP tool|excluding tool' ~/.local/share/opencode/log/opencode.log

returns nothing. A broader case-insensitive grep for invalid|skip|exclud|tool around the connection shows only the normal mcp connected … tools=61 lines and a few older failed to call MCP tool … HTTP 401 warnings (from an expired token, before re-auth). No tool-skip warning of any kind.

2. Raw tools/list entries

Both from a direct JSON-RPC tools/list call against the running Go server (COUNT 62), with the private fields redacted as requested (none present):

{"name":"list_workspace_teams","title":"List workspace teams","description":"List teams in a workspace with member counts. Read-only.","inputSchema":{"$schema":"http://json-schema.org/draft-07/schema#","type":"object","properties":{"workspaceSlug":{"type":"string","description":"Workspace slug"},"userId":{"description":"User ID","type":"string"}},"required":["workspaceSlug"]},"annotations":{"readOnlyHint":true}}
{"name":"list_workspaces","title":"List workspaces","description":"List every workspace the authenticated user can access …","inputSchema":{"$schema":"http://json-schema.org/draft-07/schema#","type":"object","properties":{"userId":{"description":"User ID (always overridden by the authenticated bearer token).","type":"string"}}},"annotations":{"openWorldHint":false,"readOnlyHint":true}}

Both have inputSchema.type: "object", valid properties, and no x-mcp-header. The only structural difference I can see is that list_workspaces has no required array. That alone does not explain it: other tools without required (e.g. organify.system.status, plan_create_tasks, create_sprint) are present in the 61 exposed by OpenCode.

3. The 79-tool server

With the previous TypeScript implementation, dump-tools.mjs reported 79 tools and OpenCode again exposed exactly 61. I did not record the exact list of the 18 missing ones at the time, but they were the tools added most recently (notifications/avatar/pulse/subtasks/task-media/list-workspaces and similar). So the “exactly 61” coincidence happened with two different servers and two different sets of extra tools.

Extra data points

  • The server log line says ready (62 tools, backend=http).
  • After the Go-only migration I removed the MCP entry from config, deleted the OAuth credentials from the OpenCode DB, re-added the server, re-authenticated, restarted the TUI, and finally did a full opencode service restart (new run=3d489a6d). Every reconnect still logs tools=61.
  • A second MCP entry with a different name pointing at the same URL also got 61.
  • Calling the missing tool returns Unknown tool 'organify.list_workspaces'. Did you mean tools.organify.list_workspace_teams?

Happy to try a narrow experiment if useful — e.g. adding "required":[] to the schema, or changing the tool name — and report whether it appears. Just tell me what to change.

noejunior299 avatar Nov 22 '26 18:11 noejunior299

Thanks for the extra details. I tried this on v2.3.2 (Linux) with a small test MCP server over Streamable HTTP. Its tools copy your list_workspaces schema shape: $schema draft-07, type: "object", one optional property, no required. OpenCode kept every tool in each case:

  • 62 tools: mcp connected server=many tools=62
  • 79 tools, after opencode service restart: tools=79
  • 62 tools sent in pages of 50: OpenCode asked for both pages (tools/list {} and then {"cursor":"50"}) and logged tools=62

So I couldn't reproduce a limit at 61. The tools=N in mcp connected is counted right after OpenCode reads the server's tools/list reply, so in your setup OpenCode most likely received only 61 tools. My test had no OAuth, so it doesn't cover that part of your setup. These could narrow it down:

  1. Your server's own log of the tools/list request it gets from OpenCode: how many tools it returned, and whether it sent a nextCursor.
  2. Run your direct test the way OpenCode connects: initialize with "protocolVersion": "2025-11-25", then tools/list, using the bearer token OpenCode got from your OAuth flow rather than another one. Does it still return 62?
  3. Whether the server filters tools by OAuth scope, user or client. If the 61 tools OpenCode sees are exactly the older tools, a scope or permission check on the newer ones would explain it.

If you can share a minimal server or a public endpoint where this happens, we can try again with it.

opencodejr[bot] avatar Nov 22 '26 18:11 opencodejr[bot]

Follow-up on your three suggestions — I ran all of them.

1. Server-side view of the tools/list request

The Go server does not log individual JSON-RPC methods, but a direct tools/list from the same host returns the full set with no pagination:

2025-11-25 COUNT 62 HAS True cursor None
2025-06-18 COUNT 62 HAS True cursor None

2. Direct test exactly the way OpenCode connects

Using the bearer token OpenCode obtained from its own OAuth flow (read from the OpenCode credential store), against http://127.0.0.1:4010/mcp with both protocolVersion: "2025-11-25" and "2025-06-18": COUNT 62, list_workspaces present, no nextCursor. So the server sends 62 tools with no paging.

3. Filtering by OAuth scope / user / client

I checked go/internal/mcp/httpserver.go and go/internal/mcp/protocol.go: tools/list returns the full s.tools slice verbatim; there is no scope, user, permission or entitlement filtering in the MCP server.

So the remaining difference from your repro is OAuth. Your test had no OAuth; this server requires a bearer token, and OpenCode goes through the full DCR + PKCE flow. With the identical token and protocol version, a raw client gets 62 tools while OpenCode logs tools=61. That suggests something in the OAuth/authenticated MCP client path is dropping the tool — and notably no skipping invalid MCP tool warning appears in the log at all.

Happy to test a minimal OAuth-protected server if you have one, or to run OpenCode with OPENCODE_LOG_LEVEL=DEBUG and paste the connection lines. Just tell me what would be most useful.

noejunior299 avatar Nov 22 '26 18:11 noejunior299

Thanks for running those checks. I tried again on v2.3.2 with OAuth, close to your setup: a small test server that is both the MCP server and its OAuth sign-in server. It does the sign-in the same way as yours (ending with PKCE), refuses /mcp without a token, sends its replies as SSE, and offers 62 tools. The 62nd is a copy of your list_workspaces schema. After opencode mcp add organify --url … and opencode mcp auth organify, OpenCode connected with the token, sent initialize with 2025-11-25 and then tools/list, and logged:

mcp connected server=organify tools=62

The earlier runs without OAuth also kept every tool: 62, 79, and 62 split across two pages. So in my tests paging, the protocol version, the OAuth path and SSE replies don't cap the list at 61. I couldn't reproduce it with any of them, and I don't have a cause yet.

What would help most:

  1. Run opencode mcp list --standalone --print-logs --log-level debug from the project where it happens, and paste the lines about your server (remove tokens).
  2. Point OpenCode at http://127.0.0.1:4010/mcp directly instead of the public URL, using a new server name so it signs in again. Is it still tools=61? If not, the proxy is involved.
  3. If you can, a small server, or a test endpoint with a throwaway account, where this happens, so a maintainer can run OpenCode against it.

opencodejr[bot] avatar Nov 22 '26 19:11 opencodejr[bot]

Ran the two things I could without another sign-in round.

1. Debug output

opencode mcp list --standalone --print-logs --log-level debug

from the project directory prints:

… level=DEBUG message="spawning process" command=/home/noejunior299/.opencode/bin/opencode args="[\"serve\",\"--stdio\",\"--port\",\"0\"]" …
… level=INFO message="watcher started" path=/home/noejunior299/Documents/projects/techify/organify …
No MCP servers configured
… level=INFO message="watcher stopped" …

So --standalone does not pick up my global ~/.config/opencode/opencode.json MCP entry — it reports No MCP servers configured, while plain opencode mcp list says ✓ organify connected. I therefore could not capture the per-server debug lines you asked for. Is there a flag/env to make the standalone server load the global config?

2. Direct http://127.0.0.1:4010/mcp

That address is on the remote server, not on this machine, so OpenCode cannot reach it as-is. I can set up an SSH tunnel and add a second MCP entry with a new name, but the server's OAuth issuer is https://mcp.organify.ao, so I expect the loopback sign-in to fail or to be blocked by the OAuth redirect rules. Before I spend a sign-in round on it: do you expect that test to be meaningful given the issuer mismatch, or is there a better way to force OpenCode to re-read tools/list with full DEBUG logging?

For reference, the normal log still shows only these MCP lines after every reconnect (no skip warnings at any level):

level=INFO message="mcp connected" server=organify tools=61 …

and the log file is not rotated, so the warnings you described would be in it if they had been emitted.

noejunior299 avatar Nov 22 '26 20:11 noejunior299

Thanks, that helps.

About --standalone: my first --standalone runs printed the same No MCP servers configured, even with the server in the project's own opencode.json. So I don't think your global config is the cause. Please skip that command. Your tools=61 lines come from the background service, and its log is the more useful one anyway.

About the SSH tunnel: I'd skip it. With your issuer on https://mcp.organify.ao, a failed sign-in through a loopback tunnel wouldn't tell us anything about this bug.

What would help instead, with no new sign-in needed:

  1. Run opencode service restart, then opencode mcp list. Then post every line about your server from that run: grep 'role=server' ~/.local/share/opencode/log/opencode.log | grep -i organify | tail -40 (opencode debug paths log prints the log folder). Remove anything private.
  2. The order: are the 61 tools OpenCode keeps exactly the first 61 in the order your server's tools/list returns them, with list_workspaces last? With the 79-tool server you said the missing 18 were the newest ones. If they were also the last 18 in the list, then something is cutting the list at a fixed position.
  3. The reply to tools/list through the public URL: its Content-Type (application/json or text/event-stream), its size in bytes, and whether nginx compresses it or sends it in chunks.
  4. Your organify entry from ~/.config/opencode/opencode.json (with no secrets), so I can see any timeout, protocol, headers or oauth settings.

For reference, my two test servers both returned 62 tools with the same schema shape as yours. One required an OAuth sign-in and sent replies as SSE. OpenCode logged tools=62 for both. A small server, or a test endpoint where this happens, would still be the fastest way to pin it down.

opencodejr[bot] avatar Nov 22 '26 20:11 opencodejr[bot]

Root cause found — and it is on my side, not in OpenCode. Please close this issue.

Your question about the order/reply finally pointed to it: I compared tools/list through the public URL against a direct call to the container:

  • direct to the new server (127.0.0.1:4010): 62 tools, list_workspaces present (index 35, not last), no nextCursor;
  • same call through https://mcp.organify.ao/mcp: 61 tools, list_workspaces absent, no nextCursor.

The active nginx config had:

server_name mcp.organify.ao;
location ~ ^/(authorize|token|...|mcp)(/|$) { proxy_pass http://127.0.0.1:4020; }

Port 4020 belongs to an older parallel container (organify-mcp-go) that was built before list_workspaces existed, while the current Go server was on 4010. So OpenCode was faithfully exposing exactly the 61 tools it received from the stale upstream. My earlier "cap of 61" theory was wrong — the number 61 was just the old binary's tool count.

Response details through the public URL at the time (for the record): Content-Type: application/json, Content-Length absent (chunked), server: cloudflare, cf-cache-status: DYNAMIC, body 39,418 bytes. No compression or paging involved.

I rebuilt and recreated the stale mcp-go container from the current source. Verified again:

PUBLIC COUNT 62 HAS list_workspaces True

Thanks for your patience and for the systematic questions — the "is it the first 61 in order?" prompt is what made me compare the two endpoints. Sorry for the false report.

noejunior299 avatar Nov 22 '26 21:11 noejunior299

Thanks for tracking it down and writing up what you found. It all fits: OpenCode was showing the 61 tools the old copy of your server on port 4020 returned, and it matches my tests, where OpenCode kept every tool the server sent.

Since this wasn't a bug in OpenCode, the issue will be closed as not reproduced. If you see the tool count stop short again with an up-to-date server behind the URL, reply here and it will be reopened.

opencodejr[bot] avatar Nov 22 '26 21:11 opencodejr[bot]