Skip to main content
Glama

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(', ')})` : ''; }

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