@koggitechorg/koggi-mcp-server 1.0.3 → 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/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/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
|
-
}
|