Skip to content

Commit a7ec04a

Browse files
authored
docs: add MCP tool docstring guidelines to AGENTS.md and styleguide (homeassistant-ai#907)
* docs(agents): add Tool Docstrings guidelines and update template Builds on the foundation laid by homeassistant-ai#752 (@julienld). Adds a structured `### Tool Docstrings` section to AGENTS.md and updates the tool template to show optional blocks as comments rather than a prescriptive skeleton. Key design choices: - Single-line template remains the default (progressive disclosure) - Optional blocks (RELATED TOOLS, EXAMPLES, NOTE) are comments in the template, with guidelines on when to use each - Explicit "What NOT to include" list to prevent over-documentation - Corrects ha_get_domain_docs -> ha_get_skill_home_assistant_best_practices * docs(styleguide): add MCP Tool Docstrings review section Complements the AGENTS.md Tool Docstrings guidelines. Gives Gemini Code Assist actionable MEDIUM-severity flags for the most common docstring problems while explicitly excluding false positives on legitimate concise docstrings (progressive disclosure: brief by default). Builds on homeassistant-ai#752 (@julienld). * fix(docs): restructure template, add remove verb, address GB findings Finding 1: Move developer guidance comments outside the docstring triple-quotes. Restores the original convention: docstring content inside """, developer notes as Python comments after closing """. This ensures the template teaches correct Python structure. Finding 2: Add `remove` to Naming Convention and verb checklist. 13 tools use ha_remove_*/ha_config_remove_* vs 4 ha_*delete_*. `remove` is the dominant verb for registry items but was undocumented. Also clarifies the delete vs remove distinction inline. Finding 3 (no change): The `# For complex schemas` in prose correctly shows a Python comment in the function body. Removing the # would conflate a developer note with docstring content -- explained in PR. * fix(docs): correct delete example in Naming Convention ha_config_delete_automation does not exist -- it was a pre-existing error in AGENTS.md. Replaced with ha_config_delete_dashboard (real tool). Also corrected the description: delete covers dashboards, config entries, and files -- not just files as GB suggested (ha_config_delete_dashboard, ha_config_delete_dashboard_resource, ha_delete_config_entry confirm this). * fix(docs): use 'delete' in delete verb description After introducing 'remove' as a separate verb category, describing 'delete' as 'remove dashboards...' was ambiguous. Using 'delete' in the description eliminates the semantic overlap. * fix(styleguide): add Remove to verb list, drop superseded Tool descriptions item
1 parent a6ff2fe commit a7ec04a

2 files changed

Lines changed: 53 additions & 6 deletions

File tree

.gemini/styleguide.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,24 @@ Flag HIGH severity if errors use plain exceptions or dict returns instead of str
9696

9797
## Code Conventions
9898

99-
1. **Tool descriptions**: Use action verbs, keep concise
100-
2. **Async/await**: Use consistently for I/O operations
101-
3. **Type hints**: Required for all function signatures
99+
## MCP Tool Docstrings
100+
101+
These rules apply to new or modified tool docstrings in the PR diff only -- not to pre-existing docstrings in unchanged files.
102+
103+
**Flag MEDIUM severity when a new or modified tool docstring:**
104+
- Does not start with an action verb (`Returns...` should be `Get...`; valid verbs: `Get`, `List`, `Search`, `Create`, `Update`, `Delete`, `Remove`, `Execute`, `Call`)
105+
- Is missing entirely or is still a placeholder
106+
- References a non-existent tool (e.g., `ha_get_domain_docs` -- the correct name is `ha_get_skill_home_assistant_best_practices`)
107+
- Embeds a full parameter schema instead of deferring to `ha_get_skill_home_assistant_best_practices`
108+
- Is a workflow-entry tool but gives no hint about the next natural tool to call
109+
110+
**Do NOT flag:**
111+
- Concise one-liners on straightforward tools (progressive disclosure: brief by default)
112+
- Missing examples on tools with obvious single-parameter calls
113+
- Multi-line docstrings that stay focused and on-topic
114+
115+
1. **Async/await**: Use consistently for I/O operations
116+
2. **Type hints**: Required for all function signatures
102117

103118
## Documentation Standards
104119

AGENTS.md

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,8 @@ src/ha_mcp/
523523
- `list` — collections (`ha_list_areas`)
524524
- `search` — filtered queries (`ha_search_entities`)
525525
- `set` — create/update (`ha_config_set_helper`)
526-
- `delete` — remove (`ha_config_delete_automation`)
526+
- `delete` — delete dashboards, config entries, or files (`ha_config_delete_dashboard`, `ha_delete_file`)
527+
- `remove` — remove registry items (`ha_remove_entity`, `ha_config_remove_area`)
527528
- `call` — execute (`ha_call_service`)
528529

529530
### Tool Structure
@@ -534,10 +535,41 @@ def register_<domain>_tools(mcp, client, **kwargs):
534535
@mcp.tool(tags={"Category Name"}, annotations={"readOnlyHint": True, "idempotentHint": True})
535536
@log_tool_usage
536537
async def ha_<verb>_<noun>(param: str) -> dict[str, Any]:
537-
"""One-line summary starting with action verb."""
538-
# For complex schemas, add: "Use ha_get_skill_home_assistant_best_practices for details."
538+
"""<Action verb> <what this tool does -- one sentence>.
539+
540+
<Optional: second sentence for key behavioral distinction or modes>
541+
"""
542+
# Add to the docstring above only when genuinely needed:
543+
# RELATED TOOLS: ha_next(): why to call this after (workflow-entry tools only)
544+
# EXAMPLES: ha_<verb>_<noun>("realistic_value") -- non-obvious call patterns only
545+
# NOTE / WARNING: non-obvious gotcha or destructive side-effect
546+
# For complex schemas: use ha_get_skill_home_assistant_best_practices
539547
```
540548

549+
### Tool Docstrings
550+
551+
The single-line template is the default -- extend it only where it genuinely helps.
552+
553+
**Required for every tool:**
554+
- Starts with an action verb (`Get`, `List`, `Search`, `Create`, `Update`, `Delete`, `Remove`, `Execute`, `Call`)
555+
- One sentence describing what the tool does (not how)
556+
557+
**Add `RELATED TOOLS` when** the tool is a workflow entry point and the natural next step is not obvious.
558+
Example: `ha_search_entities` hints at `ha_get_state`.
559+
560+
**Add `EXAMPLES` when** the tool has multiple modes or non-obvious parameters.
561+
Omit when a single required parameter makes the call self-evident.
562+
563+
**Add `NOTE` or `WARNING` when** there is a non-obvious gotcha, a destructive side-effect,
564+
or a behavioral quirk that causes silent failures if ignored.
565+
566+
**Defer complex schemas** instead of embedding them:
567+
`# For complex schemas: use ha_get_skill_home_assistant_best_practices`
568+
569+
**What NOT to include:** full parameter documentation, type descriptions already in the
570+
signature, HA domain internals the model already knows, or motivational prose.
571+
572+
541573
### Tool Tags
542574

543575
Every tool needs `tags={"Category Name"}` (native FastMCP parameter). Drives the README table, `site/src/data/tools.json`, and `homeassistant-addon/DOCS.md`. These are auto-regenerated on merge by `sync-tool-docs.yml` — no manual regeneration needed. For local testing: `python scripts/extract_tools.py`

0 commit comments

Comments
 (0)