使用说明
项目简介
'astro-mcp' 是一个 Astro 集成,它在 Astro 开发服务器中嵌入了一个 MCP (Model Context Protocol) 服务器。这个服务器提供了一组预定义的 工具 (Tools),允许 LLM 客户端查询和获取关于 Astro 项目的各种信息,例如:Astro 配置、路由信息、已安装的集成以及 Vite 配置等。这使得 LLM 驱动的工具能够更好地理解和操作 Astro 项目,例如自动化代码生成、项目分析和文档生成等。
主要功能点
- 提供标准 MCP 服务: 基于 'vite-plugin-mcp' 构建,遵循 MCP 协议,可以通过 JSON-RPC 与客户端通信。
- 集成 Astro 工具: 内置多个与 Astro 项目相关的工具,方便 LLM 获取项目信息:
- 'get-astro-config': 获取完整的 Astro 配置文件。
- 'list-astro-routes': 列出项目中的所有路由,并支持按类型过滤。
- 'get-astro-server-address': 获取 Astro 开发服务器的地址和端口信息。
- 'list-astro-integrations': 列出已安装的 Astro 集成。
- 'get-astro-integration': 获取指定 Astro 集成的详细信息。
- 同时也集成了 'vite-plugin-mcp' 提供的 Vite 相关工具,例如 'get-vite-config' 和 'get-vite-module-info'。
- 自动配置客户端连接: 在 Astro 开发服务器启动时,自动更新 '.vscode/mcp.json' 和 '.cursor/mcp.json' 文件,简化 VSCode 和 Cursor 等 MCP 客户端的连接配置。
- SSE 传输协议: 使用 Server-Sent Events (SSE) 作为默认的 MCP 通信协议。
安装步骤
-
在 Astro 项目中安装 'astro-mcp' 集成:
在你的 Astro 项目根目录下,运行以下命令:
npx astro add astro-mcp或者手动安装:
npm install astro-mcp然后在你的 'astro.config.ts' 文件中添加集成:
import { defineConfig } from "astro/config"; import mcp from "astro-mcp"; export default defineConfig({ integrations: [mcp()], }); -
启动 Astro 开发服务器:
运行 'npm run dev' 或 'astro dev' 启动 Astro 开发服务器。
服务器配置
对于 MCP 客户端,你需要配置连接到 'astro-mcp' 服务器的信息。以下是一个示例 JSON 配置,用于连接到本地运行的 'astro-mcp' 服务器。请注意,'astro-mcp' 服务器与 Astro 开发服务器一同启动,无需单独启动命令。
{ "serverName": "astro", "command": "astro", "args": ["dev"], "url": "http://localhost:4321/__mcp/sse" }
配置参数说明:
- 'serverName': 服务器名称,这里设置为 "astro"。
- 'command': 启动 Astro 开发服务器的命令,通常为 "astro"。
- 'args': 传递给 Astro 命令的参数,这里使用 "dev" 启动开发服务器。
- 'url': 重要,MCP 服务器的 SSE 连接地址。'astro-mcp' 默认在 'http://localhost:4321/__mcp/sse' 提供服务。端口 '4321' 是 Astro 开发服务器的默认端口,如果你的项目使用了不同的端口,请相应修改。
基本使用方法
- 启动 Astro 开发服务器 后,MCP 服务器也随之启动。
- 配置 MCP 客户端,例如 VSCode 或 Cursor,使用上面提供的服务器配置信息连接到 'astro-mcp' 服务器。
- 在 MCP 客户端中,你可以调用 'astro-mcp' 提供的工具,例如 'list-astro-routes' 来获取项目路由列表,或者 'get-astro-config' 来获取 Astro 配置文件内容,从而实现基于 LLM 的 Astro 项目辅助开发功能。
信息
分类
开发者工具