MCP组合服务器:3D卡通生成器和文件系统工具
提供两个主要功能的专业级服务器:
- 使用谷歌的Gemini AI生成高质量的3D风格卡通图像
- 用于读取、写入和管理文件的安全文件系统操作
🌟 特性
图像生成
- 3D卡通一代:创建高质量的3D风格卡通图像
- 儿童友好设计:注重丰富多彩、有趣和引人入胜的视觉效果
- 谷歌搜索结果预览功能:在默认浏览器中自动打开生成的图像
- 本地存储:将图像和预览保存在有组织的输出目录中
文件系统操作
- 安全文件访问:路径验证和安全检查
- 读/写文件:读取和写入文本文件内容
- 目录操作:列出、创建和导航目录
- 文件搜索:查找与图案匹配的文件
系统功能
- 专业配置:强大的错误处理和受控日志记录
- 与跨平台支持:适用于Windows、macOS和Linux的智能文件路径处理
- 智能操作系统检测:自动为每个操作系统找到最佳保存位置
- 安全控制:通过配置限制目录访问
🛠️ 技术栈
- 核心框架:模型上下文协议(MCP)SDK
- 人工智能集成:谷歌生成人工智能(Gemini)
- 运行时:Node.js v14+
- 语言:TypeScript
- 程序包管理器:npm
📋 先决条件
- Node.js(v14或更高版本)
- Google Gemini API密钥
- TypeScript
⚙️ 安装
- 克隆存储库:
git clone https://github.com/falahgs/mcp-3d-style-cartoon-gen-server.git
cd mcp-3d-style-cartoon-gen-server- 安装依赖项:
npm install- 配置环境:
创建一个 .env 根目录中的文件:
GEMINI_API_KEY=your_api_key_here
ALLOWED_DIRECTORIES=/path/to/allowed/dir1,/path/to/allowed/dir2- 构建项目:
npm run build🔧 使用MCP服务器配置Claude Desktop
要将此组合服务器与Claude Desktop集成,请执行以下操作:
- 找到配置文件:
- 窗户: %APPDATA%\Claude\claude_desktop_config.json - macOS: ~/Library/Application Support/Claude/claude_desktop_config.json - Linux: ~/.config/Claude/claude_desktop_config.json
- 添加以下配置:
{
"mcpServers": {
"mcp-3d-cartoon-generator": {
"command": "node",
"args": [
"path/to/your/build/index.js"
],
"env": {
"GEMINI_API_KEY": "your_gemini_api_key_here",
"IS_REMOTE": "true",
"SAVE_TO_DESKTOP": "true",
"DETECT_OS_PATHS": "true",
"ALLOWED_DIRECTORIES": "C:\\Users\\YourUsername\\Desktop,C:\\Users\\YourUsername\\Documents",
"DEBUG": "false"
}
}
}
}Windows PowerShell帮助程序脚本
对于Windows用户,您可以使用附带的 fix_claude_config.ps1 自动配置Claude Desktop的脚本:
- 编辑脚本以更新服务器构建的路径和Gemini API密钥
- 在PowerShell中运行脚本:
powershell -ExecutionPolicy Bypass -File .\fix_claude_config.ps1这将创建或更新具有正确编码和设置的配置文件。
🚀 可用工具
1.图像生成工具
{
"name": "generate_3d_cartoon",
"description": "Generates a 3D style cartoon image for kids based on the given prompt",
"inputSchema": {
"type": "object",
"properties": {
"prompt": {
"type": "string",
"description": "The prompt describing the 3D cartoon image to generate"
},
"fileName": {
"type": "string",
"description": "The name of the output file (without extension)"
}
},
"required": ["prompt", "fileName"]
}
}2.文件系统工具
读取文件
{
"name": "read_file",
"description": "Read the contents of a file",
"inputSchema": {
"type": "object",
"properties": {
"path": {
"type": "string",
"description": "Path to the file to read"
}
},
"required": ["path"]
}
}写入文件
{
"name": "write_file",
"description": "Write content to a file",
"inputSchema": {
"type": "object",
"properties": {
"path": {
"type": "string",
"description": "Path to the file to write"
},
"content": {
"type": "string",
"description": "Content to write to the file"
}
},
"required": ["path", "content"]
}
}列表目录
{
"name": "list_directory",
"description": "List the contents of a directory",
"inputSchema": {
"type": "object",
"properties": {
"path": {
"type": "string",
"description": "Path to the directory to list"
}
},
"required": ["path"]
}
}创建目录
{
"name": "create_directory",
"description": "Create a new directory",
"inputSchema": {
"type": "object",
"properties": {
"path": {
"type": "string",
"description": "Path to the directory to create"
}
},
"required": ["path"]
}
}搜索文件
{
"name": "search_files",
"description": "Search for files matching a pattern",
"inputSchema": {
"type": "object",
"properties": {
"path": {
"type": "string",
"description": "Base directory to search from"
},
"pattern": {
"type": "string",
"description": "Search pattern (glob format)"
},
"excludePatterns": {
"type": "array",
"items": {
"type": "string"
},
"description": "Patterns to exclude from search (glob format)"
}
},
"required": ["path", "pattern"]
}
}📄 示例用法
图像生成示例
// Generate a 3D cartoon
{
"name": "generate_3d_cartoon",
"arguments": {
"prompt": "A friendly robot playing with a cat",
"fileName": "robot_cat_play"
}
}文件系统示例
// Read a file
{
"name": "read_file",
"arguments": {
"path": "C:/Users/YourUsername/Documents/example.txt"
}
}
// Write a file
{
"name": "write_file",
"arguments": {
"path": "C:/Users/YourUsername/Documents/new-file.txt",
"content": "This is the content of the file."
}
}
// List directory contents
{
"name": "list_directory",
"arguments": {
"path": "C:/Users/YourUsername/Documents"
}
}
// Create a directory
{
"name": "create_directory",
"arguments": {
"path": "C:/Users/YourUsername/Documents/new-folder"
}
}
// Search for files
{
"name": "search_files",
"arguments": {
"path": "C:/Users/YourUsername/Documents",
"pattern": "*.txt",
"excludePatterns": ["temp*", "*.tmp"]
}
}🔒 安全功能
服务器实施了多种安全措施:
- 路径验证:所有文件路径都经过验证,以确保它们在允许的目录内。
- 允许的目录:仅在
ALLOWED_DIRECTORIES可以访问环境变量。 - Symlink保护:防止通过符号链接访问允许范围之外的目录。
- 受控测井:默认情况下禁用调试日志以防止信息泄漏。
⚙️ 配置选项
环境变量
| 变量 | 描述 | 默认值 |
|---|---|---|
GEMINI_API_KEY | 用于图像生成的Google Gemini API密钥 | (必需) |
ALLOWED_DIRECTORIES | 逗号分隔的允许文件系统路径列表 | 用户的主目录、当前目录 |
IS_REMOTE | 在不打开浏览器的情况下以远程模式运行 | false |
SAVE_TO_DESKTOP | 强制保存到桌面目录 | false |
DETECT_OS_PATHS | 启用特定于操作系统的路径检测 | true |
DEBUG | 启用详细调试日志记录 | false |
🛠️ 故障排除
常见问题:
- Claude中的JSON解析错误:
- 确保 DEBUG 设置为“false”以防止日志干扰JSON通信 - 检查Claude配置中的JSON格式是否正确
- 文件访问被拒绝:
- 验证您尝试访问的路径是否包含在 ALLOWED_DIRECTORIES - 检查目标文件/目录的文件权限
- 图像未保存:
- 集 SAVE_TO_DESKTOP 设置为“true”以确保图像保存到桌面 - 检查服务器日志中的桌面路径检测(暂时启用DEBUG)
📄 许可证
🤝 贡献
欢迎投稿!请随时提交拉取请求。
