trackmcp
Back to directory
anisirji

mcp-server-remote-setup-with-jwt-auth

View on GitHub

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.

4 stars TypeScriptAI & Machine Learning Updated Jul 11, 2025

Documentation

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

code
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

bash
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

bash
npm install

3. Create `.env` file

bash
echo "JWT_SECRET=your-secret-key" > .env

4. Run the server

bash
npm run dev

โœ… Server will run on:

code
http://localhost:3001/sse

๐Ÿงช Testing the server with MCP Inspector

Step 1 โ€” Install MCP Inspector

> ๐Ÿ“– Official Docs: MCP Inspector

bash
npx @modelcontextprotocol/inspector

Step 2 โ€” Generate a token

Use cURL to get your JWT token:

bash
curl "http://localhost:3001/auth/token?username=aniket&scope=mcp:access"

โœ… Example response:

json
{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}

Step 3 โ€” Connect MCP Inspector

1. Open Inspector UI

2. Set Transport Type: SSE

3. URL:

code
http://localhost:3001/sse

4. Add Authorization Header:

code
Authorization: Bearer

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

code
GET /auth/token?username=&scope=mcp:access

๐Ÿ”Œ SSE Endpoint (requires token)

code
GET /sse
Authorization: Bearer

๐Ÿ“ฉ Send Message to active session

code
POST /message?sessionId=
Authorization: Bearer

๐Ÿงฉ Tools Reference

Tool NameDescription
`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.

Frequently asked questions

What is mcp-server-remote-setup-with-jwt-auth?

mcp-server-remote-setup-with-jwt-auth is 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.

How do I install mcp-server-remote-setup-with-jwt-auth?

Open the GitHub repository and follow its README. Most MCP servers are added to your client's MCP config, then called by your agent.

Is mcp-server-remote-setup-with-jwt-auth open source?

Yes โ€” it is hosted on GitHub at https://github.com/anisirji/mcp-server-remote-setup-with-jwt-auth and has 4 stars.

Related MCP tools

Run your own MCP server? See who uses it and what to fix.

Measure it with TrackMCP