Skip to main content
Glama
allthatjazzleo

MantraChain MCP Server

dex-find-routes

Discover available swap routes between two tokens within MantraChain DEX pools by specifying network name and token denominations.

Instructions

Find available swap routes between two tokens - must first check two tokens are available in the DEX pools by using dex-get-pools

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
networkNameYesName of the network to use
tokenInDenomYesDenomination of the token to swap from
tokenOutDenomYesDenomination of the token to swap to

Implementation Reference

  • MCP tool handler function that initializes the MantraClient for the given network and retrieves swap routes between two tokens.
    async ({ networkName, tokenInDenom, tokenOutDenom }) => {
      await mantraClient.initialize(networkName);
      const routes = await mantraClient.findSwapRoutes(tokenInDenom, tokenOutDenom);
      return {
        content: [{type: "text", text: JSON.stringify(routes)}],
      };
    }
  • Zod schema defining the input parameters for the dex-find-routes tool: networkName, tokenInDenom, tokenOutDenom.
    {
      networkName: z.string().refine(val => Object.keys(networks).includes(val), {
        message: "Must be a valid network name"
      }).describe("Name of the network to use"),
      tokenInDenom: z.string().describe("Denomination of the token to swap from"),
      tokenOutDenom: z.string().describe("Denomination of the token to swap to"),
    },
  • src/tools/dex.ts:27-44 (registration)
    Direct registration of the dex-find-routes tool using McpServer.tool() within the registerDexTools function.
    server.tool(
      "dex-find-routes",
      "Find available swap routes between two tokens - must first check two tokens are available in the DEX pools by using `dex-get-pools`",
      {
        networkName: z.string().refine(val => Object.keys(networks).includes(val), {
          message: "Must be a valid network name"
        }).describe("Name of the network to use"),
        tokenInDenom: z.string().describe("Denomination of the token to swap from"),
        tokenOutDenom: z.string().describe("Denomination of the token to swap to"),
      },
      async ({ networkName, tokenInDenom, tokenOutDenom }) => {
        await mantraClient.initialize(networkName);
        const routes = await mantraClient.findSwapRoutes(tokenInDenom, tokenOutDenom);
        return {
          content: [{type: "text", text: JSON.stringify(routes)}],
        };
      }
    );
  • Invocation of registerDexTools in the main tools registration function, which registers dex-find-routes among other DEX tools.
    registerDexTools(server, mantraClient);
  • Core helper function in DexService that implements the route finding logic: fetches pools, finds direct routes, and constructs 2-hop multi-hop routes between tokens.
    async findRoutes(tokenInDenom: string, tokenOutDenom: string): Promise<SwapOperation[][]> {
      try {
        const pools = await this.getPools();
        
        // Check for direct routes (single pool swaps)
        const directPools = pools.filter(pool => {
          const denoms = pool.pool_info.asset_denoms;
          return denoms.includes(tokenInDenom) && denoms.includes(tokenOutDenom);
        });
    
        const directRoutes = directPools.map(pool => [{
          mantra_swap: {
            pool_identifier: pool.pool_info.pool_identifier,
            token_in_denom: tokenInDenom,
            token_out_denom: tokenOutDenom
          }
        }]);
    
        if (directRoutes.length > 0) {
          return directRoutes;
        }
    
        // Find multi-hop routes (2-hop routes only for simplicity)
        const multiHopRoutes = [];
        
        const poolsWithTokenIn = pools.filter(pool => 
          pool.pool_info.asset_denoms.some(denom => denom === tokenInDenom)
        );
    
        const poolsWithTokenOut = pools.filter(pool => 
          pool.pool_info.asset_denoms.some(denom => denom === tokenOutDenom)
        );
    
        for (const inPool of poolsWithTokenIn) {
          const inPoolDenoms = inPool.pool_info.asset_denoms;
          
          for (const intermediateToken of inPoolDenoms) {
            if (intermediateToken === tokenInDenom) continue;
            
            const connectedOutPools = poolsWithTokenOut.filter(outPool => 
              outPool.pool_info.asset_denoms.some(denom => denom === intermediateToken)
            );
            
            for (const outPool of connectedOutPools) {
              multiHopRoutes.push([
                {
                  mantra_swap: {
                    pool_identifier: inPool.pool_info.pool_identifier,
                    token_in_denom: tokenInDenom,
                    token_out_denom: intermediateToken
                  }
                },
                {
                  mantra_swap: {
                    pool_identifier: outPool.pool_info.pool_identifier,
                    token_in_denom: intermediateToken,
                    token_out_denom: tokenOutDenom
                  }
                }
              ]);
            }
          }
        }
        
        return [...directRoutes, ...multiHopRoutes];
      } catch (error) {
        throw new Error(`Failed to find swap routes: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. While it mentions a prerequisite check, it doesn't describe what the tool actually returns (e.g., route details, costs, limitations), whether it's read-only or has side effects, or any performance/rate limit considerations. For a tool that finds swap routes with no annotation coverage, this leaves significant behavioral gaps.

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 extremely concise and front-loaded: the core purpose is stated first, followed by a crucial prerequisite instruction. Both sentences earn their place by providing essential information without any wasted words, making it easy for an agent to parse quickly.

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

Completeness2/5

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

Given that there's no output schema and no annotations, the description should provide more context about what the tool returns and its behavioral characteristics. While it helpfully mentions a prerequisite, it doesn't explain the output format, potential errors, or how routes are determined, leaving the agent with incomplete information for proper tool invocation and result interpretation.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already fully documents all three parameters (networkName, tokenInDenom, tokenOutDenom). The description doesn't add any additional parameter semantics beyond what's in the schema, such as format examples or constraints. This meets the baseline expectation when schema coverage is complete.

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?

The description clearly states the tool's purpose: 'Find available swap routes between two tokens.' This specifies the verb ('find') and resource ('swap routes'), making it immediately understandable. However, it doesn't explicitly distinguish this tool from its sibling 'dex-simulate-swap' or 'dex-swap', which likely involve similar swap-related functionality.

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

Usage Guidelines5/5

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

The description provides explicit usage guidance: 'must first check two tokens are available in the DEX pools by using `dex-get-pools`.' This clearly indicates a prerequisite action and names the specific alternative tool to use first, helping the agent understand when and how to properly sequence operations.

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

Related 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/allthatjazzleo/mantrachain-mcp'

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