๐ SSE MCP Server with JWT Authentication
Mirror of
MCP-Mirror
README
๐ SSE MCP Server with JWT Authentication
This is a Model Context Protocol (MCP) SSE server with JWT-based authentication.
It allows you to expose multiple AI tools over an SSE transport, protected via secure Bearer Token flow.
Built with:
- ๐ Node.js + Express
- ๐งฉ @modelcontextprotocol/sdk
- ๐ JSON Web Tokens (JWT) for authentication
- โ๏ธ Zod for input validation
โ Fully tested with
@modelcontextprotocol/inspector
๐ Project Structure
server/
โโโ index.ts # Main Express + MCP server
โโโ .env # Environment variables
โโโ package.json # Project metadata & scripts
โโโ tsconfig.json # TypeScript config
โโโ README.md # You are here!
โจ Features
- โ Secure SSE connection using Bearer JWT token
- โ Dynamic Tool registration (echo, time, random number, etc.)
- โ Tested with MCP Inspector
- โ Logs all request lifecycle events
- โ Session management for /message endpoint
- ๐ Ready to extend for production use
โ๏ธ Setup
1. Clone the repository
git clone https://github.com/anisirji/mcp-server-remote-setup-with-jwt-auth.git
cd mcp-server-remote-setup-with-jwt-auth
2. Install dependencies
npm install
3. Create .env file
echo "JWT_SECRET=your-secret-key" > .env
4. Run the server
npm run dev
โ Server will run on:
http://localhost:3001/sse
๐งช Testing the server with MCP Inspector
Step 1 โ Install MCP Inspector
๐ Official Docs: MCP Inspector
npx @modelcontextprotocol/inspector
Step 2 โ Generate a token
Use cURL to get your JWT token:
curl "http://localhost:3001/auth/token?username=aniket&scope=mcp:access"
โ Example response:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
Step 3 โ Connect MCP Inspector
- Open Inspector UI
- Set Transport Type: SSE
- URL:
http://localhost:3001/sse - Add Authorization Header:
Authorization: Bearer <your-token> - Click Connect
๐ Success! Your server is now connected.
Step 4 โ Test tools
Go to Tools tab in Inspector and click List Tools.
You will see:
- โ
test - โ
echo - โ
get-time - โ
random-number
Test them and enjoy!
๐ API Reference
๐ Generate Token
GET /auth/token?username=<username>&scope=mcp:access
๐ SSE Endpoint (requires token)
GET /sse
Authorization: Bearer <token>
๐ฉ Send Message to active session
POST /message?sessionId=<sessionId>
Authorization: Bearer <token>
๐งฉ Tools Reference
| Tool Name | Description |
|---|---|
test |
Test connection (security check) |
echo |
Echo back provided message |
get-time |
Returns current server time |
random-number |
Returns random number (min/max) |
๐๏ธ Upcoming Changes
- [ ] Token revocation list (blacklist)
- [ ] Role-based tool access (scope checks)
- [ ] Session heartbeat / keep-alive
- [ ] Rate limiting & logging
- [ ] Dockerization for deployment
๐ Useful Resources
๐จโ๐ป Maintainer
Aniket
๐ License
This project is open-source and free to use.
๐ Build. Secure. Empower.
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.
MCP Package Docs Server
Facilitates LLMs to efficiently access and fetch structured documentation for packages in Go, Python, and NPM, enhancing software development with multi-language support and performance optimization.
Claude Code MCP
An implementation of Claude Code as a Model Context Protocol server that enables using Claude's software engineering capabilities (code generation, editing, reviewing, and file operations) through the standardized MCP interface.
@kazuph/mcp-taskmanager
Model Context Protocol server for Task Management. This allows Claude Desktop (or any MCP client) to manage and execute tasks in a queue-based system.
Linear MCP Server
Enables interaction with Linear's API for managing issues, teams, and projects programmatically through the Model Context Protocol.
mermaid-mcp-server
A Model Context Protocol (MCP) server that converts Mermaid diagrams to PNG images.
Jira-Context-MCP
MCP server to provide Jira Tickets information to AI coding agents like Cursor
Linear MCP Server
A Model Context Protocol server that integrates with Linear's issue tracking system, allowing LLMs to create, update, search, and comment on Linear issues through natural language interactions.
Sequential Thinking MCP Server
This server facilitates structured problem-solving by breaking down complex issues into sequential steps, supporting revisions, and enabling multiple solution paths through full MCP integration.