Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

Payment floor: catch wallet sends by their arguments (D8) (#342)

Oleksandr Ivanchenkoe4490794a97b
diff --git a/docs/payments.md b/docs/payments.md
index 17a56957..3265871b 100644
--- a/docs/payments.md
+++ b/docs/payments.md
@@ -31,8 +31,36 @@ every MCP tool, through claude's permission prompt and the MCP gateway), in
Payoneer, Checkout.com, Authorize.net, Plaid, MoonPay, Kraken, Binance.
- Any other tool whose name has a pay word (`pay`, `payment`, `payout`, `purchase`, `checkout`,
`buy`, `charge`, `donate`, …), a money move (`send`/`transfer`/`withdraw` with `money`,
- `funds`, `crypto`, `btc`, `usd`, …), or an order step (`place`/`submit`/`confirm` with
- `order`, `purchase`, `booking`, `subscription`).
+ `funds`, `crypto`, `btc`, `usd`, `token`, `coin`, `asset`, `stablecoin`, …), or an order step
+ (`place`/`submit`/`confirm` with `order`, `purchase`, `booking`, `subscription`).
+- Any tool that doesn't start with a read verb whose arguments (top level, or one object down;
+ any spelling: `amountIn`, `amount-in`) have both:
+ - an amount: a number (`5`, `"0.001"`, `"1e18"`, `"0x2386…"`, `"5 USDC"`, `"max"`) under
+ `amount`, `amount_in`, `amount_out`, `value`, `quantity`, `sum` or any `*_amount`;
+ - and a destination or asset: under `to`, `recipient`, `destination`, `to_address`, `address`,
+ `token`, `token_in`, `token_out`, `asset`, `currency` or `coin`, a value that looks like an
+ account address (EVM `0x` + 40 or 64 hex, ENS `*.eth`, bech32 `bc1…`/`cosmos1…`, base58
+ such as Solana accounts and mints, or an IBAN with a valid check) or a crypto asset (`USDC`,
+ `ETH`, `BTC`, `SOL`, … or `token`, `coin`, `native`). A swap pair (`token_in` with
+ `token_out`, `from_token`/`to_token`, `sell_token`/`buy_token`, `input_mint`/`output_mint`)
+ counts whatever the tokens are called, since wallets take any token there.
+
+ The key names alone aren't enough, so `convert {from: "km", to: "mi", value: 5}`,
+ `update_cell {address: "A1", value: 5}`, `set_limit {token: "t", value: 100}` or an
+ `http_request` with body `{amount: 5, to: "x"}` don't ask. Pure-compute verbs (`calculate`,
+ `compute`, `format`, `translate`, `scroll`) count as reads. `convert` doesn't: some wallets
+ call their swap that, so `convert {amount: 1, from: "USDC", to: "ETH"}` asks and a unit or
+ fiat conversion (`to: "mi"`, `to: "EUR"`) doesn't. Fiat codes are not crypto assets here.
+ The same goes for each `tool_slug` Composio runs, by that slug's own `arguments`. The reason
+ reads e.g. "send_transfer moves an amount to another account or asset".
+
+ This is what catches a crypto wallet MCP such as Incentiv's
+ ([incentiv-mcp](https://github.com/IncentivNetwork/incentiv-mcp), `src/wallet/tools.ts`):
+ `send_transfer {token, to: "0x…40 hex", amount}` and `send_swap {token_in, token_out,
+ amount_in, minimum_out, …}` name
+ no money app and no money noun, so before 0.7.1 they asked only in `ask` and `smart` (the server
+ marks them destructive) and ran without a card with approvals off or after "always allow".
+ Its reads (`get_swap_quote`, `get_agent_wallet`, `get_agent_operation`) still don't ask.
- A browser-type MCP tool (name with `click`, `tap`, `press`, `submit`) whose arguments name a
pay-type label, or one that types (`type`, `fill`, `input`, …) a card number.
- A remote shell tool (`bash`, `shell`, `exec`, `command`…) whose `command` is a payment below.
@@ -101,14 +129,21 @@ classified here.
- Shell commands that hide the host or method: variables (`$URL`), scripts, config files, other
languages' HTTP libraries without `.post(`, and SDKs (`stripe.Charge.create(...)` in Python).
- Payment services, MCP tools and wallets missing from the lists, and tools whose names don't
- say what they do.
+ say what they do and whose arguments don't carry an amount and a destination or asset in
+ reach (e.g. `{order: {lines: [{amount, to}]}}`, two levels down, or an amount under another
+ key name such as `units`).
+- A send whose destination is a name or handle rather than an address (`to: "bob"`), with a
+ token missing from the list, or a fiat send to an account number that isn't an IBAN, unless
+ its name says it pays (`send_money`, `transfer_funds`) or its app is a money app.
- Codex's own shell, which kwnt never sees. Its sandbox has no network, so it can't reach a
payment service.
- Someone else's browser tools the bot drives through an MCP server, unless the tool's label or
typed text matches the rules above.
-It also asks for some things that aren't payments, e.g. an "Upgrade" link in docs or any click on
-a `/billing` page. That's accepted: an extra card costs a tap, a missed payment costs money.
+It also asks for some things that aren't payments, e.g. an "Upgrade" link in docs, any click on
+a `/billing` page, a wallet's unsigned `build_transfer`/`build_swap` (no key moves), or an
+ordinary write that happens to hold a number and an address-shaped value (e.g. a key-value
+store's `set_limit {token: "<32-character base58 key>", value: 100}`). That's accepted: an extra card costs a tap, a missed payment costs money.
## Tests
diff --git a/src/mcp/payment_floor.rs b/src/mcp/payment_floor.rs
index cb77a1c6..eb1a8da3 100644
--- a/src/mcp/payment_floor.rs
+++ b/src/mcp/payment_floor.rs
@@ -28,6 +28,26 @@ const PAY_WORDS: &[&str] = &[
const MOVE_VERBS: &[&str] = &["send", "transfer", "withdraw", "wire", "move", "deposit"];
const MONEY_NOUNS: &[&str] = &[
"money", "funds", "fund", "cash", "crypto", "bitcoin", "btc", "eth", "ether", "usdc", "usdt", "sol", "usd", "eur", "gbp",
+ "token", "tokens", "coin", "coins", "asset", "assets", "stablecoin",
+];
+
+/// Argument keys that hold an amount (also any `*_amount`), and keys that say where it goes or
+/// what moves. A write tool moves value, whatever its name or server, when one of each also has
+/// the right shape: a number for the amount, and an account address or a crypto asset for the
+/// other (a crypto wallet's `send_transfer {token, to: "0x…", amount: "5"}`). A swap pair
+/// (`token_in` and `token_out`) counts on its own, since wallets take any token there.
+const AMOUNT_KEYS: &[&str] = &["amount", "amount_in", "amount_out", "value", "quantity", "sum"];
+const DESTINATION_KEYS: &[&str] = &[
+ "to", "recipient", "destination", "to_address", "address", "token", "token_in", "token_out", "asset", "currency", "coin",
+];
+const SWAP_PAIRS: &[(&str, &str)] =
+ &[("token_in", "token_out"), ("from_token", "to_token"), ("sell_token", "buy_token"), ("input_mint", "output_mint")];
+/// Token symbols and crypto nouns a destination or asset value can be. Symbols that are also
+/// everyday words or names (ADA, TON, DOT, LINK, ONE, OP) are left out.
+const CRYPTO_ASSETS: &[&str] = &[
+ "btc", "wbtc", "eth", "weth", "steth", "usdc", "usdt", "dai", "usde", "pyusd", "eurc", "sol", "matic", "pol", "bnb",
+ "avax", "arb", "xrp", "doge", "trx", "ltc", "bch", "xlm", "bitcoin", "ether", "ethereum", "solana", "crypto", "token",
+ "coin", "stablecoin", "native",
];
/// Verbs that complete an order.
@@ -38,6 +58,8 @@ const ORDER_NOUNS: &[&str] = &["order", "orders", "purchase", "booking", "subscr
const READ_VERBS: &[&str] = &[
"get", "list", "retrieve", "search", "find", "read", "fetch", "describe", "view", "show", "count", "lookup", "query",
"estimate", "preview", "check", "verify", "validate", "export", "download", "inspect", "status", "info", "balance",
+ // Pure compute: works something out or moves the view, nothing else
+ "calculate", "compute", "format", "translate", "scroll",
];
/// Tools that type or fill text in a page (any browser MCP): a card number typed there pays.
@@ -259,6 +281,15 @@ fn mcp_reason(server: &str, tool: &str, args: &Value) -> Option<String> {
return Some(why);
}
}
+ if let Some(why) = amount_shape_reason(tool, args, false) {
+ return Some(why);
+ }
+ // Composio runs other tools by slug, each with its own arguments
+ let mut calls = Vec::new();
+ collect_slug_calls(args, &mut calls, 0);
+ if let Some(why) = calls.into_iter().find_map(|(slug, args)| amount_shape_reason(slug, args, true)) {
+ return Some(why);
+ }
let words = words(tool);
let has = |list: &[&str]| words.iter().any(|w| list.contains(&w.as_str()));
let mut texts = Vec::new();
@@ -319,6 +350,154 @@ fn name_words_reason(server_words: &[String], words: &[String], name: &str) -> O
None
}
+/// A tool that doesn't only read and whose arguments carry a number under an amount key and an
+/// account address or crypto asset under a destination or asset key, or a swap pair (top level,
+/// or one object down): it moves value, whatever its name says. Key names alone aren't enough:
+/// `convert {to: "mi", value: 5}` or `update_cell {address: "A1", value: 5}` don't pay. A
+/// Composio `slug` starts with its app (`SOMEWALLET_GET_QUOTE`), so its first word isn't an
+/// action word.
+fn amount_shape_reason(tool: &str, args: &Value, slug: bool) -> Option<String> {
+ let action: Vec<String> = words(tool)
+ .into_iter()
+ .skip(usize::from(slug))
+ .skip_while(|w| MONEY_APPS.contains(&w.as_str()) || ["composio", "mcp"].contains(&w.as_str()))
+ .collect();
+ if action.first().is_some_and(|w| READ_VERBS.contains(&w.as_str())) {
+ return None;
+ }
+ let Value::Object(top) = args else { return None };
+ let mut pairs: Vec<(String, &Value)> = Vec::new();
+ for (k, v) in top {
+ pairs.push((arg_key(k), v));
+ if let Value::Object(inner) = v {
+ pairs.extend(inner.iter().map(|(k, v)| (arg_key(k), v)));
+ }
+ }
+ let has_key = |key: &str| pairs.iter().any(|(k, _)| k == key);
+ let amount = pairs
+ .iter()
+ .any(|(k, v)| (AMOUNT_KEYS.contains(&k.as_str()) || k.ends_with("_amount")) && amount_value(v));
+ let destination = pairs.iter().any(|(k, v)| DESTINATION_KEYS.contains(&k.as_str()) && destination_value(v))
+ || SWAP_PAIRS.iter().any(|(a, b)| has_key(a) && has_key(b));
+ (amount && destination).then(|| format!("{tool} moves an amount to another account or asset"))
+}
+
+/// A number, or a string that is one: `5`, `"0.001"`, `"1,000"`, `"1e18"`, `"0x2386f26fc10000"`,
+/// `"5 USDC"`, or `"max"`/`"all"` (send everything).
+fn amount_value(v: &Value) -> bool {
+ match v {
+ Value::Number(_) => true,
+ Value::String(s) => {
+ let first = s.split_whitespace().next().unwrap_or("").to_ascii_lowercase();
+ if matches!(first.as_str(), "max" | "all") {
+ return true;
+ }
+ if let Some(hex) = first.strip_prefix("0x") {
+ return !hex.is_empty() && hex.len() <= 64 && hex.chars().all(|c| c.is_ascii_hexdigit());
+ }
+ let plain: String = first.chars().filter(|c| !matches!(c, ',' | '_')).collect();
+ plain.starts_with(|c: char| c.is_ascii_digit() || c == '.')
+ && plain.parse::<f64>().is_ok_and(f64::is_finite)
+ }
+ _ => false,
+ }
+}
+
+/// An account address (EVM `0x…`, ENS `*.eth`, bech32, base58, IBAN) or a crypto asset (a token
+/// symbol, a crypto noun, or a mint or contract address, which the address shapes cover).
+fn destination_value(v: &Value) -> bool {
+ let Some(s) = v.as_str().map(str::trim) else { return false };
+ let lower = s.to_ascii_lowercase();
+ CRYPTO_ASSETS.contains(&lower.as_str())
+ || evm_address(s)
+ || ens_name(&lower)
+ || bech32_address(s)
+ || base58_address(s)
+ || iban(s)
+}
+
+/// `0x` and 40 hex digits (EVM), or 64 (Sui, Aptos, Starknet).
+fn evm_address(s: &str) -> bool {
+ s.strip_prefix("0x")
+ .or_else(|| s.strip_prefix("0X"))
+ .is_some_and(|h| matches!(h.len(), 40 | 64) && h.chars().all(|c| c.is_ascii_hexdigit()))
+}
+
+fn ens_name(lower: &str) -> bool {
+ lower.strip_suffix(".eth").is_some_and(|name| {
+ !name.is_empty()
+ && !name.starts_with('.')
+ && name.chars().all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '-' || c == '.')
+ })
+}
+
+/// `bc1q…`, `cosmos1…`: a lowercase prefix, `1`, then 20 or more bech32 characters.
+fn bech32_address(s: &str) -> bool {
+ const CHARSET: &str = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
+ let lower = s.to_ascii_lowercase();
+ if s != lower && s != s.to_ascii_uppercase() {
+ return false;
+ }
+ let Some((hrp, data)) = lower.rsplit_once('1') else { return false };
+ (1..=20).contains(&hrp.len())
+ && hrp.chars().all(|c| c.is_ascii_lowercase())
+ && (20..=90).contains(&data.len())
+ && data.chars().all(|c| CHARSET.contains(c))
+}
+
+/// Solana accounts and mints, Bitcoin legacy, Tron: 25–44 base58 characters, digits and letters.
+fn base58_address(s: &str) -> bool {
+ const ALPHABET: &str = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
+ (25..=44).contains(&s.len())
+ && s.chars().all(|c| ALPHABET.contains(c))
+ && s.chars().any(|c| c.is_ascii_digit())
+ && s.chars().any(|c| c.is_ascii_alphabetic())
+}
+
+/// An IBAN with a valid mod-97 check.
+fn iban(s: &str) -> bool {
+ let compact: String = s.chars().filter(|c| *c != ' ').collect::<String>().to_ascii_uppercase();
+ let b = compact.as_bytes();
+ if !(15..=34).contains(&b.len())
+ || !b[..2].iter().all(u8::is_ascii_uppercase)
+ || !b[2..4].iter().all(u8::is_ascii_digit)
+ || !b.iter().all(u8::is_ascii_alphanumeric)
+ {
+ return false;
+ }
+ let mut rem: u32 = 0;
+ for c in compact[4..].chars().chain(compact[..4].chars()) {
+ let n = c.to_digit(36).unwrap_or(0);
+ rem = if n >= 10 { (rem * 100 + n) % 97 } else { (rem * 10 + n) % 97 };
+ }
+ rem == 1
+}
+
+/// An argument key in one spelling: `amountIn`, `amount-in` and `AMOUNT_IN` → `amount_in`.
+fn arg_key(key: &str) -> String {
+ words(key).join("_")
+}
+
+/// The tools Composio runs by slug, each with its own `arguments`.
+fn collect_slug_calls<'a>(v: &'a Value, out: &mut Vec<(&'a str, &'a Value)>, depth: usize) {
+ if depth > 6 || out.len() > 50 {
+ return;
+ }
+ match v {
+ Value::Object(map) => {
+ let slug = ["tool_slug", "slug", "action", "action_name", "tool", "tool_name"]
+ .iter()
+ .find_map(|k| map.get(*k).and_then(Value::as_str));
+ if let (Some(slug), Some(args)) = (slug, map.get("arguments")) {
+ out.push((slug, args));
+ }
+ map.values().for_each(|v| collect_slug_calls(v, out, depth + 1));
+ }
+ Value::Array(list) => list.iter().for_each(|v| collect_slug_calls(v, out, depth + 1)),
+ _ => {}
+ }
+}
+
/// Composio runs other tools by slug (`COMPOSIO_MULTI_EXECUTE_TOOL {tools: [{tool_slug}]}`).
fn collect_slugs(v: &Value, out: &mut Vec<String>, depth: usize) {
if depth > 6 {
@@ -619,6 +798,118 @@ mod tests {
assert!(name_reason("", "mcp__stripe__create_charge").is_some());
}
+ /// A crypto wallet MCP (Incentiv's `src/wallet/tools.ts`): its sends name no money app and no
+ /// money noun, so the amount and destination in the arguments decide.
+ #[test]
+ fn wallet_sends_pay_by_their_arguments() {
+ let to = "0x52908400098527886E0F7030069857D2E4169EE7";
+ let transfer = json!({"request_id": "6f1c1f5e-8a0b-4c1e-9f57-0d4f1c1b2a3d", "token": "USDC", "to": to, "amount": "5", "gas_token": "USDC", "wait_for_confirmation": false});
+ let swap = json!({"request_id": "6f1c1f5e-8a0b-4c1e-9f57-0d4f1c1b2a3d", "token_in": "USDC", "token_out": "ETH", "amount_in": "5", "minimum_out": "0.001", "slippage_bps": 50});
+ for server in ["incentiv", "wallet-7", "x"] {
+ let why = mcp(server, "send_transfer", transfer.clone()).unwrap_or_else(|| panic!("{server} send_transfer"));
+ assert_eq!(why, "send_transfer moves an amount to another account or asset");
+ assert!(mcp(server, "send_swap", swap.clone()).is_some(), "{server} send_swap");
+ assert!(mcp(server, "anything", swap.clone()).is_some(), "{server}: the arguments decide, not the name");
+ }
+ // Other spellings and one object down
+ assert!(mcp("w", "execute", json!({"toAddress": to, "amountIn": 1})).is_some());
+ assert!(mcp("w", "do", json!({"transfer": {"recipient": "vitalik.eth", "fee_amount": 1}})).is_some());
+ assert!(mcp("w", "do", json!({"transfer": {"recipient": "bob", "fee_amount": 1}})).is_none(), "bob isn't an account address");
+ assert!(mcp("w", "create_order", json!({"asset": "BTC", "quantity": 2})).is_some());
+ // Through Composio, by the slug's own arguments
+ let multi = json!({"tools": [{"tool_slug": "SOMEWALLET_SEND", "arguments": {"to": to, "value": "1"}}]});
+ assert!(mcp("composio", "COMPOSIO_MULTI_EXECUTE_TOOL", multi).is_some());
+ let quote = json!({"tools": [{"tool_slug": "SOMEWALLET_GET_QUOTE", "arguments": {"to": to, "value": "1"}}]});
+ assert!(mcp("composio", "COMPOSIO_MULTI_EXECUTE_TOOL", quote).is_none(), "a read slug");
+
+ // Reads, and amounts with nowhere to go, don't pay
+ assert!(mcp("incentiv", "get_swap_quote", json!({"token_in": "USDC", "token_out": "ETH", "amount_in": "5"})).is_none());
+ assert!(mcp("incentiv", "get_agent_wallet", json!({})).is_none());
+ assert!(mcp("incentiv", "get_agent_operation", json!({"id": "6f1c1f5e-8a0b-4c1e-9f57-0d4f1c1b2a3d"})).is_none());
+ assert!(mcp("incentiv", "create_agent_wallet", json!({})).is_none());
+ assert!(mcp("github", "create_issue", json!({"title": "t", "body": "b"})).is_none());
+ assert!(mcp("speaker", "set_volume", json!({"amount": 5})).is_none(), "an amount but no destination or asset");
+ assert!(mcp("mail", "send_email", json!({"to": "[email protected]", "subject": "s"})).is_none(), "a destination but no amount");
+ assert!(mcp("w", "do", json!({"a": {"b": {"to": to, "amount": 1}}})).is_none(), "two objects down is out of reach");
+ }
+
+ /// Rigel's F7 corpus: ordinary tools with amount-like and destination-like key names.
+ #[test]
+ fn key_names_alone_dont_pay() {
+ for (tool, args) in [
+ ("convert", json!({"from": "km", "to": "mi", "value": 5})),
+ ("convert_units", json!({"to": "mi", "value": 5})),
+ ("convert_currency", json!({"amount": 100, "from": "USD", "to": "EUR"})),
+ ("calculate_tax", json!({"amount": 100, "currency": "USD"})),
+ ("format_price", json!({"currency": "USD", "value": 100})),
+ ("calculate_tip", json!({"amount": 100, "to": "split"})),
+ ("translate", json!({"text": "hi", "to": "fr", "value": "x"})),
+ ("browser_scroll", json!({"amount": 300, "to": "bottom"})),
+ ("set_volume", json!({"address": "x", "value": 50})),
+ ("update_cell", json!({"spreadsheet": "s", "address": "A1", "value": 5})),
+ ("set", json!({"address": "h", "key": "k", "value": "v"})),
+ ("put_secret", json!({"token": "abc", "value": "v"})),
+ ("set_limit", json!({"token": "t", "value": 100})),
+ ("kwnt_create_task", json!({"amount": 1, "title": "t", "to": "Ada"})),
+ ("http_request", json!({"method": "POST", "url": "https://x", "body": {"amount": 5, "to": "x"}})),
+ ] {
+ assert_eq!(mcp("x", tool, args.clone()), None, "{tool} {args}");
+ }
+ // A wallet that names its swap `convert` still asks: its values are assets
+ assert!(mcp("w", "convert", json!({"amount": "1", "from": "USDC", "to": "ETH"})).is_some());
+ assert!(mcp("w", "convert", json!({"amount_in": "1", "token_in": "CENT", "token_out": "XYZ"})).is_some(), "a swap pair");
+ // Compute verbs only read, even with wallet-shaped values
+ assert!(mcp("w", "calculate_fee", json!({"amount": "1", "to": "0x52908400098527886E0F7030069857D2E4169EE7"})).is_none());
+ // The amount must be a number
+ assert!(mcp("w", "send", json!({"amount": "lots", "to": "0x52908400098527886E0F7030069857D2E4169EE7"})).is_none());
+ }
+
+ #[test]
+ fn destination_and_amount_value_shapes() {
+ for yes in [
+ "0x52908400098527886E0F7030069857D2E4169EE7",
+ "0x52908400098527886e0f7030069857d2e4169ee752908400098527886e0f7030",
+ "vitalik.eth",
+ "pay.team-wallet.eth",
+ "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq",
+ "cosmos1qypqxpq9qcrsszg2pvxq6rs0zqg3yyc5lzv7xu",
+ "7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU",
+ "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
+ "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa",
+ "DE89 3704 0044 0532 0130 00",
+ "GB82WEST12345698765432",
+ "USDC",
+ "usdt",
+ "native",
+ ] {
+ assert!(destination_value(&json!(yes)), "{yes}");
+ }
+ for no in [
+ "A1", "mi", "fr", "EUR", "USD", "bob", "Ada", "bottom", "split", "abc", "Lin", "0x5290",
+ "DE89370400440532013001", "hello.eth.com", ".eth", "sk_live_51Habc", "C1", "/a/b.txt",
+ "https://x", "[email protected]", "climate.living_room",
+ ] {
+ assert!(!destination_value(&json!(no)), "{no}");
+ }
+ assert!(!destination_value(&json!(5)));
+ for yes in [json!(5), json!(0.5), json!("5"), json!("0.001"), json!("1,000"), json!("1e18"), json!("0x2386f26fc10000"), json!("5 USDC"), json!("max")] {
+ assert!(amount_value(&yes), "{yes}");
+ }
+ for no in [json!("v"), json!("x"), json!("lots"), json!("NaN"), json!("inf"), json!("-"), json!(""), json!(true), json!(null), json!({"a": 1})] {
+ assert!(!amount_value(&no), "{no}");
+ }
+ }
+
+ #[test]
+ fn crypto_nouns_are_money() {
+ for name in ["send_tokens", "transfer_token", "withdraw_coins", "move_assets", "send_stablecoin", "deposit_coin"] {
+ assert!(mcp("x", name, json!({})).is_some(), "{name}");
+ }
+ assert!(mcp("x", "list_tokens", json!({})).is_none());
+ assert!(mcp("auth", "create_token", json!({})).is_none(), "no move verb");
+ assert!(mcp("x", "get_asset", json!({})).is_none());
+ }
+
#[test]
fn browser_mcp_tools_pay_by_label_or_card_number() {
assert!(mcp("playwright", "browser_click", json!({"element": "Place order button", "ref": "e12"})).is_some());
diff --git a/tests/payment_floor_test.rs b/tests/payment_floor_test.rs
index e051b50f..bceec515 100644
--- a/tests/payment_floor_test.rs
+++ b/tests/payment_floor_test.rs
@@ -293,6 +293,92 @@ async fn a_payment_app_through_composio_asks_with_approvals_off() {
assert_eq!(reasons.len(), 3, "{rows}");
}
+/// A crypto wallet MCP (Incentiv's, as a community guide connects it): its sends name no money
+/// app or money noun, so the amount and destination in the arguments make them payments. They ask
+/// with approvals off, after a smart Allow and after "always allow"; its reads don't.
+#[tokio::test]
+async fn a_wallet_mcp_send_asks_with_approvals_off_and_after_always_allow() {
+ let e = setup().await;
+ let a = approver(&e, Duration::from_millis(200));
+ let transfer = || {
+ let args = json!({"request_id": "6f1c1f5e-8a0b-4c1e-9f57-0d4f1c1b2a3d", "token": "USDC", "to": "0x52908400098527886E0F7030069857D2E4169EE7", "amount": "5"});
+ request(&e, "incentiv", "send_transfer", args)
+ };
+ let swap = || {
+ let args = json!({"request_id": "6f1c1f5e-8a0b-4c1e-9f57-0d4f1c1b2a3d", "token_in": "USDC", "token_out": "ETH", "amount_in": "5", "minimum_out": "0.001"});
+ request(&e, "incentiv", "send_swap", args)
+ };
+ let quote = || request(&e, "incentiv", "get_swap_quote", json!({"token_in": "USDC", "token_out": "ETH", "amount_in": "5"}));
+
+ set_approvals(&e, "off").await;
+ assert_eq!(a.decide(transfer()).await, ApprovalOutcome::Unanswered, "send_transfer with approvals off");
+ assert_eq!(a.decide(swap()).await, ApprovalOutcome::Unanswered, "send_swap with approvals off");
+ assert_eq!(a.decide(quote()).await, ApprovalOutcome::Allowed, "a quote only reads");
+ assert_eq!(a.decide(request(&e, "incentiv", "get_agent_wallet", json!({}))).await, ApprovalOutcome::Allowed);
+
+ // "Ask only when risky" said Allow: still a card
+ set_approvals(&e, "smart").await;
+ let mut req = transfer();
+ req.smart = Some(SmartVerdict::Allow("looked safe".into()));
+ assert_eq!(a.decide(req).await, ApprovalOutcome::Unanswered, "smart Allow");
+
+ // "Always allow" for the tool in this conversation: still a card, in ask and in off
+ e.state.broker.allow_for_session(&e.bot.id, &e.general, "mcp__incentiv__send_transfer").await;
+ e.state.broker.allow_for_session(&e.bot.id, &e.general, "mcp__incentiv__get_swap_quote").await;
+ for mode in ["ask", "off"] {
+ set_approvals(&e, mode).await;
+ assert_eq!(a.decide(transfer()).await, ApprovalOutcome::Unanswered, "always allow, {mode}");
+ assert_eq!(a.decide(quote()).await, ApprovalOutcome::Allowed, "always allow covers a read, {mode}");
+ }
+
+ let (_, rows) = call(&e.app, "GET", "/api/approvals?status=waiting", None, None).await;
+ let reasons: Vec<&str> = rows.as_array().unwrap().iter().filter_map(|r| r["details"]["payment_reason"].as_str()).collect();
+ assert_eq!(reasons.len(), 5, "{rows}");
+ assert!(reasons.contains(&"send_transfer moves an amount to another account or asset"), "{reasons:?}");
+ assert!(reasons.contains(&"send_swap moves an amount to another account or asset"), "{reasons:?}");
+}
+
+/// Rigel's F7 shapes: ordinary tools whose argument names look like an amount and a destination
+/// run without a card with approvals off; the wallet's own sends still ask.
+#[tokio::test]
+async fn ordinary_tools_with_amount_like_keys_run_with_approvals_off() {
+ let e = setup().await;
+ let a = approver(&e, Duration::from_millis(200));
+ set_approvals(&e, "off").await;
+ for (server, tool, args) in [
+ ("units", "convert", json!({"from": "km", "to": "mi", "value": 5})),
+ ("units", "convert_units", json!({"to": "mi", "value": 5})),
+ ("fx", "convert_currency", json!({"amount": 100, "from": "USD", "to": "EUR"})),
+ ("fx", "calculate_tax", json!({"amount": 100, "currency": "USD"})),
+ ("fx", "format_price", json!({"currency": "USD", "value": 100})),
+ ("calc", "calculate_tip", json!({"amount": 100, "to": "split"})),
+ ("trans", "translate", json!({"text": "hi", "to": "fr", "value": "x"})),
+ ("browser", "browser_scroll", json!({"amount": 300, "to": "bottom"})),
+ ("spotify", "set_volume", json!({"address": "x", "value": 50})),
+ ("sheets", "update_cell", json!({"spreadsheet": "s", "address": "A1", "value": 5})),
+ ("redis", "set", json!({"address": "h", "key": "k", "value": "v"})),
+ ("kv", "put_secret", json!({"token": "abc", "value": "v"})),
+ ("ratelimit", "set_limit", json!({"token": "t", "value": 100})),
+ ("http", "http_request", json!({"method": "POST", "url": "https://x", "body": {"amount": 5, "to": "x"}})),
+ ] {
+ let req = request(&e, server, tool, args.clone());
+ assert_eq!(payment_floor::reason(&req, None), None, "{server}/{tool} {args}");
+ assert_eq!(a.decide(req).await, ApprovalOutcome::Allowed, "{server}/{tool} {args}");
+ }
+ let to = "0x52908400098527886E0F7030069857D2E4169EE7";
+ for (tool, args) in [
+ ("send_transfer", json!({"request_id": "r", "token": "USDC", "to": to, "amount": "5"})),
+ ("send_transfer", json!({"request_id": "r", "token": "CENT", "to": to, "amount": "5"})),
+ ("send_swap", json!({"request_id": "r", "token_in": "USDC", "token_out": "ETH", "amount_in": "5"})),
+ ("send_swap", json!({"request_id": "r", "token_in": "CENT", "token_out": to, "amount_in": "5", "minimum_out": "0.001", "slippage_bps": 50})),
+ ("build_transfer", json!({"token": "USDC", "to": to, "amount": "5"})),
+ ] {
+ let req = request(&e, "incentiv", tool, args.clone());
+ assert!(payment_floor::reason(&req, None).is_some(), "{tool} {args}");
+ assert_eq!(a.decide(req).await, ApprovalOutcome::Unanswered, "{tool} {args}");
+ }
+}
+
#[tokio::test]
async fn kwnt_browser_pay_clicks_and_card_numbers_ask_with_approvals_off() {
let e = setup().await;