WDK logoWDK documentation

API Reference

WdkMcpServer class and all 35 built-in MCP tools

WdkMcpServer

The WdkMcpServer class extends McpServer from @modelcontextprotocol/sdk with WDK-specific wallet, pricing, indexer, and protocol capabilities.

Constructor

const server = new WdkMcpServer(name: string, version: string)
ParameterTypeDescription
namestringServer name (shown to AI clients)
versionstringServer version string

Core Methods

useWdk(config)

Initializes the WDK wallet engine. Must be called before registerWallet() or registerProtocol().

server.useWdk(config: WdkConfig): WdkMcpServer
ParameterTypeRequiredDescription
config.seedstringYesBIP-39 mnemonic seed phrase

Returns: WdkMcpServer (for chaining)


registerWallet(blockchain, WalletManager, config)

Registers a wallet module for a specific blockchain.

server.registerWallet<W extends typeof WalletManager>(
  blockchain: string,
  WalletManager: W,
  config: ConstructorParameters<W>[1]
): WdkMcpServer
ParameterTypeRequiredDescription
blockchainstringYesChain name (e.g., 'ethereum', 'bitcoin')
WalletManagerclassYesWallet module class (e.g., WalletManagerEvm)
configobjectYesModule-specific config (see each wallet module's docs)

Requires: useWdk() called first


registerProtocol(chain, label, Protocol, config?)

Registers a DeFi protocol (swap, bridge, lending, or fiat) for a chain.

server.registerProtocol<P extends typeof SwapProtocol | typeof BridgeProtocol | typeof LendingProtocol | typeof FiatProtocol>(
  chain: string,
  label: string,
  Protocol: P,
  config?: ConstructorParameters<P>[1]
): WdkMcpServer
ParameterTypeRequiredDescription
chainstringYesChain name (must have a wallet registered)
labelstringYesProtocol identifier (e.g., 'velora', 'aave')
ProtocolclassYesProtocol module class
configobjectNoProtocol-specific config

Requires: useWdk() called first


useIndexer(config)

Enables the WDK Indexer client for querying token balances and transfer history.

server.useIndexer(config: { apiKey: string }): WdkMcpServer
ParameterTypeRequiredDescription
config.apiKeystringYesWDK Indexer API key

usePricing()

Enables the Bitfinex pricing client for current and historical prices.

server.usePricing(): WdkMcpServer

registerTools(tools)

Registers multiple MCP tools at once.

server.registerTools(tools: ToolFunction[]): WdkMcpServer

registerToken(chain, symbol, token)

Registers a custom token for a chain.

server.registerToken(chain: string, symbol: string, token: TokenInfo): WdkMcpServer
ParameterTypeDescription
chainstringChain name
symbolstringToken symbol (e.g., 'USDC')
token.addressstringToken contract address
token.decimalsnumberToken decimal places

close()

Disposes the WDK instance and clears seed material from memory. Call this when shutting down the server.

server.close(): void

Query Methods

MethodReturnsDescription
getChains()string[]Registered blockchain names
getTokenInfo(chain, symbol)TokenInfo | undefinedToken address and decimals
getRegisteredTokens(chain)string[]Registered token symbols for a chain
getSwapChains()string[]Chains with swap protocols
getSwapProtocols(chain)string[]Swap protocol labels for a chain
getBridgeChains()string[]Chains with bridge protocols
getBridgeProtocols(chain)string[]Bridge protocol labels for a chain
getLendingChains()string[]Chains with lending protocols
getLendingProtocols(chain)string[]Lending protocol labels for a chain
getFiatChains()string[]Chains with fiat protocols
getFiatProtocols(chain)string[]Fiat protocol labels for a chain

Getters

GetterTypeDescription
server.wdkWalletKitWDK instance (after useWdk())
server.indexerClientWdkIndexerClientIndexer client (after useIndexer())
server.pricingClientWdkPricingClientPricing client (after usePricing())

Types

type WdkConfig = {
  seed?: string
}

type TokenInfo = {
  address: string
  decimals: number
}

type ToolFunction = (server: WdkMcpServer) => void

Built-in MCP Tools

All tools use Zod for input/output validation and include MCP tool annotations that describe their behavior to AI clients.

MCP Annotations

Every tool declares these annotations:

AnnotationTypeMeaning
readOnlyHintbooleanTool does not modify state
destructiveHintbooleanTool may spend funds or make irreversible changes
idempotentHintbooleanCalling multiple times produces the same result
openWorldHintbooleanTool interacts with external systems

Human Confirmation - All tools where destructiveHint: true use MCP elicitations to show a confirmation dialog before broadcasting. The user must explicitly approve each transaction.


Wallet Tools

Requires: useWdk() + registerWallet()

getAddress

Get the wallet address for a blockchain. Read-only.

Input:

ParameterTypeRequiredDescription
chainenumYesThe blockchain to get the address for

Output:

FieldTypeDescription
addressstringThe wallet address

getBalance

Get the native token balance for a blockchain (ETH, BTC, SOL, etc.). Read-only.

Input:

ParameterTypeRequiredDescription
chainenumYesThe blockchain to query

Output:

FieldTypeDescription
balancestringBalance in base units (wei, satoshis, etc.)

getTokenBalance

Get the balance of a registered token (USDT, USDC, etc.). Read-only.

Input:

ParameterTypeRequiredDescription
chainenumYesThe blockchain to query
tokenstringYesToken symbol (e.g., "USDT")

Output:

FieldTypeDescription
balancestringHuman-readable token balance
balanceBaseUnitsstringBalance in smallest unit

getFeeRates

Get current network fee rates. Read-only.

Input:

ParameterTypeRequiredDescription
chainenumYesThe blockchain to query

Output:

FieldTypeDescription
normalstringNormal fee rate (balanced speed)
faststringFast fee rate (higher cost, faster confirmation)

Fee units vary by chain: satoshis/byte (Bitcoin), wei (Ethereum), or chain-specific units.


getMaxSpendableBtc

Get the maximum spendable Bitcoin amount after fees. Read-only. Bitcoin-only.

Input: None

Output:

FieldTypeDescription
amountstringMaximum spendable amount (satoshis)
feestringEstimated transaction fee (satoshis)
changeValuestringExpected change output (satoshis)

quoteSendTransaction

Estimate the fee for sending native currency. Read-only. Does not broadcast.

Input:

ParameterTypeRequiredDescription
chainenumYesThe blockchain
tostringYesRecipient address
valuestringYesAmount in base units (wei, satoshis)

Output:

FieldTypeDescription
feestringEstimated transaction fee in base units

quoteTransfer

Estimate the fee for transferring a token. Read-only. Does not broadcast.

Input:

ParameterTypeRequiredDescription
chainenumYesThe blockchain
tokenstringYesToken symbol (e.g., "USDT")
recipientstringYesRecipient address
amountstringYesAmount in human-readable format (e.g., "10")

Output:

FieldTypeDescription
feestringEstimated transaction fee in base units

sendTransaction

Send native currency (ETH, BTC, etc.). Destructive - requires user confirmation.

Input:

ParameterTypeRequiredDescription
chainenumYesThe blockchain
tostringYesRecipient address
valuestringYesAmount in base units (wei, satoshis)

Output:

FieldTypeDescription
hashstringTransaction hash
feestringActual fee paid

This tool shows a confirmation dialog with transaction details before broadcasting. The user must approve the transaction explicitly.


transfer

Transfer a registered token. Destructive - requires user confirmation.

Input:

ParameterTypeRequiredDescription
chainenumYesThe blockchain
tokenstringYesToken symbol (e.g., "USDT")
tostringYesRecipient address
amountstringYesAmount in human-readable format (e.g., "100")

Output:

FieldTypeDescription
hashstringTransaction hash
feestringActual fee paid

This tool shows a confirmation dialog with transaction details before broadcasting. The user must approve the transaction explicitly.


sign

Sign an arbitrary message with the wallet's private key. Does not reveal the private key.

Input:

ParameterTypeRequiredDescription
chainenumYesThe blockchain
messagestringYesMessage to sign

Output:

FieldTypeDescription
signaturestringCryptographic signature

verify

Verify that a signature is valid for a given message. Read-only.

Input:

ParameterTypeRequiredDescription
chainenumYesThe blockchain
messagestringYesOriginal message
signaturestringYesSignature to verify

Output:

FieldTypeDescription
validbooleanWhether the signature is valid

Pricing Tools

Requires: usePricing()

getCurrentPrice

Get the current spot price from Bitfinex. Read-only.

Input:

ParameterTypeRequiredDescription
basestringYesBase currency (e.g., "BTC", "ETH")
quotestringYesQuote currency (e.g., "USD", "USDT")

Output:

FieldTypeDescription
basestringBase currency
quotestringQuote currency
pricenumberCurrent spot price

getHistoricalPrice

Get historical price data (OHLCV candles) from Bitfinex. Read-only.

Input:

ParameterTypeRequiredDescription
fromstringYesBase currency (e.g., "BTC")
tostringYesQuote currency (e.g., "USD")
startnumberNoStart timestamp (ms, unix epoch)
endnumberNoEnd timestamp (ms, unix epoch)

Output:

FieldTypeDescription
fromstringBase currency
tostringQuote currency
startnumberStart timestamp (if provided)
endnumberEnd timestamp (if provided)
pointsnumber[][]Array of [timestamp, open, close, high, low, volume]

Long time ranges are automatically downscaled to ≤100 data points.


Indexer Tools

Requires: useIndexer()

getIndexerTokenBalance

Get token balance for any address via the WDK Indexer API. Read-only.

Input:

ParameterTypeRequiredDescription
blockchainenumYesBlockchain to query
tokenenumYesToken (e.g., "usdt", "xaut", "btc")
addressstringYesWallet address

Output:

FieldTypeDescription
tokenBalance.blockchainstringBlockchain name
tokenBalance.tokenstringToken name
tokenBalance.amountstringToken balance

This queries the indexed balance, which may have slight delay compared to real-time blockchain state. For your own wallet's balance, use getBalance or getTokenBalance instead.


getTokenTransfers

Get token transfer history for an address. Read-only.

Input:

ParameterTypeRequiredDescription
blockchainenumYesBlockchain to query
tokenenumYesToken (e.g., "usdt", "xaut", "btc")
addressstringYesWallet address
limitnumberNoResults per page (1–1000, default: 10)
fromTsnumberNoStart timestamp (unix seconds)
toTsnumberNoEnd timestamp (unix seconds)
sortenumNo"asc" or "desc" (default: "desc")

Output:

FieldTypeDescription
transfersobject[]Array of transfer records
transfers[].blockchainstringBlockchain
transfers[].blockNumbernumberBlock number
transfers[].transactionHashstringTransaction hash
transfers[].tokenstringToken
transfers[].amountstringTransfer amount
transfers[].timestampnumberUnix timestamp
transfers[].fromstringSender address
transfers[].tostringRecipient address

Swap Tools

Requires: registerProtocol() with a swap protocol

quoteSwap

Get a swap quote without executing. Read-only.

Input:

ParameterTypeRequiredDescription
chainenumYesBlockchain with swap protocol
tokenInstringYesToken to sell (e.g., "USDT")
tokenOutstringYesToken to buy (e.g., "USDC")
amountstringYesAmount in human-readable units
sideenumYes"sell" or "buy"

Output:

FieldTypeDescription
protocolstringDEX protocol used
tokenInstringInput token symbol
tokenOutstringOutput token symbol
tokenInAmountstringInput amount (human-readable)
tokenOutAmountstringOutput amount (human-readable)
feestringEstimated fee

swap

Execute a token swap. Destructive - requires user confirmation.

Input:

ParameterTypeRequiredDescription
chainenumYesBlockchain with swap protocol
tokenInstringYesToken to sell
tokenOutstringYesToken to buy
amountstringYesAmount in human-readable units
sideenumYes"sell" or "buy"
tostringNoRecipient address (defaults to wallet)

Output:

FieldTypeDescription
successbooleanWhether the swap succeeded
protocolstringDEX protocol used
hashstringTransaction hash
tokenInstringInput token symbol
tokenOutstringOutput token symbol
tokenInAmountstringActual input amount
tokenOutAmountstringActual output amount
feestringFee paid

This tool quotes the swap first, then shows a confirmation dialog before broadcasting.


Bridge Tools

Requires: registerProtocol() with a bridge protocol

quoteBridge

Get a bridge quote without executing. Read-only.

Input:

ParameterTypeRequiredDescription
chainenumYesSource blockchain
targetChainstringYesDestination blockchain
tokenstringYesToken to bridge (e.g., "USDT")
amountstringYesAmount in human-readable units
recipientstringNoRecipient on target chain (defaults to wallet)

Output:

FieldTypeDescription
protocolstringBridge protocol used
sourceChainstringSource blockchain
targetChainstringDestination blockchain
tokenstringToken symbol
amountstringAmount to bridge
feestringEstimated gas fee
bridgeFeestringBridge protocol fee

bridge

Execute a cross-chain bridge. Destructive - requires user confirmation.

Input:

ParameterTypeRequiredDescription
chainenumYesSource blockchain
targetChainstringYesDestination blockchain
tokenstringYesToken to bridge
amountstringYesAmount in human-readable units
recipientstringNoRecipient on target chain (defaults to wallet)

Output:

FieldTypeDescription
successbooleanWhether the bridge succeeded
protocolstringBridge protocol used
hashstringTransaction hash
sourceChainstringSource blockchain
targetChainstringDestination blockchain
tokenstringToken symbol
amountstringAmount bridged
feestringGas fee paid
bridgeFeestringBridge protocol fee paid

Bridge finality varies by target chain - tokens may take minutes to hours to arrive.


Lending Tools

Requires: registerProtocol() with a lending protocol

quoteSupply

Get a fee estimate for supplying tokens to a lending pool. Read-only.

Input:

ParameterTypeRequiredDescription
chainenumYesBlockchain with lending protocol
tokenstringYesToken to supply
amountstringYesAmount in human-readable units
onBehalfOfstringNoAddress to receive aTokens (defaults to wallet)

Output:

FieldTypeDescription
protocolstringLending protocol used
chainstringBlockchain
tokenstringToken symbol
amountstringAmount to supply
feestringEstimated gas fee

supply

Supply tokens to a lending pool. Destructive - requires user confirmation.

Same input as quoteSupply. Output includes success, protocol, hash, token, amount, and fee.


quoteWithdraw

Estimate fee for withdrawing from a lending pool. Read-only.

Input:

ParameterTypeRequiredDescription
chainenumYesBlockchain
tokenstringYesToken to withdraw
amountstringYesAmount in human-readable units

Output: Same structure as quoteSupply.


withdraw

Withdraw tokens from a lending pool. Destructive - requires user confirmation.

Same input as quoteWithdraw. Output includes success, protocol, hash, token, amount, and fee.


quoteBorrow

Estimate fee for borrowing from a lending pool. Read-only.

Input:

ParameterTypeRequiredDescription
chainenumYesBlockchain
tokenstringYesToken to borrow
amountstringYesAmount in human-readable units

Output: Same structure as quoteSupply.


borrow

Borrow tokens from a lending pool. Destructive - requires user confirmation.

Same input as quoteBorrow. Output includes success, protocol, hash, token, amount, and fee.


quoteRepay

Estimate fee for repaying a loan. Read-only.

Input:

ParameterTypeRequiredDescription
chainenumYesBlockchain
tokenstringYesToken to repay
amountstringYesAmount in human-readable units

Output: Same structure as quoteSupply.


repay

Repay borrowed tokens. Destructive - requires user confirmation.

Same input as quoteRepay. Output includes success, protocol, hash, token, amount, and fee.


Fiat Tools

Requires: registerProtocol() with a fiat protocol

quoteBuy

Get a quote for purchasing crypto with fiat. Read-only.

Input:

ParameterTypeRequiredDescription
chainenumYesBlockchain for the fiat protocol
cryptoAssetstringYesCrypto asset code (e.g., "eth", "btc")
fiatCurrencystringYesFiat currency code (e.g., "USD", "EUR")
amountstringYesAmount to quote
amountTypeenumYes"crypto" or "fiat"

Output:

FieldTypeDescription
protocolstringFiat protocol used
cryptoAssetstringCrypto asset code
fiatCurrencystringFiat currency code
cryptoAmountstringCrypto amount (base units)
fiatAmountstringFiat amount (smallest units, e.g., cents)
feestringTotal fee (fiat smallest units)
ratestringExchange rate

buy

Execute a fiat-to-crypto purchase. Destructive - requires user confirmation.

Same input as quoteBuy. Output includes success, protocol, redirect URL or transaction details.


quoteSell

Get a quote for selling crypto to fiat. Read-only.

Same input structure as quoteBuy. Same output structure.


sell

Execute a crypto-to-fiat sale. Destructive - requires user confirmation.

Same input as quoteSell. Output includes success, protocol, and transaction details.


getTransactionDetail

Get details of a fiat transaction by ID. Read-only.

Input:

ParameterTypeRequiredDescription
chainenumYesBlockchain
transactionIdstringYesTransaction ID from the fiat provider

getSupportedCryptoAssets

List crypto assets supported by the fiat provider. Read-only.

Input:

ParameterTypeRequiredDescription
chainenumYesBlockchain

getSupportedFiatCurrencies

List fiat currencies supported by the fiat provider. Read-only.

Input:

ParameterTypeRequiredDescription
chainenumYesBlockchain

getSupportedCountries

List countries supported by the fiat provider. Read-only.

Input:

ParameterTypeRequiredDescription
chainenumYesBlockchain

Utility Exports

Utility functions for converting between human-readable amounts and blockchain base units:

import {
  parseAmountToBaseUnits,
  formatBaseUnitsToAmount,
  AmountParseError,
  AMOUNT_ERROR_CODES
} from '@tetherto/wdk-mcp-toolkit'

parseAmountToBaseUnits(amount, decimals)

Converts a human-readable amount string to BigInt base units without floating-point errors.

parseAmountToBaseUnits('2.01', 6)   // → 2010000n
parseAmountToBaseUnits('100', 18)   // → 100000000000000000000n
parseAmountToBaseUnits('1,000.50', 6) // → 1000500000n

formatBaseUnitsToAmount(baseUnits, decimals)

Converts BigInt base units to a human-readable string.

formatBaseUnitsToAmount(2010000n, 6)  // → '2.01'
formatBaseUnitsToAmount(100000000000000000000n, 18) // → '100'

AmountParseError

Custom error class with a code property for programmatic handling:

Error CodeDescription
EMPTY_STRINGEmpty amount string
INVALID_FORMATNot a valid number
NEGATIVE_AMOUNTNegative amounts not allowed
EXCESSIVE_PRECISIONMore decimal places than token supports
INVALID_DECIMALSDecimals value out of range
SCIENTIFIC_NOTATION_PRECISIONScientific notation exceeds precision

Need Help?

On this page