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
| Name | Required | Description | Default |
|---|---|---|---|
| first | No | Number of items to return (default: 100) | |
| orderBy | No | Field to order by | |
| orderDirection | No | Order direction | |
| skip | No | Number of items to skip | |
| where | No |
Implementation Reference
- src/index.ts:913-971 (handler)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' } } } } } }, },
- src/index.ts:190-197 (schema)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), }) }) });
- src/index.ts:76-94 (schema)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(), }), });
- src/index.ts:894-907 (helper)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(', ')})` : ''; }