当前位置: 首页 > news >正文

MCP引导Agent示例

 为什么要使用MCP配置文件来引导Agent


使用一个配置文件(例如 mcp.json)来引导 Agent 的行为是一个非常棒且专业的做法。这完全符合AI特性,可以通过明确的指令来引导 Agent 的思路。
mcp.json 文件可以作为 Agent 的“启动手册”或“项目章程”,它将您的所有前置需求结构化、清晰地传达给 Agent。Agent 在开始任何具体任务前,首先被要求读取并遵循这个文件,从而确保它的所有行为都符合项目规范。
操作建议:创建并使用 mcp.json  ——建议在项目根目录 下创建 mcp.json 文件。

mcp.json示例

创建 mcp.json 文件这个文件将包含几个关键部分:Agent 的角色定义、必须遵守的核心原则(来自您的创世文件)、可用的工具集,以及标准工作流程。

下面是一个根据我的所有需求精心设计的 mcp.json 内容示例,以及如何指示 Agent 使用它的方法。

{

"version": "1.0",

"project_name": "Qzen (千针)",

"agent_persona": {

"role": "Gemini Code Assist, a world-class software engineering assistant for the Qzen project.",

"objective": "Your primary goal is to assist in developing the Qzen application by writing high-quality, maintainable, and well-documented code. You must strictly adhere to the project's architecture, coding standards, and the Document-Driven AI Collaboration (DDAC) workflow defined in this file."

},

"core_principles": {

"summary": "You MUST read, understand, and always follow the principles outlined in the 'source/' directory. These are your highest priority guidelines.",

"documents": [

      {

"file": "source/project_goals.rst",

"purpose": "Defines WHAT we are building. All features must align with these goals."

},

      {

"file": "source/architecture.rst",

"purpose": "Defines HOW we are building it. You must follow the 3-tier architecture, use the specified tech stack (PyQt6, SQLAlchemy, Scikit-learn), and implement all long-running tasks in background threads (QThread)."

},

      {

"file": "source/coding_style.rst",

"purpose": "Defines the code quality standards. All Python code MUST be PEP 8 compliant, use snake_case for functions/variables, PascalCase for classes, include Google-style docstrings with type hints, and use Chinese for inline comments."

},

      {

"file": "source/modules.rst",

"purpose": "Defines the code's documentation structure. Your work should be reflected in the auto-generated documentation."

      }

    ]

},

"available_tools": {

"summary": "You have access to the shell to execute commands. Use them for tasks like dependency management, testing, and building.",

"commands": [

      {

"command": "pip install -r requirements.txt",

"description": "Installs or updates all required project dependencies."

},

      {

"command": "cd docs && make html",

"description": "Generates the project's HTML documentation using Sphinx. Assumes being in the project root."

},

      {

"command": "pyinstaller your_script.spec",

"description": "Packages the application into a single executable using PyInstaller."

},

      {

"command": "pytest",

"description": "Runs the automated test suite."

      }

    ]

},

"workflow": {

"name": "Document-Driven AI Collaboration (DDAC)",

"steps": [

"1. **Analyze Request & Update Documentation**: For any new feature or significant change, first update the relevant design/requirements document (e.g., 'project_goals.rst', 'architecture.rst').",

"2. **Request Review**: After updating the documentation, explicitly ask for my (the user's) review and approval before proceeding.",

"3. **Implement Code**: Once the documentation changes are approved, write or modify the code. The code must strictly follow the approved design and 'coding_style.rst'.",

"4. **Write/Update Tests**: Accompany new code with corresponding unit or integration tests.",

"5. **Final Review**: When the implementation and tests are complete, present the code changes (as a diff) for a final review."

],

"rule": "NEVER write code for a new feature before the supporting documentation is updated and approved by the user."

  }

}

Agent启动指令示例

如何指示 Agent 使用此文件在您开始与 Agent 协作时,您的第一个指令至关重要。这个指令将“激活”mcp.json 文件。

给 Agent 的启动指令示例:

您好!我们开始在Qzen项目上工作。

你的工作环境被严格限制在当前项目的工作目录(D:\workspace\PythonProject)

在开始任何任务开始前,请首先完整地阅读并深刻理解位于根目录地mcp.json文件,这个文件定义了你的角色、必须遵守地核心原则、可用地工具以及我们之间强制性的写作流程(DDAC)

阅读完毕后,请向我确认你已理解,并准备好遵循mcp.json中的所有规定开始工作。

为什么这个方法有效?

  1. 明确性 (Clarity): mcp.json 将抽象的需求(“理解我的工作流”)转化为了具体的、机器可读的规则。Agent 不需要猜测,只需遵循文件中的指令。
  2. 一致性 (Consistency): 无论您何时启动一个新的 Agent 会话,都可以使用相同的启动指令。这确保了 Agent 的行为总是一致的,不会因为会话不同而产生偏差。
  3. 可维护性 (Maintainability): 如果未来项目规范有变(例如,增加一个新的构建工具,或者修改编码规范),您只需更新 mcp.json 文件即可,而无需在每次对话时都重复解释新的规则。
  4. 上下文注入 (Context Injection): 这个文件成为了一个强大的“上下文注入”工具。它在任务开始时就为 Agent 提供了关于项目全局的、结构化的知识,使其能更快地进入状态,并像一个已经熟悉项目的老成员一样工作。通过这种方式,您就成功地将一个通用的 Gemini Code Assist “实例化”为了一个专门为您项目服务的、遵循特定规范的、高效的 Agent。这是一个非常高效和可扩展的协作模式。

文章转载自:

http://MyoaZAXU.LqjcL.cn
http://c0JKlvmN.LqjcL.cn
http://lDxL5LPq.LqjcL.cn
http://8SJNQ7ja.LqjcL.cn
http://0c5G0UfQ.LqjcL.cn
http://zfw3mgvn.LqjcL.cn
http://yAQeMUmn.LqjcL.cn
http://KnTe0PeT.LqjcL.cn
http://xM0nPvnf.LqjcL.cn
http://kRVFwKTj.LqjcL.cn
http://UI9XEIbY.LqjcL.cn
http://NB3Epdsn.LqjcL.cn
http://1UZv9qfb.LqjcL.cn
http://gDrrPNH1.LqjcL.cn
http://C1zxUouh.LqjcL.cn
http://zWv5BFeo.LqjcL.cn
http://hz5rwna1.LqjcL.cn
http://RN7oXeO7.LqjcL.cn
http://AhLizXeM.LqjcL.cn
http://FrV9uwTC.LqjcL.cn
http://zYwcN5y4.LqjcL.cn
http://gvqkwVDO.LqjcL.cn
http://UaCe4MlK.LqjcL.cn
http://4oES78Zd.LqjcL.cn
http://ncIcUivT.LqjcL.cn
http://9u6YyzTW.LqjcL.cn
http://iaVkqq3V.LqjcL.cn
http://WzFMBdBx.LqjcL.cn
http://TvwotlrS.LqjcL.cn
http://K39JbA4F.LqjcL.cn
http://www.dtcms.com/a/385243.html

相关文章:

  • 【HTTP 响应状态码】从零到实战
  • 航线系统对频模块技术要点
  • 二十、DevOps落地:Jenkins基础入门(一)
  • 计网1.1
  • DDD领域驱动设计
  • 传智播客--MySQL
  • 不同 HLA II 类等位基因(HLA-DRB1*15:02)与 cGVHD 的关联差异
  • 【AI 辅助工作工具集合】持续更新
  • 核心信息防爬虫盗取技术方案
  • Linux网络:序列化和反序列化
  • Java 代理模式-JDK动态代理
  • RabbitMQ 消息持久化与可靠性
  • 基于YOLO8的打架斗殴行为检测系统【源码+数据集+文章】
  • 电磁超声螺栓轴力检测技术:破解法兰泄露与设备安全痛点的关键方案
  • GPT-5深度解析:它真的是AGI的拂晓晨光吗?
  • (播放器开发)音频输出
  • 视频转音频在线工具大比拼,哪家体验更胜一筹?
  • 如何选择合适的工业绝缘监测仪
  • 【沉浸式解决问题】iPhone 6 登录苹果ID时一直跳出 unexpected error with certificate 或 无法登录
  • Linux系统的系统服务与DHCP服务
  • 高系分五:数据库系统
  • 高效精准的全基因组谱系贝叶斯推断方法SINGER
  • NetSuite Landed Cost到岸成本功能包
  • linux的停止自动休眠
  • 继承与组合:C++面向对象的核心
  • Java进阶教程,全面剖析Java多线程编程,多线程的实现方式,继承Thread类方式,笔记03
  • 猫头虎开源AI分享:一款CSV to Chat AI工具,上传CSV文件提问,它可以即时返回统计结果和可视化图表
  • Android中怎么使用C语言, 以及打包/使用SO动态库
  • 信刻光盘加密刻录系统,保护光盘分发数据安全保密!
  • 自由学习记录(99)