Next.js Discord

Discord Forum

Having multiple MCP Routes not possible

Unanswered
Tonkinese posted this in #help-forum
Open in Discord
TonkineseOP
Hi, under mcp/route.tsx I have this file:

import { createMcpHandler } from "mcp-handler";
import axios from "axios";
import { string, z } from "zod";

const handler = createMcpHandler(async (server) => {
  server.registerTool(
    "test",
    {
      title: "Test!",
      description: "Get the Test!",
      inputSchema: z.object({
        test: z.string(),
        prettyFormatted: z.boolean().optional(),
      }),
      outputSchema: z.object({
        content: z.array(
          z.object({
            type: z.string(),
            text: z.string(),
          }),
        ),
      }),
      annotations: {
          title: "Test",
          readOnlyHint: true,
          destructiveHint: true,
          idempotentHint: true,
          openWorldHint: true,
      },
      _meta: {},
    },
    async () => {
        return {
          content: [
            {
              type: "text",
              text: "Test",
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: error instanceof Error ? error.message : String(error),
            },
          ],
        };
      }
    },
  );
});

export { handler as GET, handler as POST, handler as DELETE };


It works perfectly and can be found by Status Code 200.

When I place another file in /chatmcp for example it doesnt work and I get 400. But why?
I really would need to have multiple MCP Servers.

Best Regards

PING ME ON RESPONSE 🙂

1 Reply

TonkineseOP
proxy.ts

import createMiddleware from "next-intl/middleware";

export default createMiddleware({
  locales: ["en", "de"],
  localeDetection: true,
  localePrefix: "never",
  defaultLocale: "en",
});

export const config = {
  matcher: ["/((?!api|_next|internal-api|mcp|chatmcp|.*\\..*).*)"],
};