๐Ÿ” SSE MCP Server with JWT Authentication

๐Ÿ” SSE MCP Server with JWT Authentication

Mirror of

MCP-Mirror

Developer Tools
Visit Server

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

  1. Open Inspector UI
  2. Set Transport Type: SSE
  3. URL:
    http://localhost:3001/sse
    
  4. Add Authorization Header:
    Authorization: Bearer <your-token>
    
  5. 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

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.

Official
Featured
TypeScript
Magic Component Platform (MCP)

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.

Official
Featured
Local
TypeScript
MCP Package Docs Server

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.

Featured
Local
TypeScript
Claude Code MCP

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.

Featured
Local
JavaScript
@kazuph/mcp-taskmanager

@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.

Featured
Local
JavaScript
Linear MCP Server

Linear MCP Server

Enables interaction with Linear's API for managing issues, teams, and projects programmatically through the Model Context Protocol.

Featured
JavaScript
mermaid-mcp-server

mermaid-mcp-server

A Model Context Protocol (MCP) server that converts Mermaid diagrams to PNG images.

Featured
JavaScript
Jira-Context-MCP

Jira-Context-MCP

MCP server to provide Jira Tickets information to AI coding agents like Cursor

Featured
TypeScript
Linear MCP Server

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.

Featured
JavaScript
Sequential Thinking MCP Server

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.

Featured
Python