Skip to content

Architecture

Layers

Layer Files Does
Entry src/index.ts Plugin.define({ id, setup }), the host gate, the accounts, the skills, the web search default and one register call
Accounts src/accounts.ts one Tavily MCP server per alias, through the contract's accounts module
Manifest src/manifest.ts reads package.json capabilities and checks it with the contract's validator
Handlers src/handlers/ one handler per method: status and probe
Provider src/provider/client.ts the one Tavily MCP URL, the per-alias server config, and the live read of OpenCode's MCP server list
Options src/options.ts the two plugin options, with the manifest's defaults
Skills src/skills.ts registers skills/<name>/SKILL.md with OpenCode
Web search src/websearch.ts selects OpenCode's built-in Tavily web search provider, when nothing earlier chose one

The entry is deliberately thin. register from the contract wires doors 1–3: one agent tool per method in the tavily namespace, the same tools in Code Mode, one RPC registration under tavily, the permission assertions and the access rules inserted into every agent. This repository never calls ctx.tool, ctx.rpc or ctx.permission itself.

The call path

  1. OpenCode loads dist/index.js through the package's ./server export and calls setup(ctx).
  2. assertHost refuses an OpenCode release outside >=2.4.1 <2.5.0, unless allowUntestedHost is set.
  3. The plugin's options are checked, and the skills are read from the package.
  4. src/accounts.ts adds one MCP server per alias through ctx.mcp.transform, named tavily or tavily-<alias>, at Tavily's URL, with its own OAuth and the configured timeout.execution.
  5. register checks the handler table against capabilities.methods, resolves the accounts from the options, generates the access rules into every agent, and registers the tools and the one RPC id.
  6. A plugin-method call resolves the account where it takes one (probe), validates the input, asserts the method's operations, runs the handler, checks the answer and maps a failure to the contract's error table. A pass-through MCP tool runs on its alias's server and the plugin resolves no account for it.

The provider

src/provider/client.ts is the only file that names Tavily. It holds one URL, https://mcp.tavily.com/mcp/, and two reads of OpenCode's own MCP server list:

  • status maps each alias's server state to the contract's signal (connected, needs_auth, failed, disabled, pending, or no entry) and redacts a failure's reason;
  • probe answers the server entry's name as OpenCode's connection identity, mcp:tavily-<alias>.

There is no network client: Tavily's server owns every call, and the plugin never talks to the provider itself. The plugin keeps no cache and no credential. Each server config sets only the fields OpenCode 2.4.1's remote config defines: type, url, oauth and timeout.execution. The server name (tavily, tavily-work, from the contract's accountName) is what tells aliases apart; that config has no display-title field.

OpenCode APIs

API Who calls it
Plugin.define src/index.ts
ctx.app.version src/index.ts, for the host gate and status
ctx.mcp.transform src/accounts.ts
ctx.mcp.list status and probe
ctx.skill.transform src/skills.ts
ctx.websearch.transform src/websearch.ts
ctx.agent.transform, ctx.tool.transform, ctx.rpc.register, ctx.permission.assert register only

Build

scripts/build.mjs bundles src/index.ts into dist/index.js with esbuild. @opencode/* stays external, because OpenCode provides it; the contract modules are bundled, so an install needs no build and no runtime dependency. dist/ is generated by npm run bundle and committed, so a git install ships the built entry; CI rebuilds it and fails when the committed bundle is stale. The package ships dist, skills, assets, README.md and LICENSE; AGENTS.md, docs/, test/, scripts/ and fixtures/ stay in the repository.