Skip to content

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 the server in the harness’s tools and provide its client Layer:

src/Docs.mcp.ts
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] });

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.

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],
});

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.