AAnvio
Tools & MCP

MCP Setup Guide

Step-by-step guide to configuring Model Context Protocol servers in an Anvio workspace, from preset to first tool call.

4 min read

This walks through enabling an MCP server end to end — from anvio init to a working tool call.

Quick start

Initialize the workspace

anvio init

List available presets

anvio mcp preset list

Example presets live in workspace/mcp/presets/ — spotify, feishu, tinker-atropos, yuanbao.yaml.example, honcho.yaml.example, and any others shipped or added locally.

Apply a preset

anvio mcp preset apply spotify

applyMcpPreset() (packages/integrations/src/mcp-preset.ts) reads workspace/mcp/presets/spotify.yaml.example, Zod-validates each server entry against mcpServerSpecSchema, and merges it into workspace/mcp/servers.yaml — creating the file with sane defaults (firstCallApproval: true) if it doesn't exist yet. Presets merge with enabled: false by default; you turn them on explicitly.

Edit workspace/mcp/servers.yaml

Set enabled: true and fill in the environment variables the preset expects:

apiVersion: anvio.io/v1
kind: McpConfig
metadata:
  name: default
spec:
  firstCallApproval: true
  servers:
    spotify:
      command: npx
      args: ['-y', '@modelcontextprotocol/server-spotify']
      transport: stdio
      enabled: true
      env:
        SPOTIFY_CLIENT_ID: ${SPOTIFY_CLIENT_ID}
        SPOTIFY_CLIENT_SECRET: ${SPOTIFY_CLIENT_SECRET}
      allowedTools:
        - search_tracks
        - get_playback_state

${VAR} placeholders resolve from process.env at connection time — actual secrets stay in your shell/.env, not in the YAML file.

Test the server

anvio mcp test spotify

This calls McpBridge.testServer(), which lists the server's tools over the real stdio connection and reports the transport used (stdio or stub) and tool count.

Check health

anvio mcp health

servers.yaml structure reference

FieldPurpose
spec.firstCallApprovalGlobal default for first-use approval gating (see below)
spec.servers.<id>.commandBinary to spawn (npx, a direct path, etc.)
spec.servers.<id>.argsArguments array
spec.servers.<id>.transportstdio (real MCP client) — set to stub to force the built-in stub response instead
spec.servers.<id>.enabledServer is inert unless true
spec.servers.<id>.envEnvironment passed to the spawned process; ${VAR} resolves from process.env
spec.servers.<id>.allowedToolsOptional allowlist — omit to expose every tool the server reports

Per-server tool allowlist

Set allowedTools on a server to expose only the named tools to the agent:

spotify:
  allowedTools:
    - search_tracks
    - get_playback_state

Tool names in allowedTools are the MCP tool name as reported by the server (search_tracks), not the full Anvio-facing name (anvio_mcp__spotify__search_tracks). Omitting allowedTools entirely exposes every tool the server advertises.

First-call approval

When firstCallApproval: true (the default), each distinct MCP tool requires human approval once per session:

anvio approve <session> <requestId>

Once approved, the serverId/toolName pair is cached for the rest of that session — see MCP Bridge for how McpFirstCallGate tracks this.

Harness MCP-only surface

For channel deployments where an agent should only be able to act through MCP tools and channel replies — hiding the built-in gateway tools entirely:

# harness/defaults.yaml
spec:
  toolSurface: mcp_and_channel
  suppressRawOutput: true

With this set, anvio_tools__* built-in tools are hidden from the agent; it must reply via anvio_channel__reply and perform any action through an MCP tool. Useful for a locked-down Slack/Telegram deployment where you don't want the agent running arbitrary shell commands or file writes even if gateway.yaml would otherwise allow it.

Troubleshooting

SymptomFix
Server disabledSet enabled: true in servers.yaml
Empty tool listRun anvio mcp test <id> — check the command and env are correct
Tool not visible to the agentCheck the allowedTools filter on that server
Stdio timeoutVerify npx (or the configured binary) is on PATH inside the process that runs Anvio
Response looks like [MCP stub] ...The bridge fell back to the stub — usually means transport: stub was set, or ANVIO_MCP_STUB=1 is set in the environment, or the stdio connection failed
  • Observability with Langfuse — importable dashboard at configs/observability/langfuse-dashboard.json.
  • docs/72-observability-langfuse.md in the source repo for MCP-specific trace views.
Edit on GitHub

Last updated on

On this page