---
phase: 41-chatgpt-mcp-apps-upgraded-version
plan: 03
type: execute
wave: 2
depends_on: [41-01, 41-02]
files_modified:
  - cargo-pmcp/src/templates/mcp_app.rs
autonomous: true
requirements: [P41-05]

must_haves:
  truths:
    - "Scaffold template uses HtmlMcpApp MIME type (not HtmlSkybridge)"
    - "Scaffold template calls .with_ui() on the tool"
    - "Scaffold template emits _meta on Content::Resource in resource read handler"
    - "Generated scaffold compiles and runs correctly"
  artifacts:
    - path: "cargo-pmcp/src/templates/mcp_app.rs"
      provides: "Updated MCP App scaffold template"
      contains: "HtmlMcpApp"
  key_links:
    - from: "cargo-pmcp/src/templates/mcp_app.rs"
      to: "src/types/protocol.rs"
      via: "Content::Resource with meta field"
      pattern: "meta:"
    - from: "cargo-pmcp/src/templates/mcp_app.rs"
      to: "src/types/mcp_apps.rs"
      via: "ExtendedUIMimeType::HtmlMcpApp"
      pattern: "HtmlMcpApp"
---

<objective>
Update the `cargo pmcp new --mcp-app` scaffold template to use the correct MIME type, call `.with_ui()` on the tool, and emit `_meta` on resource content.

Purpose: New projects scaffolded with `cargo pmcp new --mcp-app` should produce code that is compatible with ChatGPT's MCP Apps protocol out of the box.
Output: Updated scaffold template that generates correct, ChatGPT-compatible MCP App code.
</objective>

<execution_context>
@./.claude/get-shit-done/workflows/execute-plan.md
@./.claude/get-shit-done/templates/summary.md
</execution_context>

<context>
@.planning/ROADMAP.md
@.planning/STATE.md
@.planning/phases/41-chatgpt-mcp-apps-upgraded-version/41-RESEARCH.md
@.planning/phases/41-chatgpt-mcp-apps-upgraded-version/41-01-SUMMARY.md

@cargo-pmcp/src/templates/mcp_app.rs

<interfaces>
<!-- From Plan 01: Content::Resource now has meta field -->
Content::Resource {
    uri: String,
    text: Option<String>,
    mime_type: Option<String>,
    meta: Option<serde_json::Map<String, serde_json::Value>>,  // serde rename = "_meta"
}

<!-- WidgetMeta.to_meta_map() returns Map<String, Value> for resource _meta -->
</interfaces>
</context>

<tasks>

<task type="auto">
  <name>Task 1: Update scaffold template MIME type, with_ui, and resource _meta</name>
  <files>cargo-pmcp/src/templates/mcp_app.rs</files>
  <action>
Update the MCP App scaffold template with three changes:

1. **MIME type fix:** Replace all occurrences of `ExtendedUIMimeType::HtmlSkybridge` with `ExtendedUIMimeType::HtmlMcpApp` in both the `read()` and `list()` resource handler implementations (lines ~185 and ~207).

2. **Add `.with_ui()` to tool registration:** In the scaffold's tool registration code, add `.with_ui("ui://app/{name}.html")` call on the tool. This ensures the tool's `_meta` includes `ui.resourceUri` and `openai/outputTemplate` linking the tool to its widget. Look for where the tool is registered with the server builder and add the with_ui call there.

3. **Add `_meta` to Content::Resource in read handler:** In the resource `read()` implementation, add widget metadata to the resource content:
   ```rust
   let widget_meta = WidgetMeta::new()
       .prefers_border(true)
       .description("Interactive {name} widget");

   Ok(ReadResourceResult::new(vec![Content::Resource {{
       uri: uri.to_string(),
       text: Some(html),
       mime_type: Some(ExtendedUIMimeType::HtmlMcpApp.to_string()),
       meta: Some(widget_meta.to_meta_map()),
   }}]))
   ```

4. **Update template comments** to reference `text/html;profile=mcp-app` instead of `text/html+skybridge`.

5. **Update the imports** in the template string: ensure `WidgetMeta` is imported (it already is at line 93 based on current code).

6. **Verify existing tests** in the template test module pass. Update any assertions that check for `HtmlSkybridge` to check for `HtmlMcpApp`.
  </action>
  <verify>
    <automated>cargo test -p cargo-pmcp</automated>
  </verify>
  <done>Scaffold template generates code using HtmlMcpApp MIME type, with_ui() on tool, and _meta on resource content; all cargo-pmcp tests pass</done>
</task>

</tasks>

<verification>
cargo test -p cargo-pmcp
cargo clippy -p cargo-pmcp -- -D warnings
cargo test --features full --lib
</verification>

<success_criteria>
- Template uses `ExtendedUIMimeType::HtmlMcpApp` everywhere (zero references to HtmlSkybridge)
- Template includes `.with_ui()` on tool registration
- Template includes `meta: Some(widget_meta.to_meta_map())` in Content::Resource
- All cargo-pmcp tests pass
- Full workspace test suite passes
</success_criteria>

<output>
After completion, create `.planning/phases/41-chatgpt-mcp-apps-upgraded-version/41-03-SUMMARY.md`
</output>
