Anvia
MCP

Connections

Connect Anvia to Model Context Protocol servers.

Anvia can connect to Model Context Protocol servers and expose their tools to agents.

Connect to a Stdio Server

import { connectMcp, mcp } from "@anvia/core";

const filesystem = await connectMcp(
  mcp.stdio({
    name: "filesystem",
    command: "npx",
    args: ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"],
  }),
);

connectMcp(...) connects once, lists the server tools, and returns an McpServer.

Connect to an HTTP Server

const docsServer = await connectMcp(
  mcp.http({
    name: "docs",
    url: "https://mcp.example.com/mcp",
  }),
);

Use HTTP when the MCP server is remote or managed outside the current process.

Use the Server on an Agent

const agent = new AgentBuilder("support", model)
  .instructions("Use MCP tools when external context is needed.")
  .mcp([filesystem, docsServer])
  .defaultMaxTurns(4)
  .build();

MCP tools behave like normal Anvia tools once registered on the agent.

Close Connections

Close MCP servers when the process or request scope ends.

await filesystem.close();
await docsServer.close();

For long-lived application processes, connect during startup and close during shutdown.