Skip to main content
Glama
crazyrabbitLTC

Morpho API MCP Server

get_markets

Retrieve Morpho markets with pagination, filtering, and ordering options to manage datasets efficiently. Supports querying by assets, whitelisted status, and other criteria.

Instructions

Retrieves markets from Morpho with pagination, ordering, and filtering support.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
firstNoNumber of items to return (default: 100)
orderByNoField to order by
orderDirectionNoOrder direction
skipNoNumber of items to skip
whereNo

Implementation Reference

  • The handler for the 'get_markets' tool. Constructs a GraphQL query using input parameters for pagination, ordering, and filtering, executes it against the Morpho API, validates the response with Zod, and returns the formatted markets data.
    if (name === GET_MARKETS_TOOL) {
        try {
              const queryParams = buildQueryParams(params as MarketQueryParams);
              const query = `
              query {
                markets${queryParams} {
                  pageInfo {
                    count
                    countTotal
                  }
                  items {
                    uniqueKey
                    lltv
                    oracleAddress
                    irmAddress
                    loanAsset {
                      address
                      symbol
                      decimals
                    }
                    collateralAsset {
                      address
                      symbol
                      decimals
                    }
                    state {
                      borrowApy
                      borrowAssets
                      borrowAssetsUsd
                      supplyApy
                      supplyAssets
                      supplyAssetsUsd
                      fee
                      utilization
                    }
                  }
                }
              }
            `;
    
              const response = await axios.post(MORPHO_API_BASE, { query });
              const validatedData = MarketsResponseSchema.parse(response.data);
    
              return {
                content: [
                  {
                      type: 'text',
                      text: JSON.stringify(validatedData.data.markets, null, 2),
                  },
                ],
              };
        } catch (error: any) {
          console.error('Error calling Morpho API:', error.message);
          return {
            isError: true,
            content: [{ type: 'text', text: `Error retrieving markets: ${error.message}` }],
          };
        }
    }
  • src/index.ts:595-633 (registration)
    Registration of the 'get_markets' tool in the ListToolsRequestHandler, including name, description, and JSON input schema.
    {
      name: GET_MARKETS_TOOL,
      description: 'Retrieves markets from Morpho with pagination, ordering, and filtering support.',
      inputSchema: {
        type: 'object',
        properties: {
          first: {
            type: 'number',
            description: 'Number of items to return (default: 100)'
          },
          skip: {
            type: 'number',
            description: 'Number of items to skip'
          },
          orderBy: {
            type: 'string',
            enum: ['Lltv', 'BorrowApy', 'SupplyApy', 'BorrowAssets', 'SupplyAssets', 'BorrowAssetsUsd', 'SupplyAssetsUsd', 'Fee', 'Utilization'],
            description: 'Field to order by'
          },
          orderDirection: {
            type: 'string',
            enum: ['Asc', 'Desc'],
            description: 'Order direction'
          },
          where: {
            type: 'object',
            properties: {
              whitelisted: { type: 'boolean' },
              collateralAssetAddress: { type: 'string' },
              loanAssetAddress: { type: 'string' },
              uniqueKey_in: { 
                type: 'array',
                items: { type: 'string' }
              }
            }
          }
        }
      },
    },
  • Zod schema for validating the GraphQL response from the markets query used in the get_markets handler.
    const MarketsResponseSchema = z.object({
      data: z.object({
        markets: z.object({
          pageInfo: PageInfoSchema,
          items: z.array(MarketSchema),
        })
      })
    });
  • Zod schema defining the structure of a single market object, used in response validation.
    const MarketSchema = z.object({
      uniqueKey: z.string(),
      lltv: z.union([z.string(), z.number()]).transform(stringToNumber),
      oracleAddress: z.string(),
      irmAddress: z.string(),
      whitelisted: z.boolean().optional(),
      loanAsset: AssetSchema,
      collateralAsset: AssetSchema,
      state: z.object({
        borrowApy: z.number(),
        borrowAssets: z.union([z.string(), z.number()]).transform(stringToNumber),
        borrowAssetsUsd: z.number().nullable().transform(val => val ?? 0),
        supplyApy: z.number(),
        supplyAssets: z.union([z.string(), z.number()]).transform(stringToNumber),
        supplyAssetsUsd: z.number().nullable().transform(val => val ?? 0),
        fee: z.number(),
        utilization: z.number(),
      }),
    });
  • Helper function used by the handler to construct GraphQL query parameters string from input parameters.
    function buildQueryParams(params: PaginationParams & { orderBy?: string, orderDirection?: OrderDirection, where?: Record<string, any> } = {}): string {
      const queryParts: string[] = [];
      
      if (params.first !== undefined) queryParts.push(`first: ${params.first}`);
      if (params.skip !== undefined) queryParts.push(`skip: ${params.skip}`);
      if (params.orderBy) queryParts.push(`orderBy: ${params.orderBy}`);
      if (params.orderDirection) queryParts.push(`orderDirection: ${params.orderDirection}`);
      if (params.where && Object.keys(params.where).length > 0) {
        const whereStr = JSON.stringify(params.where).replace(/"([^"]+)":/g, '$1:');
        queryParts.push(`where: ${whereStr}`);
      }
    
      return queryParts.length > 0 ? `(${queryParts.join(', ')})` : '';
    }
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. It mentions 'pagination, ordering, and filtering support' which adds some behavioral context beyond basic retrieval, but it doesn't disclose critical traits like rate limits, authentication needs, error handling, or what the return format looks like (e.g., list structure, data fields). For a tool with no annotations, this is a significant gap.

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, efficient sentence that front-loads the core purpose and lists key features without waste. Every word earns its place, making it easy to parse quickly.

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

Completeness3/5

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

Given no annotations and no output schema, the description is moderately complete for a read-only tool: it specifies the resource and key features. However, it lacks details on return values, error cases, or integration with siblings, which would be helpful for an agent to use it effectively in context with other tools like 'get_whitelisted_markets'.

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 80%, so the schema already documents most parameters well (e.g., 'first' as 'Number of items to return', enums for 'orderBy' and 'orderDirection'). The description adds value by summarizing the capabilities ('pagination, ordering, and filtering support'), but it doesn't provide additional meaning beyond what the schema offers for individual parameters. Baseline 3 is appropriate given the high schema coverage.

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 action ('Retrieves') and resource ('markets from Morpho'), making the purpose understandable. However, it doesn't differentiate this tool from sibling tools like 'get_whitelisted_markets' or 'get_vaults', which might also retrieve market-related data, so it doesn't reach the highest score.

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?

The description mentions 'pagination, ordering, and filtering support' which implies usage for data retrieval, but it provides no explicit guidance on when to use this tool versus alternatives like 'get_whitelisted_markets' or 'get_vaults'. There are no when-to-use or when-not-to-use instructions, leaving the agent to infer context.

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/crazyrabbitLTC/mcp-morpho-server'

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