How modelcontextprotocol/use-mcp works
use-mcp is a browser-side React library: an application configures the hook, which authenticates and connects to an MCP server, discovers its capabilities, then exposes tool, resource, and prompt operations. OAuth callback handling completes popup authorization; the browser provider stores OAuth state in localStorage. The source excerpts do not show every operation’s implementation or the full connection sequence, so the graph focuses on documented capabilities and excerpt-supported calls.
Main entry points: useMcp.ts useMcp hook · browser-provider.ts OAuth provider · callback.ts OAuth callback · index.ts Core exports
Components 16
React integration
- useMcp hook
src/react/useMcp.ts - Hook API types
src/react/types.ts - Runtime assertions
src/utils/assert.ts
MCP connection
- MCP client SDK
- Tool calls
src/react/useMcp.ts - Resource access
src/react/useMcp.ts - Prompt access
src/react/useMcp.ts - HTTP / SSE transport
src/react/useMcp.ts
Browser OAuth
- OAuth provider
src/auth/browser-provider.ts - OAuth browser storage
src/auth/browser-provider.ts - OAuth callback
src/auth/callback.ts - Core exports
src/index.ts
Other components
- React application
- MCP server
- OAuth authorization server
- Authorization popup
Connections 20
- React application → useMcp hook: configures
README.md - useMcp hook → OAuth provider: creates and uses
src/react/useMcp.ts - useMcp hook → HTTP / SSE transport: creates
src/react/useMcp.ts - useMcp hook → MCP client SDK: authenticates and connects
src/react/useMcp.ts - HTTP / SSE transport → MCP server: exchanges MCP messages
- useMcp hook → Tool calls: exposes
README.md - useMcp hook → Resource access: exposes
README.md - useMcp hook → Prompt access: exposes
README.md - MCP client SDK → MCP server: requests capabilities
- OAuth provider → OAuth browser storage: reads and writes
src/auth/browser-provider.ts - OAuth provider → Authorization popup: opens
src/auth/browser-provider.ts - OAuth provider → OAuth authorization server: prepares authorization
- Authorization popup → OAuth callback: returns authorization code
src/auth/callback.ts - OAuth callback → OAuth browser storage: reads state; saves tokens
src/auth/callback.ts - OAuth callback → OAuth provider: reconstructs and uses
src/auth/callback.ts - OAuth callback → OAuth authorization server: exchanges code via SDK
src/auth/callback.ts - React application → OAuth callback: invokes callback handler
README.md - useMcp hook → Runtime assertions: checks auth state
src/react/useMcp.ts - Core exports → OAuth provider: exports
src/index.ts - Core exports → OAuth callback: exports
src/index.ts