Skip to main content

Overview

The Handshake Architecture enables MCP tools to request user interaction for actions that require explicit approval:
  • Signature Requests: EIP-712 typed data signing (Hyperliquid, dYdX)
  • Transaction Proposals: direct on-chain transactions (Uniswap, NFT mints)
  • OAuth Requests: external service authentication (Discord, Twitter)
Why “Handshake”? The tool proposes an action, the user approves it, and the result is returned to the tool. That is the secure handshake between AI and human.

When to Use Handshakes

Prefer signatures over transactions when possible. Signatures are gasless, don’t require network switching, and work seamlessly with Privy embedded wallets.

Quick Start (TypeScript)

1. Install the SDK

2. Import Handshake Helpers

3. Return a Handshake from Your Tool


Quick Start (Python)

1. Install the SDK

2. Import Handshake Helpers

3. Return a Handshake from Your Tool


How It Works


Action Types

Signature Request (EIP-712)

Best for platforms with proxy wallets that accept EIP-712 signatures directly (Hyperliquid, dYdX).
Gasless & Chain-Agnostic: EIP-712 signatures don’t require gas or network switching. The chainId in the domain is purely informational: signing works from any network.

Transaction Proposal

For direct on-chain actions (Uniswap swaps, NFT mints, etc.).
Network Switching: Transaction proposals may require the user to switch networks. Use signatures when possible for better UX.

Auth Required (OAuth)

For external service authentication.
Security: The authUrl domain must match your tool’s endpoint domain. Context appends the user’s DID as ?context_did=... for you to associate the auth with the user.

Response Format

Handshake actions must be placed in structuredContent._meta.handshakeAction:
Why _meta? The MCP SDK strips unknown top-level fields. Placing the action in _meta ensures it’s preserved and detected by the Context platform.

Helper Functions

TypeScript SDK

Python SDK


Complete Example: Hyperliquid Order Tool


Complete Example: Discord Notifications (OAuth)

This example shows how to build a tool that posts messages to a user’s Discord channel, requiring OAuth authentication.

Tool Definition

OAuth Endpoint (Your Backend)

You must host OAuth endpoints on your MCP server’s domain:

How It Works

Token Security: Never expose user OAuth tokens. Store them encrypted on your backend, mapped to the user’s Context DID. Your tool receives the DID on every request, allowing you to look up the stored tokens.
Domain Requirement: Your authUrl must be on the same domain as your MCP endpoint. This prevents phishing attacks where a malicious tool redirects to a fake auth page.

UI Preview

When a handshake is detected, the Context app shows an approval card: The card displays:
  • Protocol name and action type
  • Human-readable description
  • Token amount (if applicable)
  • Gas status (gasless for signatures)
  • Sign/Reject buttons

Best Practices

The meta field powers the approval UI. Include:
  • description: What the user is approving
  • protocol: Which platform (builds trust)
  • tokenAmount + tokenSymbol: For financial actions
  • warningLevel: “caution” for large amounts, “danger” for irreversible actions
EIP-712 signatures are:
  • Gasless (no ETH needed)
  • Chain-agnostic (no network switching)
  • Faster (no block confirmation)
Many DeFi platforms (Hyperliquid, dYdX) use proxy wallets that accept signatures directly.
Don’t ask users to sign invalid orders. Validate:
  • Asset exists on the platform
  • Price is reasonable (not 100x above/below market)
  • Size is within platform limits
  • User has sufficient balance (if portfolio context available)
For flows that need the signature result:
The platform will call this tool with { signature, originalParams } after signing.

Security Considerations

Domain Validation: For auth_required, the authUrl domain must match your tool’s endpoint domain. This prevents phishing attacks where a malicious tool redirects users to fake auth pages.
No Private Keys: The user’s wallet signs the data client-side. Your tool never sees private keys, only the resulting signature.

Platform Philosophy

The Context marketplace supports authentication flows that are generalizable, so solving the problem once enables infinite integrations.
Why no API key support? Platforms like Polymarket require API keys derived from wallet signatures on their site, with custom HMAC authentication for every request. This cannot be delegated through the handshake architecture.If your tool requires API keys, you have two options:
  1. Provide read-only features with a redirect link for write actions
  2. Accept user-provided keys as input parameters (user manages their own credentials)
Want API key support? We’re monitoring demand. If you’re building a tool that needs this pattern, open an issue describing your use case.