Vite插件服务器

一个用于Vite的插件服务器,支持自定义工具和实时通信功能。

  • by rywaroy
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 rywaroy/vite-plugin-mcp-server

使用说明

使用方法

npm i vite-plugin-mcp-server -D
import { defineConfig } from "vite";
import { z } from "zod";
import vitePluginMcpServer from "vite-plugin-mcp-server";

export default defineConfig({
  plugins: [
    vitePluginMcpServer({
      port: 3333,
      register(server) {
        server.tool(
          'get-weather',
          'Get the weather of a city',
          {
            city: z.string().describe("The city to get the weather of"),
          },
          async (params) => {
            return {
              content: [
                {
                  type: "text",
                  text: `The weather of ${params.city} is sunny`,
                },
              ],
            };
          }
        )
      },
    }),
  ],
});
import { defineConfig } from "vite";
import z from "zod";
import vitePluginMcpServer from "vite-plugin-mcp-server";

export default defineConfig({
  plugins: [
    vitePluginMcpServer({
      port: 3333,
      tools: [
        {
          name: "get-weather",
          description: "Get the weather of a city",
          parameters: {
            city: z.string().describe("The city to get the weather of"),
          },
          handler: async (params) => {
            return {
              content: [
                {
                  type: "text",
                  text: `The weather of ${params.city} is sunny`,
                },
              ],
            };
          },
        },
      ],
    }),
  ],
});
http://localhost:3333/sse