本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
示例
本节提供了常见开发工作流程和用例的自定义代理配置的实际示例。
AWS 专业定制代理
此自定义代理针对 AWS 基础设施管理和开发任务进行了优化。它提供对 AWS 工具的预先批准访问权限,同时包含相关文档。
例 AWS 专家定制代理配置
{ "description": "Specialized custom agent for AWS infrastructure and development tasks", "tools": [ "fs_read", "fs_write", "execute_bash", "use_aws" ], "allowedTools": [ "fs_read", "use_aws" ], "toolsSettings": { "use_aws": { "allowedServices": [ "s3", "lambda", "cloudformation", "ec2", "iam", "logs" ] }, "fs_write": { "allowedPaths": [ "infrastructure/**", "scripts/**", "*.yaml", "*.yml", "*.json" ] } }, "resources": [ "file://README.md", "file://infrastructure/**/*.yaml", "file://infrastructure/**/*.yml", "file://docs/aws-setup.md", "file://scripts/deploy.sh" ], "hooks": { "agentSpawn": [ { "command": "aws sts get-caller-identity", "timeout_ms": 10000, "cache_ttl_seconds": 300 } ] } }
此自定义代理的用例:
-
部署 CloudFormation 堆栈
-
管理 S3 存储桶和 Lambda 函数
-
对 AWS 服务问题进行故障排除
-
审查和更新基础架构即代码
开发工作流程自定义代理
此定制代理专为一般软件开发任务而设计,包括代码审查、测试和 Git 操作。
例 开发工作流程自定义代理配置
{ "description": "General development workflow custom agent with Git integration", "mcpServers": { "git": { "command": "git-mcp-server", "args": [], "timeout": 30000 } }, "tools": [ "fs_read", "fs_write", "execute_bash", "@git" ], "allowedTools": [ "fs_read", "@git/git_status", "@git/git_log", "@git/git_diff" ], "toolAliases": { "@git/git_status": "status", "@git/git_log": "log", "@git/git_diff": "diff" }, "toolsSettings": { "fs_write": { "allowedPaths": [ "src/**", "tests/**", "docs/**", "*.md", "*.json", "package.json", "requirements.txt" ] } }, "resources": [ "file://README.md", "file://CONTRIBUTING.md", "file://docs/**/*.md", "file://package.json", "file://requirements.txt" ], "hooks": { "agentSpawn": [ { "command": "git status --porcelain", "timeout_ms": 5000 }, { "command": "git branch --show-current", "timeout_ms": 3000 } ] } }
此自定义代理的用例:
-
代码审查和分析
-
编写和更新测试
-
Git 工作流程管理
-
文档更新
-
依赖关系管理
代码审查自定义代理
此自定义代理专门用于代码审查任务,其工具和上下文经过优化,可分析代码质量、安全性和最佳实践。
例 代码审查自定义代理配置
{ "description": "Specialized custom agent for code review and quality analysis", "tools": [ "fs_read", "execute_bash" ], "allowedTools": [ "fs_read", "execute_bash" ], "toolsSettings": { "execute_bash": { "allowedCommands": [ "grep", "find", "wc", "head", "tail", "cat", "diff", "git diff", "git log", "eslint", "pylint", "rubocop" ] } }, "resources": [ "file://CONTRIBUTING.md", "file://docs/coding-standards.md", "file://docs/security-guidelines.md", "file://.eslintrc.json", "file://.pylintrc", "file://pyproject.toml" ], "hooks": { "agentSpawn": [ { "command": "git diff --name-only HEAD~1", "timeout_ms": 5000, "max_output_size": 2048 } ], "userPromptSubmit": [ { "command": "find . -name '*.py' -o -name '*.js' -o -name '*.ts' | wc -l", "timeout_ms": 3000, "cache_ttl_seconds": 60 } ] } }
此自定义代理的用例:
-
审查代码质量的拉取请求
-
识别安全漏洞
-
检查编码标准的遵守情况
-
分析代码的复杂性和可维护性
-
提出改进建议和重构机会
项目特定的定制代理
此示例说明如何创建针对特定项目量身定制的自定义代理,包括项目特定的工具、文档和生成流程。
例 特定于项目的自定义代理配置
{ "description": "Custom agent for the mobile app backend project", "mcpServers": { "docker": { "command": "docker-mcp-server", "args": ["--socket", "/var/run/docker.sock"] }, "database": { "command": "postgres-mcp-server", "args": ["--connection", "postgresql://localhost:5432/myapp"], "env": { "PGPASSWORD": "$DATABASE_PASSWORD" } } }, "tools": [ "fs_read", "fs_write", "execute_bash", "@docker", "@database" ], "allowedTools": [ "fs_read", "@docker/docker_ps", "@docker/docker_logs", "@database/query_read_only" ], "toolAliases": { "@docker/docker_ps": "containers", "@docker/docker_logs": "logs", "@database/query_read_only": "query" }, "toolsSettings": { "fs_write": { "allowedPaths": [ "src/**", "tests/**", "migrations/**", "docker-compose.yml", "Dockerfile", "requirements.txt" ] }, "execute_bash": { "allowedCommands": [ "npm test", "npm run build", "python manage.py test", "docker-compose up", "docker-compose down" ] } }, "resources": [ "file://README.md", "file://docs/api-documentation.md", "file://docs/database-schema.md", "file://docker-compose.yml", "file://requirements.txt", "file://src/config/settings.py" ], "hooks": { "agentSpawn": [ { "command": "docker-compose ps", "timeout_ms": 10000, "cache_ttl_seconds": 30 }, { "command": "git status --porcelain", "timeout_ms": 5000 } ] } }
此自定义代理的用例:
-
管理 Docker 容器和服务
-
运行数据库查询和迁移
-
构建和测试应用程序
-
调试生产问题
-
更新 API 文档
创建有效的自定义代理的技巧
-
从简单开始-从基本的工具配置开始,然后根据需要增加复杂性
-
使用描述性名称-选择能清楚表明其用途的自定义代理名称
-
包括相关上下文-将项目文档和配置文件添加到资源中
-
预先批准安全工具-在 AllowedTools 中加入常用的、低风险的工具
-
在@@ 动态上下文中使用钩子-通过命令挂钩包含当前系统状态
-
限制工具范围-使用 ToolsSettings 限制工具访问相关路径和服务
-
彻底测试-验证您的自定义代理配置是否按预期运行
-
记录您的自定义代理-使用清晰的描述帮助团队成员了解定制代理的用途