π SSE MCP Server with JWT Authentication
LocalAbout π SSE MCP Server with JWT Authentication
This Node.js and Express MCP server exposes tools over SSE and requires JWT bearer authentication. It is aimed at projects that need authenticated tool access, with dynamic registration, request lifecycle logs, and session handling.
Key features
- 01SSE transport with JWT bearer authentication
- 02Dynamically register tools
- 03Validate inputs with Zod
- 04Log request lifecycle events
- 05Manage message endpoint sessions
- 06Provide echo, time, and random-number tools
Use cases
- 01Expose tools through an authenticated SSE endpoint
- 02Connect an MCP client using a bearer token
- 03Test tools with MCP Inspector
MCP support
The server exposes tools to MCP clients over SSE, protecting the connection and message endpoint with JWT bearer tokens.
Configuration
Local server config is the same for every client. Copy it into your clientβs MCP config file.
Tools
Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.
Details
From the project 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.
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.
