Skip to main content
Glama

SSE MCP Server with JWT Authentication

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

-
security - not tested
F
license - not found
-
quality - not tested

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

模型上下文协议服务器通过基于 JWT 的安全身份验证通过 SSE 传输公开多个 AI 工具,从而实现动态工具注册和会话管理。

  1. 📂 项目结构
    1. ✨ 特点
      1. ⚙️ 设置
        1. 1. 克隆存储库
        2. 2.安装依赖项
        3. 3.创建.env文件
        4. 4.运行服务器
      2. 🧪 使用 MCP Inspector 测试服务器
        1. 步骤 1 — 安装 MCP Inspector
        2. 步骤 2 — 生成令牌
        3. 步骤 3 — 连接 MCP Inspector
        4. 步骤 4 — 测试工具
      3. 📖 API 参考
        1. 🔑 生成令牌
        2. 🔌 SSE 端点(需要令牌)
        3. 📩 向活动会话发送消息
      4. 🧩 工具参考
        1. 🗓️ 即将发生的变化
          1. 📚 有用的资源
            1. 👨‍💻 维护者
              1. 📄 许可证
                1. 🚀 构建。 安全。 赋能。

                  Related MCP Servers

                  • -
                    security
                    F
                    license
                    -
                    quality
                    A demonstration implementation of the Model Context Protocol server that facilitates communication between AI models and external tools while maintaining context awareness.
                    Last updated -
                    • Linux
                    • Apple
                  • -
                    security
                    F
                    license
                    -
                    quality
                    A comprehensive Model Context Protocol server implementation that enables AI assistants to interact with file systems, databases, GitHub repositories, web resources, and system tools while maintaining security and control.
                    Last updated -
                    7
                    1
                  • A
                    security
                    F
                    license
                    A
                    quality
                    A server that enables AI to access external services through the Model Context Protocol, specifically integrating with an authentication system to obtain login tickets.
                    Last updated -
                    1
                  • -
                    security
                    F
                    license
                    -
                    quality
                    A Model Context Protocol server that provides AI models with structured access to external data and services, acting as a bridge between AI assistants and applications, databases, and APIs in a standardized, secure way.
                    Last updated -
                    2

                  View all related MCP servers

                  MCP directory API

                  We provide all the information about MCP servers via our MCP API.

                  curl -X GET 'https://glama.ai/api/mcp/v1/servers/anisirji/mcp-server-remote-setup-with-jwt-auth'

                  If you have feedback or need assistance with the MCP directory API, please join our Discord server