Skip to content

feat(prompts): parameterized workflow prompts + server instructions + project prompt files#46

Open
dehuaichendragonplus wants to merge 1 commit into
FunplayAI:mainfrom
dehuaichendragonplus:feat/mcp-prompts-p0
Open

feat(prompts): parameterized workflow prompts + server instructions + project prompt files#46
dehuaichendragonplus wants to merge 1 commit into
FunplayAI:mainfrom
dehuaichendragonplus:feat/mcp-prompts-p0

Conversation

@dehuaichendragonplus

Copy link
Copy Markdown
Contributor

Why

The built-in MCP prompts were canned one-liners: all declared zero arguments, and prompts/get ignored its input and returned a single role:user message that just restated the prompt's own description — no real tool names, no parameters, no guidance. They were effectively undiscoverable workflow stubs.

Two more gaps:

  • Cross-client conventions lived only in CLAUDE.md/AGENTS.md (Claude Code-specific). A fresh MCP client had no protocol-native way to learn how to drive this Unity server correctly (structured envelopes, Play Mode / domain-reload sequencing, etc.).
  • A project could not register its own prompts without forking the package, so project-specific workflows (activity/build/port recipes) had nowhere to live at the protocol layer.

What changed

1. Built-in prompts → parameterized workflow templates. edit_prefab_safely, verify_compilation, enter_play_and_recover, wire_serialized_references, create_playable_prototype each now declare real arguments, and prompts/get expands into an ordered sequence of actual tool calls with the caller's arguments interpolated, plus a Guidance section on that workflow's pitfalls. Declared-required arguments are enforced (a missing one returns a clear message instead of a body full of unfilled placeholders). A single declarative PromptSpec table is the source of truth for names, arguments, and the embedded resource.

2. Live resource embedding. Prompts that act on current state embed the relevant read-only resource inline in prompts/getverify_compilationunity://errors/compilation, wire_serialized_referencesunity://selection/current, create_playable_prototypeunity://scene/active — so the model sees that state without a separate fetch. Best-effort: silently skipped if the resource provider is unavailable or the read fails.

3. Server-level instructions. The initialize result now returns an instructions string with the cross-cutting conventions a client needs (structured {success,…} envelopes and branching on code; never hand-editing serialized assets; the request_recompile / Play Mode / get_reload_recovery_status sequence; instanceId reuse via find_method=by_id; group_duplicates logs; small-payload screenshots). This reaches every MCP client, not just Claude Code.

4. Project-authored prompts. A project can drop mcp-prompts/*.md files in its root to register its own workflow prompts — no fork, no C#. Format: a --- front-matter fence (name, description, arguments: a(required), b) + a body template referencing {arg} placeholders. They appear in prompts/list alongside the built-ins and interpolate arguments in prompts/get. Reserved built-in names cannot be shadowed; malformed files are skipped with a logged warning (not fatal). Parsing is dependency-free (no YAML library).

Benefits

  • Prompts become genuinely useful, self-contained workflows a model can select and follow — with the real tool names and the pitfalls spelled out — instead of stubs.
  • Server instructions fix "conventions only Claude Code knows": every client gets them at handshake.
  • "Generic workflows in the package, project workflows in the project" — projects extend prompts without forking, which keeps this package generic.

Compatibility

  • Additive. MCPPromptProvider's new constructor parameter is optional (resourceProvider = null), so existing construction still compiles; initialize gains one field; no tool signatures change.
  • Prompt names changed (fix_compile_errorsverify_compilation, runtime_validationenter_play_and_recover, auto_wire_referenceswire_serialized_references, plus new edit_prefab_safely). Prompts are user-selected, not a hard API; README updated. Flagging it since it is a visible rename.
  • No new package dependency (front-matter parsing is hand-rolled; reflection-free).
  • instructions is part of the initialize result in protocol 2024-11-05 (the version this server declares), so no protocol-version bump is needed.

Dependency / sequencing

The edit_prefab_safely prompt and one line of instructions reference set_prefab_property, the stage-free prefab-edit tool proposed in #45 (fix(prefab): edit prefab assets without prefab-stage save corruption). This PR is text-only with respect to that tool — it compiles, and all tests pass, on the current main without #45 — but the guidance names a tool that only exists once #45 lands. Recommended merge order: land #45 first, then this PR; or merge this one knowing the edit_prefab_safely single-field path references a not-yet-present tool until #45 merges. Nothing else in this PR depends on #45.

Testing & verification

  • Verified on a live Unity 6000.3.13f1 editor via the MCP tools: prompts/list returns the reworked built-ins with their arguments; prompts/get interpolates arguments into the real tool sequences; a project mcp-prompts/*.md file is picked up and interpolated; reserved built-in names are not shadowable.
  • 22 new EditMode tests across MCPServerInstructionsTests, MCPPromptProviderTests, ProjectPromptLoaderTests: instructions content, prompt argument declarations + interpolation + required-arg enforcement, live-resource embedding, front-matter parsing (valid / missing name / missing fence / arg spec), folder scan + malformed-skip, provider merge, and the built-in-name-cannot-be-shadowed guard. All pass; no regressions in the rest of the EditMode suite.

Changelog

Added under ## Unreleased.

…roject prompt files

Turn MCP prompts from canned one-liners into real parameterized workflows, add
server-level usage instructions, and let projects register their own prompts
without forking.

- Built-in prompts (edit_prefab_safely, verify_compilation, enter_play_and_recover,
  wire_serialized_references, create_playable_prototype) now declare real arguments
  (required ones enforced) and expand in prompts/get into an ordered sequence of
  actual tool calls with the caller's arguments interpolated, plus a Guidance
  section. Prompts acting on live state embed the relevant read-only resource
  inline (compile errors / selection / active scene), best-effort.
- initialize now returns server-level `instructions` (cross-client conventions:
  structured {success,...} envelopes, no hand-editing serialized assets, the
  request_recompile/Play Mode/domain-reload sequence, instanceId reuse, etc.).
- Projects can drop mcp-prompts/*.md files (front-matter name/description/arguments
  + {arg} body template) to register their own workflow prompts; reserved built-in
  names cannot be shadowed; malformed files are skipped with a logged warning.

Declarative PromptSpec table is the single source of truth for names, arguments,
and embedded resource. Adds 22 EditMode tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant