πŸ” SSE MCP Server with JWT Authentication

by anisirji

4 stars
196 downloads
Not rated
GitHub

About

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 s

Details

Author
anisirji
GitHub stars
4
Downloads
196
Categories
Developer Tools

- Secure SSE connection with Bearer JWT token
- Dynamic tool registration (echo, time, random number)
- Tested with @modelcontextprotocol/inspector
- Session management for /message endpoint
- Ready to extend for production use

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name πŸ” SSE MCP Server with JWT Authentication
    Command (node, npx, python, etc.)

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

Clone the repository, install dependencies with npm install, create a .env file with a JWT_SECRET, and run npm run dev to start the server on http://localhost:3001/sse. Generate a JWT token via GET /auth/token?username=<username>&scope=mcp:access. Then connect to the SSE endpoint using the token in the Authorization header.

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "\ud83d\udd10 sse mcp server with jwt authentication": {
            "mcp-server-remote-setup-with-jwt-auth": {
                "command": "npx",
                "args": [
                    "@modelcontextprotocol/inspector"
                ]
            }
        }
    }
}

McpServers

{
    "mcp-server-remote-setup-with-jwt-auth": {
        "command": "npx",
        "args": [
            "@modelcontextprotocol/inspector"
        ]
    }
}

πŸ” 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

- Model Context Protocol Introduction
- MCP Inspector Docs
- JWT.io Debugger
- Zod Validation Docs

πŸ‘¨β€πŸ’» Maintainer

> Aniket

πŸ“„ License

This project is open-source and free to use.

No reviews yet β€” be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.