@koggitechorg/koggi-mcp-server 1.0.2 → 1.0.4
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 +70 -1
- package/dist/config/config.js +1 -0
- package/dist/handlers/simulator.js +3 -2
- package/dist/middlewares/middleware.js +21 -0
- package/package.json +1 -1
- package/src/config/config.ts +7 -1
- package/src/handlers/simulator.ts +3 -2
- package/src/index.ts +1 -0
- package/src/middlewares/middleware.ts +27 -0
- package/src/config/config.js +0 -7
- package/src/handlers/simulator.js +0 -10
- package/src/index.js +0 -29
- package/src/server.js +0 -20
- package/src/utils/apiClient.js +0 -16
package/README.md
CHANGED
|
@@ -1,2 +1,71 @@
|
|
|
1
|
-
# mcp-koggi-package
|
|
2
1
|
# koggi-mcp-server
|
|
2
|
+
|
|
3
|
+
Una herramienta (MCP server) ligera para exponer un comando/tool llamado `generateSimulator` 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
|
+
|
|
5
|
+
## Contenido
|
|
6
|
+
|
|
7
|
+
- `src/index.ts` - Entrada principal que registra la tool `generateSimulator` y arranca el servidor MCP usando `StdioServerTransport`.
|
|
8
|
+
- `src/handlers/simulator.ts` - Handlers/implementación auxiliar del handler `generateSimulator` (versiones JS/TS).
|
|
9
|
+
- `src/utils/apiClient.ts` - Cliente HTTP usado para llamar al endpoint interno/external que calcula el simulador.
|
|
10
|
+
- `src/config/config.ts` - Carga de variables de entorno (usa `dotenv`).
|
|
11
|
+
|
|
12
|
+
## Características
|
|
13
|
+
|
|
14
|
+
- Tool MCP: `generateSimulator`
|
|
15
|
+
- Propósito: Generar un simulador financiero para un usuario dado.
|
|
16
|
+
- Schema (Zod): `id_lead`, `email_requester`, `income_updated`, `observations` (todos obligatorios en la versión TS de `index.ts`).
|
|
17
|
+
- Comunicación: stdin/stdout (StdioServerTransport) siguiendo el SDK `@modelcontextprotocol/sdk`.
|
|
18
|
+
- Cliente HTTP: usa `node-fetch` y `EXTERNAL_URL` como base para las peticiones.
|
|
19
|
+
|
|
20
|
+
## Requisitos
|
|
21
|
+
|
|
22
|
+
- Node.js 18+ (o compatible con ESM y fetch nativo).
|
|
23
|
+
- npm
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## Configuración y ejecución (ejemplos de integración)
|
|
27
|
+
|
|
28
|
+
En lugar de instrucciones de instalación local, aquí hay ejemplos prácticos para integrar el servidor en un flujo MCP o en ADK.
|
|
29
|
+
|
|
30
|
+
Ejemplo `mcp.json` (útil para ejecutar con orquestadores que esperan ese formato):
|
|
31
|
+
|
|
32
|
+
```json
|
|
33
|
+
{
|
|
34
|
+
"servers": {
|
|
35
|
+
"koggi-mcp-server": {
|
|
36
|
+
"command": "npx",
|
|
37
|
+
"args": [
|
|
38
|
+
"-y", "@koggitechorg/koggi-mcp-server"
|
|
39
|
+
],
|
|
40
|
+
"env": {
|
|
41
|
+
"EXTERNAL_URL": "https://external-qa-502142473966.us-central1.run.app"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"inputs": []
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Ejemplo de integración en ADK (snippet Python) usando parámetros de Stdio:
|
|
50
|
+
|
|
51
|
+
```py
|
|
52
|
+
tools = [
|
|
53
|
+
MCPToolsetConParseo(
|
|
54
|
+
connection_params=StdioServerParameters(
|
|
55
|
+
command="npx",
|
|
56
|
+
args=["-y", "@koggitechorg/koggi-mcp-server"],
|
|
57
|
+
env={"EXTERNAL_URL": EXTERNAL_URL},
|
|
58
|
+
)
|
|
59
|
+
),
|
|
60
|
+
]
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Estos ejemplos muestran cómo arrancar el servidor desde `npx` (instalación bajo demanda) y pasar `EXTERNAL_URL` como variable de entorno. `EXTERNAL_URL` se concatena con las rutas internas definidas en el cliente HTTP (`src/utils/apiClient.ts`).
|
|
64
|
+
|
|
65
|
+
## Licencia
|
|
66
|
+
|
|
67
|
+
Licencia no especificada en el repo. Añade un `LICENSE` si quieres publicar bajo una licencia permissiva (MIT, Apache-2.0, etc.).
|
|
68
|
+
|
|
69
|
+
## Contacto
|
|
70
|
+
|
|
71
|
+
Si necesitas ayuda para adaptar el servidor (p. ej. cambiar transporte, añadir nuevas tools o endpoints), abre un issue o contacta al equipo de Koggitech.
|
package/dist/config/config.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { validateRequestToken } from "../middlewares/middleware.js";
|
|
1
2
|
import { apiFetch } from "../utils/apiClient.js";
|
|
2
3
|
async function generateSimulator(data) {
|
|
3
|
-
return apiFetch(`/api/monitoreo-financiero/simulate-new-calculator-by-id-lead`, {
|
|
4
|
+
return await validateRequestToken(async () => apiFetch(`/api/monitoreo-financiero/simulate-new-calculator-by-id-lead`, {
|
|
4
5
|
method: "POST",
|
|
5
6
|
body: JSON.stringify(data),
|
|
6
|
-
});
|
|
7
|
+
}));
|
|
7
8
|
}
|
|
8
9
|
export { generateSimulator };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CONFIG } from "../config/config.js";
|
|
2
|
+
import { apiFetch } from "../utils/apiClient.js";
|
|
3
|
+
async function validateRequestToken(func) {
|
|
4
|
+
const token = CONFIG.token;
|
|
5
|
+
const isValid = await validateToken(token);
|
|
6
|
+
if (!isValid) {
|
|
7
|
+
return [{ type: "text", text: "Invalid request token." }];
|
|
8
|
+
}
|
|
9
|
+
return await func();
|
|
10
|
+
}
|
|
11
|
+
async function validateToken(token) {
|
|
12
|
+
const response = await apiFetch(`/api/mcp/validate`, {
|
|
13
|
+
method: "POST",
|
|
14
|
+
headers: {
|
|
15
|
+
"Authorization": `Bearer ${token}`
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
console.log("Token validation response:", response);
|
|
19
|
+
return response?.success;
|
|
20
|
+
}
|
|
21
|
+
export { validateRequestToken };
|
package/package.json
CHANGED
package/src/config/config.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import dotenv from "dotenv";
|
|
2
2
|
dotenv.config();
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
interface Config {
|
|
5
|
+
apiUrl: string;
|
|
6
|
+
token: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const CONFIG: Config = {
|
|
5
10
|
apiUrl: process.env.EXTERNAL_URL || "",
|
|
11
|
+
token: process.env.API_TOKEN || "",
|
|
6
12
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { validateRequestToken } from "../middlewares/middleware.js";
|
|
1
2
|
import { apiFetch } from "../utils/apiClient.js";
|
|
2
3
|
|
|
3
4
|
interface SimulatorData {
|
|
@@ -5,10 +6,10 @@ interface SimulatorData {
|
|
|
5
6
|
}
|
|
6
7
|
|
|
7
8
|
async function generateSimulator(data: SimulatorData): Promise<void> {
|
|
8
|
-
return apiFetch(`/api/monitoreo-financiero/simulate-new-calculator-by-id-lead`, {
|
|
9
|
+
return await validateRequestToken(async () => apiFetch(`/api/monitoreo-financiero/simulate-new-calculator-by-id-lead`, {
|
|
9
10
|
method: "POST",
|
|
10
11
|
body: JSON.stringify(data),
|
|
11
|
-
});
|
|
12
|
+
}));
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
export {
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CONFIG } from "../config/config.js";
|
|
2
|
+
import { apiFetch } from "../utils/apiClient.js";
|
|
3
|
+
|
|
4
|
+
async function validateRequestToken(func: Function) {
|
|
5
|
+
const token = CONFIG.token;
|
|
6
|
+
const isValid = await validateToken(token);
|
|
7
|
+
if (!isValid ) {
|
|
8
|
+
return [{ type: "text", text: "Invalid request token." }];
|
|
9
|
+
}
|
|
10
|
+
return await func();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async function validateToken(token: string): Promise<boolean> {
|
|
14
|
+
const response = await apiFetch(`/api/mcp/validate`, {
|
|
15
|
+
method: "POST",
|
|
16
|
+
headers: {
|
|
17
|
+
"Authorization": `Bearer ${token}`
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
console.log("Token validation response:", response);
|
|
21
|
+
return response?.success;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
export {
|
|
26
|
+
validateRequestToken
|
|
27
|
+
}
|
package/src/config/config.js
DELETED
package/src/index.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
-
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
-
import { buildHandlers } from "./server.js";
|
|
4
|
-
|
|
5
|
-
async function main() {
|
|
6
|
-
console.log("🚀 Starting koggi-mcp-server...");
|
|
7
|
-
|
|
8
|
-
const server = new McpServer({
|
|
9
|
-
name: "koggi-mcp-server",
|
|
10
|
-
version: "1.0.0",
|
|
11
|
-
description: "Custom MCP server for Koggi",
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
const handlers = await buildHandlers();
|
|
15
|
-
|
|
16
|
-
for (const tool of handlers) {
|
|
17
|
-
server.tool(tool.name, tool.description, tool.schema, tool.handler);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const transport = new StdioServerTransport();
|
|
21
|
-
await server.connect(transport);
|
|
22
|
-
|
|
23
|
-
console.log("✅ koggi-mcp-server running...");
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
main().catch((err) => {
|
|
27
|
-
console.error("❌ Server failed:", err);
|
|
28
|
-
process.exit(1);
|
|
29
|
-
});
|
package/src/server.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { generateSimulator } from "./handlers/simulator.js";
|
|
3
|
-
|
|
4
|
-
export async function buildHandlers() {
|
|
5
|
-
return [
|
|
6
|
-
{
|
|
7
|
-
name: "generateSimulator",
|
|
8
|
-
description: "generate financial simulator for a user using document number ",
|
|
9
|
-
schema: z.object({
|
|
10
|
-
id: z.string().describe("User ID to fetch"),
|
|
11
|
-
}),
|
|
12
|
-
handler: async ({ id }) => {
|
|
13
|
-
const user = await generateSimulator(id);
|
|
14
|
-
return {
|
|
15
|
-
content: [{ type: "text", text: JSON.stringify(user, null, 2) }],
|
|
16
|
-
};
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
];
|
|
20
|
-
}
|
package/src/utils/apiClient.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { CONFIG } from "../config/config.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export async function apiFetch(path, options = {}) {
|
|
5
|
-
const res = await fetch(`${CONFIG.apiUrl}${path}`, {
|
|
6
|
-
...options,
|
|
7
|
-
headers: { ...CONFIG.apiHeaders, ...(options.headers || {}) },
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
if (!res.ok) {
|
|
11
|
-
const text = await res.text();
|
|
12
|
-
throw new Error(`API error ${res.status}: ${text}`);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return res.json();
|
|
16
|
-
}
|