MCP Authentication
The Scrapfly MCP Server supports three authentication methods, each optimized for different security requirements and deployment scenarios.
Quick Comparison
| Feature | Query Parameter | Authorization Header | OAuth2 |
|---|---|---|---|
| Setup Complexity | Easiest | Moderate | Simple |
| Security Level | Basic | Good | Best |
| Key in Config Files | Yes | Via Env Vars | No |
| Version Control Safe | No | With Env Vars | Yes |
| Automatic Rotation | No | No | Yes |
| Instant Revocation | Key Change Required | Key Change Required | Yes |
| Multi-User Support | Shared Key | Shared Key | Individual Auth |
| Audit Trail | Limited | Limited | Full |
When to Use Each Method
| Scenario | Recommended Method |
|---|---|
| Personal laptop, local development | Query Parameter |
| Custom Python/Node.js MCP client | Authorization Header |
| Docker container, cloud deployment | Authorization Header |
| CI/CD pipeline, automated workflows | Authorization Header |
| Remote MCP server (accessible by others) | OAuth2 |
| Team environment, shared configs | OAuth2 |
| Production application | OAuth2 |
| Compliance requirements (SOC2, GDPR, etc.) | OAuth2 |
Choose Your Authentication Method
OAuth2 Authentication
Enterprise-grade security with zero API key exposure. OAuth2 handles authentication automatically through your browser.
- No key exposure - API keys never appear in config files or logs
- Token rotation - Automatic refresh without manual intervention
- Revocable access - Instantly revoke access without changing keys
- Audit trail - Track who accessed what and when
- Multi-user ready - Each user authenticates with their own credentials
Setup
Simply omit the API key from the connection URL:
How It Works
- Client connects to MCP server without API key
- Server initiates OAuth2 flow and provides authorization URL
- User opens URL in browser and logs in to Scrapfly
- User grants permission for MCP access
- Server receives token and stores it securely
- Future requests use stored token automatically
Configuration Examples
Edit claude_desktop_config.json:
Location:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
Token Management
Token Storage: OAuth2 tokens are stored securely on your local machine:
- macOS:
~/Library/Application Support/scrapfly-mcp/oauth-token.json - Linux:
~/.config/scrapfly-mcp/oauth-token.json - Windows:
%APPDATA%\scrapfly-mcp\oauth-token.json
Token Expiration: Tokens automatically refresh before expiration. If a token expires or is revoked, the MCP server will re-initiate the OAuth2 flow automatically.
Revoke Access: You can revoke OAuth2 access at any time:
- Log in to your Scrapfly Dashboard
- Navigate to Account Settings → API & Integrations
- Find "MCP OAuth2 Access" and click Revoke
Best Use Cases
- Production deployments
- Remote MCP servers accessible by multiple users
- Team collaboration environments
- Compliance requirements (SOC2, GDPR, etc.)
- Any scenario where config files might be shared or committed
Security Considerations
| Security Strengths | Best For |
|---|---|
|
|
Query Parameter Authentication
Add your API key directly to the connection URL. Simple, straightforward, and perfect for local development.
Setup
Include the key parameter in your MCP connection URL:
Configuration Examples
Edit claude_desktop_config.json:
Project-Scoped Configuration
For team collaboration, use environment variables in a project-scoped config:
Step 1: Set Environment Variable
Step 2: Create .mcp.json in Project Root
The ${SCRAPFLY_API_KEY} syntax automatically uses the environment variable value. Commit .mcp.json to version control safely, but add .env to .gitignore.
Best Use Cases
- Local development and testing on your own machine
- Personal projects where security risk is minimal
- Quick prototyping and experimentation
- Single-user environments with no shared access
Security Considerations
| Security Risks | Mitigation Strategies |
|---|---|
|
|
Authorization Header Authentication
Pass your API key via HTTP Authorization header. Ideal for programmatic access and custom MCP clients.
Setup
Set the Authorization header with Bearer token:
Connection URL without API key:
Python Client Example
See MCP Tools & API Specification for a complete list of available tools and their parameters.
Docker Example
Pass API key as environment variable to Docker container:
Tip: For production deployments, use Docker secrets or Kubernetes secrets instead of -e flags to avoid exposing keys in container inspect output.
Best Use Cases
- Server-side applications and backend services
- Custom MCP clients (Python, Node.js, etc.)
- Automated workflows and CI/CD pipelines
- Docker containers and cloud deployments
- Environments where query parameters are logged
Security Considerations
| Security Benefits | Security Risks |
|---|---|
|
|
Troubleshooting
Problem: OAuth2 flow doesn't complete or token is rejected.
Solutions:
- Ensure you're logged into the correct Scrapfly account
- Check that your account is verified and active
- Clear stored tokens and try again:
- macOS:
rm ~/Library/Application\ Support/scrapfly-mcp/oauth-token.json - Linux:
rm ~/.config/scrapfly-mcp/oauth-token.json - Windows:
del %APPDATA%\scrapfly-mcp\oauth-token.json
- macOS:
- Verify your firewall allows OAuth2 redirects
- Check MCP client logs for detailed error messages
Problem: Connection fails with API key authentication.
Solutions:
- Verify API key is correct (no extra spaces or line breaks)
- Check that the API key belongs to an active project
- Ensure the project has remaining credits
- Verify the API key hasn't been rotated or revoked in your dashboard
- Test the API key with a simple curl request to verify it works
Problem: OAuth2 token fails to refresh automatically.
Solutions:
- Delete stored token file (see paths above) and re-authenticate
- Check system clock is synchronized (OAuth2 is time-sensitive)
- Verify network connectivity to Scrapfly servers
- Review MCP client logs for error details
- Ensure the refresh token hasn't been revoked in your dashboard
Problem: ${SCRAPFLY_API_KEY} syntax doesn't resolve.
Solutions:
- Verify environment variable is set:
echo $SCRAPFLY_API_KEY - Restart your MCP client after setting the variable
- Check that your MCP client supports environment variable expansion
- Use absolute path if setting variables in
.envfile
Still Having Issues?
- Check the MCP FAQ for common questions and answers
- Review your API key settings in the dashboard
- Visit our MCP Examples page for working code samples
Security Best Practices
General Guidelines
- Never commit API keys to version control - use
.gitignore - Store keys in environment variables
- Rotate keys every 90 days
- Use project-specific keys
- Monitor usage in dashboard
OAuth2-Specific
- Secure file permissions (
chmod 600) - Review OAuth2 grants in dashboard
- Revoke unused authorizations
- Use separate dev/prod accounts
Team Collaboration
- OAuth2 for multi-user teams
- Document setup in README
- Provide
.env.examplefile - Use secret management tools (AWS Secrets Manager, Vault)