Skip to content

MCP ​

MCP connects Anvia agents to tools hosted by external Model Context Protocol servers. Anvia connects to the server, lists its tools, adapts them to normal runtime tools, and manages them through the same agent loop.

Explore MCP ​

PageLearn how to
Connect a serverConnect through stdio and own the server lifecycle.
HTTP and SSEConnect to remote MCP servers.
Result mappingUnderstand how MCP content becomes Anvia tool output.
Trust boundariesReview tools, enforce permissions, and filter results.
Local toolsCombine external capabilities with app-owned actions.
ObservabilityTrace MCP tools and connection failures.
MCP checklistVerify lifecycle, safety, and failure handling.

The connection flow ​

text
Application → MCP connection → list tools → review tools → agent → call server

The application owns the connection, credentials, allowed tool set, user and tenant scope, and cleanup. The MCP server owns its remote implementation and must enforce its own permissions.

Connect and run ​

ts
import { AgentBuilder } from '@anvia/core'
import { connectMcp, mcp } from '@anvia/core/mcp'

const filesystem = await connectMcp(
  mcp.stdio({
    name: 'filesystem',
    command: 'npx',
    args: [
      '@modelcontextprotocol/server-filesystem',
      '/workspace/docs',
    ],
  }),
)

try {
  const agent = new AgentBuilder('docs-operator', model)
    .instructions('Use filesystem tools only for documentation files.')
    .mcp([filesystem])
    .build()

  const response = await agent
    .prompt('List the documentation files.')
    .send()

  console.log(response.output)
} finally {
  await filesystem.close()
}

.mcp([filesystem]) exposes all adapted tools from that connected server. For privileged or changing servers, review and allow-list filesystem.tools before adding them with .tools(...).

Treat MCP as external capability ​

An MCP connection does not grant product authorization. Keep credentials server-side, resolve tenant scope in application code, constrain broad file or command servers, and filter remote output before it reaches a user.

Built for Anvia.