Wrapper Pattern Guide
Build an MCP canister that wraps existing backend logic, providing AI agents with high-level tools and identity management.What is the Wrapper Pattern?
The wrapper pattern creates an MCP server canister that acts as an identity-owning interface to your existing backend canister(s). It orchestrates complex multi-step workflows so AI agents don’t have to. When to Use:- ✅ Complex workflows (DEX swaps, multi-step approvals)
- ✅ Need canister identity to hold allowances
- ✅ Wrapping existing protocols (DeFi, governance)
- ❌ Simple CRUD operations (use multi-tenant instead)
Example: DEX Swap Wrapper
Let’s wrap a DEX canister to provide a simple “swap” tool that handles all the complexity.What the User Wants
What the Wrapper Does
Step-by-Step Implementation
1. Set Up Your Project
2. Define Your Tool Context
3. Create Your Swap Tool
4. Register in Main Actor
Key Security Principles
1. Owner-Only Operations
2. Use Allowances, Not Direct Transfers
3. Set Expiry Times
4. Don’t Store User Funds
Testing Your Wrapper
1. Deploy Locally
2. Create API Key
3. Test the Swap
Common Patterns
Pattern 1: Multi-Step Workflows
Pattern 2: Quote Before Execute
Pattern 3: Claim Rewards
Comparison with Multi-Tenant Pattern
| Feature | Wrapper Pattern | Multi-Tenant Pattern |
|---|---|---|
| Purpose | Orchestrate complex workflows | Store user data |
| Identity | Canister holds allowances | Users identified by principal |
| Use Cases | DEX swaps, DeFi, governance | Todo lists, notes, settings |
| Complexity | High (multi-step operations) | Low (CRUD operations) |
| Backend | Wraps existing protocols | Self-contained logic |
Next Steps
- For simple data storage: See the Multi-Tenant Pattern Guide
- Deploy to production: Use
dfx deploy --network ic - Add to App Store: Submit via
prometheus submit

