mcp -remote-setup-with-jwt-auth
Secure middleware server implementing Model Context Protocol (MCP) over SSE with JWT authentication. Enables standardized communication between AI tools and clients with dynamic tool registration, request logging, and session management. Perfect for building production-ready AI systems requiring secure access patterns.
claude mcp add --transport stdio anisirji-mcp-server-remote-setup-with-jwt-auth node server/index.js \ --env JWT_SECRET="your-secret-key"
How to use
This MCP server exposes several AI tools over a secure Server-Sent Events (SSE) channel, protected by JWT Bearer authentication. Clients first obtain a JWT by calling the token endpoint, then connect to the SSE stream at /sse using the Authorization header with Bearer <token>. Once connected, you can dynamically interact with registered tools such as test, echo, get-time, and random-number through the MCP Inspector or any compatible client. The server supports session management for /message interactions, allowing you to send messages to the active session and receive structured tool results in real time over SSE. In short, you get a JWT-protected gateway that exposes a small suite of utility tools suitable for remote tool orchestration and testing, with lifecycle events logged for observability.
How to install
Prerequisites:
- Node.js (LTS version) and npm installed on your system
- Git installed
- 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
- Install dependencies
npm install
- Create a .env file with a JWT secret
echo "JWT_SECRET=your-secret-key" > .env
- Start the server (development mode)
npm run dev
- Server will run on port 3001 by default, with the SSE endpoint at http://localhost:3001/sse and the auth token endpoint at http://localhost:3001/auth/token?username=<user>&scope=mcp:access
Additional notes
Tips and caveats:
- Ensure JWT_SECRET in .env is kept secure and not checked into version control.
- The server exposes tools like test, echo, get-time, and random-number. The Inspector can list and invoke these tools once connected.
- If you change the port or host, update the client configuration accordingly (SSE URL and token endpoint).
- Token retrieval uses the /auth/token endpoint; include username and scope=mcp:access in the query parameters.
- The environment variable JWT_SECRET is required for token creation and validation.
- For production deployment, consider TLS termination and configuring a reverse proxy in front of the Node server.
Related MCP Servers
iterm
A Model Context Protocol server that executes commands in the current iTerm session - useful for REPL and CLI assistance
mcp
Octopus Deploy Official MCP Server
furi
CLI & API for MCP management
editor
MCP Server for Phaser Editor
DoorDash
MCP server from JordanDalton/DoorDash-MCP-Server
mcp
MCP сервер для автоматического создания и развертывания приложений в Timeweb Cloud