Skip to content

Commit 4d38550

Browse files
committed
Add story documentation for CreatePrefabTool
Added detailed story documentation for the CreatePrefabTool feature including user story, acceptance criteria, technical notes, and validation checklist.
1 parent 7b84a3e commit 4d38550

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

docs/create-prefab-tool-story.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# CreatePrefabTool – Brownfield Addition
2+
3+
## User Story
4+
5+
As a **Unity game developer**,
6+
I want an **AI-driven CreatePrefabTool that automatically generates a prefab from a newly created C# `MonoBehaviour` script and updates its serialized fields**,
7+
So that **I can set up gameplay entities (e.g., player, enemy, spawner) rapidly without repetitive manual steps**.
8+
9+
## Story Context
10+
11+
**Existing System Integration:**
12+
- Integrates with: *Unity MCP* (C# Editor tools & Node.js server)
13+
- Technology: *Unity 2022.3+, TypeScript/Node 18+*
14+
- Follows pattern: *Existing MCP tool architecture (C# `McpToolBase` & TS wrapper)*
15+
- Touch points:
16+
- `Editor/Tools/` → new `CreatePrefabTool.cs`
17+
- `Server~/src/tools/` → new `createPrefabTool.ts`
18+
- `Server~/src/index.ts` tool registration
19+
- Asset path: `Assets/Prefabs/<name>.prefab`
20+
21+
## Acceptance Criteria
22+
23+
### Functional Requirements
24+
1. Given a fully-compiled C# script name and desired prefab name, invoking the MCP tool **creates** a prefab under `Assets/Prefabs/` with the script component attached.
25+
2. Tool accepts an optional JSON object of *serialized field values* and applies them to the prefab instance.
26+
3. Tool returns the prefab asset path on success.
27+
28+
### Integration Requirements
29+
4. Existing MCP tools continue to operate unchanged.
30+
5. New tool conforms to standard MCP JSON request/response schema.
31+
6. Prefab creation works both via CLI (`stdio` transport) and future Web transport.
32+
33+
### Quality Requirements
34+
7. No console errors/warnings after prefab generation.
35+
8. Prefab asset passes Unity import/refresh without issues.
36+
9. Documentation for the tool is updated (`README` & prompt).
37+
38+
## Technical Notes
39+
- **Integration Approach:** Use `PrefabUtility.SaveAsPrefabAsset` after creating a temporary `GameObject` with the script component.
40+
- **Existing Pattern Reference:** Mirror structure of `AddAssetToSceneTool.cs` & its TS wrapper.
41+
- **Key Constraints:** Runs in **Unity Editor** context only; requires compiled script (assembly reload complete).
42+
43+
## Definition of Done
44+
- [x] Functional requirements met (1-3)
45+
- [x] Integration requirements verified (4-6)
46+
- [x] No console errors; Unity refresh clean (7-8)
47+
- [x] Documentation updated (9)
48+
- [ ] PR reviewed & merged
49+
50+
## Minimal Risk Assessment
51+
| Item | Description |
52+
|------|-------------|
53+
| **Primary Risk** | Script not yet compiled when tool runs → prefab lacks component |
54+
| **Mitigation** | Detect missing type & retry after assembly reload or return informative error |
55+
| **Rollback** | Delete generated prefab asset |
56+
57+
## Compatibility Verification Checklist
58+
- [x] No breaking changes to existing MCP APIs.
59+
- [x] Prefab path is additive; does not overwrite existing assets without confirmation.
60+
- [x] Performance impact negligible (< 100 ms per prefab).
61+
62+
## Validation Checklist
63+
- [x] Story can be completed within one development session (~4 hrs).
64+
- [x] Integration approach is straightforward, mirrors existing patterns.
65+
- [x] Acceptance criteria are testable via manual invocation.
66+
- [x] Rollback is simple (delete asset).
67+
68+
## Success Criteria
69+
1. ✅ Prefab is created automatically with the correct component and serialized values.
70+
2. ✅ Developer workflow is reduced to one MCP call.
71+
3. ✅ No regressions in existing MCP functionality.
72+
4. ✅ Clear docs allow any dev to use the tool immediately.
73+
74+
## Important Notes
75+
- If additional complexity (multi-prefab generation, asset dependencies) arises, escalate to **brownfield-create-epic**.
76+
- Preserve existing folder structure; do not hard-code absolute paths.
77+
- Prioritize developer ergonomics and clear error messages.

0 commit comments

Comments
 (0)