mcp-use CLI
š ļø mcp-use CLI is a powerful build and development tool for creating MCP (Model Context Protocol) applications with integrated UI widgets. It enables developers to build MCP servers with custom React components that can be served alongside their MCP tools, providing rich visual interfaces for AI interactions.
š¦ Related Packages
⨠Key Features
| š Auto Inspector | Automatically opens the MCP Inspector in your browser when development server starts |
| ā»ļø Hot Reload | Development mode with automatic reloading for both server code and UI widgets |
| šØ Widget Builder | Compiles React components into standalone HTML pages with all dependencies bundled |
| š¦ Production Ready | Optimized production builds with hashed assets for caching |
| š ļø TypeScript First | Full TypeScript support with watch mode compilation |
| š„ļø Multi-Environment | Separate commands for development, build, and production deployment |
š Installation
npm install -g @mcp-use/cli
npx @mcp-use/cli dev
npm install --save-dev @mcp-use/cli
š Usage
Development Mode
Start a development server with hot reload, automatic TypeScript compilation, and auto-opening inspector:
mcp-use dev [options]
What happens in dev mode:
- TypeScript files are compiled in watch mode
- UI widgets are built with hot reload
- Server runs with auto-restart on changes (via tsx)
- Inspector automatically opens in your browser at
http://localhost:3000/inspector
- MCP endpoint is available at
http://localhost:3000/mcp
Options:
-p, --path <path> - Project directory (default: current directory)
--port <port> - Server port (default: 3000)
--no-open - Don't auto-open inspector in browser
Production Build
Build your MCP application for production deployment:
mcp-use build [options]
What happens during build:
- TypeScript is compiled to JavaScript
- All
.tsx files in resources/ are bundled as standalone HTML pages
- Assets are hashed for optimal caching
- Output is optimized and minified
Options:
-p, --path <path> - Project directory (default: current directory)
Production Server
Start the production server from built files:
mcp-use start [options]
Options:
-p, --path <path> - Project directory (default: current directory)
--port <port> - Server port (default: 3000)
Cloud Deployment
Deploy your MCP server to mcp-use cloud:
mcp-use login
mcp-use whoami
mcp-use deploy [options]
mcp-use logout
Deploy Options:
--name <name> - Custom deployment name
--port <port> - Server port (default: 3000)
--runtime <runtime> - Runtime environment: "node" or "python"
--open - Open deployment in browser after success
Example:
mcp-use deploy
mcp-use deploy --name my-server --port 8000 --open
See ENVIRONMENT.md for configuration options.
š” Examples
Basic Development Workflow
npx create-mcp-use-app my-mcp-server
cd my-mcp-server
mcp-use dev
Custom Port Configuration
mcp-use dev --port 8080
mcp-use build
mcp-use start --port 8080
Working with Different Project Structures
mcp-use dev -p ./my-app
mcp-use build -p ./my-app
mcp-use start -p ./my-app
mcp-use dev --no-open
CI/CD Pipeline Example
npm install
npm run build
npm run start
npm run build
pm2 start "mcp-use start" --name my-mcp-server
š Project Structure
The CLI expects the following project structure:
my-mcp-app/
āāā package.json
āāā tsconfig.json
āāā src/
ā āāā index.ts # Your MCP server entry point
āāā resources/ # UI widgets (React components)
ā āāā todo-list.tsx # Becomes /widgets/todo-list/index.html
ā āāā dashboard.tsx # Becomes /widgets/dashboard/index.html
āāā dist/ # Build output
āāā index.js # Compiled server
āāā resources/
āāā mcp-use/
āāā widgets/
āāā todo-list/
ā āāā index.html
ā āāā assets/
ā āāā index-[hash].js
āāā dashboard/
āāā index.html
āāā assets/
āāā index-[hash].js
šØ Creating UI Widgets
UI widgets are React components that get compiled into standalone HTML pages. They can interact with your MCP server tools using the useMcp hook:
import React, { useState, useEffect } from 'react'
import { useMcp } from 'mcp-use/react'
export default function TaskManager() {
const { callTool, status, error } = useMcp()
const [tasks, setTasks] = useState([])
const [newTask, setNewTask] = useState('')
useEffect(() => {
loadTasks()
}, [])
const loadTasks = async () => {
const result = await callTool('list_tasks')
setTasks(result.tasks)
}
const addTask = async () => {
if (!newTask.trim()) return
await callTool('create_task', {
title: newTask,
status: 'pending',
})
setNewTask('')
await loadTasks()
}
if (status === 'connecting') return <div>Connecting...</div>
if (error) return <div>Error: {error.message}</div>
return (
<div className="p-4">
<h1 className="text-2xl font-bold mb-4">Task Manager</h1>
<div className="flex gap-2 mb-4">
<input
type="text"
value={newTask}
onChange={(e) => setNewTask(e.target.value)}
placeholder="Add a new task..."
className="flex-1 p-2 border rounded"
/>
<button
onClick={addTask}
className="px-4 py-2 bg-blue-500 text-white rounded"
>
Add Task
</button>
</div>
<ul className="space-y-2">
{tasks.map((task) => (
<li key={task.id} className="p-2 border rounded">
{task.title}
</li>
))}
</ul>
</div>
)
}
This widget will be available at http://localhost:3000/widgets/task-manager after building.
š§ Configuration
TypeScript Configuration
Ensure your tsconfig.json includes:
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"jsx": "react-jsx",
"esModuleInterop": true,
"skipLibCheck": true,
"strict": true,
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["src/**/*", "resources/**/*"]
}
Package.json Scripts
Add these scripts for convenience:
{
"scripts": {
"dev": "mcp-use dev",
"build": "mcp-use build",
"start": "mcp-use start",
"serve": "npm run build && npm run start"
}
}
š Advanced Usage
Environment Variables
Development & Build
PORT=8080 mcp-use dev
BUILD_DIR=./build mcp-use build
MCP_URL=https://myserver.com mcp-use build
Deployment & Cloud
For deploying to mcp-use cloud, see ENVIRONMENT.md for detailed configuration:
MCP_WEB_URL=https://mcp-use.com
MCP_API_URL=https://cloud.mcp-use.com
export MCP_WEB_URL=http://localhost:3000
export MCP_API_URL=http://localhost:8000
mcp-use login
mcp-use deploy
See ENVIRONMENT.md for more examples and configuration options.
Docker Deployment
# Dockerfile
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --production
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["npm", "start"]
Integration with Existing Express Apps
If you have an existing Express app, you can mount the built widgets:
import express from 'express'
import path from 'path'
const app = express()
app.use(
'/widgets',
express.static(path.join(__dirname, '../dist/resources/mcp-use/widgets'))
)
š Troubleshooting
Common Issues
Port already in use:
mcp-use dev --port 3001
TypeScript compilation errors:
npm install
Widgets not loading:
- Ensure
.tsx files are in the resources/ directory
- Check that React dependencies are installed
- Verify the build output in
dist/resources/mcp-use/widgets/
Inspector not opening:
mcp-use dev --no-open
š Learn More
š License
MIT Ā© mcp-use