
dzhng/mcp-client-auth
Developer tools이 페이지는 AI로 자동 번역되었습니다. 기술적인 세부 사항은 원문을 확인하세요. 원문 보기
Model Context Protocol (MCP) 클라이언트를 위한 OAuth2 인증 유틸리티를 제공하는 TypeScript 라이브러리.
개요
Model Context Protocol (MCP) 클라이언트를 위한 OAuth2 인증 유틸리티를 제공하는 TypeScript 라이브러리. 이 라이브러리는 MCP 클라이언트 구현에 OAuth 인증 추가 프로세스를 단순화합니다. MCP OAuth는 동적 클라이언트 등록 및 metadata discovery 단계가 일반적인 oauth 구현에 의해 지원되지 않기 때문에 추가 까다로운입니다. 이 라이브러리는 모든 것을 2개의 함수 호출에 간단히 합니다. 이 프로젝트를 좋아한다면, 스타링을 고려하고 X/Twitter에서 팔로우하십시오. 이 프로젝트는 Aomni가 후원합니다.
개요(AI 번역)
Model Context Protocol (MCP) 클라이언트를 위한 OAuth2 인증 유틸리티를 제공하는 TypeScript 라이브러리. 이 라이브러리는 MCP 클라이언트 구현에 OAuth 인증 추가 프로세스를 단순화합니다.
MCP OAuth는 동적 클라이언트 등록 및 metadata discovery 단계가 일반적인 oauth 구현에 의해 지원되지 않기 때문에 추가 까다로운입니다. 이 라이브러리는 모든 것을 2개의 함수 호출에 간단히 합니다.
이 프로젝트를 좋아한다면, 스타링을 고려하고 X/Twitter에서 팔로우하십시오. 이 프로젝트는 Aomni가 후원합니다.
특징
주요 기능:
- ** OAuth2 흐름 **: PKCE로 표준 OAuth2 인증 코드 흐름 구현
- MCP 클라이언트 통합 ** : Drop-in OAuth 지원
- ☸ 영 구성: 자동 서버 metadata discovery 및 동적 클라이언트 등록
- Ī Smart Transport Selection: 최대 호환성을 위한 SSE 수송에 StreamableHTTP에서 자동적인 fallback
- ܧ 토큰 관리: 자동 토큰 새로 고침 및 안전한 저장 (플러그 가능한 저장 공용영역을 통해)
- 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:
-
{ isRequired: true, isAuthenticated: false, authorizationRequest: AuthorizationRequest }- Authentication is required and not yet completed. TheauthorizationRequestcontains the URL and state needed to start the OAuth flow. -
{ isRequired: false, isAuthenticated: true }- No authentication is needed for this server. -
{ 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:
설치
This server does not publish a one-line install command.
Open the repository installation guide MCP 초보자라면? mcpskill.org 가이드부터 시작하세요 →