0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Next.jsでMCPサーバーを構築する

Posted at

Streamable HTTPを使用してWebアプリケーションでMCPサーバーを構築します。
mcp-handlerを使用して構築します。

app/[transport]/route.ts

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

const handler = createMcpHandler((server) => {
  server.tool(
    "roll_dice",
    "Rolls an N-sided die",
    {
      sides: z.number().int().min(2),
    },
    async ({ sides }) => {
      const value = 1 + Math.floor(Math.random() * sides);
      return {
        content: [{ type: "text", text: `${value}` }],
      };
    }
  );
});

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

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?