Overview
mcp-use is a fullstack MCP framework with implementations in both TypeScript and Python. The architecture is designed for modularity, extensibility, and ease of use.High-Level Architecture
Core Components
MCPServer
The server component implements the MCP protocol and provides the foundation for building MCP servers.- TypeScript
- Python
Location: Key Features:
packages/mcp-use/src/server/- Built on Hono web framework for performance
- Automatic inspector mounting at
/inspector - MCP endpoints at
/mcp(HTTP/SSE) - Hot reload in development mode
- Automatic widget discovery
- Type-safe tool registration
MCPClient
The client component manages connections to MCP servers and handles tool discovery.- TypeScript
- Python
Location: Architecture:Key Responsibilities:
packages/mcp-use/src/client.ts- Server lifecycle management
- Connection multiplexing
- Tool/resource discovery
- Session state management
- Transport abstraction
MCPAgent
The agent component provides high-level AI agent functionality with LangChain integration.- TypeScript
- Python
Location: Architecture:Key Features:
packages/mcp-use/src/agents/- Multiple streaming modes
- LLM-agnostic (any LangChain LLM)
- Observability integration (Langfuse)
- Dynamic server selection
- Conversation memory
- Tool access control
Transport Layer
mcp-use supports three transport mechanisms:stdio Transport
For local process communication:- Simple setup
- No network configuration
- Process isolation
- Local only
- No HTTP features
HTTP/SSE Transport
For HTTP-based communication with Server-Sent Events:- Works over network
- Firewall-friendly
- Browser compatible
- Inspector integration
- Requires server setup
- HTTP overhead
WebSocket Transport
For bidirectional communication:- Real-time bidirectional
- Low latency
- Efficient for streams
- More complex setup
- Connection management
Widget System (TypeScript)
Architecture
Widget Lifecycle
1
Discovery
Server scans
resources/ directory for widget.tsx files2
Bundling
esbuild compiles React components with dependencies
3
Registration
Widgets auto-register with metadata
4
Type Generation
TypeScript types generated for
useCallTool5
Serving
Widgets served at
/widgets/{name}6
Rendering
Client renders widget with props
Widget Example
Inspector
The built-in inspector is a critical development tool: Features:- Test tools with custom inputs
- View resources
- Try prompts
- See server logs
- Monitor performance
- OAuth flow testing
Observability
Architecture
Usage
Data Flow
Tool Execution Flow
Extension Points
mcp-use is designed for extensibility:Custom Transports
Custom Adapters
Middleware
Performance Considerations
TypeScript
- Hono framework: Fast HTTP handling
- esbuild: Fast widget bundling
- Connection pooling: Reuse connections
- Lazy loading: Load widgets on demand
Python
- asyncio: Non-blocking I/O
- Connection pooling: Efficient resource use
- Lazy imports: Faster startup
Security
Authentication
Tool Restrictions
Sandboxing (Python)
Learn More
Building Servers
Practical guide to server development
MCP Protocol
Protocol specification details
API Reference
Complete API documentation
Examples
Browse code examples