Core Library Entry Point Analysis
File: src/index.ts
Purpose
This is the main entry point for the use-mcp browser library. It provides browser-specific, framework-agnostic components for Model Context Protocol (MCP) OAuth authentication.
Line-by-Line Analysis
Lines 1-4: File Documentation
/**
* Core entry point for the use-mcp browser library.
* Provides browser-specific, framework-agnostic components for MCP OAuth.
*/
- Purpose: Documents the file's role as the main entry point
- Scope: Browser-specific implementation for MCP OAuth functionality
- Framework-agnostic: Designed to work with any JavaScript framework, not just React
Lines 6-7: Auth Provider Exports
export { BrowserOAuthClientProvider } from './auth/browser-provider.js'
export { onMcpAuthorization } from './auth/callback.js'
- Line 6: Exports the
BrowserOAuthClientProviderclass from./auth/browser-provider.js- This is likely the main OAuth client implementation for browser environments
- Handles OAuth flow management in web browsers
- Line 7: Exports the
onMcpAuthorizationfunction from./auth/callback.js- Handles OAuth callback processing after authorization
- Typically used in OAuth redirect/callback pages
Lines 9-10: Type Exports
// Optionally re-export relevant types from SDK or internal types if needed
export type { StoredState as InternalStoredState } from './auth/types.js'
- Line 10: Exports the
StoredStatetype with aliasInternalStoredState - Purpose: Provides type definitions for internal authentication state management
- Comment on Line 9: Indicates this is an optional type export for internal use
Lines 12-14: Commented SDK Type Exports
// It's generally better to have users import SDK types directly from the SDK
// export type { Tool, JSONRPCMessage } from '@modelcontextprotocol/sdk/types.js';
// export type { OAuthClientInformation, OAuthMetadata, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
- Line 12: Design philosophy comment - encourages direct SDK imports
- Lines 13-14: Commented out type exports from the MCP SDK
- Reasoning: Prevents duplicate type exports, encourages users to import types directly from the SDK
Dependencies
./auth/browser-provider.js- Browser OAuth provider implementation./auth/callback.js- OAuth callback handler./auth/types.js- Authentication type definitions
Exports Summary
- BrowserOAuthClientProvider - Main OAuth client for browsers
- onMcpAuthorization - OAuth callback handler function
- InternalStoredState (type) - Internal authentication state type
Integration Points
- This file serves as the main public API for the browser-specific MCP library
- Users import from
use-mcpto get OAuth functionality - Separate from React-specific exports (which are in
src/react/) - Designed to be framework-agnostic while providing browser OAuth capabilities
Architecture Notes
- Clean separation between browser-specific and React-specific functionality
- Minimal surface area - only exports essential OAuth components
- Encourages direct SDK type imports to avoid duplication
- Uses explicit file extensions (
.js) for ESM compatibility