Skip to main content

Overview

Configure authentication for MCP servers that require credentials.

Usage

Parameters

  • command (str): Command string to run MCP server
  • url (str): URL for SSE or Streamable HTTP transport
  • env (Dict[str, str]): Dictionary of environment variables for authentication
    • Common keys: API_KEY, API_SECRET, AUTH_TOKEN, ACCESS_TOKEN
    • Service-specific keys: GITHUB_PERSONAL_ACCESS_TOKEN, SLACK_BOT_TOKEN, etc.
  • timeout_seconds (int): Connection timeout in seconds (default: 5)

Best Practices

  • Store credentials securely (use environment variables or secrets management)
  • Never hardcode credentials in source code
  • Use separate credentials for development and production
  • Rotate credentials regularly
  • Follow the principle of least privilege

Example with Environment Variables

SSE Server Authentication

Use SSEClientParams to pass authentication headers to an SSE MCP server:

Streamable HTTP Authentication

Use StreamableHTTPClientParams to pass authentication headers to a Streamable HTTP MCP server:

Troubleshooting Authentication

Common authentication issues:
  • Invalid credentials: Verify tokens and keys are correct
  • Expired tokens: Refresh or regenerate authentication tokens
  • Permission errors: Ensure credentials have required scopes/permissions
  • Network errors: Check firewall and proxy settings for authenticated connections