@koggitechorg/koggi-mcp-server 1.0.4 → 1.0.6
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 +8 -7
- package/dist/error/error.handler.js +11 -0
- package/dist/index.js +20 -11
- package/dist/middlewares/middleware.js +9 -4
- package/package.json +1 -1
- package/src/error/error.handler.ts +10 -0
- package/src/handlers/simulator.ts +1 -1
- package/src/index.ts +22 -11
- package/src/middlewares/middleware.ts +9 -4
package/README.md
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
# koggi-mcp-server
|
|
2
2
|
|
|
3
|
-
Una herramienta (MCP server) ligera para exponer un comando/tool llamado `
|
|
3
|
+
Una herramienta (MCP server) ligera para exponer un comando/tool llamado `generate_simulator` usado para generar un simulador financiero basándose en el número de documento (id de lead) de un usuario. El servidor implementa el protocolo Model Context Protocol (MCP) y está pensado para integrarse con agentes o sistemas que hablen MCP por stdin/stdout.
|
|
4
4
|
|
|
5
5
|
## Contenido
|
|
6
6
|
|
|
7
|
-
- `src/index.ts` - Entrada principal que registra la tool `
|
|
8
|
-
- `src/handlers/simulator.ts` - Handlers/implementación auxiliar del handler `
|
|
7
|
+
- `src/index.ts` - Entrada principal que registra la tool `generate_simulator` y arranca el servidor MCP usando `StdioServerTransport`.
|
|
8
|
+
- `src/handlers/simulator.ts` - Handlers/implementación auxiliar del handler `generate_simulator` (versiones JS/TS).
|
|
9
9
|
- `src/utils/apiClient.ts` - Cliente HTTP usado para llamar al endpoint interno/external que calcula el simulador.
|
|
10
10
|
- `src/config/config.ts` - Carga de variables de entorno (usa `dotenv`).
|
|
11
11
|
|
|
12
12
|
## Características
|
|
13
13
|
|
|
14
|
-
- Tool MCP: `
|
|
14
|
+
- Tool MCP: `generate_simulator`
|
|
15
15
|
- Propósito: Generar un simulador financiero para un usuario dado.
|
|
16
|
-
- Schema (Zod): `id_lead`, `email_requester`, `income_updated`, `observations` (
|
|
16
|
+
- Schema (Zod): `id_lead`, `identification_number`,`builder`,`email_requester`, `income_updated`, `observations` (email_requester,income_updated,observations son obligatorios `index.ts`).
|
|
17
17
|
- Comunicación: stdin/stdout (StdioServerTransport) siguiendo el SDK `@modelcontextprotocol/sdk`.
|
|
18
18
|
- Cliente HTTP: usa `node-fetch` y `EXTERNAL_URL` como base para las peticiones.
|
|
19
19
|
|
|
@@ -38,7 +38,8 @@ Ejemplo `mcp.json` (útil para ejecutar con orquestadores que esperan ese format
|
|
|
38
38
|
"-y", "@koggitechorg/koggi-mcp-server"
|
|
39
39
|
],
|
|
40
40
|
"env": {
|
|
41
|
-
"EXTERNAL_URL": "https://external-qa-502142473966.us-central1.run.app"
|
|
41
|
+
"EXTERNAL_URL": "https://external-qa-502142473966.us-central1.run.app",
|
|
42
|
+
"API_TOKEN": "23slKk2..."
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
},
|
|
@@ -54,7 +55,7 @@ tools = [
|
|
|
54
55
|
connection_params=StdioServerParameters(
|
|
55
56
|
command="npx",
|
|
56
57
|
args=["-y", "@koggitechorg/koggi-mcp-server"],
|
|
57
|
-
env={"EXTERNAL_URL": EXTERNAL_URL},
|
|
58
|
+
env={"EXTERNAL_URL": EXTERNAL_URL, "API_TOKEN": "..."},
|
|
58
59
|
)
|
|
59
60
|
),
|
|
60
61
|
]
|
package/dist/index.js
CHANGED
|
@@ -3,31 +3,40 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
3
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { generateSimulator } from "./handlers/simulator.js";
|
|
6
|
+
import { errorHandler } from "./error/error.handler.js";
|
|
6
7
|
// Create an MCP server
|
|
7
8
|
const server = new McpServer({
|
|
8
9
|
name: "koggi-mcp-server",
|
|
9
10
|
version: "1.0.0",
|
|
10
11
|
description: "Custom MCP server for Koggi",
|
|
11
12
|
});
|
|
12
|
-
server.tool("
|
|
13
|
+
server.tool("generate_simulator", "Genera un simulador financiero para un usuario usando su número de documento. Campos requeridos: \
|
|
13
14
|
id_lead (string, identificador único del lead), \
|
|
15
|
+
identification_number (string, número de documento del cliente), \
|
|
16
|
+
builder (string, nombre de la constructora), \
|
|
14
17
|
email_requester (string, correo electrónico de quien solicita el simulador), \
|
|
15
18
|
income_updated (number, ingreso mensual actualizado del cliente), \
|
|
16
19
|
observations (string, observaciones o comentarios adicionales sobre la solicitud).", {
|
|
17
|
-
id_lead: z.string().
|
|
20
|
+
id_lead: z.string().isOptional(),
|
|
21
|
+
identification_number: z.string().isOptional(),
|
|
22
|
+
builder: z.string().isOptional(),
|
|
18
23
|
email_requester: z.string().email().min(1, "Email is required"),
|
|
19
24
|
income_updated: z.number().min(1, "Income is required"),
|
|
20
25
|
observations: z.string().min(1, "Observations are required"),
|
|
21
|
-
}, async ({ id_lead, email_requester, income_updated, observations }) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
}, async ({ id_lead, identification_number, builder, email_requester, income_updated, observations }) => {
|
|
27
|
+
return errorHandler(async () => {
|
|
28
|
+
const user = await generateSimulator({
|
|
29
|
+
idLead: id_lead,
|
|
30
|
+
identification_number,
|
|
31
|
+
builder,
|
|
32
|
+
ingresosActualizados: income_updated,
|
|
33
|
+
observaciones: observations,
|
|
34
|
+
emailRequest: email_requester,
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
content: [{ type: "text", text: JSON.stringify(user, null, 2) }]
|
|
38
|
+
};
|
|
27
39
|
});
|
|
28
|
-
return {
|
|
29
|
-
content: [{ type: "text", text: JSON.stringify(user, null, 2) }]
|
|
30
|
-
};
|
|
31
40
|
});
|
|
32
41
|
// Start receiving messages on stdin and sending messages on stdout
|
|
33
42
|
const transport = new StdioServerTransport();
|
|
@@ -2,11 +2,16 @@ import { CONFIG } from "../config/config.js";
|
|
|
2
2
|
import { apiFetch } from "../utils/apiClient.js";
|
|
3
3
|
async function validateRequestToken(func) {
|
|
4
4
|
const token = CONFIG.token;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
try {
|
|
6
|
+
const isValid = await validateToken(token);
|
|
7
|
+
if (!isValid) {
|
|
8
|
+
throw new Error("Invalid request token.");
|
|
9
|
+
}
|
|
10
|
+
return await func();
|
|
11
|
+
}
|
|
12
|
+
catch (err) {
|
|
13
|
+
return [{ type: "text", text: `Error al validar token o ejecutando la acción: ${err?.message ?? String(err)}` }];
|
|
8
14
|
}
|
|
9
|
-
return await func();
|
|
10
15
|
}
|
|
11
16
|
async function validateToken(token) {
|
|
12
17
|
const response = await apiFetch(`/api/mcp/validate`, {
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@ interface SimulatorData {
|
|
|
5
5
|
[key: string]: any;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
async function generateSimulator(data: SimulatorData): Promise<
|
|
8
|
+
async function generateSimulator(data: SimulatorData): Promise<any> {
|
|
9
9
|
return await validateRequestToken(async () => apiFetch(`/api/monitoreo-financiero/simulate-new-calculator-by-id-lead`, {
|
|
10
10
|
method: "POST",
|
|
11
11
|
body: JSON.stringify(data),
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
3
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { generateSimulator } from "./handlers/simulator.js";
|
|
6
|
+
import { errorHandler } from "./error/error.handler.js";
|
|
6
7
|
|
|
7
8
|
// Create an MCP server
|
|
8
9
|
const server = new McpServer({
|
|
@@ -13,31 +14,41 @@ const server = new McpServer({
|
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
server.tool(
|
|
16
|
-
"
|
|
17
|
+
"generate_simulator",
|
|
17
18
|
"Genera un simulador financiero para un usuario usando su número de documento. Campos requeridos: \
|
|
18
19
|
id_lead (string, identificador único del lead), \
|
|
20
|
+
identification_number (string, número de documento del cliente), \
|
|
21
|
+
builder (string, nombre de la constructora), \
|
|
19
22
|
email_requester (string, correo electrónico de quien solicita el simulador), \
|
|
20
23
|
income_updated (number, ingreso mensual actualizado del cliente), \
|
|
21
24
|
observations (string, observaciones o comentarios adicionales sobre la solicitud).",
|
|
22
25
|
{
|
|
23
|
-
id_lead: z.string().
|
|
26
|
+
id_lead: z.string().isOptional(),
|
|
27
|
+
identification_number: z.string().isOptional(),
|
|
28
|
+
builder: z.string().isOptional(),
|
|
24
29
|
email_requester: z.string().email().min(1, "Email is required"),
|
|
25
30
|
income_updated: z.number().min(1, "Income is required"),
|
|
26
31
|
observations: z.string().min(1, "Observations are required"),
|
|
27
32
|
},
|
|
28
|
-
async ({ id_lead, email_requester, income_updated, observations }) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
async ({ id_lead, identification_number, builder, email_requester, income_updated, observations }) => {
|
|
34
|
+
return errorHandler(async () => {
|
|
35
|
+
const user = await generateSimulator({
|
|
36
|
+
idLead: id_lead,
|
|
37
|
+
identification_number,
|
|
38
|
+
builder,
|
|
39
|
+
ingresosActualizados: income_updated,
|
|
40
|
+
observaciones: observations,
|
|
41
|
+
emailRequest: email_requester,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
content: [{ type: "text", text: JSON.stringify(user, null, 2) }]
|
|
46
|
+
};
|
|
34
47
|
});
|
|
35
|
-
return {
|
|
36
|
-
content: [{ type: "text", text: JSON.stringify(user, null, 2) }]
|
|
37
|
-
};
|
|
38
48
|
}
|
|
39
49
|
);
|
|
40
50
|
|
|
51
|
+
|
|
41
52
|
// Start receiving messages on stdin and sending messages on stdout
|
|
42
53
|
const transport = new StdioServerTransport();
|
|
43
54
|
await server.connect(transport);
|
|
@@ -3,13 +3,18 @@ import { apiFetch } from "../utils/apiClient.js";
|
|
|
3
3
|
|
|
4
4
|
async function validateRequestToken(func: Function) {
|
|
5
5
|
const token = CONFIG.token;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
try {
|
|
7
|
+
const isValid = await validateToken(token);
|
|
8
|
+
if (!isValid) {
|
|
9
|
+
throw new Error("Invalid request token.");
|
|
10
|
+
}
|
|
11
|
+
return await func();
|
|
12
|
+
} catch (err: any) {
|
|
13
|
+
return [{ type: "text", text: `Error al validar token o ejecutando la acción: ${err?.message ?? String(err)}` }];
|
|
9
14
|
}
|
|
10
|
-
return await func();
|
|
11
15
|
}
|
|
12
16
|
|
|
17
|
+
|
|
13
18
|
async function validateToken(token: string): Promise<boolean> {
|
|
14
19
|
const response = await apiFetch(`/api/mcp/validate`, {
|
|
15
20
|
method: "POST",
|