Skip to content

Commit bc9499b

Browse files
committed
fix(docs-gen): smarter sentence split for frontmatter descriptions
PR #1157 review (Copilot + CodeRabbit) flagged that several tool pages had truncated frontmatter, e.g. manage_asset rendering as: description: "Performs asset operations (import, create, modify, delete, etc" Root cause: the generator used `description.split(".")[0]` to derive the frontmatter blurb. That cuts at the FIRST period — including periods inside abbreviations and parenthesized lists ("etc.) in Unity."), so the rendered description stopped mid-clause. Fix: introduce `_first_sentence()` that splits on real sentence boundaries — `.` / `!` / `?` followed by whitespace + capital, or a paragraph break — and falls back to the whole string if no boundary exists. Also caps absurdly long single-sentence descriptions at ~240 chars to keep frontmatter compact. All three call sites that used the old split: - frontmatter `description:` in render_tool_page - group-index bullets in render_group_index - catalog-index bullets in render_catalog_index Regenerated all 43 tool pages + 9 group landings + catalog index + resources catalog. Verified `--check` passes round-trip and full website build is clean. manage_asset now reads: "Performs asset operations (import, create, modify, delete, etc.) in Unity."
1 parent 45962b2 commit bc9499b

54 files changed

Lines changed: 159 additions & 132 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

tools/generate_docs_reference.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,33 @@ def introspect_params(func: Any) -> list[ParamDoc]:
227227
# ---------------------------------------------------------------------------
228228

229229

230+
_SENTENCE_BOUNDARY = re.compile(r"(?<=[.!?])\s+(?=[A-Z])|\n\s*\n")
231+
232+
233+
def _first_sentence(description: str) -> str:
234+
"""Return the first sentence of a tool description, suitable for
235+
frontmatter / catalog blurbs.
236+
237+
The earlier implementation used `description.split(".")[0]` which
238+
cut the string at the first period — including periods inside
239+
abbreviations and parenthesized lists (e.g. `etc.) in Unity`),
240+
producing truncated frontmatter like `"...modify, delete, etc"`.
241+
242+
Split on a real sentence boundary instead: a `.`, `!`, or `?`
243+
followed by whitespace + a capital letter (or a paragraph break).
244+
Fall back to the entire string if no boundary is found, then
245+
smart-truncate to keep frontmatter compact.
246+
"""
247+
text = (description or "").strip().replace('"', "'")
248+
if not text:
249+
return ""
250+
first = _SENTENCE_BOUNDARY.split(text, maxsplit=1)[0].strip()
251+
# Cap absurdly long single-sentence descriptions
252+
if len(first) > 240:
253+
first = first[:237].rstrip() + "…"
254+
return first
255+
256+
230257
def _escape_table_cell(s: str) -> str:
231258
return s.replace("|", "\\|").replace("\n", " ")
232259

@@ -262,7 +289,7 @@ def render_tool_page(tool: dict[str, Any], existing_examples: str) -> str:
262289
params = introspect_params(func)
263290

264291
# Sidebar/title metadata
265-
desc_for_meta = description.split(".")[0].strip().replace('"', "'") or name
292+
desc_for_meta = _first_sentence(description) or name
266293
front_matter = textwrap.dedent(
267294
f"""\
268295
---
@@ -315,7 +342,7 @@ def render_group_index(group: str, tools: list[dict[str, Any]], group_blurb: str
315342
bullets = []
316343
for tool in sorted(tools, key=lambda t: t["name"]):
317344
n = tool["name"]
318-
d = (tool.get("description") or "").split(".")[0].strip()
345+
d = _first_sentence(tool.get("description") or "")
319346
bullets.append(f"- **[`{n}`](./{n}.md)** — {d}")
320347
body = "\n".join(bullets) if bullets else "_No tools in this group._"
321348

@@ -354,7 +381,7 @@ def render_catalog_index(tools_by_group: dict[str, list[dict[str, Any]]],
354381
sections.append(group_blurbs.get(group, ""))
355382
for tool in sorted(tools, key=lambda t: t["name"]):
356383
n = tool["name"]
357-
d = (tool.get("description") or "").split(".")[0].strip()
384+
d = _first_sentence(tool.get("description") or "")
358385
sections.append(f"- **[`{n}`](./{group}/{n}.md)** — {d}")
359386
sections.append("")
360387

website/docs/reference/tools/animation/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ description: "MCP for Unity tools in the animation group."
88

99
Animator control & AnimationClip creation
1010

11-
- **[`manage_animation`](./manage_animation.md)** — Manage Unity animation: Animator control and AnimationClip creation
11+
- **[`manage_animation`](./manage_animation.md)** — Manage Unity animation: Animator control and AnimationClip creation.

website/docs/reference/tools/animation/manage_animation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: manage_animation
33
sidebar_label: manage_animation
4-
description: "Manage Unity animation: Animator control and AnimationClip creation"
4+
description: "Manage Unity animation: Animator control and AnimationClip creation."
55
---
66

77
# `manage_animation`

website/docs/reference/tools/core/apply_text_edits.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: apply_text_edits
33
sidebar_label: apply_text_edits
4-
description: "Apply small text edits to a C# script identified by URI"
4+
description: "Apply small text edits to a C# script identified by URI."
55
---
66

77
# `apply_text_edits`

website/docs/reference/tools/core/batch_execute.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: batch_execute
33
sidebar_label: batch_execute
4-
description: "Executes multiple MCP commands in a single batch for dramatically better performance"
4+
description: "Executes multiple MCP commands in a single batch for dramatically better performance."
55
---
66

77
# `batch_execute`

website/docs/reference/tools/core/create_script.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: create_script
33
sidebar_label: create_script
4-
description: "Create a new C# script at the given project path"
4+
description: "Create a new C# script at the given project path."
55
---
66

77
# `create_script`

website/docs/reference/tools/core/debug_request_context.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: debug_request_context
33
sidebar_label: debug_request_context
4-
description: "Return the current FastMCP request context details (client_id, session_id, and meta dump)"
4+
description: "Return the current FastMCP request context details (client_id, session_id, and meta dump)."
55
---
66

77
# `debug_request_context`

website/docs/reference/tools/core/delete_script.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: delete_script
33
sidebar_label: delete_script
4-
description: "Delete a C# script by URI or Assets-relative path"
4+
description: "Delete a C# script by URI or Assets-relative path."
55
---
66

77
# `delete_script`

website/docs/reference/tools/core/execute_custom_tool.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: execute_custom_tool
33
sidebar_label: execute_custom_tool
4-
description: "Execute a project-scoped custom tool registered by Unity"
4+
description: "Execute a project-scoped custom tool registered by Unity."
55
---
66

77
# `execute_custom_tool`

website/docs/reference/tools/core/execute_menu_item.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: execute_menu_item
33
sidebar_label: execute_menu_item
4-
description: "Execute a Unity menu item by path"
4+
description: "Execute a Unity menu item by path."
55
---
66

77
# `execute_menu_item`

0 commit comments

Comments
 (0)