code cleanup. gismeteo prompt injection
This commit is contained in:
+22
-3
@@ -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) }],
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user