Configuration
Prerequisites
Before you begin, you will need:- An AWS Account with access to create AWS Cognito user pools
- Basic familiarity with AWS Cognito concepts (user pools, app clients)
- Your FastMCP serverâs URL (can be localhost for development, e.g.,
http://localhost:8000)
Step 1: Create an AWS Cognito User Pool and App Client
Set up AWS Cognito user pool with an app client to get the credentials needed for authentication:1
Navigate to AWS Cognito
Go to the AWS Cognito Console and ensure youâre in your desired AWS region.Select âUser poolsâ from the side navigation (click on the hamburger icon at the top left in case you donât see any), and click âCreate user poolâ to create a new user pool.
2
Define Your Application
AWS Cognito now provides a streamlined setup experience:
- Application type: Select âTraditional web applicationâ (this is the correct choice for FastMCP server-side authentication)
- Name your application: Enter a descriptive name (e.g.,
FastMCP Server)
- Server-side authentication with client secrets
- Authorization code grant flow
- Appropriate security settings for confidential clients
Choose âTraditional web applicationâ rather than SPA, Mobile app, or Machine-to-machine options. This ensures proper OAuth 2.0 configuration for FastMCP.
3
Configure Options
AWS will guide you through configuration options:
- Sign-in identifiers: Choose how users will sign in (email, username, or phone)
- Required attributes: Select any additional user information you need
- Return URL: Add your callback URL (e.g.,
http://localhost:8000/auth/callbackfor development)
4
Review and Create
Review your configuration and click âCreate user poolâ.After creation, youâll see your user pool details. Save these important values:
- User pool ID (format:
eu-central-1_XXXXXXXXX) - Client ID (found under â âApplicationsâ â âApp clientsâ in the side navigation â <Your application name, e.g.,
FastMCP Server> â âApp client informationâ) - Client Secret (found under â âApplicationsâ â âApp clientsâ in the side navigation â <Your application name, e.g.,
FastMCP Server> â âApp client informationâ)
5
Configure OAuth Settings
Under âLogin pagesâ in your app clientâs settings, you can double check and adjust the OAuth configuration:
- Allowed callback URLs: Add your server URL +
/auth/callback(e.g.,http://localhost:8000/auth/callback) - Allowed sign-out URLs: Optional, for logout functionality
- OAuth 2.0 grant types: Ensure âAuthorization code grantâ is selected
- OpenID Connect scopes: Select scopes your application needs (e.g.,
openid,email,profile)
6
Configure Resource Server
AWS Cognito requires a resource server entry to support OAuth with protected resources. Without this, token exchange will fail with an
invalid_grant error.Navigate to âBrandingâ â âDomainâ in the side navigation, then:- Click âCreate resource serverâ
- Resource server name: Enter a descriptive name (e.g.,
My MCP Server) - Resource server identifier: Enter your MCP endpoint URL exactly as it will be accessed (e.g.,
http://localhost:8000/mcpfor development, orhttps://your-server.com/mcpfor production) - Click âCreate resource serverâ
7
Save Your Credentials
After setup, youâll have:
- User Pool ID: Format like
eu-central-1_XXXXXXXXX - Client ID: Your applicationâs client identifier
- Client Secret: Generated client secret (keep secure)
- AWS Region: Where Your AWS Cognito user pool is located
Step 2: FastMCP Configuration
Create your FastMCP server using theAWSCognitoProvider, which handles AWS Cognitoâs JWT tokens and user claims automatically:
server.py
Testing
Running the Server
Start your FastMCP server with HTTP transport to enable OAuth flows:Testing with a Client
Create a test client that authenticates with Your AWS Cognito-protected server:test_client.py
- Your browser will open to AWS Cognitoâs hosted UI login page
- After you sign in (or sign up), youâll be redirected back to your MCP server
- The client receives the JWT token and can make authenticated requests
The client caches tokens locally, so you wonât need to re-authenticate for subsequent runs unless the token expires or you explicitly clear the cache.
Production Configuration
For production deployments with persistent token management across server restarts, configurejwt_signing_key, and client_storage:
server.py
Parameters (
jwt_signing_key and client_storage) work together to ensure tokens and client registrations survive server restarts. Wrap your storage in FernetEncryptionWrapper to encrypt sensitive OAuth tokens at rest - without it, tokens are stored in plaintext. Store secrets in environment variables and use a persistent storage backend like Redis for distributed deployments.For complete details on these parameters, see the OAuth Proxy documentation.Features
JWT Token Validation
The AWS Cognito provider includes robust JWT token validation:- Signature Verification: Validates tokens against AWS Cognitoâs public keys (JWKS)
- Expiration Checking: Automatically rejects expired tokens
- Issuer Validation: Ensures tokens come from your specific AWS Cognito user pool
- Scope Enforcement: Verifies required OAuth scopes are present
User Claims and Groups
Access rich user information from AWS Cognito JWT tokens:Enterprise Integration
Perfect for enterprise environments with:- Single Sign-On (SSO): Integrate with corporate identity providers
- Multi-Factor Authentication (MFA): Leverage AWS Cognitoâs built-in MFA
- User Groups: Role-based access control through AWS Cognito groups
- Custom Attributes: Access custom user attributes defined in your AWS Cognito user pool
- Compliance: Meet enterprise security and compliance requirements

