SSE MCP Server with JWT Authentication

Integrations

  • Manages environment variables for server configuration, including JWT secrets.

  • Serves as the web framework for the MCP server, handling HTTP requests and SSE connections for AI tool communication.

  • Used for version control and project setup via cloning.

🔐 JWT 認証を備えた SSE MCP サーバー

これは、JWT ベースの認証を備えたモデル コンテキスト プロトコル (MCP) SSE サーバーです。
安全なベアラー トークン フローによって保護された SSE トランスポートを介して複数の AI ツールを公開できます。

搭載コンポーネント:

  • 🚀 Node.js + エクスプレス
  • 🧩 @modelcontextprotocol/sdk
  • 🔒 認証のためのJSON Web Token(JWT)
  • ⚙️ 入力検証のための Zod

@modelcontextprotocol/inspectorで完全にテスト済み

📂 プロジェクト構造

server/ ├── index.ts # Main Express + MCP server ├── .env # Environment variables ├── package.json # Project metadata & scripts ├── tsconfig.json # TypeScript config └── README.md # You are here!

✨ 特徴

  • ✅ Bearer JWT トークンを使用した安全な SSE 接続
  • ✅ 動的ツールの登録(エコー、時間、乱数など)
  • ✅ MCP Inspectorでテスト済み
  • ✅ すべてのリクエストライフサイクルイベントをログに記録します
  • ✅ /message エンドポイントのセッション管理
  • 🚀 本番環境での使用に拡張可能

⚙️ セットアップ

1. リポジトリをクローンする

git clone https://github.com/anisirji/mcp-server-remote-setup-with-jwt-auth.git cd mcp-server-remote-setup-with-jwt-auth

2. 依存関係をインストールする

npm install

3. .envファイルを作成する

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

4. サーバーを実行する

npm run dev

✅ サーバーは以下で実行されます:

http://localhost:3001/sse

🧪 MCP Inspector でサーバーをテストする

ステップ1 - MCP Inspectorをインストールする

📖 公式ドキュメント: MCP インスペクター

npx @modelcontextprotocol/inspector

ステップ2 — トークンを生成する

cURL を使用して JWT トークンを取得します。

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

✅ 回答例:

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

ステップ3 - MCP Inspectorを接続する

  1. インスペクターUIを開く
  2. トランスポートタイプを設定: SSE
  3. URL:
    http://localhost:3001/sse
  4. 認証ヘッダーを追加します:
    Authorization: Bearer <your-token>
  5. **「接続」**をクリック

🎉 成功しました!サーバーが接続されました。

ステップ4 — テストツール

インスペクタの**「ツール」**タブに移動し、 「リスト ツール」をクリックします。

次のように表示されます。

  • test
  • echo
  • get-time
  • random-number

ぜひテストして楽しんでください!

📖 APIリファレンス

🔑 トークンを生成する

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

🔌 SSEエンドポイント(トークンが必要)

GET /sse Authorization: Bearer <token>

📩 アクティブセッションにメッセージを送信する

POST /message?sessionId=<sessionId> Authorization: Bearer <token>

🧩 ツールリファレンス

ツール名説明
testテスト接続(セキュリティチェック)
echo提供されたメッセージをエコーバックする
get-time現在のサーバー時刻を返します
random-number乱数(最小/最大)を返します

🗓️ 今後の変更点

  • [ ] トークン失効リスト(ブラックリスト)
  • [ ] ロールベースのツールアクセス(スコープチェック)
  • [ ] セッションハートビート/キープアライブ
  • [ ] レート制限とログ記録
  • [ ] デプロイメントのためのDocker化

📚 役立つリソース

👨‍💻 メンテナー

アニケット

📄 ライセンス

このプロジェクトはオープンソースであり、無料で使用できます。

🚀 構築する。保護する。強化する。

-
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. 📂 Project Structure
    1. ✨ Features
      1. ⚙️ Setup
        1. 1. Clone the repository
        2. 2. Install dependencies
        3. 3. Create .env file
        4. 4. Run the server
      2. 🧪 Testing the server with MCP Inspector
        1. Step 1 — Install MCP Inspector
        2. Step 2 — Generate a token
        3. Step 3 — Connect MCP Inspector
        4. Step 4 — Test tools
      3. 📖 API Reference
        1. 🔑 Generate Token
        2. 🔌 SSE Endpoint (requires token)
        3. 📩 Send Message to active session
      4. 🧩 Tools Reference
        1. 🗓️ Upcoming Changes
          1. 📚 Useful Resources
            1. 👨‍💻 Maintainer
              1. 📄 License
                1. 🚀 Build. Secure. Empower.

                  Related MCP Servers

                  • A
                    security
                    F
                    license
                    A
                    quality
                    A Model Context Protocol server that allows secure execution of pre-approved commands, enabling AI assistants to safely interact with the user's system.
                    Last updated -
                    1
                    3
                    18
                    JavaScript
                  • -
                    security
                    A
                    license
                    -
                    quality
                    A Model Context Protocol server that enables seamless execution of commands, Python code, web content fetching, and reusable task management with secure credentials handling.
                    Last updated -
                    2
                    Python
                    MIT License
                    • 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 -
                    16
                    TypeScript
                  • -
                    security
                    A
                    license
                    -
                    quality
                    A Model Context Protocol server that provides AI agents with secure access to local filesystem operations, enabling reading, writing, and managing files through a standardized interface.
                    Last updated -
                    14
                    1
                    TypeScript
                    Apache 2.0

                  View all related MCP servers

                  ID: miwcfrgnmg