@koggitechorg/koggi-mcp-server 1.0.3 → 1.0.5

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 CHANGED
@@ -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
  ]
@@ -2,4 +2,5 @@ import dotenv from "dotenv";
2
2
  dotenv.config();
3
3
  export const CONFIG = {
4
4
  apiUrl: process.env.EXTERNAL_URL || "",
5
+ token: process.env.API_TOKEN || "",
5
6
  };
@@ -0,0 +1,11 @@
1
+ export async function errorHandler(func) {
2
+ try {
3
+ return await func();
4
+ }
5
+ catch (err) {
6
+ console.error('Error:', err);
7
+ return {
8
+ content: [{ type: "text", text: `Ocurrió un error: ${err?.message ?? String(err)}` }]
9
+ };
10
+ }
11
+ }
@@ -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 };
package/dist/index.js 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
  // Create an MCP server
7
8
  const server = new McpServer({
8
9
  name: "koggi-mcp-server",
@@ -19,15 +20,17 @@ server.tool("generateSimulator", "Genera un simulador financiero para un usuario
19
20
  income_updated: z.number().min(1, "Income is required"),
20
21
  observations: z.string().min(1, "Observations are required"),
21
22
  }, async ({ id_lead, email_requester, income_updated, observations }) => {
22
- const user = await generateSimulator({
23
- idLead: id_lead,
24
- ingresosActualizados: income_updated,
25
- observaciones: observations,
26
- emailRequest: email_requester,
23
+ return errorHandler(async () => {
24
+ const user = await generateSimulator({
25
+ idLead: id_lead,
26
+ ingresosActualizados: income_updated,
27
+ observaciones: observations,
28
+ emailRequest: email_requester,
29
+ });
30
+ return {
31
+ content: [{ type: "text", text: JSON.stringify(user, null, 2) }]
32
+ };
27
33
  });
28
- return {
29
- content: [{ type: "text", text: JSON.stringify(user, null, 2) }]
30
- };
31
34
  });
32
35
  // Start receiving messages on stdin and sending messages on stdout
33
36
  const transport = new StdioServerTransport();
@@ -0,0 +1,26 @@
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
+ 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)}` }];
14
+ }
15
+ }
16
+ async function validateToken(token) {
17
+ const response = await apiFetch(`/api/mcp/validate`, {
18
+ method: "POST",
19
+ headers: {
20
+ "Authorization": `Bearer ${token}`
21
+ }
22
+ });
23
+ console.log("Token validation response:", response);
24
+ return response?.success;
25
+ }
26
+ export { validateRequestToken };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koggitechorg/koggi-mcp-server",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -1,6 +1,12 @@
1
1
  import dotenv from "dotenv";
2
2
  dotenv.config();
3
3
 
4
- export const CONFIG: { apiUrl: string } = {
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
  };
@@ -0,0 +1,10 @@
1
+ export async function errorHandler(func: Function) {
2
+ try {
3
+ return await func();
4
+ } catch (err: any) {
5
+ console.error('Error:', err);
6
+ return {
7
+ content: [{ type: "text", text: `Ocurrió un error: ${err?.message ?? String(err)}` }]
8
+ };
9
+ }
10
+ }
@@ -1,14 +1,15 @@
1
+ import { validateRequestToken } from "../middlewares/middleware.js";
1
2
  import { apiFetch } from "../utils/apiClient.js";
2
3
 
3
4
  interface SimulatorData {
4
5
  [key: string]: any;
5
6
  }
6
7
 
7
- async function generateSimulator(data: SimulatorData): Promise<void> {
8
- return apiFetch(`/api/monitoreo-financiero/simulate-new-calculator-by-id-lead`, {
8
+ async function generateSimulator(data: SimulatorData): Promise<any> {
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
@@ -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({
@@ -11,6 +12,7 @@ const server = new McpServer({
11
12
  description: "Custom MCP server for Koggi",
12
13
  });
13
14
 
15
+
14
16
  server.tool(
15
17
  "generateSimulator",
16
18
  "Genera un simulador financiero para un usuario usando su número de documento. Campos requeridos: \
@@ -25,18 +27,22 @@ server.tool(
25
27
  observations: z.string().min(1, "Observations are required"),
26
28
  },
27
29
  async ({ id_lead, email_requester, income_updated, observations }) => {
28
- const user = await generateSimulator({
29
- idLead: id_lead,
30
- ingresosActualizados: income_updated,
31
- observaciones: observations,
32
- emailRequest: email_requester,
30
+ return errorHandler(async () => {
31
+ const user = await generateSimulator({
32
+ idLead: id_lead,
33
+ ingresosActualizados: income_updated,
34
+ observaciones: observations,
35
+ emailRequest: email_requester,
36
+ });
37
+
38
+ return {
39
+ content: [{ type: "text", text: JSON.stringify(user, null, 2) }]
40
+ };
33
41
  });
34
- return {
35
- content: [{ type: "text", text: JSON.stringify(user, null, 2) }]
36
- };
37
42
  }
38
43
  );
39
44
 
45
+
40
46
  // Start receiving messages on stdin and sending messages on stdout
41
47
  const transport = new StdioServerTransport();
42
48
  await server.connect(transport);
@@ -0,0 +1,32 @@
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
+ 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)}` }];
14
+ }
15
+ }
16
+
17
+
18
+ async function validateToken(token: string): Promise<boolean> {
19
+ const response = await apiFetch(`/api/mcp/validate`, {
20
+ method: "POST",
21
+ headers: {
22
+ "Authorization": `Bearer ${token}`
23
+ }
24
+ });
25
+ console.log("Token validation response:", response);
26
+ return response?.success;
27
+ }
28
+
29
+
30
+ export {
31
+ validateRequestToken
32
+ }
@@ -1,7 +0,0 @@
1
- import dotenv from "dotenv";
2
- dotenv.config();
3
-
4
- export const CONFIG = {
5
- apiUrl: process.env.EXTERNAL_URL || "https://api.miapi.com/v1",
6
- apiHeaders: JSON.parse(process.env.OPENAPI_MCP_HEADERS || "{}"),
7
- };
@@ -1,10 +0,0 @@
1
- import { apiFetch } from "../utils/apiClient.js";
2
-
3
- async function generateSimulator(id) {
4
- return apiFetch(`/simulators/${id}`);
5
- }
6
-
7
-
8
- export {
9
- generateSimulator
10
- }
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
- }
@@ -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
- }