Skip to main content
Glama

execute_swap

Swap a user's credits along a swap pair: deducts source_amount of the source type and credits the converted amount (after fee) in the target type. Errors: 400 INSUFFICIENT_CREDITS, 404 USER_NOT_FOUND, 400 outside min/max. On a bidirectional pair, direction "reverse" spends the target type for the source type at 1/rate (else 400 SWAP_NOT_BIDIRECTIONAL). Pass an idempotency_key so a retry replays the original swap (idempotent_replay: true); the same key on a different request is 409 IDEMPOTENCY_KEY_REUSED. Costs 1 CRD (platform credit) per call, charged even when the call is then rejected (a 429 RATE_LIMITED costs nothing). Error results include request_id; quote it to support.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "swap_pair_id": "<swap_pair_id>",
      "source_amount": "<source_amount>"
    },
    "name": "execute_swap"
  }
}

Input Schema

NameRequiredDescriptionDefault
api_keyNoCred API key (optional if set via the x-api-key header)
user_idNoExternal user ID
directionNoDefault forward
project_idNoCred project ID (optional; the API key already identifies the project. Signed in with 1Profile and owning several projects, it picks one)
user_emailNoUser email (alternative)
swap_pair_idYesSwap pair ID
x402_paymentNoBase64 x402 PaymentPayload, only when a previous call failed with an x402 PaymentRequired because the account is out of CRD
source_amountYesCredits to spend (in the target type when direction is reverse)
idempotency_keyNoUnique key for this swap (max 255 chars). Retrying with the same key and same arguments returns the first result instead of repeating it; reusing it for different arguments fails with 409 IDEMPOTENCY_KEY_REUSED. Generate a fresh key (e.g. a UUID) per intended operation and reuse it only to retry that operation.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changed
    • changedInput schema / properties / project_id / description
      Previous value: -"Cred project ID (optional; the API key already identifies the project)"New value: +"Cred project ID (optional; the API key already identifies the project. Signed in with 1Profile and owning several projects, it picks one)"
  2. First observed

TDQS

A4/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations supplied, the description carries the full burden and does so thoroughly: it discloses the 1 CRD per-call cost charged even on rejected calls, that a 429 costs nothing, the exact error codes (INSUFFICIENT_CREDITS, USER_NOT_FOUND, out-of-bounds amount, SWAP_NOT_BIDIRECTIONAL, IDEMPOTENCY_KEY_REUSED), idempotent replay semantics, and that error results carry a request_id to quote to support.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The core operation is front-loaded in the first clause, followed by errors, direction semantics, idempotency, and cost in a logical order with no filler sentences. It is dense to the point of being crowded in one paragraph, but every clause carries operational information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 9-parameter mutation with no output schema, the description covers cost, failure modes, idempotency, and direction semantics well. The remaining gap is the success response shape — what the returned swap contains (amounts, fee, balance) is left unstated, and no output schema exists to compensate.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3, but the description adds genuine meaning beyond the schema for direction (reverse spends the target type at 1/rate) and for idempotency_key (replay on retry, 409 on reuse). It does not explain min/max bounds or the fee rate, which are referenced but not quantified.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource (swap a user's credits along a swap pair) plus the exact mechanics: deduct source_amount of the source type and credit the converted amount after fee in the target type. This clearly separates it from siblings like deduct_credits or issue_credits, which move a single credit type, though it never names an alternative explicitly.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It gives real conditional guidance for the direction parameter (reverse spends the target type at 1/rate, else 400 SWAP_NOT_BIDIRECTIONAL) and instructs passing an idempotency_key for retries. What's missing is routing guidance against siblings — nothing says when to swap versus deduct or issue credits, or when a swap pair is the wrong tool.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.

Resources