examples/redteam-mcp-auth/README.md
You can run this example with:
npx promptfoo@latest init --example redteam-mcp-auth
cd redteam-mcp-auth
This example demonstrates how to configure authentication for red team evaluations against MCP (Model Context Protocol) servers. It shows OAuth 2.0 client credentials flow for authenticating with remote MCP servers.
When running red team evaluations against protected MCP servers, you need to configure authentication. This example shows how to set up OAuth authentication in your MCP target configuration.
The promptfooconfig.oauth.yaml file demonstrates OAuth 2.0 client credentials flow:
targets:
- id: mcp
label: MCP Example
config:
enabled: true
server:
url: https://example-app.promptfoo.app/mcp/minnow?auth_type=bearer
auth:
type: oauth
grantType: client_credentials
clientId: '{{env.PROMPTFOO_TARGET_CLIENT_ID}}'
clientSecret: '{{env.PROMPTFOO_TARGET_CLIENT_SECRET}}'
tokenUrl: https://example-app.promptfoo.app/oauth/token
scopes: []
This example requires the following environment variables:
PROMPTFOO_TARGET_CLIENT_ID - Your OAuth client IDPROMPTFOO_TARGET_CLIENT_SECRET - Your OAuth client secretNOTE: The values for these environment variables are available upon request.
export PROMPTFOO_TARGET_CLIENT_ID=your-client-id
export PROMPTFOO_TARGET_CLIENT_SECRET=your-client-secret
promptfoo redteam run -c promptfooconfig.oauth.yaml
promptfoo view
When using OAuth authentication with MCP servers:
tokenUrl is not specified, the provider discovers it using RFC 8414 OAuth metadatatokenUrl using client credentialsAuthorization: Bearer <token> headerThe MCP provider implements proactive token refresh:
The MCP provider also supports these authentication types:
server:
url: https://mcp-server.example.com
auth:
type: bearer
token: '{{env.MCP_BEARER_TOKEN}}'
server:
url: https://mcp-server.example.com
auth:
type: basic
username: '{{env.MCP_USERNAME}}'
password: '{{env.MCP_PASSWORD}}'
server:
url: https://mcp-server.example.com
auth:
type: api_key
value: '{{env.MCP_API_KEY}}'
placement: header # or 'query'
keyName: X-API-Key # header/param name
server:
url: https://mcp-server.example.com
auth:
type: oauth
grantType: password
tokenUrl: https://auth.example.com/token
username: '{{env.MCP_USERNAME}}'
password: '{{env.MCP_PASSWORD}}'
clientId: '{{env.MCP_CLIENT_ID}}' # optional
clientSecret: '{{env.MCP_CLIENT_SECRET}}' # optional
scopes: ['read', 'write']
To use this example with your own MCP server:
url to point to your MCP server endpointtokenUrl for OAuth authenticationredteam.purpose to describe your systemFor more information, see the MCP Provider documentation and Red Team documentation.