Are you sure you want to delete this access key?
This example demonstrates how to use the MCP provider for security testing and red-teaming 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.
Model Context Protocol (MCP) is an open protocol that standardizes how applications provide context to LLMs. With promptfoo's MCP provider, you can:
You can run this example with:
npx promptfoo@latest init --example 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:
tool: 'read_file'
args:
path: '../../../etc/passwd'
assert:
- type: contains
value: 'Path traversal not allowed'
# Test command injection prevention
- vars:
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:
tool: 'fetch_url'
args:
url: 'http://localhost:8080/admin'
assert:
- type: contains
value: 'Internal network access blocked'
# SQL injection prevention
- vars:
tool: 'query_database'
args:
query: 'SELECT * FROM users; DROP TABLE users;'
assert:
- type: contains
value: 'dangerous SQL query blocked'
# XSS sanitization
- vars:
tool: 'process_data'
args:
data: '<script>alert("xss")</script>Hello'
operation: 'sanitize'
assert:
- type: contains
value: '[SCRIPT_REMOVED]'
providers:
- id: mcp
config:
enabled: true
servers:
- name: tools-server
url: http://localhost:3000/mcp
- name: data-server
path: ./data-server.py
- name: npm-server
command: npx
args: [some-mcp-package]
tools:
- generate_text
- analyze_data
exclude_tools:
- dangerous_tool
verbose: true
debug: true
The MCP provider supports several formats:
mcp
- Basic MCP provider for tool callingmcp:server_name
- Target specific server (when using multiple servers)Each test case specifies the tool to call and its arguments:
tests:
- vars:
tool: 'tool_name' # Required: name of the MCP tool to call
args: # Optional: arguments to pass to the tool
param1: 'value1'
param2: 'value2'
# Alternative argument formats:
# arguments: { ... } # Can use 'arguments' instead of 'args'
# params: { ... } # Can use 'params' instead of 'args'
assert:
- type: contains
value: 'expected output'
The example includes test cases for:
../
patterns to ensure proper path validationrm -rf /
/etc/passwd
"No tool specified": Each test case must specify which tool to call in the vars.tool
field.
"Tool Not Found": Verify that the tool name exists in your MCP server and is not excluded by the exclude_tools
configuration.
Connection Failed: Check that your MCP server is running and accessible at the specified URL or path.
Invalid Arguments: Ensure the arguments match what the MCP tool expects. Check the tool's input schema.
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
For testing, you can use example MCP servers:
@modelcontextprotocol/sdk
redteam-mcp
example for security testing of MCP implementationsPress p or to see the previous file or, n or to see the next file
Browsing data directories saved to S3 is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
promptfoo is now integrated with AWS S3!
Are you sure you want to delete this access key?
Browsing data directories saved to Google Cloud Storage is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
promptfoo is now integrated with Google Cloud Storage!
Are you sure you want to delete this access key?
Browsing data directories saved to Azure Cloud Storage is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
promptfoo is now integrated with Azure Cloud Storage!
Are you sure you want to delete this access key?
Browsing data directories saved to S3 compatible storage is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
promptfoo is now integrated with your S3 compatible storage!
Are you sure you want to delete this access key?