Cover image
MCP-Server-setup-setup-with-jwt-auth
Public

MCP-Server-setup-setup-with-jwt-auth

Try Now
2025-04-05

使用JWT身份验证,安全中间件服务器在SSE上实现模型上下文协议(MCP)。通过动态工具注册,请求记录和会话管理启用AI工具与客户之间的标准化通信。非常适合建立准备生产的AI系统,需要安全的访问模式。

3 years

Works with Finder

1

Github Watches

0

Github Forks

1

Github Stars

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

相关推荐

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • lumpenspace
  • Take an adjectivised noun, and create images making it progressively more adjective!

  • Lists Tailwind CSS classes in monospaced font

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • tomoyoshi hirata
  • Sony α7IIIマニュアルアシスタント

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • apappascs
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • jae-jae
  • MCP服务器使用剧作《无头浏览器》获取网页内容。

  • ravitemer
  • 一个功能强大的Neovim插件,用于管理MCP(模型上下文协议)服务器

  • patruff
  • Ollama和MCP服务器之间的桥梁,使本地LLMS可以使用模型上下文协议工具

  • pontusab
  • 光标与风浪冲浪社区,查找规则和MCP

  • JackKuo666
  • 🔍使AI助手可以通过简单的MCP接口搜索和访问PYPI软件包信息。

  • av
  • 毫不费力地使用一个命令运行LLM后端,API,前端和服务。

    Reviews

    4 (1)
    Avatar
    user_dw2fwAJ1
    2025-04-17

    I've been using mcp-server-remote-setup-with-jwt-auth for a while now, and it has simplified my server setup process tremendously. The JWT authentication ensures a secure connection, and the documentation on GitHub by anisirji is clear and easy to follow. Highly recommend this for anyone in need of a reliable remote setup solution.