@leanmcp/cli 0.2.11 → 0.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +428 -428
- package/bin/leanmcp.js +3 -3
- package/dist/index.js +1098 -215
- package/package.json +72 -70
package/README.md
CHANGED
|
@@ -1,428 +1,428 @@
|
|
|
1
|
-
# @leanmcp/cli
|
|
2
|
-
|
|
3
|
-
Command-line tool for creating LeanMCP projects with production-ready templates.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- **Interactive setup** - Guided prompts for dependency installation and dev server
|
|
8
|
-
- **Quick project scaffolding** - Create new MCP servers in seconds
|
|
9
|
-
- **Complete setup** - Includes TypeScript, dependencies, and configuration
|
|
10
|
-
- **Best practices** - Generated projects follow MCP standards
|
|
11
|
-
- **Ready to run** - Start developing immediately with hot reload
|
|
12
|
-
- **Example service** - Includes working examples to get started
|
|
13
|
-
- **Pure ESM** - Modern ES modules with full TypeScript support
|
|
14
|
-
|
|
15
|
-
## Installation
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
# npm
|
|
19
|
-
npm install -g @leanmcp/cli
|
|
20
|
-
|
|
21
|
-
# GitHub Packages
|
|
22
|
-
npm install -g @leanmcp/cli --registry=https://npm.pkg.github.com
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
Or use without installing:
|
|
26
|
-
```bash
|
|
27
|
-
npx @leanmcp/cli create my-mcp-server
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
## Usage
|
|
31
|
-
|
|
32
|
-
### Create a New Project
|
|
33
|
-
|
|
34
|
-
```bash
|
|
35
|
-
leanmcp create <project-name>
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
Or with npx:
|
|
39
|
-
```bash
|
|
40
|
-
npx @leanmcp/cli create my-mcp-server
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
### Example
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
$ leanmcp create my-sentiment-tool
|
|
47
|
-
✔ Project my-sentiment-tool created!
|
|
48
|
-
|
|
49
|
-
Success! Your MCP server is ready.
|
|
50
|
-
|
|
51
|
-
Next, navigate to your project:
|
|
52
|
-
cd my-sentiment-tool
|
|
53
|
-
|
|
54
|
-
? Would you like to install dependencies now? (Y/n) Yes
|
|
55
|
-
✔ Dependencies installed successfully!
|
|
56
|
-
? Would you like to start the development server? (Y/n) Yes
|
|
57
|
-
|
|
58
|
-
Starting development server...
|
|
59
|
-
|
|
60
|
-
> my-sentiment-tool@1.0.0 dev
|
|
61
|
-
> tsx watch main.ts
|
|
62
|
-
|
|
63
|
-
[HTTP][INFO] Starting LeanMCP HTTP Server...
|
|
64
|
-
[HTTP][INFO] Server running on http://localhost:3001
|
|
65
|
-
[HTTP][INFO] MCP endpoint: http://localhost:3001/mcp
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
### Add a New Service
|
|
69
|
-
|
|
70
|
-
After creating a project, you can quickly add new services:
|
|
71
|
-
|
|
72
|
-
```bash
|
|
73
|
-
leanmcp add <service-name>
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
This command:
|
|
77
|
-
- Creates a new service file in `mcp/<service-name>.ts`
|
|
78
|
-
- Includes example Tool, Prompt, and Resource decorators
|
|
79
|
-
- Automatically registers the service in `main.ts`
|
|
80
|
-
- Includes schema validation examples
|
|
81
|
-
|
|
82
|
-
**Example:**
|
|
83
|
-
|
|
84
|
-
```bash
|
|
85
|
-
$ leanmcp add weather
|
|
86
|
-
✔ Created new service: weather
|
|
87
|
-
File: mcp/weather.ts
|
|
88
|
-
Tool: greet
|
|
89
|
-
Prompt: welcomePrompt
|
|
90
|
-
Resource: getStatus
|
|
91
|
-
|
|
92
|
-
Service automatically registered in main.ts!
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
The generated service includes:
|
|
96
|
-
- **Tool** - `greet()`: A callable function with schema validation
|
|
97
|
-
- **Prompt** - `welcomePrompt()`: A reusable prompt template
|
|
98
|
-
- **Resource** - `getStatus()`: A data endpoint
|
|
99
|
-
|
|
100
|
-
You can then customize these to fit your needs.
|
|
101
|
-
|
|
102
|
-
## Generated Project Structure
|
|
103
|
-
|
|
104
|
-
```
|
|
105
|
-
my-mcp-server/
|
|
106
|
-
├── main.ts # Entry point with HTTP server
|
|
107
|
-
├── package.json # Dependencies and scripts
|
|
108
|
-
├── tsconfig.json # TypeScript configuration
|
|
109
|
-
└── mcp/ # Services directory
|
|
110
|
-
└── example.ts # Example service with tools
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
## Generated Files
|
|
114
|
-
|
|
115
|
-
### main.ts
|
|
116
|
-
Entry point that:
|
|
117
|
-
- Loads environment variables
|
|
118
|
-
- Creates MCP server instance
|
|
119
|
-
- Registers services
|
|
120
|
-
- Starts HTTP server with session management
|
|
121
|
-
|
|
122
|
-
### mcp/example.ts
|
|
123
|
-
Example service demonstrating:
|
|
124
|
-
- `@Tool` decorator for callable functions
|
|
125
|
-
- `@Resource` decorator for data sources
|
|
126
|
-
- `@Prompt` decorator for prompt templates
|
|
127
|
-
- Class-based schema validation with `@SchemaConstraint`
|
|
128
|
-
- Input/output type safety
|
|
129
|
-
|
|
130
|
-
### package.json
|
|
131
|
-
Includes:
|
|
132
|
-
- `@leanmcp/core` - Core MCP functionality
|
|
133
|
-
- `@modelcontextprotocol/sdk` - Official MCP SDK
|
|
134
|
-
- `express` - HTTP server
|
|
135
|
-
- `tsx` - TypeScript execution with hot reload
|
|
136
|
-
- All type definitions
|
|
137
|
-
|
|
138
|
-
### tsconfig.json
|
|
139
|
-
Configured with:
|
|
140
|
-
- ESNext modules
|
|
141
|
-
- Decorator support
|
|
142
|
-
- Strict type checking
|
|
143
|
-
- Source maps
|
|
144
|
-
|
|
145
|
-
## NPM Scripts
|
|
146
|
-
|
|
147
|
-
Generated projects include:
|
|
148
|
-
|
|
149
|
-
```bash
|
|
150
|
-
npm run dev # Start with hot reload (tsx watch)
|
|
151
|
-
npm run build # Build for production
|
|
152
|
-
npm run start # Run production build
|
|
153
|
-
npm run clean # Remove build artifacts
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
## Development Workflow
|
|
157
|
-
|
|
158
|
-
### Interactive Setup (Recommended)
|
|
159
|
-
|
|
160
|
-
The CLI provides an interactive setup experience:
|
|
161
|
-
|
|
162
|
-
```bash
|
|
163
|
-
# Create project
|
|
164
|
-
leanmcp create my-mcp-server
|
|
165
|
-
|
|
166
|
-
# The CLI will:
|
|
167
|
-
# 1. Create project structure
|
|
168
|
-
# 2. Ask if you want to install dependencies (Y/n)
|
|
169
|
-
# 3. If yes, ask if you want to start dev server (Y/n)
|
|
170
|
-
# 4. If yes, start server with hot reload
|
|
171
|
-
|
|
172
|
-
# If you choose "No" to installation:
|
|
173
|
-
cd my-mcp-server
|
|
174
|
-
npm install
|
|
175
|
-
npm run dev
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
### Manual Setup
|
|
179
|
-
|
|
180
|
-
If you prefer manual control:
|
|
181
|
-
|
|
182
|
-
```bash
|
|
183
|
-
# 1. Create project (answer "No" to prompts)
|
|
184
|
-
leanmcp create my-mcp-server
|
|
185
|
-
|
|
186
|
-
# 2. Navigate to project
|
|
187
|
-
cd my-mcp-server
|
|
188
|
-
|
|
189
|
-
# 3. Install dependencies
|
|
190
|
-
npm install
|
|
191
|
-
|
|
192
|
-
# 4. Start development server
|
|
193
|
-
npm run dev
|
|
194
|
-
|
|
195
|
-
# 5. Server starts on http://localhost:3001
|
|
196
|
-
# - Endpoint: http://localhost:3001/mcp
|
|
197
|
-
# - Health check: http://localhost:3001/health
|
|
198
|
-
# - Hot reload enabled
|
|
199
|
-
|
|
200
|
-
# 6. Edit files in mcp/ directory
|
|
201
|
-
# Server automatically reloads on changes
|
|
202
|
-
```
|
|
203
|
-
|
|
204
|
-
## Testing Your Server
|
|
205
|
-
|
|
206
|
-
Test with curl:
|
|
207
|
-
```bash
|
|
208
|
-
# List available tools
|
|
209
|
-
curl http://localhost:3001/mcp \
|
|
210
|
-
-X POST \
|
|
211
|
-
-H "Content-Type: application/json" \
|
|
212
|
-
-d '{
|
|
213
|
-
"jsonrpc": "2.0",
|
|
214
|
-
"id": 1,
|
|
215
|
-
"method": "tools/list"
|
|
216
|
-
}'
|
|
217
|
-
|
|
218
|
-
# Call a tool
|
|
219
|
-
curl http://localhost:3001/mcp \
|
|
220
|
-
-X POST \
|
|
221
|
-
-H "Content-Type: application/json" \
|
|
222
|
-
-d '{
|
|
223
|
-
"jsonrpc": "2.0",
|
|
224
|
-
"id": 1,
|
|
225
|
-
"method": "tools/call",
|
|
226
|
-
"params": {
|
|
227
|
-
"name": "calculate",
|
|
228
|
-
"arguments": {
|
|
229
|
-
"a": 10,
|
|
230
|
-
"b": 5,
|
|
231
|
-
"operation": "add"
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}'
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
## Customizing Generated Projects
|
|
238
|
-
|
|
239
|
-
### Add New Services
|
|
240
|
-
|
|
241
|
-
**Quick Way (Recommended):**
|
|
242
|
-
|
|
243
|
-
Use the `add` command to automatically generate and register a new service:
|
|
244
|
-
|
|
245
|
-
```bash
|
|
246
|
-
leanmcp add weather
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
This creates `mcp/weather.ts` with example Tool, Prompt, and Resource decorators, and automatically registers it in `main.ts`.
|
|
250
|
-
|
|
251
|
-
**Manual Way:**
|
|
252
|
-
|
|
253
|
-
Create a new file in `mcp/`:
|
|
254
|
-
|
|
255
|
-
```typescript
|
|
256
|
-
// mcp/weather.ts
|
|
257
|
-
import { Tool } from "@leanmcp/core";
|
|
258
|
-
|
|
259
|
-
export class WeatherService {
|
|
260
|
-
@Tool({ description: 'Get weather for a city' })
|
|
261
|
-
async getWeather(input: { city: string }) {
|
|
262
|
-
// Your implementation
|
|
263
|
-
return { temperature: 72, condition: 'sunny' };
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
Register in `main.ts`:
|
|
269
|
-
```typescript
|
|
270
|
-
import { WeatherService } from "./mcp/weather.js";
|
|
271
|
-
|
|
272
|
-
server.registerService(new WeatherService());
|
|
273
|
-
```
|
|
274
|
-
|
|
275
|
-
### Add Authentication
|
|
276
|
-
|
|
277
|
-
Install auth package:
|
|
278
|
-
```bash
|
|
279
|
-
npm install @leanmcp/auth
|
|
280
|
-
```
|
|
281
|
-
|
|
282
|
-
See [@leanmcp/auth](../auth) documentation for details.
|
|
283
|
-
|
|
284
|
-
### Configure Port
|
|
285
|
-
|
|
286
|
-
Set in environment variable:
|
|
287
|
-
```bash
|
|
288
|
-
PORT=4000 npm run dev
|
|
289
|
-
```
|
|
290
|
-
|
|
291
|
-
Or in `.env` file:
|
|
292
|
-
```bash
|
|
293
|
-
PORT=4000
|
|
294
|
-
```
|
|
295
|
-
|
|
296
|
-
## Advanced Options
|
|
297
|
-
|
|
298
|
-
### Custom Project Location
|
|
299
|
-
|
|
300
|
-
```bash
|
|
301
|
-
leanmcp create my-project
|
|
302
|
-
cd my-project
|
|
303
|
-
```
|
|
304
|
-
|
|
305
|
-
Project is created in current directory with the specified name.
|
|
306
|
-
|
|
307
|
-
### Modify Template
|
|
308
|
-
|
|
309
|
-
The generated project is fully customizable:
|
|
310
|
-
- Edit `main.ts` for server configuration
|
|
311
|
-
- Add/remove services in `mcp/` directory
|
|
312
|
-
- Modify `package.json` for additional dependencies
|
|
313
|
-
- Update `tsconfig.json` for compiler options
|
|
314
|
-
|
|
315
|
-
## Troubleshooting
|
|
316
|
-
|
|
317
|
-
### Port Already in Use
|
|
318
|
-
|
|
319
|
-
Change the port in `.env`:
|
|
320
|
-
```bash
|
|
321
|
-
PORT=3002
|
|
322
|
-
```
|
|
323
|
-
|
|
324
|
-
### Module Not Found Errors
|
|
325
|
-
|
|
326
|
-
Ensure you've installed dependencies:
|
|
327
|
-
```bash
|
|
328
|
-
npm install
|
|
329
|
-
```
|
|
330
|
-
|
|
331
|
-
### TypeScript Errors
|
|
332
|
-
|
|
333
|
-
Check your `tsconfig.json` and ensure:
|
|
334
|
-
- `experimentalDecorators: true`
|
|
335
|
-
- `emitDecoratorMetadata: true`
|
|
336
|
-
|
|
337
|
-
### Hot Reload Not Working
|
|
338
|
-
|
|
339
|
-
Try restarting the dev server:
|
|
340
|
-
```bash
|
|
341
|
-
npm run dev
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
## Project Types
|
|
345
|
-
|
|
346
|
-
Currently supports:
|
|
347
|
-
- **MCP Server** - Standard MCP server with HTTP transport
|
|
348
|
-
|
|
349
|
-
Coming soon:
|
|
350
|
-
- MCP Server with Auth
|
|
351
|
-
- MCP Server with Database
|
|
352
|
-
- MCP Server with File Storage
|
|
353
|
-
|
|
354
|
-
## Examples
|
|
355
|
-
|
|
356
|
-
See the [examples](../../examples) directory for complete working examples:
|
|
357
|
-
- [basic-sentiment-tool](../../examples/basic-sentiment-tool) - Simple sentiment analysis
|
|
358
|
-
- [slack-with-auth](../../examples/slack-with-auth) - Slack integration with Cognito auth
|
|
359
|
-
|
|
360
|
-
## Requirements
|
|
361
|
-
|
|
362
|
-
- Node.js >= 18.0.0
|
|
363
|
-
- npm >= 9.0.0
|
|
364
|
-
|
|
365
|
-
## CLI Commands
|
|
366
|
-
|
|
367
|
-
```bash
|
|
368
|
-
leanmcp create <name> # Create new project
|
|
369
|
-
leanmcp add <service> # Add new service to existing project
|
|
370
|
-
leanmcp --version # Show version
|
|
371
|
-
leanmcp --help # Show help
|
|
372
|
-
```
|
|
373
|
-
|
|
374
|
-
### Command Details
|
|
375
|
-
|
|
376
|
-
#### `create <project-name>`
|
|
377
|
-
Creates a complete MCP server project with:
|
|
378
|
-
- Entry point (`main.ts`)
|
|
379
|
-
- Example service with Tool, Resource, and Prompt decorators
|
|
380
|
-
- TypeScript configuration
|
|
381
|
-
- Package.json with all dependencies
|
|
382
|
-
- Development and build scripts
|
|
383
|
-
|
|
384
|
-
**Interactive Prompts:**
|
|
385
|
-
- Asks if you want to install dependencies
|
|
386
|
-
- If installed, asks if you want to start dev server
|
|
387
|
-
- Runs commands in the project directory automatically
|
|
388
|
-
|
|
389
|
-
#### `add <service-name>`
|
|
390
|
-
Adds a new service to an existing project:
|
|
391
|
-
- Must be run inside a LeanMCP project directory
|
|
392
|
-
- Creates `mcp/<service-name>.ts` with template code
|
|
393
|
-
- Automatically imports and registers in `main.ts`
|
|
394
|
-
- Includes example Tool, Prompt, and Resource implementations
|
|
395
|
-
- Uses schema validation with `@SchemaConstraint` decorators
|
|
396
|
-
|
|
397
|
-
## 🌟 Showcase Your MCP Server
|
|
398
|
-
|
|
399
|
-
Built something cool with LeanMCP? We'd love to feature it!
|
|
400
|
-
|
|
401
|
-
### How to Get Featured
|
|
402
|
-
|
|
403
|
-
1. **Build** an awesome MCP server using LeanMCP
|
|
404
|
-
2. **Share** your project on GitHub
|
|
405
|
-
3. **Submit** for showcase:
|
|
406
|
-
- Open an issue: [Request Showcase](https://github.com/LeanMCP/leanmcp-sdk/issues/new?title=[Showcase]%20Your%20Project%20Name)
|
|
407
|
-
- Include:
|
|
408
|
-
- Project name and description
|
|
409
|
-
- GitHub repository link
|
|
410
|
-
- What makes it unique
|
|
411
|
-
- Screenshots or demo
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
## License
|
|
415
|
-
|
|
416
|
-
MIT
|
|
417
|
-
|
|
418
|
-
## Related Packages
|
|
419
|
-
|
|
420
|
-
- [@leanmcp/core](../core) - Core MCP server functionality
|
|
421
|
-
- [@leanmcp/auth](../auth) - Authentication decorators
|
|
422
|
-
- [@leanmcp/utils](../utils) - Utility functions
|
|
423
|
-
|
|
424
|
-
## Links
|
|
425
|
-
|
|
426
|
-
- [GitHub Repository](https://github.com/LeanMCP/leanmcp-sdk)
|
|
427
|
-
- [Documentation](https://github.com/LeanMCP/leanmcp-sdk#readme)
|
|
428
|
-
- [MCP Specification](https://spec.modelcontextprotocol.io/)
|
|
1
|
+
# @leanmcp/cli
|
|
2
|
+
|
|
3
|
+
Command-line tool for creating LeanMCP projects with production-ready templates.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Interactive setup** - Guided prompts for dependency installation and dev server
|
|
8
|
+
- **Quick project scaffolding** - Create new MCP servers in seconds
|
|
9
|
+
- **Complete setup** - Includes TypeScript, dependencies, and configuration
|
|
10
|
+
- **Best practices** - Generated projects follow MCP standards
|
|
11
|
+
- **Ready to run** - Start developing immediately with hot reload
|
|
12
|
+
- **Example service** - Includes working examples to get started
|
|
13
|
+
- **Pure ESM** - Modern ES modules with full TypeScript support
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# npm
|
|
19
|
+
npm install -g @leanmcp/cli
|
|
20
|
+
|
|
21
|
+
# GitHub Packages
|
|
22
|
+
npm install -g @leanmcp/cli --registry=https://npm.pkg.github.com
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Or use without installing:
|
|
26
|
+
```bash
|
|
27
|
+
npx @leanmcp/cli create my-mcp-server
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
### Create a New Project
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
leanmcp create <project-name>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Or with npx:
|
|
39
|
+
```bash
|
|
40
|
+
npx @leanmcp/cli create my-mcp-server
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Example
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
$ leanmcp create my-sentiment-tool
|
|
47
|
+
✔ Project my-sentiment-tool created!
|
|
48
|
+
|
|
49
|
+
Success! Your MCP server is ready.
|
|
50
|
+
|
|
51
|
+
Next, navigate to your project:
|
|
52
|
+
cd my-sentiment-tool
|
|
53
|
+
|
|
54
|
+
? Would you like to install dependencies now? (Y/n) Yes
|
|
55
|
+
✔ Dependencies installed successfully!
|
|
56
|
+
? Would you like to start the development server? (Y/n) Yes
|
|
57
|
+
|
|
58
|
+
Starting development server...
|
|
59
|
+
|
|
60
|
+
> my-sentiment-tool@1.0.0 dev
|
|
61
|
+
> tsx watch main.ts
|
|
62
|
+
|
|
63
|
+
[HTTP][INFO] Starting LeanMCP HTTP Server...
|
|
64
|
+
[HTTP][INFO] Server running on http://localhost:3001
|
|
65
|
+
[HTTP][INFO] MCP endpoint: http://localhost:3001/mcp
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Add a New Service
|
|
69
|
+
|
|
70
|
+
After creating a project, you can quickly add new services:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
leanmcp add <service-name>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
This command:
|
|
77
|
+
- Creates a new service file in `mcp/<service-name>.ts`
|
|
78
|
+
- Includes example Tool, Prompt, and Resource decorators
|
|
79
|
+
- Automatically registers the service in `main.ts`
|
|
80
|
+
- Includes schema validation examples
|
|
81
|
+
|
|
82
|
+
**Example:**
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
$ leanmcp add weather
|
|
86
|
+
✔ Created new service: weather
|
|
87
|
+
File: mcp/weather.ts
|
|
88
|
+
Tool: greet
|
|
89
|
+
Prompt: welcomePrompt
|
|
90
|
+
Resource: getStatus
|
|
91
|
+
|
|
92
|
+
Service automatically registered in main.ts!
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The generated service includes:
|
|
96
|
+
- **Tool** - `greet()`: A callable function with schema validation
|
|
97
|
+
- **Prompt** - `welcomePrompt()`: A reusable prompt template
|
|
98
|
+
- **Resource** - `getStatus()`: A data endpoint
|
|
99
|
+
|
|
100
|
+
You can then customize these to fit your needs.
|
|
101
|
+
|
|
102
|
+
## Generated Project Structure
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
my-mcp-server/
|
|
106
|
+
├── main.ts # Entry point with HTTP server
|
|
107
|
+
├── package.json # Dependencies and scripts
|
|
108
|
+
├── tsconfig.json # TypeScript configuration
|
|
109
|
+
└── mcp/ # Services directory
|
|
110
|
+
└── example.ts # Example service with tools
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Generated Files
|
|
114
|
+
|
|
115
|
+
### main.ts
|
|
116
|
+
Entry point that:
|
|
117
|
+
- Loads environment variables
|
|
118
|
+
- Creates MCP server instance
|
|
119
|
+
- Registers services
|
|
120
|
+
- Starts HTTP server with session management
|
|
121
|
+
|
|
122
|
+
### mcp/example.ts
|
|
123
|
+
Example service demonstrating:
|
|
124
|
+
- `@Tool` decorator for callable functions
|
|
125
|
+
- `@Resource` decorator for data sources
|
|
126
|
+
- `@Prompt` decorator for prompt templates
|
|
127
|
+
- Class-based schema validation with `@SchemaConstraint`
|
|
128
|
+
- Input/output type safety
|
|
129
|
+
|
|
130
|
+
### package.json
|
|
131
|
+
Includes:
|
|
132
|
+
- `@leanmcp/core` - Core MCP functionality
|
|
133
|
+
- `@modelcontextprotocol/sdk` - Official MCP SDK
|
|
134
|
+
- `express` - HTTP server
|
|
135
|
+
- `tsx` - TypeScript execution with hot reload
|
|
136
|
+
- All type definitions
|
|
137
|
+
|
|
138
|
+
### tsconfig.json
|
|
139
|
+
Configured with:
|
|
140
|
+
- ESNext modules
|
|
141
|
+
- Decorator support
|
|
142
|
+
- Strict type checking
|
|
143
|
+
- Source maps
|
|
144
|
+
|
|
145
|
+
## NPM Scripts
|
|
146
|
+
|
|
147
|
+
Generated projects include:
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
npm run dev # Start with hot reload (tsx watch)
|
|
151
|
+
npm run build # Build for production
|
|
152
|
+
npm run start # Run production build
|
|
153
|
+
npm run clean # Remove build artifacts
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Development Workflow
|
|
157
|
+
|
|
158
|
+
### Interactive Setup (Recommended)
|
|
159
|
+
|
|
160
|
+
The CLI provides an interactive setup experience:
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
# Create project
|
|
164
|
+
leanmcp create my-mcp-server
|
|
165
|
+
|
|
166
|
+
# The CLI will:
|
|
167
|
+
# 1. Create project structure
|
|
168
|
+
# 2. Ask if you want to install dependencies (Y/n)
|
|
169
|
+
# 3. If yes, ask if you want to start dev server (Y/n)
|
|
170
|
+
# 4. If yes, start server with hot reload
|
|
171
|
+
|
|
172
|
+
# If you choose "No" to installation:
|
|
173
|
+
cd my-mcp-server
|
|
174
|
+
npm install
|
|
175
|
+
npm run dev
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Manual Setup
|
|
179
|
+
|
|
180
|
+
If you prefer manual control:
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
# 1. Create project (answer "No" to prompts)
|
|
184
|
+
leanmcp create my-mcp-server
|
|
185
|
+
|
|
186
|
+
# 2. Navigate to project
|
|
187
|
+
cd my-mcp-server
|
|
188
|
+
|
|
189
|
+
# 3. Install dependencies
|
|
190
|
+
npm install
|
|
191
|
+
|
|
192
|
+
# 4. Start development server
|
|
193
|
+
npm run dev
|
|
194
|
+
|
|
195
|
+
# 5. Server starts on http://localhost:3001
|
|
196
|
+
# - Endpoint: http://localhost:3001/mcp
|
|
197
|
+
# - Health check: http://localhost:3001/health
|
|
198
|
+
# - Hot reload enabled
|
|
199
|
+
|
|
200
|
+
# 6. Edit files in mcp/ directory
|
|
201
|
+
# Server automatically reloads on changes
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## Testing Your Server
|
|
205
|
+
|
|
206
|
+
Test with curl:
|
|
207
|
+
```bash
|
|
208
|
+
# List available tools
|
|
209
|
+
curl http://localhost:3001/mcp \
|
|
210
|
+
-X POST \
|
|
211
|
+
-H "Content-Type: application/json" \
|
|
212
|
+
-d '{
|
|
213
|
+
"jsonrpc": "2.0",
|
|
214
|
+
"id": 1,
|
|
215
|
+
"method": "tools/list"
|
|
216
|
+
}'
|
|
217
|
+
|
|
218
|
+
# Call a tool
|
|
219
|
+
curl http://localhost:3001/mcp \
|
|
220
|
+
-X POST \
|
|
221
|
+
-H "Content-Type: application/json" \
|
|
222
|
+
-d '{
|
|
223
|
+
"jsonrpc": "2.0",
|
|
224
|
+
"id": 1,
|
|
225
|
+
"method": "tools/call",
|
|
226
|
+
"params": {
|
|
227
|
+
"name": "calculate",
|
|
228
|
+
"arguments": {
|
|
229
|
+
"a": 10,
|
|
230
|
+
"b": 5,
|
|
231
|
+
"operation": "add"
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}'
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Customizing Generated Projects
|
|
238
|
+
|
|
239
|
+
### Add New Services
|
|
240
|
+
|
|
241
|
+
**Quick Way (Recommended):**
|
|
242
|
+
|
|
243
|
+
Use the `add` command to automatically generate and register a new service:
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
leanmcp add weather
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
This creates `mcp/weather.ts` with example Tool, Prompt, and Resource decorators, and automatically registers it in `main.ts`.
|
|
250
|
+
|
|
251
|
+
**Manual Way:**
|
|
252
|
+
|
|
253
|
+
Create a new file in `mcp/`:
|
|
254
|
+
|
|
255
|
+
```typescript
|
|
256
|
+
// mcp/weather.ts
|
|
257
|
+
import { Tool } from "@leanmcp/core";
|
|
258
|
+
|
|
259
|
+
export class WeatherService {
|
|
260
|
+
@Tool({ description: 'Get weather for a city' })
|
|
261
|
+
async getWeather(input: { city: string }) {
|
|
262
|
+
// Your implementation
|
|
263
|
+
return { temperature: 72, condition: 'sunny' };
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
Register in `main.ts`:
|
|
269
|
+
```typescript
|
|
270
|
+
import { WeatherService } from "./mcp/weather.js";
|
|
271
|
+
|
|
272
|
+
server.registerService(new WeatherService());
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Add Authentication
|
|
276
|
+
|
|
277
|
+
Install auth package:
|
|
278
|
+
```bash
|
|
279
|
+
npm install @leanmcp/auth
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
See [@leanmcp/auth](../auth) documentation for details.
|
|
283
|
+
|
|
284
|
+
### Configure Port
|
|
285
|
+
|
|
286
|
+
Set in environment variable:
|
|
287
|
+
```bash
|
|
288
|
+
PORT=4000 npm run dev
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
Or in `.env` file:
|
|
292
|
+
```bash
|
|
293
|
+
PORT=4000
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## Advanced Options
|
|
297
|
+
|
|
298
|
+
### Custom Project Location
|
|
299
|
+
|
|
300
|
+
```bash
|
|
301
|
+
leanmcp create my-project
|
|
302
|
+
cd my-project
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
Project is created in current directory with the specified name.
|
|
306
|
+
|
|
307
|
+
### Modify Template
|
|
308
|
+
|
|
309
|
+
The generated project is fully customizable:
|
|
310
|
+
- Edit `main.ts` for server configuration
|
|
311
|
+
- Add/remove services in `mcp/` directory
|
|
312
|
+
- Modify `package.json` for additional dependencies
|
|
313
|
+
- Update `tsconfig.json` for compiler options
|
|
314
|
+
|
|
315
|
+
## Troubleshooting
|
|
316
|
+
|
|
317
|
+
### Port Already in Use
|
|
318
|
+
|
|
319
|
+
Change the port in `.env`:
|
|
320
|
+
```bash
|
|
321
|
+
PORT=3002
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### Module Not Found Errors
|
|
325
|
+
|
|
326
|
+
Ensure you've installed dependencies:
|
|
327
|
+
```bash
|
|
328
|
+
npm install
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
### TypeScript Errors
|
|
332
|
+
|
|
333
|
+
Check your `tsconfig.json` and ensure:
|
|
334
|
+
- `experimentalDecorators: true`
|
|
335
|
+
- `emitDecoratorMetadata: true`
|
|
336
|
+
|
|
337
|
+
### Hot Reload Not Working
|
|
338
|
+
|
|
339
|
+
Try restarting the dev server:
|
|
340
|
+
```bash
|
|
341
|
+
npm run dev
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
## Project Types
|
|
345
|
+
|
|
346
|
+
Currently supports:
|
|
347
|
+
- **MCP Server** - Standard MCP server with HTTP transport
|
|
348
|
+
|
|
349
|
+
Coming soon:
|
|
350
|
+
- MCP Server with Auth
|
|
351
|
+
- MCP Server with Database
|
|
352
|
+
- MCP Server with File Storage
|
|
353
|
+
|
|
354
|
+
## Examples
|
|
355
|
+
|
|
356
|
+
See the [examples](../../examples) directory for complete working examples:
|
|
357
|
+
- [basic-sentiment-tool](../../examples/basic-sentiment-tool) - Simple sentiment analysis
|
|
358
|
+
- [slack-with-auth](../../examples/slack-with-auth) - Slack integration with Cognito auth
|
|
359
|
+
|
|
360
|
+
## Requirements
|
|
361
|
+
|
|
362
|
+
- Node.js >= 18.0.0
|
|
363
|
+
- npm >= 9.0.0
|
|
364
|
+
|
|
365
|
+
## CLI Commands
|
|
366
|
+
|
|
367
|
+
```bash
|
|
368
|
+
leanmcp create <name> # Create new project
|
|
369
|
+
leanmcp add <service> # Add new service to existing project
|
|
370
|
+
leanmcp --version # Show version
|
|
371
|
+
leanmcp --help # Show help
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
### Command Details
|
|
375
|
+
|
|
376
|
+
#### `create <project-name>`
|
|
377
|
+
Creates a complete MCP server project with:
|
|
378
|
+
- Entry point (`main.ts`)
|
|
379
|
+
- Example service with Tool, Resource, and Prompt decorators
|
|
380
|
+
- TypeScript configuration
|
|
381
|
+
- Package.json with all dependencies
|
|
382
|
+
- Development and build scripts
|
|
383
|
+
|
|
384
|
+
**Interactive Prompts:**
|
|
385
|
+
- Asks if you want to install dependencies
|
|
386
|
+
- If installed, asks if you want to start dev server
|
|
387
|
+
- Runs commands in the project directory automatically
|
|
388
|
+
|
|
389
|
+
#### `add <service-name>`
|
|
390
|
+
Adds a new service to an existing project:
|
|
391
|
+
- Must be run inside a LeanMCP project directory
|
|
392
|
+
- Creates `mcp/<service-name>.ts` with template code
|
|
393
|
+
- Automatically imports and registers in `main.ts`
|
|
394
|
+
- Includes example Tool, Prompt, and Resource implementations
|
|
395
|
+
- Uses schema validation with `@SchemaConstraint` decorators
|
|
396
|
+
|
|
397
|
+
## 🌟 Showcase Your MCP Server
|
|
398
|
+
|
|
399
|
+
Built something cool with LeanMCP? We'd love to feature it!
|
|
400
|
+
|
|
401
|
+
### How to Get Featured
|
|
402
|
+
|
|
403
|
+
1. **Build** an awesome MCP server using LeanMCP
|
|
404
|
+
2. **Share** your project on GitHub
|
|
405
|
+
3. **Submit** for showcase:
|
|
406
|
+
- Open an issue: [Request Showcase](https://github.com/LeanMCP/leanmcp-sdk/issues/new?title=[Showcase]%20Your%20Project%20Name)
|
|
407
|
+
- Include:
|
|
408
|
+
- Project name and description
|
|
409
|
+
- GitHub repository link
|
|
410
|
+
- What makes it unique
|
|
411
|
+
- Screenshots or demo
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
## License
|
|
415
|
+
|
|
416
|
+
MIT
|
|
417
|
+
|
|
418
|
+
## Related Packages
|
|
419
|
+
|
|
420
|
+
- [@leanmcp/core](../core) - Core MCP server functionality
|
|
421
|
+
- [@leanmcp/auth](../auth) - Authentication decorators
|
|
422
|
+
- [@leanmcp/utils](../utils) - Utility functions
|
|
423
|
+
|
|
424
|
+
## Links
|
|
425
|
+
|
|
426
|
+
- [GitHub Repository](https://github.com/LeanMCP/leanmcp-sdk)
|
|
427
|
+
- [Documentation](https://github.com/LeanMCP/leanmcp-sdk#readme)
|
|
428
|
+
- [MCP Specification](https://spec.modelcontextprotocol.io/)
|