Skip to content

fix(mcp): don't fail connection for resource-only servers#14223

Open
aasmall wants to merge 2 commits intoanomalyco:devfrom
aasmall:fix/mcp-resource-only-servers
Open

fix(mcp): don't fail connection for resource-only servers#14223
aasmall wants to merge 2 commits intoanomalyco:devfrom
aasmall:fix/mcp-resource-only-servers

Conversation

@aasmall
Copy link

@aasmall aasmall commented Feb 19, 2026

Issue for this PR

Closes #11841

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

After connecting, create() calls listTools() as a health check and closes the client if it fails. Servers that only expose resources (no tools capability) get rejected because the SDK throws CapabilityNotSupported on listTools(), which the .catch() swallows into undefined, triggering the "Failed to get tools" path.

The listTools() result here was never cached or reused — tool discovery already happens lazily via MCP.tools() when tools are actually needed. Removed the gate and replaced it with a capabilities log.

How did you verify your code works?

Added 3 tests in test/mcp/resource-only.test.ts covering resource-only, empty capability, and mixed capability servers. All connect successfully. Verified the tests fail against the old code (listTools() throws on the mock client). Full test suite passes (1095 pass, 0 fail). Typecheck clean.

Screenshots / recordings

N/A — no UI changes.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Remove the listTools() gate from create() that closed MCP clients when
tool listing failed. Servers exposing only resources (no tools capability)
were incorrectly marked as failed. Tool discovery is already deferred
to MCP.tools() which handles per-server listing lazily.

Fixes anomalyco#11841
Tests that MCP servers exposing only resources (no tools capability)
are not rejected during connection. Covers resource-only, empty
capability, and mixed capability scenarios.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug where MCP servers that only expose resources (no tools capability) were incorrectly failing to connect. The issue occurred because create() was calling listTools() as a health check immediately after connection, which threw CapabilityNotSupported for resource-only servers.

Changes:

  • Removed the listTools() health check from the connection flow in create() function
  • Added capabilities logging to show which capabilities (tools, resources, prompts) the server supports
  • Added comprehensive tests covering resource-only, empty capability, and mixed capability servers

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/opencode/src/mcp/index.ts Removed premature listTools() health check and replaced with capabilities logging
packages/opencode/test/mcp/resource-only.test.ts Added test coverage for resource-only, empty, and mixed capability MCP servers

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP server not loaded when it only exposes a resource

1 participant

Comments