fix: make mcp work?

This commit is contained in:
2025-08-07 11:54:18 -07:00
parent b8b17b72a3
commit 04f1efa6b8
4 changed files with 356 additions and 24 deletions
+2
View File
@@ -19,9 +19,11 @@
"@anthropic-ai/sdk": "0.56.0",
"@atproto/api": "0.15.26",
"@fastify/cors": "11.0.1",
"@modelcontextprotocol/sdk": "1.17.1",
"@nhcarrigan/logger": "1.0.0",
"@prisma/client": "6.11.1",
"fastify": "5.4.0",
"fastify-mcp-server": "0.4.1",
"gray-matter": "4.0.3",
"twitter-api-v2": "1.24.0"
},
+26 -2
View File
@@ -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) {
-21
View File
@@ -1,21 +0,0 @@
/**
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { documentationData } from "../data/docs.js";
import type { FastifyPluginAsync } from "fastify";
/**
* Mounts the Model Context Protocol routes for the application. These routes
* should not require CORS, as they are used by external services
* such as ChatGPT.
* @param server - The Fastify server instance.
*/
export const mcpRoutes: FastifyPluginAsync = async(server) => {
server.get("/mcp", async(_request, reply) => {
return await reply.status(200).send(documentationData);
});
};