DM

dzhng/mcp-client-auth

Developer tools

このページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。 原文を見る

39 stars 3 forks 品質 50 トレンド 12MIT

モデルコンテキストプロトコル(MCP)クライアントの OAuth2 認証ユーティリティを提供する TypeScript ライブラリ.

概要

モデルコンテキストプロトコル(MCP)クライアントの OAuth2 認証ユーティリティを提供する TypeScript ライブラリ。 このライブラリは、OAuth 認証を MCP クライアントの実装に追加するプロセスを簡素化します。 MCP OAuthは、動的クライアントの登録とメタデータ検出の手順は、典型的なオース実装ではサポートされていないため、追加のトリッキーです。 このライブラリは2つの関数呼び出しにすべてを簡素化します。 このプロジェクトが好きなら、それをスターリングしてX/Twitterでフォローしてください。 Aomniが主催するプロジェクトです.

概要(AI 翻訳)

モデルコンテキストプロトコル(MCP)クライアントの OAuth2 認証ユーティリティを提供する TypeScript ライブラリ。 このライブラリは、OAuth 認証を MCP クライアントの実装に追加するプロセスを簡素化します。

MCP OAuthは、動的クライアントの登録とメタデータ検出の手順は、典型的なオース実装ではサポートされていないため、追加のトリッキーです。 このライブラリは2つの関数呼び出しにすべてを簡素化します。

このプロジェクトが好きなら、それをスターリングしてX/Twitterでフォローしてください。 Aomniが主催するプロジェクトです。

##特徴

主な機能:

  • 🔐 完全な OAuth2 フロー: PKCE で標準の OAuth2 認可コードフローを実装
  • MCPクライアントの統合**:MCPクライアントのOAuthサポートをドロップイン
  • ''ゼロコンフィギュレーション**: 自動サーバーメタデータ発見と動的クライアント登録
  • バックアップスマートトランスポートセレクション:ストリーム可能なHTTPからSSEへの自動フォールバックで最大互換性
  • ✓トークン管理**:自動トークンのリフレッシュと安全なストレージ(プラグイン可能なストレージインターフェイス経由)
  • 確かにTypeScript First:フルタイプの安全とIntelliSenseのサポート

インストール

クイックスタート

##ハイレベルMCPクライアントを使用する

このページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。

README

以下は原文 README の抜粋です。原文を見る。

MCP Client Auth

A TypeScript library providing OAuth2 authentication utilities for Model Context Protocol (MCP) clients. This library simplifies the process of adding OAuth authentication to MCP client implementations.

MCP OAuth is extra tricky because the dynamic client registration and metadata discovery steps are not supported by typical oauth implementations. This library simplifies everything to 2 function calls.

If you like this project, please consider starring it and giving me a follow on X/Twitter. This project is sponsored by Aomni.

Features

Key capabilities:

  • 🔐 Complete OAuth2 Flow: Implements the standard OAuth2 authorization code flow with PKCE
  • 🚀 MCP Client Integration: Drop-in OAuth support for MCP clients
  • 📦 Zero Configuration: Automatic server metadata discovery and dynamic client registration
  • 🌐 Smart Transport Selection: Automatic fallback from StreamableHTTP to SSE transport for maximum compatibility
  • 🔄 Token Management: Automatic token refresh and secure storage (via pluggable storage interface)
  • 🎯 TypeScript First: Full type safety and IntelliSense support

Installation

npm install mcp-client-auth

Quick Start

Using the High-Level MCP Client

Init the client

import { McpClient } from 'mcp-client-auth';

const client = new McpClient({
  url: 'https://mcp.example.com',
  oauthRedirectUri: 'localhost:3000/mcp/oauth/callback',
  // store: -- add your own database store here --
});

There are only 2 methods that are needed to connect to a MCP server (and handle OAuth if needed).

Checking for auth status

The isAuthRequired() method returns an AuthStatus object that indicates the authentication state. This status can be one of three types:

  1. { isRequired: true, isAuthenticated: false, authorizationRequest: AuthorizationRequest } - Authentication is required and not yet completed. The authorizationRequest contains the URL and state needed to start the OAuth flow.

  2. { isRequired: false, isAuthenticated: true } - No authentication is needed for this server.

  3. { isRequired: true, isAuthenticated: true } - Authentication is required and has already been completed successfully.

This status object helps you determine whether to redirect the user to the OAuth authorization page or proceed with using the client directly.

// Check if authentication is required
const authStatus = await client.isAuthRequired();

if (authStatus.isRequired && !authStatus.isAuthenticated) {
  console.log('Please visit:', authStatus.authorizationRequest.url);

  // ... REDIRECT USER ...
}

Note you should save the AuthorizationRequest object for the next step.

Handling the OAuth callback

The handleAuthByCode method is used to complete the OAuth flow by exchanging the authorization code for access tokens. It takes two parameters:

GitHub で README 全文を見る

インストール

This server does not publish a one-line install command.

Open the repository installation guide MCP 初心者?mcpskill.org のガイドから始めましょう →