Skip to content

Commit ce6981e

Browse files
ShotaroKataokaShotaro Kataoka
andauthored
refactor(tools): rewrite MCP tool descriptions from zero (#683)
* refactor(tools): rewrite MCP tool descriptions from zero Every tool description, argument description and the server instructions are rewritten from what the model needs to call each tool. Names, arguments and behaviour are unchanged. Tools-only bundle: Local MCP 3,533 -> 2,645 tokens, Remote MCP 3,669 -> 2,799, Local Web UI 3,716 -> 2,900. * fix(tools): restore routing and timing the rewrite dropped - start_presentation routes a reusable-style request to start_style (local and remote); the old server instructions carried that route and the rewrite removed it. - init_deck_workspace says when: once the brief is agreed, before apply_style. - hearing: the recommended option says why; ask more on another card after the reply. - run_python: only a write to a build input rebuilds; the result says what was rebuilt. - include_all and read_attachment wording in positive form. - test_tool_descriptions: check that start_presentation does not describe the style listing, instead of forbidding the word "style". --------- Co-authored-by: Shotaro Kataoka <sktok@amazon.co.jp>
1 parent c718a18 commit ce6981e

8 files changed

Lines changed: 191 additions & 291 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@ Under an Upgrading section, the bullets after **Local installs (`sdpm update`).*
5959
measure. CI writes the table, with +/- against the base commit, to the `python` job
6060
summary. Report only; nothing fails on size. Development only.
6161

62+
### Changed
63+
64+
- **Shorter MCP tool descriptions and server instructions.** Every tool description,
65+
argument description and the server `instructions` were rewritten from what the model
66+
needs to call the tool: when to use it, what each argument means, and what the tool does
67+
not tell it back. Text the role documents, guides or the tool's own result already carry
68+
is gone. Tool names, arguments and behaviour are unchanged. The tool list every session
69+
loads is about 25% smaller (Local MCP 3,533 → 2,645 tokens; Remote MCP 3,669 → 2,799;
70+
Local Web UI 3,716 → 2,900). Redeploy every MCP surface: Local MCP and the Local Web UI
71+
(`sdpm update`), and the AWS stack (SdpmRuntime; the agent uses the same tools).
72+
6273
### Fixed
6374

6475
- **A textbox border keeps its `lineOpacity`** (#667). The textbox builder ignored

‎sdpm/sdpm/tools/__init__.py‎

Lines changed: 60 additions & 103 deletions
Large diffs are not rendered by default.

‎sdpm/sdpm/tools/attachment/contracts.py‎

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@
2727

2828

2929
def read_attachment(
30-
source: Annotated[str, Field(description='Absolute path, S3 key (cloud), or https:// URL.')],
31-
offset: Annotated[int, Field(description='UTF-8 byte offset into the text to start from.')] = 0,
32-
limit: Annotated[int, Field(description='Max bytes returned, 512–10240.')] = PAGING_DEFAULT_LIMIT,
30+
source: Annotated[str, Field(description='Absolute path or https:// URL.')],
31+
offset: Annotated[int, Field(description='Byte offset to start from.')] = 0,
32+
limit: Annotated[int, Field(description='Max bytes, 512–10240.')] = PAGING_DEFAULT_LIMIT,
3333
) -> dict[str, Any]:
34-
"""Read a user-supplied file or URL as paged, line-numbered text — PDF, DOCX, XLSX, PPTX,
35-
text, CSV, HTML, JSON — or image metadata. Pure read, nothing is stored.
36-
Formats and paging: read_guides(["attachments"]).
37-
"""
34+
"""Read a user's file or URL (PDF, Office, text, HTML, JSON) as paged, line-numbered
35+
text, or an image's metadata. Read-only; works before any deck exists. Paging:
36+
read_guides(["attachments"])."""
3837
# Parameter validation
3938
if offset < 0:
4039
return {"error": {"code": "INVALID_OFFSET", "message": f"offset must be >= 0, got {offset}"}}
@@ -101,15 +100,13 @@ def read_attachment(
101100

102101

103102
def import_attachment(
104-
source: Annotated[str, Field(description='Absolute path, S3 key (cloud), or https:// URL.')],
103+
source: Annotated[str, Field(description='Absolute path or https:// URL.')],
105104
deck_id: Annotated[str, Field(description='Deck directory path.')],
106-
filename: Annotated[str, Field(description="Filename override; defaults to the source's name.")] = "",
105+
filename: Annotated[str, Field(description="File name; the source's name when empty.")] = "",
107106
) -> dict[str, Any]:
108-
"""Import a file or URL into the deck's attachments/ so slides can use it: images
109-
(converted to PNG), PDF/DOCX/XLSX (text + images), PPTX (full deck structure), URLs.
110-
Idempotent per source. On IMPORT_INCOMPLETE call again with the same arguments.
111-
Bundle layout: read_guides(["attachments"]).
112-
"""
107+
"""Copy a file or URL into the deck's attachments/ for slides to use: images become PNG,
108+
PDF/DOCX/XLSX give text and images, a PPTX gives its whole deck. Layout:
109+
read_guides(["attachments"])."""
113110
deck_dir = Path(deck_id)
114111
if not deck_dir.is_dir():
115112
return {"error": {"code": "DECK_NOT_FOUND", "message": f"Deck directory not found: {deck_id}"}}

‎sdpm/sdpm/tools/instructions.py‎

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,9 @@
99

1010
import os
1111

12-
INSTRUCTIONS = """spec-driven-presentation-maker: AI-powered PowerPoint generation from JSON.
13-
14-
Call the entry tool for the role first — it returns the role document and its inputs:
15-
- Anything about slides (new deck, edit/import a PPTX, restyle): `start_presentation()`
16-
- Write assigned slides for a deck: `start_composing(deck_id, assigned_slugs, mode)`
17-
- Create a reusable style guide: `start_style()`
18-
- Translate an existing deck: `start_translation(deck_id, language)`
19-
20-
Deck files are written only through `run_python` (never with client-side file tools):
21-
it validates the slides, rebuilds the PPTX (or `output.html` for HTML decks) and,
22-
with `measure_slides`, renders previews.
12+
INSTRUCTIONS = """sdpm makes slide decks (PPTX or HTML). Start any slide work with \
13+
start_presentation; it says what to do next. Read and write deck files only through \
14+
run_python, never with your own file tools.
2315
"""
2416

2517

‎servers/local/sandbox_tools.py‎

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,12 @@ def run_python(
114114
purpose: Annotated[str, Field(description='One line on what this code does (shown in the UI).')],
115115
code: Annotated[str, Field(description='Python code; no import statements.')],
116116
deck_id: Annotated[str, Field(description='Deck directory path.')],
117-
measure_slides: Annotated[list[str] | None, Field(description='Slugs to measure for text overflow after the code ran — the ones you edited.')] = None,
117+
measure_slides: Annotated[list[str] | None, Field(description='Slugs you edited: checks text overflow and previews them.')] = None,
118118
) -> str:
119-
"""Run Python inside the deck directory — the way to read and write deck files
120-
(deck.json, specs/, slides/, includes/). No import or open(); helpers:
121-
read_json(path), write_json(path, data), read_text(path), write_text(path, text),
122-
list_files(subdir=".") (folders end with "/"). Writes persist; output.pptx (output.html for HTML decks)
123-
rebuilds and changed slides are re-rendered and previewed when deck.json, slides/,
124-
includes/ or specs/outline.md changed. measure_slides measures text overflow on those
125-
slugs and previews them; HTML decks get static checks plus browser layout / JS checks
126-
and PNG previews when Chrome or Edge is available.
127-
"""
119+
"""Run Python in the deck directory: the only way to read and write deck files. No
120+
import or open(); use read_json(path), write_json(path, data), read_text(path),
121+
write_text(path, text), list_files(subdir). A write to a build input rebuilds the deck
122+
and previews the changed slides; the result says what was rebuilt."""
128123
result: dict[str, Any] = {}
129124
if not deck_id or not Path(deck_id).is_dir():
130125
result["error"] = (
@@ -300,10 +295,9 @@ def run_style_python(
300295
purpose: Annotated[str, Field(description='One line on what this code does (shown in the UI).')],
301296
code: Annotated[str, Field(description='Python code; no import statements.')],
302297
) -> str:
303-
"""Run Python for style authoring. Helpers: read_style(name) returns an existing style's
304-
HTML (bundled or user); write_style(name, html) saves to the user style store
305-
(name = file stem, no .html). No import or file access; print() for output.
306-
"""
298+
"""Run Python to write a style. read_style(name) returns a style's HTML;
299+
write_style(name, html) saves it to the user's styles (name without .html). No import
300+
or file access; print() shows output."""
307301
from sandbox import check_code, make_style_runner
308302

309303
result: dict[str, Any] = {}

‎servers/local/server_acp.py‎

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,12 @@
4848

4949
def read_attachment(
5050
source: Annotated[str, Field(description="Absolute path under the attachment home, or https:// URL.")],
51-
offset: Annotated[int, Field(description="UTF-8 byte offset into the text to start from.")] = 0,
52-
limit: Annotated[int, Field(description="Max bytes returned, 512–10240.")] = 10240,
51+
offset: Annotated[int, Field(description="Byte offset to start from.")] = 0,
52+
limit: Annotated[int, Field(description="Max bytes, 512–10240.")] = 10240,
5353
) -> dict:
54-
"""Read a user-supplied file or URL as paged, line-numbered text — PDF, DOCX, XLSX, PPTX,
55-
text, CSV, HTML, JSON — or image metadata. Pure read, nothing is stored.
56-
Formats and paging: read_guides(["attachments"]).
57-
"""
54+
"""Read a user's file or URL (PDF, Office, text, HTML, JSON) as paged, line-numbered
55+
text, or an image's metadata. Read-only; works before any deck exists. Paging:
56+
read_guides(["attachments"])."""
5857
if classify_source(source) == "local_path":
5958
try:
6059
validate_local_source(source, allow_any_path=False, root=_RAW_ATTACHMENT_ROOT)
@@ -66,13 +65,11 @@ def read_attachment(
6665
def import_attachment(
6766
source: Annotated[str, Field(description="Absolute path under the attachment home, or https:// URL.")],
6867
deck_id: Annotated[str, Field(description="Deck directory path.")],
69-
filename: Annotated[str, Field(description="Filename override; defaults to the source's name.")] = "",
68+
filename: Annotated[str, Field(description="File name; the source's name when empty.")] = "",
7069
) -> dict:
71-
"""Import a file or URL into the deck's attachments/ so slides can use it: images
72-
(converted to PNG), PDF/DOCX/XLSX (text + images), PPTX (full deck structure), URLs.
73-
Idempotent per source. On IMPORT_INCOMPLETE call again with the same arguments.
74-
Bundle layout: read_guides(["attachments"]).
75-
"""
70+
"""Copy a file or URL into the deck's attachments/ for slides to use: images become PNG,
71+
PDF/DOCX/XLSX give text and images, a PPTX gives its whole deck. Layout:
72+
read_guides(["attachments"])."""
7673
try:
7774
deck_path = Path(deck_id).resolve(strict=True)
7875
deck_path.relative_to(_DECK_ROOT)
@@ -135,13 +132,11 @@ def import_attachment(
135132

136133

137134
_Q_DESC = (
138-
'Question object: {"header": str (short chip label, ~6 Japanese / ~12 English chars), '
139-
'"type": "single_select" | "multi_select" | "free_text", "text": str, '
140-
'"options": [{"label": str (short), "description": str (one line: what choosing it '
141-
'leads to, or its trade-off), "recommended": bool (optional)}] (2-4, select types), '
142-
'"placeholder": str (free_text, optional)}.'
135+
'{"header": chip label, ~6 CJK / ~12 Latin chars, "type": "single_select" | "multi_select" '
136+
'| "free_text", "text": str, "options": 2-4 for select types, each {"label": short, '
137+
'"description": one line on what it leads to, "recommended"?: bool}, "placeholder"?: str}.'
143138
)
144-
_Q = Annotated[dict | None, Field(description="Next question; same shape as q0.")]
139+
_Q = Annotated[dict | None, Field(description="Next question, same shape as q0.")]
145140

146141

147142
@mcp.tool()
@@ -151,11 +146,9 @@ def hearing(
151146
q2: _Q = None,
152147
q3: _Q = None,
153148
) -> str:
154-
"""Show the user a card of up to four structured questions, one at a time; the answers
155-
arrive in the user's next message. Share your hypothesis as the recommended option and
156-
its description. The card adds an "Other" choice itself. For more, call again after
157-
the reply.
158-
"""
149+
"""Ask the user up to four questions on one card; the answers arrive in their next
150+
message. Make your hypothesis the recommended option and say why in its description.
151+
The card adds "Other" itself. For more, ask on another card after the reply."""
159152
return "Questions displayed to user. Wait for their response."
160153

161154

0 commit comments

Comments
 (0)