generated from nhcarrigan/template
fix: make mcp work?
This commit is contained in:
+26
-2
@@ -5,12 +5,15 @@
|
||||
*/
|
||||
|
||||
import cors from "@fastify/cors";
|
||||
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||
import fastify from "fastify";
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention -- 'Tis a class.
|
||||
import FastifyMcpServer from "fastify-mcp-server";
|
||||
import { documentationData } from "./data/docs.js";
|
||||
import { corsHook } from "./hooks/cors.js";
|
||||
import { ipHook } from "./hooks/ips.js";
|
||||
import { announcementRoutes } from "./routes/announcement.js";
|
||||
import { baseRoutes } from "./routes/base.js";
|
||||
import { mcpRoutes } from "./routes/mcp.js";
|
||||
import { logger } from "./utils/logger.js";
|
||||
|
||||
const server = fastify({
|
||||
@@ -33,7 +36,28 @@ server.addHook("preHandler", ipHook);
|
||||
|
||||
server.register(baseRoutes);
|
||||
server.register(announcementRoutes);
|
||||
server.register(mcpRoutes);
|
||||
|
||||
const mcp = new McpServer({
|
||||
name: "nhcarrigan-mcp",
|
||||
version: process.env.npm_package_version ?? "0.0.0",
|
||||
});
|
||||
|
||||
// Define MCP tools
|
||||
mcp.tool("docs", () => {
|
||||
return {
|
||||
content: documentationData.documents.map((document) => {
|
||||
return {
|
||||
text: JSON.stringify(document, null, 2),
|
||||
type: "text",
|
||||
};
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
await server.register(FastifyMcpServer, {
|
||||
endpoint: "/mcp",
|
||||
server: mcp.server,
|
||||
});
|
||||
|
||||
server.listen({ port: 20_000 }, (error) => {
|
||||
if (error) {
|
||||
|
||||
Reference in New Issue
Block a user