Skip to main content

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.
Location: packages/mcp-use/src/server/
Key Features:
  • 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
Architecture:

MCPClient

The client component manages connections to MCP servers and handles tool discovery.
Location: packages/mcp-use/src/client.ts
Architecture:
Key Responsibilities:
  • 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.
Location: packages/mcp-use/src/agents/
Architecture:
Key Features:
  • 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:
Pros:
  • Simple setup
  • No network configuration
  • Process isolation
Cons:
  • Local only
  • No HTTP features

HTTP/SSE Transport

For HTTP-based communication with Server-Sent Events:
Pros:
  • Works over network
  • Firewall-friendly
  • Browser compatible
  • Inspector integration
Cons:
  • Requires server setup
  • HTTP overhead

WebSocket Transport

For bidirectional communication:
Pros:
  • Real-time bidirectional
  • Low latency
  • Efficient for streams
Cons:
  • More complex setup
  • Connection management

Widget System (TypeScript)

Architecture

Widget Lifecycle

1

Discovery

Server scans resources/ directory for widget.tsx files
2

Bundling

esbuild compiles React components with dependencies
3

Registration

Widgets auto-register with metadata
4

Type Generation

TypeScript types generated for useCallTool
5

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
Auto-Mounting:
Standalone Usage:

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