Skip to main content

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

Then connect to your local canister and test the tools interactively.

Common Patterns

Pattern 1: Multi-Step Workflows

Pattern 2: Quote Before Execute

Pattern 3: Claim Rewards


Comparison with Multi-Tenant Pattern


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