Skip to main content
Glama

jupiter_build_swap_transaction

Builds a Solana blockchain transaction for token swaps using Jupiter's API, converting quotes into executable swap transactions.

Instructions

Build a swap transaction on Jupiter

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
quoteResponseYes
userPublicKeyYes
prioritizationFeeLamportsNo
computeUnitPriceMicroLamportsNo
asLegacyTransactionNo

Implementation Reference

  • The main handler function that executes the tool: validates user public key, parses quote response, builds request to Jupiter /swap-instructions API, and returns the serialized swap transaction.
    export const buildSwapTransactionHandler = async (input: BuildSwapTransactionInput): Promise<ToolResultSchema> => {
      try {
        // Validate user public key
        const userPublicKeyResult = validatePublicKey(input.userPublicKey);
        if (!(userPublicKeyResult instanceof PublicKey)) {
          return userPublicKeyResult;
        }
        
        // Parse the quote response
        let quoteResponse;
        try {
          quoteResponse = JSON.parse(input.quoteResponse);
        } catch (error) {
          return createErrorResponse(`Invalid quote response: ${error instanceof Error ? error.message : String(error)}`);
        }
        
        // Build the request body
        const requestBody: any = {
          quoteResponse,
          userPublicKey: input.userPublicKey
        };
        
        if (input.prioritizationFeeLamports !== undefined) {
          requestBody.prioritizationFeeLamports = input.prioritizationFeeLamports;
        }
        
        if (input.computeUnitPriceMicroLamports !== undefined) {
          requestBody.computeUnitPriceMicroLamports = input.computeUnitPriceMicroLamports;
        }
        
        if (input.asLegacyTransaction !== undefined) {
          requestBody.asLegacyTransaction = input.asLegacyTransaction;
        }
        
        // Make the API request
        const response = await fetch(`${JUPITER_API_BASE_URL}/swap-instructions`, {
          method: "POST",
          headers: {
            "Content-Type": "application/json"
          },
          body: JSON.stringify(requestBody)
        });
        
        if (!response.ok) {
          const errorText = await response.text();
          return createErrorResponse(`Error building swap transaction: ${response.status} ${response.statusText} - ${errorText}`);
        }
        
        const swapData = await response.json();
        return createSuccessResponse(`Swap transaction: ${JSON.stringify(swapData, null, 2)}`);
      } catch (error) {
        return createErrorResponse(`Error building swap transaction: ${error instanceof Error ? error.message : String(error)}`);
      }
    };
  • Input schema and metadata definition for the tool used in MCP tool list.
    {
      name: "jupiter_build_swap_transaction",
      description: "Build a swap transaction on Jupiter",
      inputSchema: {
        type: "object",
        properties: {
          quoteResponse: { type: "string" },
          userPublicKey: { type: "string" },
          prioritizationFeeLamports: { type: "number" },
          computeUnitPriceMicroLamports: { type: "number" },
          asLegacyTransaction: { type: "boolean" }
        },
        required: ["quoteResponse", "userPublicKey"]
      }
    },
  • src/tools.ts:59-63 (registration)
    Maps the tool name to its handler function for dynamic dispatch.
    export const handlers: handlerDictionary = {
      "jupiter_get_quote": getQuoteHandler,
      "jupiter_build_swap_transaction": buildSwapTransactionHandler,
      "jupiter_send_swap_transaction": sendSwapTransactionHandler
    };
  • TypeScript type definition for the tool's input parameters, matching the inputSchema.
    export interface BuildSwapTransactionInput {
      quoteResponse: string;
      userPublicKey: string;
      prioritizationFeeLamports?: number;
      computeUnitPriceMicroLamports?: number;
      asLegacyTransaction?: boolean;
    }
  • Helper function used in the handler to validate the userPublicKey.
    export const validatePublicKey = (publicKeyString: string): PublicKey | ToolResultSchema => {
      const { publicKey, error } = createPublicKey(publicKeyString);
      if (error) {
        return createErrorResponse(error);
      }
      return publicKey!;
    };
Behavior1/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure but fails to do so. It does not explain if this is a read-only or mutative operation, what permissions or authentication are needed, potential side effects, or any rate limits, making it inadequate for a tool with transactional implications.

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

Conciseness5/5

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

The description is a single, straightforward sentence with no wasted words, making it highly concise and front-loaded. It efficiently states the core action without unnecessary elaboration.

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

Completeness1/5

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

Given the complexity of a swap transaction tool with 5 parameters, 0% schema coverage, no annotations, and no output schema, the description is severely incomplete. It lacks essential details on behavior, parameters, usage context, and expected outcomes, failing to provide adequate guidance for an AI agent.

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

Parameters1/5

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

Schema description coverage is 0%, meaning parameters are undocumented in the schema. The description adds no meaning beyond the tool name, failing to explain what parameters like 'quoteResponse' or 'userPublicKey' represent, their formats, or how they influence the transaction build process.

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

Purpose3/5

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

The description states the action ('Build') and resource ('a swap transaction on Jupiter'), which provides a basic purpose. However, it lacks specificity about what 'build' entails (e.g., creating a transaction object vs. executing it) and does not distinguish it from sibling tools like 'jupiter_send_swap_transaction', making it vague in context.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives. It does not mention prerequisites (e.g., needing a quote from 'jupiter_get_quote'), exclusions, or contextual cues for selection among siblings, leaving the agent without usage direction.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/dcSpark/mcp-server-jupiter'

If you have feedback or need assistance with the MCP directory API, please join our Discord server