Manages environment variables for server configuration, including JWT secrets.
Serves as the web framework for the MCP server, handling HTTP requests and SSE connections for AI tool communication.
Used for version control and project setup via cloning.
Hosts the repository for the MCP server project.
Enables secure authentication for MCP server access through Bearer token flow.
Provides the runtime environment for the MCP server implementation.
Used for type-safe implementation of the MCP server codebase.
Handles input validation for MCP tool parameters and request data.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@SSE MCP Server with JWT Authenticationget the current server time"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
๐ 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!Related MCP server: MCP Toolkit
โจ 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-auth2. Install dependencies
npm install3. Create .env file
echo "JWT_SECRET=your-secret-key" > .env4. 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/inspectorStep 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/sseAdd 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 connection (security check) |
| Echo back provided message |
| Returns current server time |
| 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.