apprecio-mcp-base 1.0.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 +301 -0
- package/dist/core/McpBaseServer.d.ts +59 -0
- package/dist/core/McpBaseServer.d.ts.map +1 -0
- package/dist/core/McpBaseServer.js +113 -0
- package/dist/core/McpBaseServer.js.map +1 -0
- package/dist/core/config.d.ts +81 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +122 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/logger.d.ts +14 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/logger.js +65 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/types.d.ts +113 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +2 -0
- package/dist/core/types.js.map +1 -0
- package/dist/database/mongodb.d.ts +35 -0
- package/dist/database/mongodb.d.ts.map +1 -0
- package/dist/database/mongodb.js +85 -0
- package/dist/database/mongodb.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware/auth.d.ts +26 -0
- package/dist/middleware/auth.d.ts.map +1 -0
- package/dist/middleware/auth.js +100 -0
- package/dist/middleware/auth.js.map +1 -0
- package/dist/server/createExpressServer.d.ts +13 -0
- package/dist/server/createExpressServer.d.ts.map +1 -0
- package/dist/server/createExpressServer.js +98 -0
- package/dist/server/createExpressServer.js.map +1 -0
- package/dist/src/core/McpBaseServer.d.ts +59 -0
- package/dist/src/core/McpBaseServer.d.ts.map +1 -0
- package/dist/src/core/McpBaseServer.js +113 -0
- package/dist/src/core/McpBaseServer.js.map +1 -0
- package/dist/src/core/config.d.ts +81 -0
- package/dist/src/core/config.d.ts.map +1 -0
- package/dist/src/core/config.js +122 -0
- package/dist/src/core/config.js.map +1 -0
- package/dist/src/core/logger.d.ts +14 -0
- package/dist/src/core/logger.d.ts.map +1 -0
- package/dist/src/core/logger.js +65 -0
- package/dist/src/core/logger.js.map +1 -0
- package/dist/src/core/types.d.ts +113 -0
- package/dist/src/core/types.d.ts.map +1 -0
- package/dist/src/core/types.js +2 -0
- package/dist/src/core/types.js.map +1 -0
- package/dist/src/database/mongodb.d.ts +35 -0
- package/dist/src/database/mongodb.d.ts.map +1 -0
- package/dist/src/database/mongodb.js +85 -0
- package/dist/src/database/mongodb.js.map +1 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +13 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/middleware/auth.d.ts +26 -0
- package/dist/src/middleware/auth.d.ts.map +1 -0
- package/dist/src/middleware/auth.js +100 -0
- package/dist/src/middleware/auth.js.map +1 -0
- package/dist/src/server/createExpressServer.d.ts +13 -0
- package/dist/src/server/createExpressServer.d.ts.map +1 -0
- package/dist/src/server/createExpressServer.js +98 -0
- package/dist/src/server/createExpressServer.js.map +1 -0
- package/dist/src/utils/portFinder.d.ts +13 -0
- package/dist/src/utils/portFinder.d.ts.map +1 -0
- package/dist/src/utils/portFinder.js +43 -0
- package/dist/src/utils/portFinder.js.map +1 -0
- package/dist/utils/portFinder.d.ts +13 -0
- package/dist/utils/portFinder.d.ts.map +1 -0
- package/dist/utils/portFinder.js +43 -0
- package/dist/utils/portFinder.js.map +1 -0
- package/package.json +63 -0
package/README.md
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
# @apprecio/mcp-base
|
|
2
|
+
|
|
3
|
+
Base package para crear servidores MCP (Model Context Protocol) de Apprecio con consistencia y reutilización de código.
|
|
4
|
+
|
|
5
|
+
## 🚀 Características
|
|
6
|
+
|
|
7
|
+
- **Servidor Base Abstracto**: Clase `McpBaseServer` que encapsula toda la lógica común
|
|
8
|
+
- **Configuración Centralizada**: Sistema de configuración con validación Zod
|
|
9
|
+
- **Logger Unificado**: Winston logger con niveles configurables y rotación de archivos
|
|
10
|
+
- **Middlewares Reutilizables**: Autenticación, Rate Limiting, CORS, Helmet
|
|
11
|
+
- **Conectores Database**: MongoDB y Redis pre-configurados
|
|
12
|
+
- **Port Management**: Búsqueda automática de puertos disponibles
|
|
13
|
+
- **Graceful Shutdown**: Manejo automático de señales SIGINT/SIGTERM
|
|
14
|
+
- **TypeScript First**: Completamente tipado con soporte para path aliases
|
|
15
|
+
|
|
16
|
+
## 📦 Instalación
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @apprecio/mcp-base
|
|
20
|
+
# o
|
|
21
|
+
pnpm add @apprecio/mcp-base
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## 🎯 Uso Básico
|
|
25
|
+
|
|
26
|
+
### 1. Crear un nuevo servidor MCP
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import {
|
|
30
|
+
McpBaseServer,
|
|
31
|
+
createExpressServer,
|
|
32
|
+
findAvailablePort,
|
|
33
|
+
createMongoDBConnector
|
|
34
|
+
} from '@apprecio/mcp-base';
|
|
35
|
+
import type { FeatureModule } from '@apprecio/mcp-base';
|
|
36
|
+
|
|
37
|
+
// Definir tu servidor MCP personalizado
|
|
38
|
+
class MyCustomMcpServer extends McpBaseServer {
|
|
39
|
+
private dbConnector?: MongoDBConnector;
|
|
40
|
+
|
|
41
|
+
protected async registerFeatures(): Promise<void> {
|
|
42
|
+
// Registrar tus features personalizadas
|
|
43
|
+
this.registerFeature('myFeature', myFeatureModule);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
protected async onBeforeStart(): Promise<void> {
|
|
47
|
+
// Conectar a MongoDB si es necesario
|
|
48
|
+
if (this.config.mongodbUri) {
|
|
49
|
+
this.dbConnector = createMongoDBConnector(this.config.mongodbUri);
|
|
50
|
+
await this.dbConnector.connect();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
protected async onBeforeShutdown(): Promise<void> {
|
|
55
|
+
// Cleanup
|
|
56
|
+
if (this.dbConnector) {
|
|
57
|
+
await this.dbConnector.disconnect();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Iniciar el servidor
|
|
63
|
+
async function main() {
|
|
64
|
+
const server = new MyCustomMcpServer({
|
|
65
|
+
name: 'my-custom-mcp',
|
|
66
|
+
version: '1.0.0',
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const port = await findAvailablePort(server.getConfig().ssePort);
|
|
70
|
+
|
|
71
|
+
const httpServer = await createExpressServer({
|
|
72
|
+
mcpServer: server.getMcpServer(),
|
|
73
|
+
config: server.getConfig(),
|
|
74
|
+
port,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
await server.start(httpServer, port);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
main();
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### 2. Crear un Feature Module
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
87
|
+
import type { FeatureModule } from '@apprecio/mcp-base';
|
|
88
|
+
|
|
89
|
+
export const myFeatureModule: FeatureModule = {
|
|
90
|
+
name: 'myFeature',
|
|
91
|
+
|
|
92
|
+
register(mcpServer: McpServer): void {
|
|
93
|
+
// Registrar tools
|
|
94
|
+
mcpServer.tool(
|
|
95
|
+
'my_tool',
|
|
96
|
+
'Description of my tool',
|
|
97
|
+
{
|
|
98
|
+
type: 'object',
|
|
99
|
+
properties: {
|
|
100
|
+
param: { type: 'string' }
|
|
101
|
+
},
|
|
102
|
+
required: ['param']
|
|
103
|
+
},
|
|
104
|
+
async (params) => {
|
|
105
|
+
// Implementación del tool
|
|
106
|
+
return {
|
|
107
|
+
content: [{
|
|
108
|
+
type: 'text',
|
|
109
|
+
text: `Result: ${params.param}`
|
|
110
|
+
}]
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
async initialize(): Promise<void> {
|
|
117
|
+
// Inicialización opcional
|
|
118
|
+
console.log('Feature initialized');
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
async cleanup(): Promise<void> {
|
|
122
|
+
// Cleanup opcional
|
|
123
|
+
console.log('Feature cleaned up');
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### 3. Configuración (.env)
|
|
129
|
+
|
|
130
|
+
```env
|
|
131
|
+
# Authentication
|
|
132
|
+
API_KEY=your-secret-api-key
|
|
133
|
+
|
|
134
|
+
# Database
|
|
135
|
+
MONGODB_URI=mongodb://localhost:27017/mydb
|
|
136
|
+
|
|
137
|
+
# Server
|
|
138
|
+
MCP_SSE_PORT=3200
|
|
139
|
+
|
|
140
|
+
# Timeouts (ms)
|
|
141
|
+
MCP_TIMEOUT=180000
|
|
142
|
+
SSE_TIMEOUT=1800000
|
|
143
|
+
|
|
144
|
+
# Logging
|
|
145
|
+
LOG_LEVEL=info
|
|
146
|
+
|
|
147
|
+
# CORS
|
|
148
|
+
CORS_ALLOW_ORIGIN=*
|
|
149
|
+
|
|
150
|
+
# Rate Limiting
|
|
151
|
+
RATE_LIMIT_WINDOW_MS=900000
|
|
152
|
+
RATE_LIMIT_MAX_REQUESTS=100
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## 📚 API Reference
|
|
156
|
+
|
|
157
|
+
### McpBaseServer
|
|
158
|
+
|
|
159
|
+
Clase abstracta base para servidores MCP.
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
abstract class McpBaseServer {
|
|
163
|
+
constructor(options: ServerOptions)
|
|
164
|
+
|
|
165
|
+
// Métodos abstractos (deben implementarse)
|
|
166
|
+
protected abstract registerFeatures(): Promise<void>
|
|
167
|
+
|
|
168
|
+
// Hooks opcionales
|
|
169
|
+
protected async onBeforeStart?(): Promise<void>
|
|
170
|
+
protected async onBeforeShutdown?(): Promise<void>
|
|
171
|
+
|
|
172
|
+
// Métodos públicos
|
|
173
|
+
public getMcpServer(): McpServer
|
|
174
|
+
public getConfig(): BaseConfig
|
|
175
|
+
public getFeatures(): Map<string, FeatureModule>
|
|
176
|
+
|
|
177
|
+
// Método para iniciar el servidor
|
|
178
|
+
async start(httpServer: HttpServer, port: number): Promise<void>
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### BaseConfig
|
|
183
|
+
|
|
184
|
+
Sistema de configuración con validación.
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
class BaseConfig {
|
|
188
|
+
constructor(envPath?: string)
|
|
189
|
+
|
|
190
|
+
// Getters
|
|
191
|
+
get apiKey(): string
|
|
192
|
+
get mongodbUri(): string | undefined
|
|
193
|
+
get ssePort(): number
|
|
194
|
+
get logLevel(): 'debug' | 'info' | 'warn' | 'error'
|
|
195
|
+
// ... más getters
|
|
196
|
+
|
|
197
|
+
// Métodos
|
|
198
|
+
getAll(): BaseConfigType
|
|
199
|
+
extend<T>(customConfig: T): BaseConfigType & T
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Logger
|
|
204
|
+
|
|
205
|
+
Logger centralizado con Winston.
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
import { logger, createChildLogger, setLogLevel } from '@apprecio/mcp-base';
|
|
209
|
+
|
|
210
|
+
// Uso básico
|
|
211
|
+
logger.info('Message');
|
|
212
|
+
logger.error('Error', error);
|
|
213
|
+
logger.debug('Debug info', { metadata });
|
|
214
|
+
|
|
215
|
+
// Logger con contexto
|
|
216
|
+
const childLogger = createChildLogger('MyFeature');
|
|
217
|
+
childLogger.info('Feature message');
|
|
218
|
+
|
|
219
|
+
// Cambiar nivel dinámicamente
|
|
220
|
+
setLogLevel('debug');
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### Middlewares
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
import { createAuthMiddleware } from '@apprecio/mcp-base';
|
|
227
|
+
|
|
228
|
+
const authMiddleware = createAuthMiddleware(apiKey);
|
|
229
|
+
|
|
230
|
+
app.use('/protected', authMiddleware.authenticate);
|
|
231
|
+
app.use('/optional', authMiddleware.optionalAuth);
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Database Connectors
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
import { createMongoDBConnector } from '@apprecio/mcp-base';
|
|
238
|
+
|
|
239
|
+
const db = createMongoDBConnector('mongodb://localhost:27017/db');
|
|
240
|
+
await db.connect();
|
|
241
|
+
|
|
242
|
+
// Usar mongoose normalmente
|
|
243
|
+
const connection = db.getConnection();
|
|
244
|
+
|
|
245
|
+
await db.disconnect();
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## 🔧 Desarrollo
|
|
249
|
+
|
|
250
|
+
### Estructura del proyecto base
|
|
251
|
+
|
|
252
|
+
```
|
|
253
|
+
@apprecio/mcp-base/
|
|
254
|
+
├── src/
|
|
255
|
+
│ ├── core/ # Núcleo del framework
|
|
256
|
+
│ │ ├── McpBaseServer.ts # Clase base
|
|
257
|
+
│ │ ├── config.ts # Configuración
|
|
258
|
+
│ │ ├── logger.ts # Logger
|
|
259
|
+
│ │ └── types.ts # Tipos compartidos
|
|
260
|
+
│ ├── middleware/ # Middlewares Express
|
|
261
|
+
│ ├── database/ # Conectores DB
|
|
262
|
+
│ ├── server/ # Server builders
|
|
263
|
+
│ ├── utils/ # Utilidades
|
|
264
|
+
│ └── index.ts # Exports principales
|
|
265
|
+
├── package.json
|
|
266
|
+
├── tsconfig.json
|
|
267
|
+
└── README.md
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### Build
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
npm run build
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### Desarrollo
|
|
277
|
+
|
|
278
|
+
```bash
|
|
279
|
+
npm run dev
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
## 🎨 Ejemplos Completos
|
|
283
|
+
|
|
284
|
+
Ver el directorio `examples/` para ejemplos completos de:
|
|
285
|
+
|
|
286
|
+
- Servidor MCP simple
|
|
287
|
+
- Servidor con MongoDB
|
|
288
|
+
- Servidor con múltiples features
|
|
289
|
+
- Servidor con autenticación personalizada
|
|
290
|
+
|
|
291
|
+
## 📝 Licencia
|
|
292
|
+
|
|
293
|
+
MIT
|
|
294
|
+
|
|
295
|
+
## 🤝 Contribuir
|
|
296
|
+
|
|
297
|
+
1. Fork el proyecto
|
|
298
|
+
2. Crea una branch para tu feature
|
|
299
|
+
3. Commit tus cambios
|
|
300
|
+
4. Push a la branch
|
|
301
|
+
5. Abre un Pull Request
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import type { Express } from 'express';
|
|
3
|
+
import type { Server as HttpServer } from 'http';
|
|
4
|
+
import { HttpTerminator } from 'http-terminator';
|
|
5
|
+
import { BaseConfig } from './config.js';
|
|
6
|
+
import type { FeatureModule, ServerOptions } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Clase base abstracta para servidores MCP de Apprecio
|
|
9
|
+
* Proporciona funcionalidad común para todos los servidores MCP
|
|
10
|
+
*/
|
|
11
|
+
export declare abstract class McpBaseServer {
|
|
12
|
+
protected mcpServer: McpServer;
|
|
13
|
+
protected httpServer?: HttpServer;
|
|
14
|
+
protected httpTerminator?: HttpTerminator;
|
|
15
|
+
protected config: BaseConfig;
|
|
16
|
+
protected features: Map<string, FeatureModule>;
|
|
17
|
+
constructor(options: ServerOptions);
|
|
18
|
+
/**
|
|
19
|
+
* Registra un feature module (debe implementar cada servidor MCP)
|
|
20
|
+
*/
|
|
21
|
+
protected abstract registerFeatures(): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Hook para inicialización personalizada
|
|
24
|
+
*/
|
|
25
|
+
protected onBeforeStart?(): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Hook para cleanup personalizado
|
|
28
|
+
*/
|
|
29
|
+
protected onBeforeShutdown?(): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Registra una feature genérica
|
|
32
|
+
*/
|
|
33
|
+
protected registerFeature(name: string, feature: FeatureModule): void;
|
|
34
|
+
/**
|
|
35
|
+
* Configura el servidor Express con middlewares base
|
|
36
|
+
*/
|
|
37
|
+
protected setupHttpServer(app: Express): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Inicia el servidor MCP
|
|
40
|
+
*/
|
|
41
|
+
start(httpServer: HttpServer, port: number): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Configura el apagado graceful del servidor
|
|
44
|
+
*/
|
|
45
|
+
private setupGracefulShutdown;
|
|
46
|
+
/**
|
|
47
|
+
* Obtiene la instancia del MCP Server
|
|
48
|
+
*/
|
|
49
|
+
getMcpServer(): McpServer;
|
|
50
|
+
/**
|
|
51
|
+
* Obtiene la configuración
|
|
52
|
+
*/
|
|
53
|
+
getConfig(): BaseConfig;
|
|
54
|
+
/**
|
|
55
|
+
* Obtiene las features registradas
|
|
56
|
+
*/
|
|
57
|
+
getFeatures(): Map<string, FeatureModule>;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=McpBaseServer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"McpBaseServer.d.ts","sourceRoot":"","sources":["../../src/core/McpBaseServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,MAAM,CAAC;AACjD,OAAO,EAAwB,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGvE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE/D;;;GAGG;AACH,8BAAsB,aAAa;IAC/B,SAAS,CAAC,SAAS,EAAE,SAAS,CAAC;IAC/B,SAAS,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC;IAClC,SAAS,CAAC,cAAc,CAAC,EAAE,cAAc,CAAC;IAC1C,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC;IAC7B,SAAS,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAa;gBAE/C,OAAO,EAAE,aAAa;IAWlC;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAEpD;;OAEG;cACa,aAAa,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;IAE/C;;OAEG;cACa,gBAAgB,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;IAElD;;OAEG;IACH,SAAS,CAAC,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,IAAI;IAUrE;;OAEG;cACa,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5D;;OAEG;IACG,KAAK,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAyBhE;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAiC7B;;OAEG;IACI,YAAY,IAAI,SAAS;IAIhC;;OAEG;IACI,SAAS,IAAI,UAAU;IAI9B;;OAEG;IACI,WAAW,IAAI,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC;CAGnD"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { createHttpTerminator } from 'http-terminator';
|
|
3
|
+
import { logger } from './logger.js';
|
|
4
|
+
import { BaseConfig } from './config.js';
|
|
5
|
+
/**
|
|
6
|
+
* Clase base abstracta para servidores MCP de Apprecio
|
|
7
|
+
* Proporciona funcionalidad común para todos los servidores MCP
|
|
8
|
+
*/
|
|
9
|
+
export class McpBaseServer {
|
|
10
|
+
mcpServer;
|
|
11
|
+
httpServer;
|
|
12
|
+
httpTerminator;
|
|
13
|
+
config;
|
|
14
|
+
features = new Map();
|
|
15
|
+
constructor(options) {
|
|
16
|
+
this.config = new BaseConfig(options.envPath);
|
|
17
|
+
this.mcpServer = new McpServer({
|
|
18
|
+
name: options.name,
|
|
19
|
+
version: options.version,
|
|
20
|
+
});
|
|
21
|
+
logger.info(`Initializing ${options.name} v${options.version}`);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Registra una feature genérica
|
|
25
|
+
*/
|
|
26
|
+
registerFeature(name, feature) {
|
|
27
|
+
if (this.features.has(name)) {
|
|
28
|
+
logger.warn(`Feature ${name} ya está registrada. Sobrescribiendo...`);
|
|
29
|
+
}
|
|
30
|
+
feature.register(this.mcpServer);
|
|
31
|
+
this.features.set(name, feature);
|
|
32
|
+
logger.info(`Feature '${name}' registered successfully`);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Configura el servidor Express con middlewares base
|
|
36
|
+
*/
|
|
37
|
+
async setupHttpServer(app) {
|
|
38
|
+
// Implementado en el server builder
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Inicia el servidor MCP
|
|
42
|
+
*/
|
|
43
|
+
async start(httpServer, port) {
|
|
44
|
+
try {
|
|
45
|
+
// Hook pre-start
|
|
46
|
+
if (this.onBeforeStart) {
|
|
47
|
+
await this.onBeforeStart();
|
|
48
|
+
}
|
|
49
|
+
// Registrar features
|
|
50
|
+
await this.registerFeatures();
|
|
51
|
+
// Guardar referencia al servidor HTTP
|
|
52
|
+
this.httpServer = httpServer;
|
|
53
|
+
this.httpTerminator = createHttpTerminator({ server: httpServer });
|
|
54
|
+
logger.info(`MCP Server started successfully on port ${port}`);
|
|
55
|
+
// Setup graceful shutdown
|
|
56
|
+
this.setupGracefulShutdown();
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
logger.error('Failed to start MCP server:', error);
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Configura el apagado graceful del servidor
|
|
65
|
+
*/
|
|
66
|
+
setupGracefulShutdown() {
|
|
67
|
+
const shutdown = async (signal) => {
|
|
68
|
+
logger.info(`Received ${signal} signal. Starting graceful shutdown...`);
|
|
69
|
+
// Pequeño delay para completar requests en curso
|
|
70
|
+
await new Promise(resolve => setTimeout(resolve, 500));
|
|
71
|
+
try {
|
|
72
|
+
// Hook pre-shutdown
|
|
73
|
+
if (this.onBeforeShutdown) {
|
|
74
|
+
await this.onBeforeShutdown();
|
|
75
|
+
}
|
|
76
|
+
// Terminar servidor HTTP
|
|
77
|
+
if (this.httpTerminator) {
|
|
78
|
+
await this.httpTerminator.terminate();
|
|
79
|
+
}
|
|
80
|
+
logger.info('Server terminated successfully. Exiting.');
|
|
81
|
+
process.exit(0);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
logger.error('Error during server termination:', error);
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
process.on('SIGINT', () => shutdown('SIGINT'));
|
|
89
|
+
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
|
90
|
+
process.on('unhandledRejection', (reason) => {
|
|
91
|
+
logger.error('Unhandled promise rejection:', reason);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Obtiene la instancia del MCP Server
|
|
96
|
+
*/
|
|
97
|
+
getMcpServer() {
|
|
98
|
+
return this.mcpServer;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Obtiene la configuración
|
|
102
|
+
*/
|
|
103
|
+
getConfig() {
|
|
104
|
+
return this.config;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Obtiene las features registradas
|
|
108
|
+
*/
|
|
109
|
+
getFeatures() {
|
|
110
|
+
return this.features;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=McpBaseServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"McpBaseServer.js","sourceRoot":"","sources":["../../src/core/McpBaseServer.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Schema de validación para la configuración base
|
|
4
|
+
*/
|
|
5
|
+
declare const baseConfigSchema: z.ZodObject<{
|
|
6
|
+
apiKey: z.ZodString;
|
|
7
|
+
mongodbUri: z.ZodOptional<z.ZodString>;
|
|
8
|
+
redisUri: z.ZodOptional<z.ZodString>;
|
|
9
|
+
ssePort: z.ZodDefault<z.ZodNumber>;
|
|
10
|
+
mcpTimeout: z.ZodDefault<z.ZodNumber>;
|
|
11
|
+
sseTimeout: z.ZodDefault<z.ZodNumber>;
|
|
12
|
+
logLevel: z.ZodDefault<z.ZodEnum<["debug", "info", "warn", "error"]>>;
|
|
13
|
+
corsAllowOrigin: z.ZodDefault<z.ZodString>;
|
|
14
|
+
rateLimitWindowMs: z.ZodDefault<z.ZodNumber>;
|
|
15
|
+
rateLimitMaxRequests: z.ZodDefault<z.ZodNumber>;
|
|
16
|
+
rateLimitSseMax: z.ZodDefault<z.ZodNumber>;
|
|
17
|
+
rateLimitMessagesMax: z.ZodDefault<z.ZodNumber>;
|
|
18
|
+
defaultUserRateLimit: z.ZodDefault<z.ZodNumber>;
|
|
19
|
+
}, "strip", z.ZodTypeAny, {
|
|
20
|
+
apiKey: string;
|
|
21
|
+
ssePort: number;
|
|
22
|
+
mcpTimeout: number;
|
|
23
|
+
sseTimeout: number;
|
|
24
|
+
logLevel: "info" | "error" | "debug" | "warn";
|
|
25
|
+
corsAllowOrigin: string;
|
|
26
|
+
rateLimitWindowMs: number;
|
|
27
|
+
rateLimitMaxRequests: number;
|
|
28
|
+
rateLimitSseMax: number;
|
|
29
|
+
rateLimitMessagesMax: number;
|
|
30
|
+
defaultUserRateLimit: number;
|
|
31
|
+
mongodbUri?: string | undefined;
|
|
32
|
+
redisUri?: string | undefined;
|
|
33
|
+
}, {
|
|
34
|
+
apiKey: string;
|
|
35
|
+
mongodbUri?: string | undefined;
|
|
36
|
+
redisUri?: string | undefined;
|
|
37
|
+
ssePort?: number | undefined;
|
|
38
|
+
mcpTimeout?: number | undefined;
|
|
39
|
+
sseTimeout?: number | undefined;
|
|
40
|
+
logLevel?: "info" | "error" | "debug" | "warn" | undefined;
|
|
41
|
+
corsAllowOrigin?: string | undefined;
|
|
42
|
+
rateLimitWindowMs?: number | undefined;
|
|
43
|
+
rateLimitMaxRequests?: number | undefined;
|
|
44
|
+
rateLimitSseMax?: number | undefined;
|
|
45
|
+
rateLimitMessagesMax?: number | undefined;
|
|
46
|
+
defaultUserRateLimit?: number | undefined;
|
|
47
|
+
}>;
|
|
48
|
+
export type BaseConfigType = z.infer<typeof baseConfigSchema>;
|
|
49
|
+
/**
|
|
50
|
+
* Clase de configuración base para servidores MCP
|
|
51
|
+
*/
|
|
52
|
+
export declare class BaseConfig {
|
|
53
|
+
private config;
|
|
54
|
+
constructor(envPath?: string);
|
|
55
|
+
/**
|
|
56
|
+
* Obtiene toda la configuración
|
|
57
|
+
*/
|
|
58
|
+
getAll(): BaseConfigType;
|
|
59
|
+
/**
|
|
60
|
+
* Getters individuales
|
|
61
|
+
*/
|
|
62
|
+
get apiKey(): string;
|
|
63
|
+
get mongodbUri(): string | undefined;
|
|
64
|
+
get redisUri(): string | undefined;
|
|
65
|
+
get ssePort(): number;
|
|
66
|
+
get mcpTimeout(): number;
|
|
67
|
+
get sseTimeout(): number;
|
|
68
|
+
get logLevel(): 'debug' | 'info' | 'warn' | 'error';
|
|
69
|
+
get corsAllowOrigin(): string;
|
|
70
|
+
get rateLimitWindowMs(): number;
|
|
71
|
+
get rateLimitMaxRequests(): number;
|
|
72
|
+
get rateLimitSseMax(): number;
|
|
73
|
+
get rateLimitMessagesMax(): number;
|
|
74
|
+
get defaultUserRateLimit(): number;
|
|
75
|
+
/**
|
|
76
|
+
* Permite extender la configuración con valores personalizados
|
|
77
|
+
*/
|
|
78
|
+
extend<T extends Record<string, any>>(customConfig: T): BaseConfigType & T;
|
|
79
|
+
}
|
|
80
|
+
export {};
|
|
81
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;GAEG;AACH,QAAA,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2BpB,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE9D;;GAEG;AACH,qBAAa,UAAU;IACnB,OAAO,CAAC,MAAM,CAAiB;gBAEnB,OAAO,CAAC,EAAE,MAAM;IAmC5B;;OAEG;IACI,MAAM,IAAI,cAAc;IAI/B;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,UAAU,IAAI,MAAM,GAAG,SAAS,CAEnC;IAED,IAAI,QAAQ,IAAI,MAAM,GAAG,SAAS,CAEjC;IAED,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,IAAI,QAAQ,IAAI,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAElD;IAED,IAAI,eAAe,IAAI,MAAM,CAE5B;IAED,IAAI,iBAAiB,IAAI,MAAM,CAE9B;IAED,IAAI,oBAAoB,IAAI,MAAM,CAEjC;IAED,IAAI,eAAe,IAAI,MAAM,CAE5B;IAED,IAAI,oBAAoB,IAAI,MAAM,CAEjC;IAED,IAAI,oBAAoB,IAAI,MAAM,CAEjC;IAED;;OAEG;IACI,MAAM,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,cAAc,GAAG,CAAC;CAGpF"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { config as dotenvConfig } from 'dotenv';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { logger } from './logger.js';
|
|
4
|
+
/**
|
|
5
|
+
* Schema de validación para la configuración base
|
|
6
|
+
*/
|
|
7
|
+
const baseConfigSchema = z.object({
|
|
8
|
+
// Authentication
|
|
9
|
+
apiKey: z.string().min(1, 'API_KEY is required'),
|
|
10
|
+
// Database
|
|
11
|
+
mongodbUri: z.string().optional(),
|
|
12
|
+
redisUri: z.string().optional(),
|
|
13
|
+
// Server
|
|
14
|
+
ssePort: z.coerce.number().min(1000).max(65535).default(3200),
|
|
15
|
+
// Timeouts
|
|
16
|
+
mcpTimeout: z.coerce.number().default(180000),
|
|
17
|
+
sseTimeout: z.coerce.number().default(1800000),
|
|
18
|
+
// Logging
|
|
19
|
+
logLevel: z.enum(['debug', 'info', 'warn', 'error']).default('info'),
|
|
20
|
+
// CORS
|
|
21
|
+
corsAllowOrigin: z.string().default('*'),
|
|
22
|
+
// Rate Limiting
|
|
23
|
+
rateLimitWindowMs: z.coerce.number().default(900000),
|
|
24
|
+
rateLimitMaxRequests: z.coerce.number().default(100),
|
|
25
|
+
rateLimitSseMax: z.coerce.number().default(5),
|
|
26
|
+
rateLimitMessagesMax: z.coerce.number().default(30),
|
|
27
|
+
defaultUserRateLimit: z.coerce.number().default(1000),
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* Clase de configuración base para servidores MCP
|
|
31
|
+
*/
|
|
32
|
+
export class BaseConfig {
|
|
33
|
+
config;
|
|
34
|
+
constructor(envPath) {
|
|
35
|
+
// Cargar variables de entorno
|
|
36
|
+
dotenvConfig({ path: envPath });
|
|
37
|
+
// Parsear y validar configuración
|
|
38
|
+
const rawConfig = {
|
|
39
|
+
apiKey: process.env.API_KEY,
|
|
40
|
+
mongodbUri: process.env.MONGODB_URI,
|
|
41
|
+
redisUri: process.env.REDIS_URI,
|
|
42
|
+
ssePort: process.env.MCP_SSE_PORT,
|
|
43
|
+
mcpTimeout: process.env.MCP_TIMEOUT,
|
|
44
|
+
sseTimeout: process.env.SSE_TIMEOUT,
|
|
45
|
+
logLevel: process.env.LOG_LEVEL,
|
|
46
|
+
corsAllowOrigin: process.env.CORS_ALLOW_ORIGIN,
|
|
47
|
+
rateLimitWindowMs: process.env.RATE_LIMIT_WINDOW_MS,
|
|
48
|
+
rateLimitMaxRequests: process.env.RATE_LIMIT_MAX_REQUESTS,
|
|
49
|
+
rateLimitSseMax: process.env.RATE_LIMIT_SSE_MAX,
|
|
50
|
+
rateLimitMessagesMax: process.env.RATE_LIMIT_MESSAGES_MAX,
|
|
51
|
+
defaultUserRateLimit: process.env.DEFAULT_USER_RATE_LIMIT,
|
|
52
|
+
};
|
|
53
|
+
try {
|
|
54
|
+
this.config = baseConfigSchema.parse(rawConfig);
|
|
55
|
+
logger.info('Configuration loaded and validated successfully');
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (error instanceof z.ZodError) {
|
|
59
|
+
logger.error('Configuration validation failed:');
|
|
60
|
+
error.errors.forEach(err => {
|
|
61
|
+
logger.error(` - ${err.path.join('.')}: ${err.message}`);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
throw new Error('Invalid configuration');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Obtiene toda la configuración
|
|
69
|
+
*/
|
|
70
|
+
getAll() {
|
|
71
|
+
return this.config;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Getters individuales
|
|
75
|
+
*/
|
|
76
|
+
get apiKey() {
|
|
77
|
+
return this.config.apiKey;
|
|
78
|
+
}
|
|
79
|
+
get mongodbUri() {
|
|
80
|
+
return this.config.mongodbUri;
|
|
81
|
+
}
|
|
82
|
+
get redisUri() {
|
|
83
|
+
return this.config.redisUri;
|
|
84
|
+
}
|
|
85
|
+
get ssePort() {
|
|
86
|
+
return this.config.ssePort;
|
|
87
|
+
}
|
|
88
|
+
get mcpTimeout() {
|
|
89
|
+
return this.config.mcpTimeout;
|
|
90
|
+
}
|
|
91
|
+
get sseTimeout() {
|
|
92
|
+
return this.config.sseTimeout;
|
|
93
|
+
}
|
|
94
|
+
get logLevel() {
|
|
95
|
+
return this.config.logLevel;
|
|
96
|
+
}
|
|
97
|
+
get corsAllowOrigin() {
|
|
98
|
+
return this.config.corsAllowOrigin;
|
|
99
|
+
}
|
|
100
|
+
get rateLimitWindowMs() {
|
|
101
|
+
return this.config.rateLimitWindowMs;
|
|
102
|
+
}
|
|
103
|
+
get rateLimitMaxRequests() {
|
|
104
|
+
return this.config.rateLimitMaxRequests;
|
|
105
|
+
}
|
|
106
|
+
get rateLimitSseMax() {
|
|
107
|
+
return this.config.rateLimitSseMax;
|
|
108
|
+
}
|
|
109
|
+
get rateLimitMessagesMax() {
|
|
110
|
+
return this.config.rateLimitMessagesMax;
|
|
111
|
+
}
|
|
112
|
+
get defaultUserRateLimit() {
|
|
113
|
+
return this.config.defaultUserRateLimit;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Permite extender la configuración con valores personalizados
|
|
117
|
+
*/
|
|
118
|
+
extend(customConfig) {
|
|
119
|
+
return { ...this.config, ...customConfig };
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=config.js.map
|