Chapter 20 Exercises
These exercises help you build complete MCP Apps powered by the standard SDK APIs.
AI-Guided Exercises
The following exercises are designed for AI-guided learning. Use an AI assistant with the course MCP server to get personalized guidance, hints, and feedback.
-
Build a Widget-Enabled MCP Server (60 min)
- Create a server with
ToolInfo::with_ui()andUIResource::html_mcp_app() - Build a widget using the ext-apps
Appclass with all required handlers - Return
structuredContentfrom a tool and render it in the widget - Bundle with Vite and test with
cargo pmcp preview
- Create a server with
-
Multi-Host Validation (30 min)
- Add
with_host_layer(HostType::ChatGpt)to your server - Validate metadata with
mcp-tester apps http://localhost:3000 - Run with
--mode chatgptand--mode claude-desktopto check host-specific compliance - Fix any warnings reported by
mcp-tester apps --strict
- Add
-
External Resource Loading (45 min)
- Add external image loading to a widget
- Declare CDN domains using
WidgetCSPon the server side - Implement the fetch-blob pattern in the widget for cross-host compatibility
- Test in
cargo pmcp previewand verify images render correctly
Prerequisites
Before starting these exercises, ensure you have:
- Completed all previous chapters
cargo-pmcpinstalled (cargo install cargo-pmcp)- Node.js installed (for Vite bundling)
- Understanding of MCP resource patterns
Next Steps
Congratulations! You've completed the PMCP course. Continue your learning:
- Template Gallery - Production templates
- Troubleshooting - Common issues
- Contribute to the PMCP SDK community