MCP Server Framework
Themcp-use package provides a powerful and intuitive framework for building Model Context Protocol (MCP) servers with TypeScript. It combines the official MCP SDK with Express.js to enable both MCP protocol communication and HTTP endpoints for UI widgets and custom routes.
Key Features
- Fluent API Design: Chain methods to configure tools, resources, prompts, and UI widgets
- Express Integration: Built-in Express server for HTTP endpoints, static file serving, and custom routes
- UI Widget Support: Native support for MCP-UI widgets and OpenAI Apps SDK components
- Type Safety: Full TypeScript support with comprehensive type definitions
- Resource Templates: Dynamic resource generation with URI templates and parameters
- Inspector UI: Optional development UI for testing and debugging your MCP server
- Flexible Architecture: Modular design supporting tools, resources, prompts, and UI components
Installation
Recommended: Using create-mcp-use-app
The easiest way to get started is to use thecreate-mcp-use-app command, which scaffolds a complete MCP server project with all necessary configuration:
Manual Installation
If you prefer to set up manually or add mcp-use to an existing project, install the package via npm:Quick Start
The easiest way to start is withcreate-mcp-use-app, which provides a working example. After running the scaffold command above, your server is ready to go!
For manual setup, here’s a minimal example:
- MCP Endpoint:
http://localhost:3000/mcp- For MCP client connections - Inspector UI:
http://localhost:3000/inspector- Development and testing interface (if @mcp-use/inspector is installed)
Architecture Overview
The MCP server framework is built on several core concepts:1. Server Instance
The main server object created viacreateMCPServer(). It manages all MCP functionality and HTTP endpoints.
2. Tools
Functions that MCP clients can invoke with parameters. Tools perform actions and return results.3. Resources
Static or dynamic content that clients can read. Resources can be simple files or complex data structures.4. Prompts
Template-based prompt generation for AI models, accepting parameters to create structured prompts.5. UI Resources
Interactive widgets that can be embedded in web applications, supporting both MCP-UI and OpenAI Apps SDK formats.6. Express Integration
Full access to Express.js functionality for adding custom routes, middleware, and static file serving.Core Components
McpServer Class
The main server class that orchestrates all functionality:Type System
The framework provides comprehensive TypeScript types for all components:ServerConfig- Server configurationToolDefinition- Tool configuration and callbacksResourceDefinition- Resource configuration and read callbacksPromptDefinition- Prompt template configurationUIResourceDefinition- UI widget configurationInputDefinition- Parameter definitions for tools and prompts
MCP Protocol Support
The server fully implements the MCP protocol specification:- Transport: HTTP with Server-Sent Events (SSE) for streaming
- Tools: Function execution with typed parameters
- Resources: Content serving with MIME types and annotations
- Prompts: Template-based prompt generation
- Resource Templates: Dynamic resource generation with URI parameters
UI Widget System
The framework supports multiple UI widget formats:MCP-UI Widgets
- External URL widgets (iframe-based)
- Raw HTML widgets
- Remote DOM scripting
OpenAI Apps SDK
- Text/HTML+Skybridge format
- Widget CSP configuration
- Tool output templates
Next Steps
- Getting Started Guide - Detailed setup and first server
- API Reference - Complete API documentation
- Tools Guide - Building and configuring tools
- Resources Guide - Static and dynamic resources
- UI Widgets - Creating interactive widgets
- Examples - Real-world implementation examples