Integrate LLMs with External Tools via MCP
Promptfoo example wiring Claude to an MCP server via the Anthropic Messages provider, auto-executing tool calls.
Why it matters
Connect large language models like Claude to external tools and services using the Model Context Protocol. This asset enables LLMs to leverage tool outputs and integrate them back into conversations for more dynamic interactions.
Outcomes
What it gets done
Wire Anthropic's Claude to an MCP server.
Expose MCP server tools to the LLM.
Execute tool_use blocks emitted by the model.
Feed tool results back into the conversation.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/pfoo-mcp | bash Steps
Steps in the chain
Overview
Mcp
A promptfoo example wiring Claude to an MCP server through the Anthropic Messages provider, with automatic multi-round tool_use/tool_result execution. Use when you want promptfoo to auto-execute MCP tool calls during a Claude eval instead of manually scripting the tool-call loop.
What it does
This example wires Claude up to a Model Context Protocol (MCP) server through the Anthropic Messages provider. Promptfoo exposes the MCP server's tools to Claude, executes any tool_use blocks the model emits, and feeds the tool_result back into the conversation until Claude produces a final reply. The bundled config uses the public deepwiki MCP server so the example works out of the box without installing anything.
When to use - and when NOT to
Use this example when you want promptfoo to automatically execute MCP tool calls that Claude emits during an eval, rather than manually scripting the tool-call loop yourself. It is not specific to a single MCP server - the bundled deepwiki server is just a zero-setup default; swap the mcp block to point at a local stdio server or a remote SSE/streamable HTTP server instead.
Inputs and outputs
Set ANTHROPIC_API_KEY, then scaffold and run:
npx promptfoo@latest init --example anthropic/mcp
cd anthropic/mcp
export ANTHROPIC_API_KEY=sk-ant-...
npx promptfoo@latest eval
To swap in a custom server, replace the mcp block, e.g. a local stdio server: mcp: { enabled: true, server: { command: npx, args: ['-y', '@modelcontextprotocol/server-filesystem', '/tmp/workspace'] } }, or a remote server under a servers list with name/url.
Integrations
Demonstrates tool discovery (MCP-exposed tools are forwarded to Claude alongside any inline tools defined in config), multi-round execution (when Claude returns a tool_use block matching an MCP tool, promptfoo invokes it with the model's arguments and appends a tool_result on the next turn, looping until Claude returns text, bounded by max_tool_calls, default 8), error pass-through (tool errors return as tool_result blocks with is_error: true so Claude can recover or report the failure), and mixed tool handling (non-MCP tools, including built-ins like web_search, fall through to the existing tool-use output without being auto-executed). Promptfoo's disk response cache is automatically skipped when mcp.enabled is true, since tool results can vary between runs; max_tool_calls bounds per-request cost instead. The same pattern is shown elsewhere via the OpenAI Responses API (examples/openai-mcp), and an MCP server can be tested directly without an LLM provider via examples/simple-mcp.
Who it's for
Teams building Claude-based agents that call MCP tools who want promptfoo to handle the full tool-call execution loop automatically during evals, rather than hand-writing the multi-round tool_use/tool_result exchange themselves.
Source README
anthropic/mcp (Anthropic Messages + MCP tools)
This example wires Claude up to a Model Context Protocol server through the Anthropic Messages provider. Promptfoo exposes the MCP server's tools to Claude, executes any tool_use blocks the model emits, and feeds the tool_result back into the conversation until Claude produces a final reply.
npx promptfoo@latest init --example anthropic/mcp
cd anthropic/mcp
Setup
export ANTHROPIC_API_KEY=sk-ant-...
npx promptfoo@latest eval
The bundled config uses the public deepwiki MCP server so the example works out of the box without installing anything. To swap in your own server, replace the mcp block:
mcp:
enabled: true
# Local stdio server
server:
command: npx
args: ['-y', '@modelcontextprotocol/server-filesystem', '/tmp/workspace']
# …or remote SSE / streamable HTTP
# servers:
# - name: my-server
# url: https://example.com/mcp
What it demonstrates
- Tool discovery: Tools exposed by the MCP server are forwarded to Claude alongside any inline
toolsyou define. - Multi-round execution: When Claude returns a
tool_useblock matching an MCP tool, promptfoo invokes the tool with the model's arguments and appends atool_resulton the next user turn. The loop continues until Claude returns text - bounded bymax_tool_calls(default8). - Error pass-through: Tool errors come back as
tool_resultblocks withis_error: trueso Claude can recover or report the failure. - Mixed tool handling: Non-MCP tools (regular function-calling tools, or built-ins like
web_search) fall through to the existing tool-use output without being auto-executed.
Caching
Promptfoo's disk response cache is skipped automatically when mcp.enabled is true, because tool results can vary between runs. Use max_tool_calls to bound the per-request cost.
See also
- Anthropic provider docs
- MCP integration guide - full server configuration (auth, timeouts, multi-server)
- examples/openai-mcp - the same pattern via the OpenAI Responses API
- examples/simple-mcp - testing an MCP server directly without an LLM provider
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.