AI Validation & Polish Skill
This skill orchestrates Phase 4 of the mcp-builder pipeline: validating deterministically-generated MCP server code for correctness and suggesting hint-driven improvements. The pipeline transforms an OpenAPI spec into a ToolHive-ready MCP server across four phases — AI Scoping (Phase 1) produces a validated mcp-scope.yaml, Human Review (Phase 2) refines it, Deterministic Code Generation (Phase 3) scaffolds the server, and this skill (Phase 4) validates the generated code against the YAML and spec, then suggests improvements driven by hints from the scoping phase.
Startup
Before beginning the workflow:
Determine the base directory for this skill (the absolute path to the directory containing this SKILL.md). The repo root is two levels up: {skill_base_dir}/../... Agent files are at {repo_root}/agents/{agent-name}.md. Assets are at {skill_base_dir}/assets/. Do not share these internal paths with the user.
All uv and task commands must run from {repo_root} (where pyproject.toml lives).
Clone or locate the reference repos that agents need for grounding their checks:
Record the absolute paths to both repos. These will be passed to agents.
Workflow
Given a generated project directory, mcp-scope.yaml, and OpenAPI spec path ($ARGUMENTS), execute the following steps:
- Collect and verify inputs
- Code validation (agent)
- Validation gate (user gate)
- Polish suggestions (agent)
- Polish application gate (user gate)
- Final build verification (if code was modified)
- Present results
Step 1: Collect and Verify Inputs
Parse $ARGUMENTS for three required paths:
- Generated project directory — output from Phase 3 code generation
- mcp-scope.yaml — the scope file that drove generation
- OpenAPI spec — the original spec file
If fewer than 3 arguments are provided, ask the user for the missing paths.
Verify all three paths exist. If any is missing, tell the user and exit.
Read the server.name from mcp-scope.yaml. Derive the module name: replace hyphens with underscores, append _mcp (e.g., google-drive → google_drive_mcp).
Verify the generated project has the expected structure by checking these files exist:
src/{module_name}/api/tools.py
src/{module_name}/api/mcp_builder.py
src/{module_name}/client.py
deploy/mcpserver.yaml
pyproject.toml
Dockerfile
If key files are missing, note which ones and continue — the validator will report them as failures.
Create a working directory for output files: {cwd}/validation-output-{date}/
Step 2: Code Validation (Agent)
Spawn a code-validator sub-agent using the Agent tool. Pass file paths — do NOT read or paste file contents into the prompt. The agent reads everything itself.
Agent tool parameters:
- subagent_type: [path to code-validator agent: {repo_root}/agents/code-validator.md]
- description: "Validate generated MCP server code"
- prompt: |
Validate the generated MCP server code for correctness.
CONTEXT:
Pipeline context path: [absolute path to {skill_base_dir}/../ai-scoping/assets/pipeline-context.md]
Report template path: [absolute path to {skill_base_dir}/assets/validation-report-template.md]
Working directory: [absolute path to validation-output/]
SERVER METADATA:
Server name: [from YAML server.name]
Module name: [derived module name]
FILE PATHS:
Project directory: [absolute path to generated project]
MCP scope YAML: [absolute path to mcp-scope.yaml]
OpenAPI spec: [absolute path to spec file]
REFERENCE REPOS:
ToolHive repo: [absolute path to toolhive clone]
mcp-template-py repo: [absolute path to mcp-template-py clone]
- mode: acceptEdits
- run_in_background: false
The code-validator agent will read all files, run the Docker build check, and write {working_dir}/validation-report.md.
Step 3: Validation Gate
Read {working_dir}/validation-report.md — pay particular attention to the Build Verification row and any error-severity failures.
Present the validation summary to the user using the structure below.
## Validation Summary
**Report:** {path to validation-report.md}
- Total checks: {X} passed, {Y} failed, {Z} skipped
### 🏗️ Docker build: {✅ PASS / ❌ FAIL / ⏭️ SKIP}
<copy reason build failed or skipped>
If there are error-severity failures from other checks, list each one prominently under a separate ### ❌ Errors heading with the check ID, file, and one-line fix description from Detailed Findings.
Run the appropriate user gate based on what the report contains:
Case A — error-severity failures exist (USER GATE — wait for response):
Use AskUserQuestion. Explain how many errors were found and — if the build also failed or was skipped — mention that. Ask how the user wants to proceed. Offer these paths:
- Have AI fix the errors (spawn the fix agent, then re-validate)
- Proceed to polish despite the errors
- Fix manually and re-run the skill later
Do NOT proceed past this step until the user responds.
Case B — no error-severity failures, but build is FAIL or SKIP (USER GATE — wait for response):
Use AskUserQuestion. Explain the situation (build failed or was skipped, include the reason from the Build Verification row) and make clear this is not a blocker for the rest of the flow. Ask what the user wants to do. Offer these paths:
- Retry the build (re-run the code-validator agent, but instruct it to re-run only the build check and reuse the existing report for everything else)
- Have AI investigate and fix the build (only when the build actually FAILED — spawn the fix agent scoped to the build, then re-validate)
- Acknowledge and continue to polish
- Stop here
Do NOT proceed past this step until the user responds.
Case C — no errors and build is PASS:
Tell the user all checks passed (including build) and automatically proceed to Step 4 (polish suggestions). No gate needed.
Step 3b: AI Error Fixing (conditional)
If the user chose "Have AI fix the errors":
- Spawn a sub-agent to fix the errors. Pass file paths — do NOT paste file contents.
Agent tool parameters:
- description: "Fix validation errors in generated code"
- prompt: |
Fix the validation errors in the generated MCP server project.
PROJECT DIRECTORY: [absolute path]
MODULE NAME: [module name]
Read the validation report at: [absolute path to {working_dir}/validation-report.md]
Read the mcp-scope.yaml at: [absolute path to mcp-scope.yaml]
For each FAIL item in the Detailed Findings section:
1. Read the file mentioned in the finding
2. Apply the fix described
3. Verify the fix is consistent with the YAML and the rest of the codebase
Only fix items marked FAIL. Do not make other changes.
- mode: acceptEdits
- run_in_background: false
After the agent completes, re-run validation by looping back to Step 2 (re-spawn the code-validator agent).
Present the updated results. If errors remain, ask the user again (same choices). Do not loop more than 2 fix attempts — if errors persist after 2 rounds, ask the user to fix manually.
Step 4: Polish Suggestions (Agent)
Spawn a polish-suggester sub-agent using the Agent tool. Pass file paths — do NOT read or paste file contents into the prompt.
Agent tool parameters:
- subagent_type: [path to polish-suggester agent: {repo_root}/agents/polish-suggester.md]
- description: "Suggest hint-driven code improvements"
- prompt: |
Analyze the generated MCP server code and suggest improvements based on YAML hints.
CONTEXT:
Pipeline context path: [absolute path to {skill_base_dir}/../ai-scoping/assets/pipeline-context.md]
Working directory: [absolute path to validation-output/]
Validation report path: [absolute path to {working_dir}/validation-report.md]
SERVER METADATA:
Server name: [from YAML]
Module name: [derived module name]
FILE PATHS:
Project directory: [absolute path to generated project]
MCP scope YAML: [absolute path to mcp-scope.yaml]
OpenAPI spec: [absolute path to spec file]
REFERENCE REPOS:
ToolHive repo: [absolute path to toolhive clone]
mcp-template-py repo: [absolute path to mcp-template-py clone]
- mode: acceptEdits
- run_in_background: false
The polish-suggester agent will read all files and write {working_dir}/polish-suggestions.md.
Step 5: Polish Application Gate (USER GATE)
Read {working_dir}/polish-suggestions.md.
Present the suggestions to the user using the format below. Do not flatten the report into one-line bullets — the user needs to be able to judge severity and decide fix-or-skip from the chat output alone.
2a. Overview block — a severity-count table plus an at-a-glance index table:
## Polish Suggestions ({N} total)
**Report:** {path to polish-suggestions.md}
| Severity | Count | What it means |
|----------|-------|---------------|
| 🟠 high | {N} | Tool is broken OR LLM callers are very likely to misuse it |
| 🟡 medium | {N} | Robustness / quality improvement |
| ⚪ low | {N} | Minor polish |
| # | Severity | Category | Tool(s) | Summary |
|----|----------|----------|---------|---------|
| P1 | 🟠 high | ... | ... | ... |
| P2 | 🟡 medium | ... | ... | ... |
| … | … | … | … | … |
2b. Per-suggestion detail — for EACH suggestion in the report, render:
### P{n}: {title} — {severity emoji} {severity}
| Field | Value |
|-------|-------|
| Category | {category} |
| Affected | `{tool(s)}` |
| File(s) | `{paths}` |
| Hint | {hint text or "AI-analyzed"} |
**Problem:** {copy the Problem paragraph from the report verbatim}
**Impact if unfixed:** {copy verbatim}
**Proposed fix:** {copy verbatim}
<details><summary>View diff</summary>
```python
# Before
{before snippet}
# After
{after snippet}
Required fields per suggestion: severity, category, affected tool(s), file(s), problem, impact, proposed fix. If the report is missing any of these fields, say so explicitly to the user instead of silently omitting — it means the polish-suggester agent produced an incomplete suggestion and should be re-run.
Ordering: render high-severity suggestions first, then medium, then low. Within a severity tier, preserve the P-number order from the report. When a high-severity suggestion flags a functional bug in its Problem paragraph, mention that fact when you introduce it so the user understands it isn't just a docstring nit.
Length: do not truncate Problem / Impact / Proposed fix — they are the whole point. DO wrap long diffs in <details> so the chat stays scannable.
If there are no suggestions, say so briefly and skip to Step 7 (Step 6 is a no-op when no code was modified).
Use AskUserQuestion to ask the user how they want to handle the suggestions. Summarize the counts by severity, then offer these paths:
- Have AI apply all suggestions
- Have AI apply selected suggestions (user names the P-numbers)
- Review manually
- Skip
If any high-severity suggestions flagged themselves as functional bugs in the Problem paragraph, mention that in the question so the user knows skipping will leave those behind. Otherwise keep the framing neutral.
Do NOT proceed past this step until the user responds.
Step 5b: AI Polish Application (conditional)
If the user chose to have AI apply suggestions (all or selected):
If "selected", ask the user which suggestion IDs to apply (e.g., "P1, P3, P5").
Spawn a sub-agent to apply the suggestions. Pass file paths — do NOT paste suggestion contents.
Agent tool parameters:
- description: "Apply polish suggestions to generated code"
- prompt: |
Apply polish suggestions to the generated MCP server project.
PROJECT DIRECTORY: [absolute path]
MODULE NAME: [module name]
Read the suggestions at: [absolute path to {working_dir}/polish-suggestions.md]
[If selected: "Only apply suggestions: P1, P3, P5"]
For each suggestion to apply:
1. Read the target file listed in the suggestion
2. Find the "Before" code pattern
3. Replace it with the "After" code
4. Verify the change is syntactically valid
Only apply the listed suggestions. Do not make other changes.
- mode: acceptEdits
- run_in_background: false
Step 6: Final Build Verification (conditional)
Skip this step entirely if no code was modified — no fixes were applied in Step 3b AND no polish was applied in Step 5b. The validation report's existing Build Verification result is still accurate and stands as-is.
Otherwise, rebuild the Docker image to confirm the post-fix / post-polish code still builds. The validator ran its build check against the generator's original output; edits applied after that (either error fixes or polish) may have introduced problems the initial build can't catch.
Run the build from the generated project directory:
cd {project_dir} && docker build -t {server_name}-mcp:validation-test . 2>&1
Append a Final Build Verification subsection to {working_dir}/validation-report.md (do not overwrite the original Build Verification row — the reader should be able to see both the pre-fix and post-fix results). Record PASS/FAIL/SKIP and, for FAIL or SKIP, the concrete reason including enough build output for the user to understand what broke.
If the final build failed, present the failure to the user with AskUserQuestion. Summarize what code was modified (errors fixed, polish applied, or both) and paste the failing build excerpt. Offer:
- Have AI investigate and fix the build (spawn an inline fix agent scoped to the build failure, then re-run this step)
- Fix manually and re-run the skill later
- Acknowledge and continue to Step 7
Do not loop more than 2 AI-fix attempts here. If the build still fails after 2 rounds, ask the user to fix manually.
If the final build passed or was skipped (Docker not installed etc.), continue to Step 7 without a gate.
Step 7: Present Results
Present the user with:
- Path to
{working_dir}/validation-report.md
- Path to
{working_dir}/polish-suggestions.md (if generated)
- Summary:
- Validation: X checks passed, Y failed
- Build: PASS/FAIL/SKIP (report the final build outcome from Step 6 if it ran; otherwise the validator's original result)
- Polish: N suggestions generated, M applied (if any)
- Files modified (if any fixes or polish were applied)
Error Handling
| Failure |
Behavior |
| Project directory doesn't exist |
Tell the user, exit |
| Expected files missing from project |
Note as missing, continue — validator reports as FAIL |
| mcp-scope.yaml fails to parse |
Tell the user, exit |
| Reference repos can't be cloned |
Warn the user, continue — agent checks will be less grounded but still functional |
| Docker not installed |
Agent records build check as SKIP, continues |
| Docker build fails |
Agent records as FAIL, continues to user gate |
| Code-validator agent fails |
Present error to user, ask if they want to proceed to manual review |
| Polish-suggester agent fails |
Present error to user, note that validation report is still valid |
| Fix agent fails |
Present error to user, ask them to fix manually |
Important Notes
Sub-Agent Invocation
- Use the Agent tool with the appropriate subagent_type for code-validator and polish-suggester
- Fix/apply agents use inline prompts (no dedicated agent file) since they're straightforward edit tasks
- Always set
run_in_background: false and mode: acceptEdits
- Pass file paths in the prompt — agents read files themselves. Never paste file contents into agent prompts.
Working Directory
- All output files go in
{cwd}/validation-output-{date}/
- This includes
validation-report.md and polish-suggestions.md
Read-Only by Default
- The skill only modifies the generated project if the user explicitly chooses "Have AI fix" or "Have AI apply"
- Validation and suggestion generation are entirely read-only operations
1---2name: ai-validation3description: Validate a generated MCP server project against the mcp-scope.yaml and OpenAPI spec that drove its generation, then suggest hint-driven improvements. Part of the mcp-builder pipeline that transforms an OpenAPI 3.x spec into a ToolHive-ready MCP server across four phases — AI Scoping, Human Review, Deterministic Code Generation, and AI Validation & Polish (this skill). Use when a user has a generated MCP server project (Phase 3 output) and wants to validate it before deployment.4---56# AI Validation & Polish Skill78This skill orchestrates Phase 4 of the mcp-builder pipeline: validating deterministically-generated MCP server code for correctness and suggesting hint-driven improvements. The pipeline transforms an OpenAPI spec into a ToolHive-ready MCP server across four phases — AI Scoping (Phase 1) produces a validated `mcp-scope.yaml`, Human Review (Phase 2) refines it, Deterministic Code Generation (Phase 3) scaffolds the server, and this skill (Phase 4) validates the generated code against the YAML and spec, then suggests improvements driven by hints from the scoping phase.910## Startup1112Before beginning the workflow:13141. Determine the base directory for this skill (the absolute path to the directory containing this SKILL.md). The repo root is two levels up: `{skill_base_dir}/../..`. Agent files are at `{repo_root}/agents/{agent-name}.md`. Assets are at `{skill_base_dir}/assets/`. Do not share these internal paths with the user.15162. All `uv` and `task` commands must run from `{repo_root}` (where `pyproject.toml` lives).17183. Clone or locate the reference repos that agents need for grounding their checks:1920 - **ToolHive** (`stacklok/toolhive`) — CRD schemas, auth patterns. Check if a local clone exists nearby (e.g., sibling directory). If not, clone to a temp directory:21 ```bash22 gh repo clone stacklok/toolhive /tmp/toolhive-ref -- --depth 123 ```24 - **mcp-template-py** (`stacklok/mcp-template-py`) — the base Python MCP server template. Same approach:25 ```bash26 gh repo clone stacklok/mcp-template-py /tmp/mcp-template-py-ref -- --depth 127 ```2829 Record the absolute paths to both repos. These will be passed to agents.3031## Workflow3233Given a generated project directory, mcp-scope.yaml, and OpenAPI spec path ($ARGUMENTS), execute the following steps:34351. Collect and verify inputs362. Code validation (agent)373. Validation gate (user gate)384. Polish suggestions (agent)395. Polish application gate (user gate)406. Final build verification (if code was modified)417. Present results4243---4445### Step 1: Collect and Verify Inputs46471. Parse $ARGUMENTS for three required paths:48 - **Generated project directory** — output from Phase 3 code generation49 - **mcp-scope.yaml** — the scope file that drove generation50 - **OpenAPI spec** — the original spec file5152 If fewer than 3 arguments are provided, ask the user for the missing paths.53542. Verify all three paths exist. If any is missing, tell the user and exit.55563. Read the `server.name` from `mcp-scope.yaml`. Derive the module name: replace hyphens with underscores, append `_mcp` (e.g., `google-drive` → `google_drive_mcp`).57584. Verify the generated project has the expected structure by checking these files exist:59 - `src/{module_name}/api/tools.py`60 - `src/{module_name}/api/mcp_builder.py`61 - `src/{module_name}/client.py`62 - `deploy/mcpserver.yaml`63 - `pyproject.toml`64 - `Dockerfile`6566 If key files are missing, note which ones and continue — the validator will report them as failures.67685. Create a working directory for output files: `{cwd}/validation-output-{date}/`6970---7172### Step 2: Code Validation (Agent)7374Spawn a **code-validator** sub-agent using the Agent tool. Pass file paths — do NOT read or paste file contents into the prompt. The agent reads everything itself.7576```77Agent tool parameters:78- subagent_type: [path to code-validator agent: {repo_root}/agents/code-validator.md]79- description: "Validate generated MCP server code"80- prompt: |81 Validate the generated MCP server code for correctness.8283 CONTEXT:84 Pipeline context path: [absolute path to {skill_base_dir}/../ai-scoping/assets/pipeline-context.md]85 Report template path: [absolute path to {skill_base_dir}/assets/validation-report-template.md]86 Working directory: [absolute path to validation-output/]8788 SERVER METADATA:89 Server name: [from YAML server.name]90 Module name: [derived module name]9192 FILE PATHS:93 Project directory: [absolute path to generated project]94 MCP scope YAML: [absolute path to mcp-scope.yaml]95 OpenAPI spec: [absolute path to spec file]9697 REFERENCE REPOS:98 ToolHive repo: [absolute path to toolhive clone]99 mcp-template-py repo: [absolute path to mcp-template-py clone]100- mode: acceptEdits101- run_in_background: false102```103104The code-validator agent will read all files, run the Docker build check, and write `{working_dir}/validation-report.md`.105106---107108### Step 3: Validation Gate1091101. Read `{working_dir}/validation-report.md` — pay particular attention to the `Build Verification` row and any error-severity failures.1111122. Present the validation summary to the user using the structure below.113114 ```markdown115 ## Validation Summary116117 **Report:** {path to validation-report.md}118119 - Total checks: {X} passed, {Y} failed, {Z} skipped120121 ### 🏗️ Docker build: {✅ PASS / ❌ FAIL / ⏭️ SKIP}122123 <copy reason build failed or skipped>124 ```125126 If there are `error`-severity failures from other checks, list each one prominently under a separate `### ❌ Errors` heading with the check ID, file, and one-line fix description from Detailed Findings.1271283. Run the appropriate user gate based on what the report contains:129130 **Case A — error-severity failures exist (USER GATE — wait for response):**131132 Use AskUserQuestion. Explain how many errors were found and — if the build also failed or was skipped — mention that. Ask how the user wants to proceed. Offer these paths:133134 - Have AI fix the errors (spawn the fix agent, then re-validate)135 - Proceed to polish despite the errors136 - Fix manually and re-run the skill later137138 **Do NOT proceed past this step until the user responds.**139140 **Case B — no error-severity failures, but build is FAIL or SKIP (USER GATE — wait for response):**141142 Use AskUserQuestion. Explain the situation (build failed or was skipped, include the reason from the Build Verification row) and make clear this is not a blocker for the rest of the flow. Ask what the user wants to do. Offer these paths:143144 - Retry the build (re-run the code-validator agent, but instruct it to re-run only the build check and reuse the existing report for everything else)145 - Have AI investigate and fix the build (only when the build actually FAILED — spawn the fix agent scoped to the build, then re-validate)146 - Acknowledge and continue to polish147 - Stop here148149 **Do NOT proceed past this step until the user responds.**150151 **Case C — no errors and build is PASS:**152153 Tell the user all checks passed (including build) and automatically proceed to Step 4 (polish suggestions). No gate needed.154155---156157### Step 3b: AI Error Fixing (conditional)158159If the user chose "Have AI fix the errors":1601611. Spawn a sub-agent to fix the errors. Pass file paths — do NOT paste file contents.162163```164Agent tool parameters:165- description: "Fix validation errors in generated code"166- prompt: |167 Fix the validation errors in the generated MCP server project.168169 PROJECT DIRECTORY: [absolute path]170 MODULE NAME: [module name]171172 Read the validation report at: [absolute path to {working_dir}/validation-report.md]173 Read the mcp-scope.yaml at: [absolute path to mcp-scope.yaml]174175 For each FAIL item in the Detailed Findings section:176 1. Read the file mentioned in the finding177 2. Apply the fix described178 3. Verify the fix is consistent with the YAML and the rest of the codebase179180 Only fix items marked FAIL. Do not make other changes.181- mode: acceptEdits182- run_in_background: false183```1841852. After the agent completes, re-run validation by looping back to Step 2 (re-spawn the code-validator agent).1861873. Present the updated results. If errors remain, ask the user again (same choices). Do not loop more than 2 fix attempts — if errors persist after 2 rounds, ask the user to fix manually.188189---190191### Step 4: Polish Suggestions (Agent)192193Spawn a **polish-suggester** sub-agent using the Agent tool. Pass file paths — do NOT read or paste file contents into the prompt.194195```196Agent tool parameters:197- subagent_type: [path to polish-suggester agent: {repo_root}/agents/polish-suggester.md]198- description: "Suggest hint-driven code improvements"199- prompt: |200 Analyze the generated MCP server code and suggest improvements based on YAML hints.201202 CONTEXT:203 Pipeline context path: [absolute path to {skill_base_dir}/../ai-scoping/assets/pipeline-context.md]204 Working directory: [absolute path to validation-output/]205 Validation report path: [absolute path to {working_dir}/validation-report.md]206207 SERVER METADATA:208 Server name: [from YAML]209 Module name: [derived module name]210211 FILE PATHS:212 Project directory: [absolute path to generated project]213 MCP scope YAML: [absolute path to mcp-scope.yaml]214 OpenAPI spec: [absolute path to spec file]215216 REFERENCE REPOS:217 ToolHive repo: [absolute path to toolhive clone]218 mcp-template-py repo: [absolute path to mcp-template-py clone]219- mode: acceptEdits220- run_in_background: false221```222223The polish-suggester agent will read all files and write `{working_dir}/polish-suggestions.md`.224225---226227### Step 5: Polish Application Gate (USER GATE)2282291. Read `{working_dir}/polish-suggestions.md`.2302312. Present the suggestions to the user using the format below. Do not flatten the report into one-line bullets — the user needs to be able to judge severity and decide fix-or-skip from the chat output alone.232233 **2a. Overview block** — a severity-count table plus an at-a-glance index table:234235 ```markdown236 ## Polish Suggestions ({N} total)237238 **Report:** {path to polish-suggestions.md}239240 | Severity | Count | What it means |241 |----------|-------|---------------|242 | 🟠 high | {N} | Tool is broken OR LLM callers are very likely to misuse it |243 | 🟡 medium | {N} | Robustness / quality improvement |244 | ⚪ low | {N} | Minor polish |245246 | # | Severity | Category | Tool(s) | Summary |247 |----|----------|----------|---------|---------|248 | P1 | 🟠 high | ... | ... | ... |249 | P2 | 🟡 medium | ... | ... | ... |250 | … | … | … | … | … |251 ```252253 **2b. Per-suggestion detail** — for EACH suggestion in the report, render:254255 ```markdown256 ### P{n}: {title} — {severity emoji} {severity}257258 | Field | Value |259 |-------|-------|260 | Category | {category} |261 | Affected | `{tool(s)}` |262 | File(s) | `{paths}` |263 | Hint | {hint text or "AI-analyzed"} |264265 **Problem:** {copy the Problem paragraph from the report verbatim}266267 **Impact if unfixed:** {copy verbatim}268269 **Proposed fix:** {copy verbatim}270271 <details><summary>View diff</summary>272273 ```python274 # Before275 {before snippet}276 ```277278 ```python279 # After280 {after snippet}281 ```282 </details>283 ```284285 **Required fields per suggestion:** severity, category, affected tool(s), file(s), problem, impact, proposed fix. If the report is missing any of these fields, say so explicitly to the user instead of silently omitting — it means the polish-suggester agent produced an incomplete suggestion and should be re-run.286287 **Ordering:** render high-severity suggestions first, then medium, then low. Within a severity tier, preserve the P-number order from the report. When a `high`-severity suggestion flags a functional bug in its Problem paragraph, mention that fact when you introduce it so the user understands it isn't just a docstring nit.288289 **Length:** do not truncate Problem / Impact / Proposed fix — they are the whole point. DO wrap long diffs in `<details>` so the chat stays scannable.290291 If there are no suggestions, say so briefly and skip to Step 7 (Step 6 is a no-op when no code was modified).2922933. Use AskUserQuestion to ask the user how they want to handle the suggestions. Summarize the counts by severity, then offer these paths:294295 - Have AI apply all suggestions296 - Have AI apply selected suggestions (user names the P-numbers)297 - Review manually298 - Skip299300 If any `high`-severity suggestions flagged themselves as functional bugs in the Problem paragraph, mention that in the question so the user knows skipping will leave those behind. Otherwise keep the framing neutral.301302**Do NOT proceed past this step until the user responds.**303304---305306### Step 5b: AI Polish Application (conditional)307308If the user chose to have AI apply suggestions (all or selected):3093101. If "selected", ask the user which suggestion IDs to apply (e.g., "P1, P3, P5").3113122. Spawn a sub-agent to apply the suggestions. Pass file paths — do NOT paste suggestion contents.313314```315Agent tool parameters:316- description: "Apply polish suggestions to generated code"317- prompt: |318 Apply polish suggestions to the generated MCP server project.319320 PROJECT DIRECTORY: [absolute path]321 MODULE NAME: [module name]322323 Read the suggestions at: [absolute path to {working_dir}/polish-suggestions.md]324 [If selected: "Only apply suggestions: P1, P3, P5"]325326 For each suggestion to apply:327 1. Read the target file listed in the suggestion328 2. Find the "Before" code pattern329 3. Replace it with the "After" code330 4. Verify the change is syntactically valid331332 Only apply the listed suggestions. Do not make other changes.333- mode: acceptEdits334- run_in_background: false335```336337---338339### Step 6: Final Build Verification (conditional)340341Skip this step entirely if no code was modified — no fixes were applied in Step 3b AND no polish was applied in Step 5b. The validation report's existing Build Verification result is still accurate and stands as-is.342343Otherwise, rebuild the Docker image to confirm the post-fix / post-polish code still builds. The validator ran its build check against the generator's original output; edits applied after that (either error fixes or polish) may have introduced problems the initial build can't catch.3443451. Run the build from the generated project directory:346347 ```bash348 cd {project_dir} && docker build -t {server_name}-mcp:validation-test . 2>&1349 ```3503512. Append a **Final Build Verification** subsection to `{working_dir}/validation-report.md` (do not overwrite the original Build Verification row — the reader should be able to see both the pre-fix and post-fix results). Record PASS/FAIL/SKIP and, for FAIL or SKIP, the concrete reason including enough build output for the user to understand what broke.3523533. If the final build **failed**, present the failure to the user with AskUserQuestion. Summarize what code was modified (errors fixed, polish applied, or both) and paste the failing build excerpt. Offer:354355 - Have AI investigate and fix the build (spawn an inline fix agent scoped to the build failure, then re-run this step)356 - Fix manually and re-run the skill later357 - Acknowledge and continue to Step 7358359 Do not loop more than 2 AI-fix attempts here. If the build still fails after 2 rounds, ask the user to fix manually.3603614. If the final build **passed** or was **skipped** (Docker not installed etc.), continue to Step 7 without a gate.362363---364365### Step 7: Present Results366367Present the user with:368369- Path to `{working_dir}/validation-report.md`370- Path to `{working_dir}/polish-suggestions.md` (if generated)371- Summary:372 - Validation: X checks passed, Y failed373 - Build: PASS/FAIL/SKIP (report the **final** build outcome from Step 6 if it ran; otherwise the validator's original result)374 - Polish: N suggestions generated, M applied (if any)375 - Files modified (if any fixes or polish were applied)376377---378379## Error Handling380381| Failure | Behavior |382|---------|----------|383| Project directory doesn't exist | Tell the user, exit |384| Expected files missing from project | Note as missing, continue — validator reports as FAIL |385| mcp-scope.yaml fails to parse | Tell the user, exit |386| Reference repos can't be cloned | Warn the user, continue — agent checks will be less grounded but still functional |387| Docker not installed | Agent records build check as SKIP, continues |388| Docker build fails | Agent records as FAIL, continues to user gate |389| Code-validator agent fails | Present error to user, ask if they want to proceed to manual review |390| Polish-suggester agent fails | Present error to user, note that validation report is still valid |391| Fix agent fails | Present error to user, ask them to fix manually |392393## Important Notes394395### Sub-Agent Invocation396- Use the Agent tool with the appropriate subagent_type for code-validator and polish-suggester397- Fix/apply agents use inline prompts (no dedicated agent file) since they're straightforward edit tasks398- Always set `run_in_background: false` and `mode: acceptEdits`399- Pass file paths in the prompt — agents read files themselves. Never paste file contents into agent prompts.400401### Working Directory402- All output files go in `{cwd}/validation-output-{date}/`403- This includes `validation-report.md` and `polish-suggestions.md`404405### Read-Only by Default406- The skill only modifies the generated project if the user explicitly chooses "Have AI fix" or "Have AI apply"407- Validation and suggestion generation are entirely read-only operations