Secure MCP TypeScript Server
Enables authenticated user profile retrieval via the 'whoami' tool, using OAuth2 and Asgardeo.
README
Secure MCP TypeScript Server
A TypeScript-based Model Context Protocol (MCP) server with OAuth2 authentication powered by Asgardeo.
Overview
This project demonstrates how to create a secure MCP server that:
- Uses TypeScript for type safety
- Implements OAuth2 authentication with Asgardeo
- Exposes MCP tools that require authentication
- Returns authenticated user profile information
Prerequisites
- Node.js (v16 or higher)
- npm, yarn, or pnpm
- Asgardeo account
- Claude Desktop
Quick Start
1. Clone the Repository
git clone https://github.com/ngsanthosh/typescript-mcp-auth-quickstart.git
cd typescript-mcp-auth-quickstart
2. Install Dependencies
npm install
3. Configure Asgardeo
- Sign into your Asgardeo console
- Navigate to Applications > New Application
- Select Single Page Application and complete the wizard
- Name: SecureMCPServer
- Authorized Redirect URL: http://localhost:3000/oauth/callback
- Save the following values from the application:
client-id(from Protocol tab)- Base URL (e.g.,
https://api.asgardeo.io/t/your-org)
4. Set Up Environment Variables
Create a .env file in the root directory:
cp .env.example .env
Update .env with your Asgardeo configuration:
ASGARDEO_BASE_URL=https://api.asgardeo.io/t/your-org
PORT=3000
5. Build and Run
Development mode:
npm run dev
Production mode:
npm run build
npm start
The server will start on http://localhost:3000/mcp
6. Configure Claude Desktop
- Open Claude Desktop
- Go to Settings > Developer
- Click Edit Config to open
claude_desktop_config.json - Add the following configuration:
{
"mcpServers": {
"secure-whoami-server": {
"command": "npx",
"args": [
"mcp-remote@latest",
"http://localhost:3000/mcp",
"--static-oauth-client-info",
"{\"client_id\": \"<your-client-id>\"}",
"--static-oauth-client-metadata",
"{\"scope\": \"openid profile email\"}"
]
}
}
}
Replace <your-client-id> with the client ID from your Asgardeo application.
7. Test the Server
- Restart Claude Desktop
- You'll be redirected to Asgardeo for login
- After authentication, ask Claude: "Who am I?"
- The server will return your authenticated user profile information
Project Structure
.
├── src/
│ └── index.ts # Main MCP server implementation
├── package.json # Dependencies and scripts
├── tsconfig.json # TypeScript configuration
├── .env.example # Example environment variables
├── .gitignore # Git ignore rules
├── README.md # This file
└── LICENSE # License
Key Features
- OAuth2 Authentication: Secure authentication via Asgardeo
- Type Safety: Full TypeScript support
- MCP Tools: Expose
whoamitool that returns user profile - Express Server: Built on Express.js for HTTP transport
- Authentication Middleware: Protect MCP endpoints with
mcpAuthServer.protect()
Available Tools
whoami
Returns the authenticated user's profile information.
Input: None
Output:
{
"profile": {
"sub": "user-id",
"email": "user@example.com",
"given_name": "John",
"family_name": "Doe",
...
}
}
Environment Variables
| Variable | Description | Example |
|---|---|---|
ASGARDEO_BASE_URL |
Your Asgardeo organization base URL | https://api.asgardeo.io/t/my-org |
PORT |
Server port (default: 3000) | 3000 |
Troubleshooting
"Not authenticated" Error
- Ensure you've created a test user in Asgardeo (guide)
- Verify your client ID is correct in Claude Desktop config
- Clear browser cache and try logging in again
Server Won't Start
- Check that port 3000 is not in use:
lsof -i :3000 - Verify all environment variables are set in
.env - Ensure Node.js version is 16+
Module Not Found Errors
- Run
npm installagain - Delete
node_modulesandpackage-lock.json, then reinstall
Learn More
License
MIT
Support
For issues and questions:
- Check the Asgardeo Documentation
- Visit Stack Overflow
- Open an issue in this repository
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.