使用方法

使用方法

site icon
2025.03.26 0
TypeScriptVite 插件MCP 服务器开发效率
vite-plugin-mcp-server 是一个 Vite 插件,用于快速创建和管理 MCP(Micro-Communication Protocol)服务器。它允许开发者在 Vite 项目中轻松集成 MCP 服务,并通过自定义工具扩展功能。
View on GitHub

Overview

基本能力

产品定位

vite-plugin-mcp-server 是一个用于 Vite 项目的 MCP 服务器插件,旨在简化 MCP 服务的集成和管理。

核心功能

  1. 快速集成 MCP 服务器:通过 Vite 插件的形式,快速在项目中启动 MCP 服务器。
  2. 自定义工具扩展:支持开发者通过配置自定义工具(如示例中的 get-weather 工具)来扩展服务器功能。
  3. 参数验证:使用 zod 库对工具参数进行验证,确保输入数据的有效性。

适用场景

  1. 前端开发:在 Vite 项目中快速集成 MCP 服务,用于前后端通信。
  2. 工具扩展:通过自定义工具扩展服务器功能,满足特定业务需求。
  3. 原型开发:快速搭建原型,验证功能可行性。

工具列表

  1. get-weather:获取指定城市的天气信息。
  2. 能力:接收城市名称作为参数,返回该城市的天气信息。

常见问题解答

暂无常见问题解答。

使用教程

使用依赖

  1. 确保已安装 Node.js 和 npm/yarn。
  2. 在项目中安装 Vite 和 zod 库: bash npm install vite zod

安装教程

  1. 安装插件: bash npm install vite-plugin-mcp-server
  2. vite.config.ts 中配置插件: ```ts 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, }, ], }; }, }, ], }), ], }); ```

调试方式

  1. 启动 Vite 开发服务器: bash npm run dev
  2. 访问 http://localhost:3333,验证 MCP 服务器是否正常运行。
  3. 调用自定义工具(如 get-weather),检查返回结果是否符合预期。

许可证

None