Home

MCP Server Authentication Overview

This document provides an overview of the authentication methods available for MCP servers that you deploy through MCP-Cloud.ai. Understanding these options will help you secure your MCP server and implement the right authentication strategy for your use case.

Authentication Methods

MCP servers support three primary authentication methods:

  1. API Key Authentication - Simple token-based authentication for programmatic access
  2. Client Authentication - For applications with multiple users or for website/mobile integration
  3. Server-to-Server Authentication - For secure backend-to-backend communication

API Key Authentication

API keys are long-lived tokens that provide access to your MCP server. They are the simplest way to authenticate and are ideal for:

Each MCP server you deploy comes with a primary API key. You can also create additional API keys with different permission scopes.

Authorization: Bearer mcp_sk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Advantages of API Keys

Limitations of API Keys

Learn more about API key authentication in the API Key Authentication guide.

Client Authentication

When building applications with multiple users, you'll likely need more sophisticated authentication. MCP servers support several options for client authentication:

Session-Based Authentication

For web applications, you can implement session-based authentication:

  1. Your application authenticates users through your own auth system
  2. Your backend creates a session with the MCP server for that user
  3. The client receives a short-lived token to use directly with the MCP server

This approach allows for per-user tracking and permissions without exposing your main API key.

OAuth 2.0

For more complex scenarios, MCP servers support OAuth 2.0 integration:

OAuth is particularly useful for third-party integrations or multi-tenant applications.

Learn more about client authentication in the Client Authentication guide.

Security Best Practices

Regardless of which authentication method you choose, follow these security practices:

API Key Security

Request Security

User Management

Choosing the Right Authentication Method

Select your authentication method based on your use case:

Use Case Recommended Authentication
Personal project API key authentication
Server-to-server API key authentication
Web application Session-based authentication
Mobile app Session-based or OAuth
Third-party integration OAuth 2.0
Multi-tenant SaaS OAuth 2.0

Authentication Flow Examples

Simple API Key Authentication Flow

┌─────────────┐                            ┌─────────────┐
│             │                            │             │
│   Client    │                            │ MCP Server  │
│             │                            │             │
└──────┬──────┘                            └──────┬──────┘
       │                                          │
       │  Request with API Key in Header          │
       │  Authorization: Bearer mcp_sk_xxx        │
       │ ─────────────────────────────────────►  │
       │                                          │
       │                                          │
       │                                          │
       │  Response                                │
       │ ◄─────────────────────────────────────  │
       │                                          │

Session-Based Authentication Flow

┌─────────────┐       ┌─────────────┐       ┌─────────────┐
│             │       │             │       │             │
│    User     │       │  Your App   │       │ MCP Server  │
│             │       │             │       │             │
└──────┬──────┘       └──────┬──────┘       └──────┬──────┘
       │                     │                     │
       │  1. Login           │                     │
       │ ──────────────────► │                     │
       │                     │                     │
       │  2. App auth        │                     │
       │ ◄────────────────── │                     │
       │                     │                     │
       │                     │  3. Create Session  │
       │                     │ ──────────────────► │
       │                     │                     │
       │                     │  4. Session Token   │
       │                     │ ◄─────────────────  │
       │                     │                     │
       │  5. Session Token   │                     │
       │ ◄────────────────── │                     │
       │                     │                     │
       │                     │                     │
       │  6. Request with Session Token            │
       │ ─────────────────────────────────────────►│
       │                     │                     │
       │  7. Response        │                     │
       │ ◄─────────────────────────────────────────│
       │                     │                     │

OAuth 2.0 Flow

┌─────────────┐       ┌─────────────┐       ┌─────────────┐
│             │       │             │       │             │
│    User     │       │  Your App   │       │ MCP Server  │
│             │       │             │       │             │
└──────┬──────┘       └──────┬──────┘       └──────┬──────┘
       │                     │                     │
       │                     │  1. Register App    │
       │                     │ ──────────────────► │
       │                     │                     │
       │                     │  2. Client ID/Secret│
       │                     │ ◄─────────────────  │
       │                     │                     │
       │  3. Access App      │                     │
       │ ──────────────────► │                     │
       │                     │                     │
       │  4. Redirect to OAuth                     │
       │ ◄────────────────── │                     │
       │                     │                     │
       │  5. Auth Request    │                     │
       │ ─────────────────────────────────────────►│
       │                     │                     │
       │  6. Auth Consent    │                     │
       │ ◄─────────────────────────────────────────│
       │                     │                     │
       │  7. Approve         │                     │
       │ ─────────────────────────────────────────►│
       │                     │                     │
       │  8. Redirect with Code                    │
       │ ◄─────────────────────────────────────────│
       │                     │                     │
       │  9. Code            │                     │
       │ ──────────────────► │                     │
       │                     │                     │
       │                     │  10. Exchange Code  │
       │                     │ ──────────────────► │
       │                     │                     │
       │                     │  11. Access Token   │
       │                     │ ◄─────────────────  │
       │                     │                     │
       │  12. API Access     │                     │
       │ ──────────────────► │                     │
       │                     │                     │
       │                     │  13. API Request    │
       │                     │ ──────────────────► │
       │                     │                     │
       │                     │  14. Response       │
       │                     │ ◄─────────────────  │
       │                     │                     │
       │  15. Results        │                     │
       │ ◄────────────────── │                     │
       │                     │                     │

Troubleshooting

Common authentication issues and their solutions:

Issue Possible Cause Solution
401 Unauthorized Invalid API key Check for typos, verify the key is active
403 Forbidden Insufficient permissions Request a key with appropriate scopes
Token expired Session timeout Implement token refresh or reauthenticate
Rate limiting Too many requests Implement backoff strategy, request higher limits