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, options?: ServerOptions)
ParameterTypeDescription
namestringServer name (shown to AI clients)
versionstringServer version string
options.capabilities.elicitationbooleanDefaults to true. When false, confirmation requests are automatically accepted; see confirmation settings.

Core Methods

useWdk(config)

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

server.useWdk(config: WdkConfig): WdkMcpServer
ParameterTypeRequiredDescription
config.seedstringUnless WDK_SEED is setBIP-39 mnemonic seed phrase. An omitted or empty value falls back to WDK_SEED.

Pass a mnemonic resolved by your application's secret-manager integration. This method does not execute WDK_SEED_COMMAND or read WDK_SEED_FILE; those are seed sources for the built-in serve command. See the custom server example for an explicit command loader.

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., 'XAUT')
token.addressstringToken contract address
token.decimalsnumberToken decimal places

close()

Attempts WDK disposal, then clears the server's WDK reference and closes the MCP server. Await this when shutting down. If disposal throws, close() rejects before clearing the reference or closing the transport. Successful cleanup does not guarantee erasure of every seed or key copy in process memory.

server.close(): Promise<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

Configurable confirmation - Tools that request confirmation use MCP elicitation when enabled. Disabling elicitation automatically accepts confirmation requests. The annotations are descriptive hints, not authorization checks; see confirmation and agent access.


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, such as USD₮ or XAU₮. 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 - requests confirmation when elicitation is enabled.

Input:

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

Output:

FieldTypeDescription
hashstringTransaction hash
feestringActual fee paid

With elicitation enabled and a compatible MCP client, this tool requests approval before broadcasting. With elicitation disabled, the confirmation request is automatically accepted.


transfer

Transfer a registered token. Destructive - requests confirmation when elicitation is enabled.

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

With elicitation enabled and a compatible MCP client, this tool requests approval before broadcasting. With elicitation disabled, the confirmation request is automatically accepted.


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., "XAUT" on Ethereum, when supported by the registered protocol)
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 - requests confirmation when elicitation is enabled.

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 requests approval when elicitation is enabled. With elicitation disabled, the confirmation request is automatically accepted.


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 - requests confirmation when elicitation is enabled.

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 - requests confirmation when elicitation is enabled.

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 - requests confirmation when elicitation is enabled.

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 - requests confirmation when elicitation is enabled.

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 - requests confirmation when elicitation is enabled.

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

Generate a provider URL for a fiat-to-crypto purchase. This tool does not request MCP confirmation; the user opens the URL to complete the purchase with the provider.

Accepts the quoteBuy inputs plus an optional recipient address, which defaults to the wallet address. Returns protocol and buyUrl.


quoteSell

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

Requires chain, cryptoAsset, fiatCurrency, and cryptoAmount (a string in base units). Returns the same output fields as quoteBuy.


sell

Generate a provider URL for a crypto-to-fiat sale. This tool does not request MCP confirmation; the user opens the URL to complete the sale with the provider.

Requires chain, cryptoAsset, fiatCurrency, and cryptoAmount (a string in base units). The optional refundAddress defaults to the wallet address. Returns protocol and sellUrl.


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