@leanmcp/core 0.2.0 → 0.3.0
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/README.md +82 -54
- package/dist/index.d.mts +12 -2
- package/dist/index.d.ts +12 -2
- package/dist/index.js +875 -812
- package/dist/index.mjs +28 -9
- package/package.json +7 -7
- package/dist/chunk-O6YSETKJ.mjs +0 -6
- package/dist/dist-LQ4M5W3M.mjs +0 -587
package/README.md
CHANGED
|
@@ -77,28 +77,18 @@ export class SentimentService {
|
|
|
77
77
|
|
|
78
78
|
#### Option A: Zero-Config Auto-Discovery (Recommended)
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
The simplest way to create an HTTP server with auto-discovery:
|
|
81
81
|
|
|
82
82
|
```typescript
|
|
83
|
-
import { createHTTPServer
|
|
84
|
-
|
|
85
|
-
// Create MCP server with auto-discovery
|
|
86
|
-
const serverFactory = async () => {
|
|
87
|
-
const server = new MCPServer({
|
|
88
|
-
name: "my-mcp-server",
|
|
89
|
-
version: "1.0.0",
|
|
90
|
-
logging: true // Enable HTTP server logs
|
|
91
|
-
});
|
|
83
|
+
import { createHTTPServer } from "@leanmcp/core";
|
|
92
84
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
// Start HTTP server
|
|
98
|
-
await createHTTPServer(serverFactory, {
|
|
85
|
+
// Create and start HTTP server with auto-discovery
|
|
86
|
+
await createHTTPServer({
|
|
87
|
+
name: "my-mcp-server",
|
|
88
|
+
version: "1.0.0",
|
|
99
89
|
port: 3000,
|
|
100
90
|
cors: true,
|
|
101
|
-
logging: true
|
|
91
|
+
logging: true
|
|
102
92
|
});
|
|
103
93
|
|
|
104
94
|
console.log('\nMCP Server running');
|
|
@@ -106,6 +96,12 @@ console.log('HTTP endpoint: http://localhost:3000/mcp');
|
|
|
106
96
|
console.log('Health check: http://localhost:3000/health');
|
|
107
97
|
```
|
|
108
98
|
|
|
99
|
+
**What happens automatically:**
|
|
100
|
+
- Services are discovered from `./mcp` directory
|
|
101
|
+
- HTTP server is created and started
|
|
102
|
+
- Session management is configured
|
|
103
|
+
- CORS is enabled (if specified)
|
|
104
|
+
|
|
109
105
|
**Directory Structure:**
|
|
110
106
|
```
|
|
111
107
|
your-project/
|
|
@@ -119,15 +115,15 @@ your-project/
|
|
|
119
115
|
└── index.ts # export class DatabaseService
|
|
120
116
|
```
|
|
121
117
|
|
|
122
|
-
#### Option B:
|
|
118
|
+
#### Option B: Factory Pattern (Advanced)
|
|
123
119
|
|
|
124
|
-
|
|
120
|
+
For advanced use cases requiring manual service registration or custom configuration:
|
|
125
121
|
|
|
126
122
|
```typescript
|
|
127
123
|
import { createHTTPServer, MCPServer } from "@leanmcp/core";
|
|
128
124
|
import { SentimentService } from "./services/sentiment";
|
|
129
125
|
|
|
130
|
-
// Create MCP server
|
|
126
|
+
// Create MCP server with factory function
|
|
131
127
|
const serverFactory = async () => {
|
|
132
128
|
const server = new MCPServer({
|
|
133
129
|
name: "my-mcp-server",
|
|
@@ -142,11 +138,11 @@ const serverFactory = async () => {
|
|
|
142
138
|
return server.getServer();
|
|
143
139
|
};
|
|
144
140
|
|
|
145
|
-
// Start HTTP server
|
|
141
|
+
// Start HTTP server with factory
|
|
146
142
|
await createHTTPServer(serverFactory, {
|
|
147
143
|
port: 3000,
|
|
148
144
|
cors: true,
|
|
149
|
-
logging: true
|
|
145
|
+
logging: true
|
|
150
146
|
});
|
|
151
147
|
```
|
|
152
148
|
|
|
@@ -295,32 +291,27 @@ server.getServer(): Server;
|
|
|
295
291
|
|
|
296
292
|
Services are automatically discovered and registered from the `./mcp` directory when the server is created:
|
|
297
293
|
|
|
298
|
-
**Basic Usage:**
|
|
294
|
+
**Basic Usage (Simplified API):**
|
|
299
295
|
```typescript
|
|
300
|
-
|
|
301
|
-
const server = new MCPServer({
|
|
302
|
-
name: "my-server",
|
|
303
|
-
version: "1.0.0",
|
|
304
|
-
logging: true // Enable logging
|
|
305
|
-
});
|
|
296
|
+
import { createHTTPServer } from "@leanmcp/core";
|
|
306
297
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
298
|
+
await createHTTPServer({
|
|
299
|
+
name: "my-server",
|
|
300
|
+
version: "1.0.0",
|
|
301
|
+
port: 3000,
|
|
302
|
+
logging: true // Enable logging
|
|
303
|
+
});
|
|
310
304
|
```
|
|
311
305
|
|
|
312
306
|
**With Debug Logging:**
|
|
313
307
|
```typescript
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
return server.getServer();
|
|
323
|
-
};
|
|
308
|
+
await createHTTPServer({
|
|
309
|
+
name: "my-server",
|
|
310
|
+
version: "1.0.0",
|
|
311
|
+
port: 3000,
|
|
312
|
+
logging: true,
|
|
313
|
+
debug: true // Show detailed service registration logs
|
|
314
|
+
});
|
|
324
315
|
```
|
|
325
316
|
|
|
326
317
|
**With Shared Dependencies:**
|
|
@@ -369,16 +360,16 @@ export class SlackService {
|
|
|
369
360
|
Your main file stays clean:
|
|
370
361
|
|
|
371
362
|
```typescript
|
|
372
|
-
|
|
373
|
-
const server = new MCPServer({
|
|
374
|
-
name: "my-server",
|
|
375
|
-
version: "1.0.0",
|
|
376
|
-
logging: true
|
|
377
|
-
});
|
|
363
|
+
import { createHTTPServer } from "@leanmcp/core";
|
|
378
364
|
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
365
|
+
await createHTTPServer({
|
|
366
|
+
name: "my-server",
|
|
367
|
+
version: "1.0.0",
|
|
368
|
+
port: 3000,
|
|
369
|
+
logging: true
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
// Services are automatically discovered and registered
|
|
382
373
|
```
|
|
383
374
|
|
|
384
375
|
**How It Works:**
|
|
@@ -406,17 +397,54 @@ your-project/
|
|
|
406
397
|
|
|
407
398
|
Create and start an HTTP server with streamable transport.
|
|
408
399
|
|
|
400
|
+
**Simplified API (Recommended):**
|
|
401
|
+
```typescript
|
|
402
|
+
await createHTTPServer({
|
|
403
|
+
name: string; // Server name (required)
|
|
404
|
+
version: string; // Server version (required)
|
|
405
|
+
port?: number; // Port number (default: 3001)
|
|
406
|
+
cors?: boolean | object; // Enable CORS (default: false)
|
|
407
|
+
logging?: boolean; // Enable logging (default: false)
|
|
408
|
+
debug?: boolean; // Enable debug logs (default: false)
|
|
409
|
+
autoDiscover?: boolean; // Auto-discover services (default: true)
|
|
410
|
+
mcpDir?: string; // Custom mcp directory path (optional)
|
|
411
|
+
sessionTimeout?: number; // Session timeout in ms (optional)
|
|
412
|
+
});
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
**Factory Pattern (Advanced):**
|
|
409
416
|
```typescript
|
|
410
417
|
await createHTTPServer(
|
|
411
418
|
serverFactory: () => Server | Promise<Server>,
|
|
412
419
|
options: {
|
|
413
|
-
port?: number;
|
|
414
|
-
cors?: boolean;
|
|
415
|
-
logging?: boolean;
|
|
420
|
+
port?: number; // Port number (default: 3001)
|
|
421
|
+
cors?: boolean | object; // Enable CORS (default: false)
|
|
422
|
+
logging?: boolean; // Enable HTTP request logging (default: false)
|
|
423
|
+
sessionTimeout?: number; // Session timeout in ms (optional)
|
|
416
424
|
}
|
|
417
425
|
);
|
|
418
426
|
```
|
|
419
427
|
|
|
428
|
+
**CORS Configuration:**
|
|
429
|
+
```typescript
|
|
430
|
+
// Simple CORS (allow all origins - not recommended for production)
|
|
431
|
+
await createHTTPServer({
|
|
432
|
+
name: "my-server",
|
|
433
|
+
version: "1.0.0",
|
|
434
|
+
cors: true
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
// Advanced CORS configuration
|
|
438
|
+
await createHTTPServer({
|
|
439
|
+
name: "my-server",
|
|
440
|
+
version: "1.0.0",
|
|
441
|
+
cors: {
|
|
442
|
+
origin: 'https://example.com', // Specific origin
|
|
443
|
+
credentials: true // Allow credentials
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
```
|
|
447
|
+
|
|
420
448
|
### Schema Generation
|
|
421
449
|
|
|
422
450
|
Generate JSON Schema from TypeScript classes:
|
package/dist/index.d.mts
CHANGED
|
@@ -223,11 +223,15 @@ interface HTTPServerOptions {
|
|
|
223
223
|
interface MCPServerFactory {
|
|
224
224
|
(): Server | Promise<Server>;
|
|
225
225
|
}
|
|
226
|
+
type HTTPServerInput = MCPServerFactory | MCPServerConstructorOptions;
|
|
226
227
|
/**
|
|
227
228
|
* Create an HTTP server for MCP with Streamable HTTP transport
|
|
228
229
|
* Returns the HTTP server instance to keep the process alive
|
|
230
|
+
*
|
|
231
|
+
* @param serverInput - Either MCPServerConstructorOptions or a factory function that returns a Server
|
|
232
|
+
* @param options - HTTP server options (only used when serverInput is a factory function)
|
|
229
233
|
*/
|
|
230
|
-
declare function createHTTPServer(
|
|
234
|
+
declare function createHTTPServer(serverInput: HTTPServerInput, options?: HTTPServerOptions): Promise<any>;
|
|
231
235
|
|
|
232
236
|
/**
|
|
233
237
|
* Input validation utilities for LeanMCP
|
|
@@ -324,6 +328,12 @@ interface MCPServerConstructorOptions {
|
|
|
324
328
|
autoDiscover?: boolean;
|
|
325
329
|
mcpDir?: string;
|
|
326
330
|
serviceFactories?: Record<string, () => any>;
|
|
331
|
+
port?: number;
|
|
332
|
+
cors?: boolean | {
|
|
333
|
+
origin?: string | string[];
|
|
334
|
+
credentials?: boolean;
|
|
335
|
+
};
|
|
336
|
+
sessionTimeout?: number;
|
|
327
337
|
}
|
|
328
338
|
interface RegisteredTool {
|
|
329
339
|
name: string;
|
|
@@ -487,4 +497,4 @@ declare class MCPServerRuntime {
|
|
|
487
497
|
*/
|
|
488
498
|
declare function startMCPServer(options: MCPServerOptions): Promise<MCPServerRuntime>;
|
|
489
499
|
|
|
490
|
-
export { Auth, type AuthOptions, Deprecated, type HTTPServerOptions, LogLevel, Logger, type LoggerOptions, MCPServer, type MCPServerConstructorOptions, type MCPServerFactory, type MCPServerOptions, MCPServerRuntime, Optional, Prompt, type PromptOptions, Render, Resource, type ResourceOptions, SchemaConstraint, Tool, type ToolOptions, UI, UserEnvs, classToJsonSchema, classToJsonSchemaWithConstraints, createHTTPServer, defaultLogger, getDecoratedMethods, getMethodMetadata, startMCPServer, validateNonEmpty, validatePath, validatePort, validateServiceName, validateUrl };
|
|
500
|
+
export { Auth, type AuthOptions, Deprecated, type HTTPServerInput, type HTTPServerOptions, LogLevel, Logger, type LoggerOptions, MCPServer, type MCPServerConstructorOptions, type MCPServerFactory, type MCPServerOptions, MCPServerRuntime, Optional, Prompt, type PromptOptions, Render, Resource, type ResourceOptions, SchemaConstraint, Tool, type ToolOptions, UI, UserEnvs, classToJsonSchema, classToJsonSchemaWithConstraints, createHTTPServer, defaultLogger, getDecoratedMethods, getMethodMetadata, startMCPServer, validateNonEmpty, validatePath, validatePort, validateServiceName, validateUrl };
|
package/dist/index.d.ts
CHANGED
|
@@ -223,11 +223,15 @@ interface HTTPServerOptions {
|
|
|
223
223
|
interface MCPServerFactory {
|
|
224
224
|
(): Server | Promise<Server>;
|
|
225
225
|
}
|
|
226
|
+
type HTTPServerInput = MCPServerFactory | MCPServerConstructorOptions;
|
|
226
227
|
/**
|
|
227
228
|
* Create an HTTP server for MCP with Streamable HTTP transport
|
|
228
229
|
* Returns the HTTP server instance to keep the process alive
|
|
230
|
+
*
|
|
231
|
+
* @param serverInput - Either MCPServerConstructorOptions or a factory function that returns a Server
|
|
232
|
+
* @param options - HTTP server options (only used when serverInput is a factory function)
|
|
229
233
|
*/
|
|
230
|
-
declare function createHTTPServer(
|
|
234
|
+
declare function createHTTPServer(serverInput: HTTPServerInput, options?: HTTPServerOptions): Promise<any>;
|
|
231
235
|
|
|
232
236
|
/**
|
|
233
237
|
* Input validation utilities for LeanMCP
|
|
@@ -324,6 +328,12 @@ interface MCPServerConstructorOptions {
|
|
|
324
328
|
autoDiscover?: boolean;
|
|
325
329
|
mcpDir?: string;
|
|
326
330
|
serviceFactories?: Record<string, () => any>;
|
|
331
|
+
port?: number;
|
|
332
|
+
cors?: boolean | {
|
|
333
|
+
origin?: string | string[];
|
|
334
|
+
credentials?: boolean;
|
|
335
|
+
};
|
|
336
|
+
sessionTimeout?: number;
|
|
327
337
|
}
|
|
328
338
|
interface RegisteredTool {
|
|
329
339
|
name: string;
|
|
@@ -487,4 +497,4 @@ declare class MCPServerRuntime {
|
|
|
487
497
|
*/
|
|
488
498
|
declare function startMCPServer(options: MCPServerOptions): Promise<MCPServerRuntime>;
|
|
489
499
|
|
|
490
|
-
export { Auth, type AuthOptions, Deprecated, type HTTPServerOptions, LogLevel, Logger, type LoggerOptions, MCPServer, type MCPServerConstructorOptions, type MCPServerFactory, type MCPServerOptions, MCPServerRuntime, Optional, Prompt, type PromptOptions, Render, Resource, type ResourceOptions, SchemaConstraint, Tool, type ToolOptions, UI, UserEnvs, classToJsonSchema, classToJsonSchemaWithConstraints, createHTTPServer, defaultLogger, getDecoratedMethods, getMethodMetadata, startMCPServer, validateNonEmpty, validatePath, validatePort, validateServiceName, validateUrl };
|
|
500
|
+
export { Auth, type AuthOptions, Deprecated, type HTTPServerInput, type HTTPServerOptions, LogLevel, Logger, type LoggerOptions, MCPServer, type MCPServerConstructorOptions, type MCPServerFactory, type MCPServerOptions, MCPServerRuntime, Optional, Prompt, type PromptOptions, Render, Resource, type ResourceOptions, SchemaConstraint, Tool, type ToolOptions, UI, UserEnvs, classToJsonSchema, classToJsonSchemaWithConstraints, createHTTPServer, defaultLogger, getDecoratedMethods, getMethodMetadata, startMCPServer, validateNonEmpty, validatePath, validatePort, validateServiceName, validateUrl };
|