anisirji mcp server remote setup with jwt auth

anisirji mcp server remote setup with jwt auth avatar

by anisirji

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.

What is anisirji mcp server remote setup with jwt auth

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

Leave a Comment

Frequently Asked Questions

What is MCP?

MCP (Model Context Protocol) is an open protocol that standardizes how applications provide context to LLMs. Think of MCP like a USB-C port for AI applications, providing a standardized way to connect AI models to different data sources and tools.

What are MCP Servers?

MCP Servers are lightweight programs that expose specific capabilities through the standardized Model Context Protocol. They act as bridges between LLMs like Claude and various data sources or services, allowing secure access to files, databases, APIs, and other resources.

How do MCP Servers work?

MCP Servers follow a client-server architecture where a host application (like Claude Desktop) connects to multiple servers. Each server provides specific functionality through standardized endpoints and protocols, enabling Claude to access data and perform actions through the standardized protocol.

Are MCP Servers secure?

Yes, MCP Servers are designed with security in mind. They run locally with explicit configuration and permissions, require user approval for actions, and include built-in security features to prevent unauthorized access and ensure data privacy.

Related MCP Servers

chrisdoc hevy mcp avatar

chrisdoc hevy mcp

mcp
sylphlab pdf reader mcp avatar

sylphlab pdf reader mcp

An MCP server built with Node.js/TypeScript that allows AI agents to securely read PDF files (local or URL) and extract text, metadata, or page counts. Uses pdf-parse.

pdf-parsetypescriptnodejs
aashari mcp server atlassian bitbucket avatar

aashari mcp server atlassian bitbucket

Node.js/TypeScript MCP server for Atlassian Bitbucket. Enables AI systems (LLMs) to interact with workspaces, repositories, and pull requests via tools (list, get, comment, search). Connects AI directly to version control workflows through the standard MCP interface.

atlassianrepositorymcp
aashari mcp server atlassian confluence avatar

aashari mcp server atlassian confluence

Node.js/TypeScript MCP server for Atlassian Confluence. Provides tools enabling AI systems (LLMs) to list/get spaces & pages (content formatted as Markdown) and search via CQL. Connects AI seamlessly to Confluence knowledge bases using the standard MCP interface.

atlassianmcpconfluence
prisma prisma avatar

prisma prisma

Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB

cockroachdbgomcp
Zzzccs123 mcp sentry avatar

Zzzccs123 mcp sentry

mcp sentry for typescript sdk

mcptypescript
zhuzhoulin dify mcp server avatar

zhuzhoulin dify mcp server

mcp
zhongmingyuan mcp my mac avatar

zhongmingyuan mcp my mac

mcp
zhixiaoqiang desktop image manager mcp avatar

zhixiaoqiang desktop image manager mcp

MCP ๆœๅŠกๅ™จ๏ผŒ็”จไบŽ็ฎก็†ๆกŒ้ขๅ›พ็‰‡ใ€ๆŸฅ็œ‹่ฏฆๆƒ…ใ€ๅŽ‹็ผฉใ€็งปๅŠจ็ญ‰๏ผˆๅฎŒๅ…จ่ฎฉTraeๅฎž็Žฐ๏ผ‰

mcp
zhixiaoqiang antd components mcp avatar

zhixiaoqiang antd components mcp

An MCP service for Ant Design components query | ไธ€ไธชๅ‡ๅฐ‘ Ant Design ็ป„ไปถไปฃ็ ็”Ÿๆˆๅนป่ง‰็š„ MCP ๆœๅŠก๏ผŒๅŒ…ๅซ็ณป็ปŸๆ็คบ่ฏใ€็ป„ไปถๆ–‡ๆกฃใ€API ๆ–‡ๆกฃใ€ไปฃ็ ็คบไพ‹ๅ’Œๆ›ดๆ–ฐๆ—ฅๅฟ—ๆŸฅ่ฏข

designantdapi

Submit Your MCP Server

Share your MCP server with the community

Submit Now