Skip to content
Guides Vaern 0.0.8
Documentation

Local MCP tools

Expose a local Vaern tool over stdio, connect from another script, and replay the caller's journal.

Declare a server

Save the example as calc.ts. A Vaern MCP server exposes declared tools over standard input and output. The server redirects ordinary console logging to stderr when it serves the protocol.

calc.ts
import { tool } from "vaern:ai";
import { server } from "vaern:mcp";

const answer = tool({
  name: "answer",
  description: "Return a sample value.",
  run: () => ({ value: 42 }),
});

server({ name: "calc", version: "1.0.0", tools: [answer] });
Terminal
vaern mcp serve calc.ts

Connect from a Vaern script

Place client.ts next to calc.ts. connect() starts the server with the same Vaern binary and negotiates the local connection. Close the connection after you finish using it.

client.ts
import { connect } from "vaern:mcp";

const calc = await connect({ script: "./calc.ts" });
try {
  const [answer] = await calc.tools();
  console.log(JSON.stringify(await answer.call({})));
} finally {
  await calc.close();
}
Terminal
vaern run client.ts
  • The example prints {"value":42}. The caller and server each write a separate journal.

Replay the caller's journal

Both runs appear under .vaern/runs. Identify the directory whose journal starts with client.ts in the script field and use its directory name as RUN_ID. The latest alias can point to the newer server run.

Replaying the caller uses the recorded MCP connection and call outcomes without starting a server.

Terminal
vaern journal verify RUN_ID
vaern replay RUN_ID

Supported transport

Vaern 0.0.8 connects to local Vaern scripts over stdio. Its client expects a Vaern server script and resolves the script path relative to the calling module. HTTP transport, external MCP server executables, Tasks, and elicitation are outside this release's scope.