DEV Community

Muhammad Usman
Muhammad Usman

Posted on

πŸš€ Building an AWS Cognito MCP Server (Model Context Protocol) – CLI & Manual Setup Guide

Modern AI apps need secure, scalable, and context-aware integrations. That’s where MCP (Model Context Protocol) comes in β€” and when paired with AWS Cognito, you get a powerful authentication + knowledge retrieval pipeline.

In this post, I’ll walk you through:

  • What MCP is πŸ€”
  • Why it’s useful
  • How to set up an AWS Cognito MCP server
  • Two methods:

    • βœ… Using AWS CLI
    • βœ… Manual (Console-based) setup
  • Pros & Cons of both approaches


🧠 What is MCP (Model Context Protocol)?

Model Context Protocol (MCP) is a standardized way to connect AI models (like LLMs) with external tools, APIs, and knowledge bases.

πŸ’‘ Why MCP matters:

  • πŸ”— Connects AI to real-world data sources
  • πŸ” Enables secure access via authentication systems (like Cognito)
  • ⚑ Makes AI apps more dynamic and production-ready
  • 🧩 Plug-and-play architecture for tools & services

πŸ” Why Use AWS Cognito with MCP?

AWS Cognito provides:

  • User authentication (Sign up / Sign in)
  • Token-based authorization (JWT)
  • Secure access control for APIs

When combined with MCP:
πŸ‘‰ Your AI tools can securely fetch user-specific or protected data.


βš™οΈ MCP Server Configuration (Example)

Here’s a basic MCP server config using AWS knowledge base retrieval:

{
  "mcpServers": {
    "aws-cognito": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-aws-kb-retrieval"
      ],
      "env": {
        "AWS_PROFILE": "",
        "AWS_REGION": "",
        "COGNITO_USER_POOL_ID": ""
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

πŸ› οΈ Method 1: Setup Using AWS CLI

Step 1: Install AWS CLI

pip install awscli
aws configure
Enter fullscreen mode Exit fullscreen mode

Enter:

  • AWS Access Key
  • Secret Key
  • Region

Step 2: Create Cognito User Pool

aws cognito-idp create-user-pool \
  --pool-name my-mcp-pool
Enter fullscreen mode Exit fullscreen mode

Step 3: Create App Client

aws cognito-idp create-user-pool-client \
  --user-pool-id <POOL_ID> \
  --client-name mcp-client \
  --generate-secret
Enter fullscreen mode Exit fullscreen mode

πŸ‘‰ This returns:

  • ClientId
  • ClientSecret

Step 4: Configure MCP Environment

Update your config:

"env": {
  "AWS_PROFILE": "default",
  "AWS_REGION": "us-east-1",
  "COGNITO_USER_POOL_ID": "your_pool_id"
}
Enter fullscreen mode Exit fullscreen mode

βœ… Pros of AWS CLI Method

  • ⚑ Fast & scriptable
  • πŸ” Easy to automate (CI/CD)
  • πŸ§‘β€πŸ’» Developer-friendly

❌ Cons

  • Harder for beginners
  • Requires CLI familiarity
  • Debugging can be tricky

πŸ–₯️ Method 2: Manual Setup (AWS Console)

Step 1: Go to AWS Console

  • Navigate to Cognito β†’ User Pools
  • Click Create User Pool

Step 2: Configure Pool

  • Choose Email/Username login
  • Set password policies
  • Enable self sign-up (optional)

Step 3: Create App Client

  • Go to App Integration β†’ App Clients
  • Click Create App Client
  • Enable:

    • βœ… Generate client secret

πŸ‘‰ Save:

  • Client ID
  • Client Secret

Step 4: Configure Domain (Optional)

  • Set a Cognito domain for hosted UI

Step 5: Update MCP Config

"env": {
  "AWS_PROFILE": "default",
  "AWS_REGION": "us-east-1",
  "COGNITO_USER_POOL_ID": "your_pool_id"
}
Enter fullscreen mode Exit fullscreen mode

πŸ” Important Note About Secrets

When using the manual flow:

  • Store Client Secret securely (e.g., AWS Secrets Manager)
  • Never expose it in frontend apps

βœ… Pros of Manual Method

  • πŸ‘ Beginner-friendly
  • πŸ‘€ Visual interface
  • Easier to understand setup

❌ Cons

  • 🐒 Slower
  • ❌ Not easily repeatable
  • ⚠️ Human error risk

βš–οΈ CLI vs Manual – Quick Comparison

Feature AWS CLI ⚑ Manual Console πŸ–₯️
Speed Fast Slow
Automation Yes No
Ease Medium Easy
Scalability High Low

🎯 Final Thoughts

Using AWS Cognito with MCP is a powerful way to:

  • Secure your AI applications
  • Enable authenticated data access
  • Build production-grade AI systems

πŸ‘‰ If you’re building scalable systems β†’ use CLI
πŸ‘‰ If you’re learning or experimenting β†’ use manual setup


πŸ’¬ Let’s Connect

If you’re experimenting with MCP or building AI-powered apps, I’d love to hear your approach!

Drop your thoughts πŸ‘‡

Top comments (0)