Files
linuztx 5918463f0e Add MCP server instructions to the agent system prompt
MCP servers can return usage instructions in their initialize result,
such as which tool to call first or what an argument means. Agent Zero
discarded them. Capture them when a server connects and add them to the
MCP part of the system prompt, the way reference clients do.

- Capture InitializeResult.instructions on the update_tools (re)connect
  path and cache them with the tools. A failed reconnect clears them, and
  tool calls never change them.
- Render one "MCP Server Instructions" section after the MCP tools, with
  a part for each server that offers at least one allowed tool. The
  framing tells the model that the instructions are context, not
  capabilities, and that tool names in them are the server's own.
- Contain each server's text. Cap it at 4096 characters, demote its
  headings (including --- and === underlined ones) below its part, close
  open code fences, drop control characters and neutralize template
  syntax.
- Build the section inside get_tools_prompt. The Responses transport
  rebuilds the MCP section from that method, so it keeps the section.
- Report has_instructions in the server status API, mark such servers in
  the server list, and show the text in the server detail modal. Pass
  the instructions to the MCP scanner's AI review.
- Document the behavior, note it in the agent's self-knowledge, and add
  tests.
2026-11-26 04:33:05 +00:00

1.8 KiB

System Prompt Extensions DOX

Purpose

  • Own construction of core system prompt sections.

Ownership

  • Ordered Python files own main, tools, MCP, secrets, skills, and project prompt sections.
  • Active project instruction bodies and active-project AGENTS.md path-chain guidance are moved into prompt protocol; the system prompt keeps project metadata and stable project rules.

Local Contracts

  • Preserve ordering where sections depend on earlier context.
  • Main, local-tool and MCP section owners identify their sections to helpers.responses_tools.register_prompt while retaining normal text prompts. That helper owns alternate protocol templates; Chat and fallback keep the text protocol. MCP supplies policy-filtered server context independently of endpoint mode.
  • MCP server instructions are rendered inside MCPConfig.get_tools_prompt so the Responses replacement keeps them. Do not append MCP text to the registered MCP prompt here or in a build_prompt end hook: Responses rebuilds that section and would drop it.
  • Keep secret-related prompt sections masked and scoped.
  • Prompt additions must be bounded and compatible with tool-call contracts.
  • Keep non-tool sections free of configurable capability guidance; tool-owned guidance belongs in policy-filtered agent.system.tool.*.md prompts.
  • Discover local tool prompts through helpers.subagents.get_paths and apply helpers.tool_policy before including their text.
  • Omit the discoverable-skills catalog when profile policy blocks skills_tool actions list or load; loaded skill history remains independent.

Work Guidance

  • Coordinate broad system prompt changes with profiles, skills, tools, plugins, and prompt tests.

Verification

  • Inspect rendered system prompts or run prompt-construction tests after changes.

Child DOX Index

No child DOX files.