Skip to content
This repository was archived by the owner on May 21, 2026. It is now read-only.

Commit a92d879

Browse files
committed
feat: implement esbuild-based file routing for UI resources
- Replace Vite with esbuild for faster, more reliable builds - Add file-based routing system for resources/**/*.tsx files - Each TSX file becomes a route at /mcp-use/widgets/{filename} - Self-contained React components with createRoot mounting - Production-ready asset serving with proper hashing - Fix ES module compatibility issues (require -> import) - Add fallback routes for browser-resolved asset paths - Update CLI templates with new build system
1 parent 8a71032 commit a92d879

70 files changed

Lines changed: 11947 additions & 3 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/cli-usage-example.md

Lines changed: 315 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,315 @@
1+
# Create MCP App CLI Usage
2+
3+
The `create-mcp-app` CLI tool allows you to quickly scaffold MCP server projects with different templates.
4+
5+
## Installation
6+
7+
```bash
8+
# Install globally
9+
npm install -g mcp-use
10+
11+
# Or use with npx (recommended)
12+
npx create-mcp-app my-server
13+
```
14+
15+
## Usage
16+
17+
### Basic Usage
18+
19+
```bash
20+
# Create a basic MCP server
21+
npx create-mcp-app my-server
22+
23+
# Create with specific template
24+
npx create-mcp-app my-server --template filesystem
25+
26+
# Skip dependency installation
27+
npx create-mcp-app my-server --no-install
28+
```
29+
30+
### Available Templates
31+
32+
#### 1. Basic Template (default)
33+
```bash
34+
npx create-mcp-app my-server --template basic
35+
```
36+
37+
**Features:**
38+
- Simple echo tool
39+
- Server information resource
40+
- Greeting prompt
41+
- Perfect for learning MCP basics
42+
43+
#### 2. Filesystem Template
44+
```bash
45+
npx create-mcp-app my-server --template filesystem
46+
```
47+
48+
**Features:**
49+
- File reading and listing tools
50+
- Directory operations
51+
- File information tool
52+
- File access templates
53+
- Great for file management servers
54+
55+
#### 3. API Template
56+
```bash
57+
npx create-mcp-app my-server --template api
58+
```
59+
60+
**Features:**
61+
- HTTP GET/POST requests
62+
- Weather API integration
63+
- JSONPlaceholder API
64+
- API documentation prompts
65+
- Perfect for API integration servers
66+
67+
## Project Structure
68+
69+
After running `create-mcp-app`, you'll get:
70+
71+
```
72+
my-server/
73+
├── src/
74+
│ └── server.ts # Main server file
75+
├── package.json # Dependencies and scripts
76+
├── tsconfig.json # TypeScript configuration
77+
└── README.md # Project documentation
78+
```
79+
80+
## Getting Started
81+
82+
1. **Navigate to your project:**
83+
```bash
84+
cd my-server
85+
```
86+
87+
2. **Install dependencies:**
88+
```bash
89+
npm install
90+
# or
91+
pnpm install
92+
# or
93+
yarn install
94+
```
95+
96+
3. **Run in development mode:**
97+
```bash
98+
npm run dev
99+
```
100+
101+
4. **Build for production:**
102+
```bash
103+
npm run build
104+
npm start
105+
```
106+
107+
## Customization
108+
109+
### Adding New Tools
110+
111+
Edit `src/server.ts` to add your own tools:
112+
113+
```typescript
114+
// Add a new tool
115+
mcp.tool({
116+
name: 'my-tool',
117+
description: 'My custom tool',
118+
inputs: [
119+
{
120+
name: 'input',
121+
type: 'string',
122+
description: 'Input parameter',
123+
required: true
124+
}
125+
],
126+
fn: async ({ input }: { input: string }) => {
127+
return `Processed: ${input}`
128+
}
129+
})
130+
```
131+
132+
### Adding New Resources
133+
134+
```typescript
135+
// Add a new resource
136+
mcp.resource({
137+
uri: 'my://resource',
138+
name: 'My Resource',
139+
description: 'Custom resource',
140+
mimeType: 'application/json',
141+
fn: async () => {
142+
return JSON.stringify({ data: 'Hello World' })
143+
}
144+
})
145+
```
146+
147+
### Adding New Prompts
148+
149+
```typescript
150+
// Add a new prompt
151+
mcp.prompt({
152+
name: 'my-prompt',
153+
description: 'Generate custom content',
154+
args: [
155+
{
156+
name: 'topic',
157+
type: 'string',
158+
description: 'Topic to generate content about',
159+
required: true
160+
}
161+
],
162+
fn: async ({ topic }: { topic: string }) => {
163+
return `Generate content about ${topic}`
164+
}
165+
})
166+
```
167+
168+
## Examples
169+
170+
### Basic Server Example
171+
172+
```typescript
173+
import { create } from 'mcp-use/server'
174+
175+
const mcp = create('my-server', {
176+
version: '1.0.0',
177+
description: 'My custom MCP server'
178+
})
179+
180+
// Simple echo tool
181+
mcp.tool({
182+
name: 'echo',
183+
description: 'Echo back the input',
184+
inputs: [
185+
{ name: 'message', type: 'string', required: true }
186+
],
187+
fn: async ({ message }: { message: string }) => {
188+
return `Echo: ${message}`
189+
}
190+
})
191+
192+
mcp.serve().catch(console.error)
193+
```
194+
195+
### Filesystem Server Example
196+
197+
```typescript
198+
import { create } from 'mcp-use/server'
199+
import { readFile, readdir } from 'fs/promises'
200+
201+
const mcp = create('filesystem-server', {
202+
version: '1.0.0'
203+
})
204+
205+
// File reading tool
206+
mcp.tool({
207+
name: 'read-file',
208+
description: 'Read file contents',
209+
inputs: [
210+
{ name: 'path', type: 'string', required: true }
211+
],
212+
fn: async ({ path }: { path: string }) => {
213+
const content = await readFile(path, 'utf-8')
214+
return `Contents of ${path}:\n\n${content}`
215+
}
216+
})
217+
218+
mcp.serve().catch(console.error)
219+
```
220+
221+
### API Server Example
222+
223+
```typescript
224+
import { create } from 'mcp-use/server'
225+
import axios from 'axios'
226+
227+
const mcp = create('api-server', {
228+
version: '1.0.0'
229+
})
230+
231+
// HTTP GET tool
232+
mcp.tool({
233+
name: 'http-get',
234+
description: 'Make HTTP GET requests',
235+
inputs: [
236+
{ name: 'url', type: 'string', required: true }
237+
],
238+
fn: async ({ url }: { url: string }) => {
239+
const response = await axios.get(url)
240+
return JSON.stringify(response.data, null, 2)
241+
}
242+
})
243+
244+
mcp.serve().catch(console.error)
245+
```
246+
247+
## Advanced Usage
248+
249+
### Environment Variables
250+
251+
Create a `.env` file for configuration:
252+
253+
```bash
254+
# .env
255+
API_KEY=your_api_key_here
256+
PORT=3000
257+
DEBUG=true
258+
```
259+
260+
### Custom Templates
261+
262+
You can create your own templates by:
263+
264+
1. Creating a new template directory in `src/cli/templates/`
265+
2. Adding the template files (package.json, tsconfig.json, src/server.ts, README.md)
266+
3. Updating the CLI to include your template
267+
268+
### Publishing Your Server
269+
270+
1. **Build your server:**
271+
```bash
272+
npm run build
273+
```
274+
275+
2. **Test your server:**
276+
```bash
277+
npm start
278+
```
279+
280+
3. **Publish to npm (optional):**
281+
```bash
282+
npm publish
283+
```
284+
285+
## Troubleshooting
286+
287+
### Common Issues
288+
289+
1. **"Cannot find module 'mcp-use/server'"**
290+
- Make sure you've installed dependencies: `npm install`
291+
- Check that mcp-use is in your package.json
292+
293+
2. **"Template not found"**
294+
- Use one of the available templates: basic, filesystem, api
295+
- Check the template name spelling
296+
297+
3. **"Permission denied"**
298+
- Make sure you have write permissions in the current directory
299+
- Try running with `sudo` if necessary (not recommended)
300+
301+
### Getting Help
302+
303+
- **Documentation**: https://docs.mcp-use.io
304+
- **GitHub**: https://github.com/mcp-use/mcp-use-ts
305+
- **Issues**: https://github.com/mcp-use/mcp-use-ts/issues
306+
- **Discord**: https://discord.gg/XkNkSkMz3V
307+
308+
## Next Steps
309+
310+
1. **Explore the examples** in the `examples/` directory
311+
2. **Read the documentation** at https://docs.mcp-use.io
312+
3. **Join the community** on Discord
313+
4. **Contribute** to the project on GitHub
314+
315+
Happy coding! 🚀

0 commit comments

Comments
 (0)