get_vaults
Retrieve detailed information on all vaults including their current states, sorted and filtered by assets, APY, or net APY in ascending or descending order.
Instructions
Retrieves all vaults with their current states.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| first | No | ||
| orderBy | No | ||
| orderDirection | No | ||
| skip | No |
Input Schema (JSON Schema)
{
"properties": {
"first": {
"type": "number"
},
"orderBy": {
"enum": [
"TotalAssetsUsd",
"Apy",
"NetApy"
],
"type": "string"
},
"orderDirection": {
"enum": [
"Asc",
"Desc"
],
"type": "string"
},
"skip": {
"type": "number"
}
},
"type": "object"
}
Implementation Reference
- src/index.ts:800-818 (registration)Registration of the 'get_vaults' tool in the listTools handler, including input schema definition.{ name: GET_VAULTS_TOOL, description: 'Retrieves all vaults with their current states.', inputSchema: { type: 'object', properties: { first: { type: 'number' }, skip: { type: 'number' }, orderBy: { type: 'string', enum: ['TotalAssetsUsd', 'Apy', 'NetApy'] }, orderDirection: { type: 'string', enum: ['Asc', 'Desc'] } } } },
- src/index.ts:1450-1506 (handler)Handler function for 'get_vaults' tool that constructs a GraphQL query to fetch vaults data from Morpho API, validates the response using VaultsResponseSchema, and returns formatted JSON.if (name === GET_VAULTS_TOOL) { try { const queryParams = buildQueryParams(params as VaultQueryParams); const query = ` query { vaults${queryParams} { pageInfo { count countTotal } items { address symbol name creationBlockNumber creationTimestamp creatorAddress whitelisted asset { id address decimals } chain { id network } state { id apy netApy totalAssets totalAssetsUsd fee timelock } warnings { type level } } } }`; const response = await axios.post(MORPHO_API_BASE, { query }); const validatedData = VaultsResponseSchema.parse(response.data); return { content: [{ type: 'text', text: JSON.stringify(validatedData.data.vaults, null, 2) }] }; } catch (error: any) { return { isError: true, content: [{ type: 'text', text: `Error retrieving vaults: ${error.message}` }] }; } }
- src/index.ts:441-448 (schema)Zod schema for validating the response from the Morpho API vaults query.const VaultsResponseSchema = z.object({ data: z.object({ vaults: z.object({ pageInfo: PageInfoSchema, items: z.array(VaultSchema) }) }) });
- src/index.ts:379-411 (schema)Detailed Zod schema defining the structure of a single vault object used in response validation.const VaultSchema = z.object({ address: z.string(), symbol: z.string(), name: z.string(), creationBlockNumber: z.number(), creationTimestamp: z.number(), creatorAddress: z.string(), whitelisted: z.boolean(), asset: z.object({ id: z.string(), address: z.string(), decimals: z.number() }), chain: z.object({ id: z.number(), network: z.string() }), state: z.object({ id: z.string(), apy: z.number().nullable(), netApy: z.number().nullable(), totalAssets: z.union([z.string(), z.number()]).transform(stringToNumber), totalAssetsUsd: z.union([z.string(), z.number(), z.null()]).transform(val => val === null ? 0 : stringToNumber(val)), fee: z.number(), timelock: z.number() }), warnings: z.array(WarningSchema).optional(), pendingCaps: z.array(PendingCapSchema).optional(), allocators: z.array(z.object({ address: z.string() })).optional(), publicAllocatorConfig: PublicAllocatorConfigSchema.optional() });
- src/index.ts:488-488 (helper)Constant defining the tool name 'get_vaults' for use in registration and handler dispatch.const GET_VAULTS_TOOL = 'get_vaults';