Skip to content

refactor(core): contribute MCP tools through a built-in plugin - #47389

Closed
kitlangton wants to merge 1 commit into
v2from
mcp-tool-plugin
Closed

kitlangton wants to merge 1 commit into
v2from
mcp-tool-plugin

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

MCP-discovered tools currently register from a Location layer outside the built-in plugin lifecycle. Registration also happens after discovery, so a slow server can place its transform after a later plugin's override or removal. This draft moves that contribution into opencode.tool.mcp and reserves its transform before discovery starts.

The plugin captures internal MCP, permission, and bus services through PluginInternal; it contributes through ctx.tool.transform/reload. Connections and invocation remain in Mcp.Service. The plugin owns discovery and subscriptions, retains the stable transform and 100ms debounce, and participates in activation/disposal and grouped transform failures.

A small McpTool readiness service preserves Session's existing wait before its tool snapshot. Plugin activation stays asynchronous with respect to slow MCP discovery. Removing or replacing an activation cancels its discovery and releases its waiters; disabling the adapter makes readiness a no-op. The public Protocol, Server API, and plugin API are unchanged.

This is an exploratory proposal against v2, based on 97303c39dd, rather than the materially different tool architecture on dev. The tradeoff is retaining a small readiness bridge; consumers assembling McpTool.node directly must now activate the plugin explicitly.

Validation from packages/core:

  • bun typecheck — passed.
  • bun run test test/mcp.test.ts test/mcp-tool-plugin.test.ts test/plugin.test.ts test/mcp-instructions.test.ts test/location-layer.test.ts — 108 passed, 0 failed.
  • The new real-host regression covers delayed discovery without blocking activation, replacement while discovery and a waiter are pending, subsequent override/removal precedence, catalog refresh, disposal, and reactivation without extra catalog reads or leaked contributions.
  • Existing tests cover invalid-tool isolation, debounce, permission checks, session forwarding, direct/Code Mode exposure, grouped plugin failures, and assembled Location boot.
  • Formatting and git diff --check passed. Integration tests required loopback access outside the filesystem sandbox.

The broader audit is recorded in packages/core/docs/mcp-tool-plugin.md:

Candidate Recommendation
MCP OAuth Integration transforms A real cross-domain adapter, but its registration supplies connection credential identity and follows server scopes. Retain until an explicit auth/connection contract exists.
MCP configuration and well-known discovery Already plugins; direct internal injection and directory placement are not architectural inconsistencies.
MCP, reference, and skill instructions Pull-based domain producers, not stray State registrations. Keep with their observed domains.
Environment/date, Code Mode guidance, and Session instructions Core context responsibilities; no plugin conversion proposed.

One limitation deserves follow-up: MCP instructions filter the raw MCP catalog rather than the effective Tool snapshot. Guidance can mention tools removed by plugins, including disabling this adapter. Deriving reachability from the selected snapshot would address both cases. Moving instruction rendering alone would not.

Fully plugin-provided MCP is a separate design question involving discovery, invocation, resources/prompts, cancellation, readiness, and credential ownership. This draft deliberately proposes only the tool contribution boundary. Draft for review; do not merge yet.

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant