Babylon MCP服务器
模型上下文协议(MCP)服务器,通过语义搜索为AI代理提供对Babylon.js文档、API参考和源代码的访问。
概述
Babylon MCP服务器使AI助手能够:
- 搜索和检索Babylon.js文档
- 查询API文档中的类、方法和属性
- 搜索Babylon.js源代码
- 检索特定的源代码文件或行范围
这为Babylon.js框架信息提供了一个规范的来源,减少了令牌的使用,提高了使用AI代理时的准确性。
特性
- 文档搜索:跨Babylon.js文档的语义搜索
- API 文档:搜索具有完整TSDoc详细信息的TypeScript API文档
- 源代码搜索:通过Babylon.js源代码进行基于矢量的语义搜索
- 源代码检索:从存储库中获取特定文件或行范围
- 本地存储库管理:自动克隆和更新Babylon.js存储库
先决条件
- Node.js 18或更高版本
- npm或纱线
- ~2GB磁盘空间用于存储库和矢量数据库
安装
- 克隆此存储库:
git clone
cd babylon-mcp- 安装依赖项:
npm install- 构建项目:
npm run buildAlpine Linux安装程序
如果您在Alpine Linux(musl-libc)上运行,则在安装依赖项后需要额外的设置步骤:
npm install
npm run alpine:setup
npm run build这将删除不兼容的 onnxruntime-node 本机模块,并将系统配置为使用WASM后端。WASM后端稍慢,但适用于所有平台。
初始设置
在使用MCP服务器之前,您需要克隆Babylon.js存储库并对其进行索引。这是一个一次性的设置过程。
步骤1:克隆存储库
克隆所需的Babylon.js存储库:
npm run clone:repos这将克隆:
- BabylonJS/文档(文档网站内容)
- BabylonJS/Babylon.js(主框架源代码)
- BabylonJS/havok(物理引擎)
第二步:索引所有数据(推荐)
运行主索引脚本以索引文档、API和源代码:
npm run index:all这将:
- 索引所有文档文件(~5-10分钟)
- 从TypeScript源为API文档编制索引(约10-15分钟)
- 从核心包中索引源代码(~15-20分钟)
总索引时间: 30-45分钟 这取决于你的系统。
索引单个组件
您还可以单独索引组件:
# Index documentation only
npm run index:docs
# Index API documentation only
npm run index:api
# Index source code only
npm run index:source运行服务器
发展模式
使用热重载运行服务器:
npm run dev生产模式
npm start服务器运行在 端口4000 默认情况下。
与AI助手集成
Babylon MCP服务器使用HTTP传输,在连接AI助手之前必须运行。
启动服务器
首先,启动MCP服务器:
# Development mode with hot reload
npm run dev
# OR production mode
npm start服务器运行在 http://localhost:4000 默认情况下。
Claude桌面配置
要将此MCP服务器与Claude Desktop一起使用,请将其添加到您的Claude配置文件中。
配置文件位置
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - 视窗:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
配置
将以下内容添加到您的 claude_desktop_config.json:
{
"mcpServers": {
"babylon-mcp": {
"url": "http://localhost:4000/mcp"
}
}
}重新启动克劳德桌面
更新配置后,重新启动Claude Desktop以使更改生效。
Claude代码CLI配置
要将此MCP服务器与Claude Code(命令行)一起使用,请使用CLI命令直接连接。
重要:在连接之前,确保MCP服务器正在运行(请参阅上面的“启动服务器”部分)。
CLI使用情况
使用连接到MCP服务器 /mcp 带有服务器URL的命令:
# In Claude Code, connect to the running MCP server
/mcp http://localhost:4000/mcp
# Now you can use the tools
Search for "Vector3" in Babylon.js documentation这 /mcp 命令连接到HTTP端点,并使Babylon.js工具在会话中可用。
备注:正在调查HTTP MCP服务器的配置文件支持。目前,使用上面的CLI命令可获得最可靠的连接方法。
可用的MCP工具
配置后,Claude将可以访问这些工具:
1.search_babyn_docs
使用语义搜索搜索Babylon.js文档。
参数:
query(字符串,必填):搜索查询category(字符串,可选):按类别筛选(例如,“api”、“tutorial”)limit(数字,可选):最大结果(默认值:5)
例子:
Search for "how to create a mesh" in Babylon.js documentation2.get_baby_doc
检索特定文档页面的完整内容。
参数:
path(字符串,必填):文档文件路径或标识符
例子:
Get the full documentation for "features/featuresDeepDive/mesh/creation"3.search_babyon_api
搜索Babylon.js API文档(类、方法、属性)。
参数:
query(字符串,必需):API搜索查询(例如“getMeshByName”、“Scene”)limit(数字,可选):最大结果(默认值:5)
例子:
Search the API for "getMeshByName"4.搜索源
使用语义搜索搜索Babylon.js源代码。
参数:
query(字符串,必填):搜索源代码查询package(字符串,可选):按包过滤(例如,“core”、“gui”)limit(数字,可选):最大结果(默认值:5)
例子:
Search the source code for "mesh rendering implementation"5.获取源代码
检索完整的源代码文件或特定的行范围。
参数:
filePath(字符串,必填):从存储库根的相对路径startLine(数字,可选):起始行号(1-索引)endLine(数字,可选):结束行号(1-索引)
例子:
Get the source code from "packages/dev/core/src/scene.ts" lines 4100-4110项目结构
babylon-mcp/
├── src/
│ ├── mcp/ # MCP server implementation
│ │ ├── index.ts # Server entry point
│ │ ├── server.ts # BabylonMCPServer class
│ │ ├── handlers.ts # MCP tool handlers
│ │ └── ...
│ └── search/ # Search and indexing
│ ├── lancedb-search.ts # Search implementation
│ ├── lancedb-indexer.ts # Documentation indexer
│ ├── api-indexer.ts # API indexer
│ ├── source-code-indexer.ts # Source code indexer
│ └── ...
├── scripts/ # Indexing scripts
│ ├── index-docs.ts # Index documentation
│ ├── index-api.ts # Index API docs
│ └── index-source.ts # Index source code
├── data/ # Data directory (created during indexing)
│ ├── repositories/ # Cloned repositories
│ └── lancedb/ # Vector database
└── dist/ # Compiled output发展
运行测试
# Run tests in watch mode
npm test
# Run tests once
npm run test:run
# Run tests with UI
npm run test:ui
# Run tests with coverage
npm run test:coverage类型检查
npm run typecheck建筑
npm run build数据存储
服务器将数据存储在 ./data 目录:
./data/repositories/:克隆的Git存储库(文档、Babylon.js、havok)./data/lancedb/:包含索引内容的矢量数据库
此目录大约为 1.5-2GB 在完全索引之后。
更新数据
要使用最新的Babylon.js内容更新索引数据:
- 在索引过程中,存储库会自动更新
- 重新运行索引脚本:
npm run index:all故障排除
服务器无法启动
- 确保端口4000可用
- 检查项目是否已构建:
npm run build - 验证Node.js版本是否为18或更高
索引失败
- 确保您有互联网连接(用于克隆存储库)
- 检查磁盘空间(需要~2GB)
- 尝试单独索引组件以隔离问题
克劳德没有看到工具
- 确保服务器正在运行:
npm run dev或npm start - 验证服务器是否可访问:
curl http://localhost:4000/health应返回{"status":"healthy"...} - 检查配置:确保
~/.claude/config.json或者Claude Desktop配置具有正确的URL - 重新启动克劳德:配置更改后重新启动Claude Desktop或Claude Code
- 检查服务器日志:在服务器输出中查找连接尝试
搜索未返回任何结果
- 确保索引已成功完成
- 检查一下
./data/lancedb目录存在并包含数据 - 尝试重新索引:
npm run index:all
建筑
服务器使用:
- LanceDB:用于语义搜索的矢量数据库
- Xenova/全迷你LM-L6-v2:嵌入式变压器模型
- TypeDoc:用于提取TypeScript API文档
- Express.js:Web服务器框架
- MCP-SDK:模型上下文协议实现
贡献
欢迎投稿!请确保:
- 所有测试均通过:
npm test - 类型检查通过:
npm run typecheck - 代码遵循项目样式
许可证
ISC
