code cleanup. gismeteo prompt injection

This commit is contained in:
azykov@mail.ru
2026-07-10 15:25:56 +03:00
parent 6cfff5ef4b
commit 3b46f15e9f
6 changed files with 41 additions and 23 deletions
+22 -3
View File
@@ -1,5 +1,5 @@
import Fastify, { type FastifyInstance } from "fastify";
import { ToolDef } from "./types";
import { TextResult, ToolDef } from "./types";
import McpSession from "./mcpConnection";
import { isInitializeRequest } from "@modelcontextprotocol/sdk/types.js";
import * as mcpTools from "./mcpTools";
@@ -10,7 +10,7 @@ export class Server {
private readonly app: FastifyInstance;
private readonly port: number;
private readonly sessions: McpSession[] = [];
public readonly tools: Record<string, ToolDef> = {};
public readonly tools: Record<string, ToolDef<TextResult>> = {};
constructor(port: number = Number(process.env.PORT ?? 3000)) {
this.port = port;
@@ -63,7 +63,26 @@ export class Server {
for (const tool of tools) {
if (!this.getTool(tool.title)) {
// console.log(`Registering new tool ${tool.title}`);
this.tools[tool.title] = logged(tool);
const toolLogged = logged(tool);
this.tools[tool.title] = {
...toolLogged,
handler: async (args) => {
try {
const res = await toolLogged.handler(args);
if (typeof res === 'string')
return { content: [{ type: "text", text: res, }] };
else
return res;
}
catch (err) {
console.error(err);
return {
isError: true,
content: [{ type: "text", text: (err as Error).message ?? String(err) }],
};
}
},
};
}
}