examples/simple-mcp/README.md
This example demonstrates how to use the MCP provider for evaluating MCP servers. The MCP provider is designed for direct tool calling evaluation rather than text generation, making it ideal for testing tool behavior, security vulnerabilities, and edge cases.
You can run this example with:
npx promptfoo@latest init --example simple-mcp
cd simple-mcp
Initialize the example:
npx promptfoo@latest init --example simple-mcp
Navigate to the example directory:
cd simple-mcp
Configure your MCP server in promptfooconfig.yaml
Run the evaluation:
npx promptfoo eval
providers:
- id: mcp
config:
enabled: true
servers:
- name: security-test-server
path: ./example-server.js
tests:
# Test path traversal prevention
- vars:
prompt: '{"tool": "read_file", "args": {"path": "../../../etc/passwd"}}'
assert:
- type: contains
value: 'Path traversal not allowed'
# Test command injection prevention
- vars:
prompt: '{"tool": "execute_command", "args": {"command": "rm -rf /"}}'
assert:
- type: contains
value: 'Dangerous command blocked'
Test various security scenarios and edge cases:
tests:
# SSRF prevention
- vars:
prompt: '{"tool": "fetch_url", "args": {"url": "http://localhost:8080/admin"}}'
assert:
- type: contains
value: 'Internal network access blocked'
# SQL injection prevention
- vars:
prompt: '{"tool": "query_database", "args": {"query": "SELECT * FROM users; DROP TABLE users;"}}'
assert:
- type: contains
value: 'dangerous SQL query blocked'
# Data previewing
- vars:
prompt: '{"tool": "process_data", "args": {"data": "Hello from the MCP example", "operation": "preview"}}'
assert:
- type: contains
value: 'Preview: Hello from the MCP example'
Enable debug mode to see detailed information about MCP connections and tool calls:
providers:
- id: mcp
config:
enabled: true
debug: true
verbose: true
servers:
- name: my-server
url: http://localhost:3000/mcp
The example also includes response-parser.js, which reads structuredContent from the raw MCP
tool result and falls back to Promptfoo's normalized content string:
providers:
- id: mcp
config:
enabled: true
servers:
- name: security-test-server
path: ./example-server.js
transformResponse: 'file://response-parser.js'
export default function parseMcpResponse(result, content) {
return result.structuredContent?.summary ?? content;
}
The get_user_profile test proves the parser is reading structured MCP output by asserting on
Ada Lovelace is active, which is not present in the tool's text content.
Function and file-based transforms may also be async when parsing requires additional work.
Relative file reads in example-server.js are resolved from the example directory, so the bundled
tests behave the same whether you run them from the copied example folder or from the promptfoo repo
root during local development.
For testing, you can use example MCP servers:
@modelcontextprotocol/sdkredteam-mcp example for security testing of MCP implementations