mcpField
πŸ”
πŸ” SSE MCP Server with JWT Authentication

πŸ” SSE MCP Server with JWT Authentication

Local
github.com/anisirjiDeveloper Tools4Updated 79w ago

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

  1. 01SSE transport with JWT bearer authentication
  2. 02Dynamically register tools
  3. 03Validate inputs with Zod
  4. 04Log request lifecycle events
  5. 05Manage message endpoint sessions
  6. 06Provide echo, time, and random-number tools

Use cases

  1. 01Expose tools through an authenticated SSE endpoint
  2. 02Connect an MCP client using a bearer token
  3. 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.

mcp.json Β· Universal config
{
"mcpServers": {
"remote-setup-with-jwt-auth": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/inspector"
]
}
}
}
Run commandnpx -y @modelcontextprotocol/inspector

Local servers need a runtime on your machine (e.g. Node.js 18+). Config file locations differ by client; see your client’s docs.

Packages
npm@modelcontextprotocol/inspector

Tools

No tool list yet

Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.

Details

From the project README

MseeP.ai Security Assessment Badge

πŸ” 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 NameDescription
testTest connection (security check)
echoEcho back provided message
get-timeReturns current server time
random-numberReturns 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

Markdown supported

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.