generated from nhcarrigan/template
fix: make mcp work?
This commit is contained in:
@@ -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
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user