
使用方法

Overview
基本能力
产品定位
vite-plugin-mcp-server 是一个用于 Vite 项目的 MCP 服务器插件,旨在简化 MCP 服务的集成和管理。
核心功能
- 快速集成 MCP 服务器:通过 Vite 插件的形式,快速在项目中启动 MCP 服务器。
- 自定义工具扩展:支持开发者通过配置自定义工具(如示例中的
get-weather
工具)来扩展服务器功能。 - 参数验证:使用
zod
库对工具参数进行验证,确保输入数据的有效性。
适用场景
- 前端开发:在 Vite 项目中快速集成 MCP 服务,用于前后端通信。
- 工具扩展:通过自定义工具扩展服务器功能,满足特定业务需求。
- 原型开发:快速搭建原型,验证功能可行性。
工具列表
- get-weather:获取指定城市的天气信息。
- 能力:接收城市名称作为参数,返回该城市的天气信息。
常见问题解答
暂无常见问题解答。
使用教程
使用依赖
- 确保已安装 Node.js 和 npm/yarn。
- 在项目中安装 Vite 和 zod 库:
bash npm install vite zod
安装教程
- 安装插件:
bash npm install vite-plugin-mcp-server
- 在
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
,
},
],
};
},
},
],
}),
],
});
```
调试方式
- 启动 Vite 开发服务器:
bash npm run dev
- 访问
http://localhost:3333
,验证 MCP 服务器是否正常运行。 - 调用自定义工具(如
get-weather
),检查返回结果是否符合预期。
许可证
None