generated from nhcarrigan/template
feat: error logging
This commit is contained in:
@@ -50,7 +50,10 @@ export const ai = async(
|
|||||||
name: "nhcarrigan-mcp",
|
name: "nhcarrigan-mcp",
|
||||||
type: "url",
|
type: "url",
|
||||||
url: "https://hikari.nhcarrigan.com/api/mcp",
|
url: "https://hikari.nhcarrigan.com/api/mcp",
|
||||||
authorization_token: "hikari"
|
tool_configuration: {
|
||||||
|
allowed_tools: ["docs"],
|
||||||
|
enabled: true
|
||||||
|
}
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
messages: messages.map((message) => {
|
messages: messages.map((message) => {
|
||||||
|
|||||||
+20
-1
@@ -8,7 +8,7 @@ import cors from "@fastify/cors";
|
|||||||
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
import fastify from "fastify";
|
import fastify from "fastify";
|
||||||
// eslint-disable-next-line @typescript-eslint/naming-convention -- 'Tis a class.
|
// eslint-disable-next-line @typescript-eslint/naming-convention -- 'Tis a class.
|
||||||
import FastifyMcpServer from "fastify-mcp-server";
|
import FastifyMcpServer, { getMcpDecorator } from "fastify-mcp-server";
|
||||||
import { documentationData } from "./data/docs.js";
|
import { documentationData } from "./data/docs.js";
|
||||||
import { corsHook } from "./hooks/cors.js";
|
import { corsHook } from "./hooks/cors.js";
|
||||||
import { ipHook } from "./hooks/ips.js";
|
import { ipHook } from "./hooks/ips.js";
|
||||||
@@ -54,6 +54,25 @@ mcp.tool("docs", () => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const mcpServer = getMcpDecorator(server);
|
||||||
|
|
||||||
|
const sessionManager = mcpServer.getSessionManager();
|
||||||
|
|
||||||
|
// Session created
|
||||||
|
sessionManager.on("sessionCreated", (sessionId: string) => {
|
||||||
|
void logger.log("debug", `New MCP session: ${sessionId}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Session destroyed
|
||||||
|
sessionManager.on("sessionDestroyed", (sessionId: string) => {
|
||||||
|
void logger.log("debug", `MCP session ended: ${sessionId}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Transport errors
|
||||||
|
sessionManager.on("transportError", (sessionId: string, error: Error) => {
|
||||||
|
void logger.error(`Error in session ${sessionId}:`, error);
|
||||||
|
});
|
||||||
|
|
||||||
await server.register(FastifyMcpServer, {
|
await server.register(FastifyMcpServer, {
|
||||||
endpoint: "/mcp",
|
endpoint: "/mcp",
|
||||||
server: mcp.server,
|
server: mcp.server,
|
||||||
|
|||||||
Reference in New Issue
Block a user