MCP servers
An OpenCode harness takes an AI.McpServer beside its other tools. The harness connects to the server with the client Layer you provide, so the connection uses your bindings and your credentials.
List a server
Section titled “List a server”List the server in the harness’s tools and provide its client Layer:
import * as AI from "@alchemy.run/ai";import { McpClient, McpProtocol } from "effect/ai";import * as FetchHttpClient from "effect/http/FetchHttpClient";import * as Layer from "effect/Layer";
export class Docs extends AI.McpServer<Docs>()("docs") {}
export const DocsLive = Docs.layer( McpClient.layerHttp({ name: "my-agent", version: "1.0.0", protocol: McpProtocol.v2025_11_25, url: "https://docs.example.com/mcp", }).pipe(Layer.provide(FetchHttpClient.layer)),);const harness = yield* OpenCode.Harness({ models: [Fast], tools: [AI.CodingTools, Docs] });How its tools are named
Section titled “How its tools are named”The harness asks the server for its tools and registers each with OpenCode. The model sees each as <server>_<tool>: the search tool of docs is docs_search.
Select a server for a prompt
Section titled “Select a server for a prompt”In a prompt’s tools, the server stands for every tool it has:
const reply = yield* session.prompt("What does the docs site say about retries?", { tools: [Docs],});OpenCode’s own MCP connections
Section titled “OpenCode’s own MCP connections”To have OpenCode connect to a remote server itself, add it to OpenCode’s own configuration with the harness’s config. OpenCode then makes the connection, with whatever credentials that configuration holds.