Skip to main content
Glama

get_vault_positions

Retrieve vault positions by specifying the vault address, sorting order, and pagination parameters to access detailed asset and shares data efficiently.

Instructions

Get positions for a specific vault.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
firstNo
orderByNo
orderDirectionNo
skipNo
vaultAddressYes

Implementation Reference

  • Handler for get_vault_positions tool: constructs GraphQL query for vaultPositions filtered by vaultAddress, fetches from Morpho API, validates with Zod schema, returns JSON response.
    if (name === GET_VAULT_POSITIONS_TOOL) { try { const { vaultAddress, ...rest } = params as VaultPositionsParams; const queryParams = buildQueryParams({ ...rest, where: { vaultAddress_in: [vaultAddress] } }); const query = ` query { vaultPositions${queryParams} { items { shares assets assetsUsd user { address } } } }`; const response = await axios.post(MORPHO_API_BASE, { query }); const validatedData = VaultPositionsResponseSchema.parse(response.data); return { content: [{ type: 'text', text: JSON.stringify(validatedData.data.vaultPositions, null, 2) }] }; } catch (error: any) { return { isError: true, content: [{ type: 'text', text: `Error retrieving vault positions: ${error.message}` }] }; } }
  • src/index.ts:820-839 (registration)
    Tool registration in ListToolsRequestHandler: defines name, description, and inputSchema for get_vault_positions.
    name: GET_VAULT_POSITIONS_TOOL, description: 'Get positions for a specific vault.', inputSchema: { type: 'object', properties: { vaultAddress: { type: 'string' }, first: { type: 'number' }, skip: { type: 'number' }, orderBy: { type: 'string', enum: ['Shares', 'Assets', 'AssetsUsd'] }, orderDirection: { type: 'string', enum: ['Asc', 'Desc'] } }, required: ['vaultAddress'] } },
  • Zod schema for validating the response from the vaultPositions GraphQL query.
    const VaultPositionsResponseSchema = z.object({ data: z.object({ vaultPositions: z.object({ items: z.array(z.object({ shares: z.union([z.string(), z.number()]).transform(stringToNumber), assets: z.union([z.string(), z.number()]).transform(stringToNumber), assetsUsd: z.union([z.string(), z.number()]).transform(stringToNumber), user: z.object({ address: z.string() }) })) }) }) });
  • TypeScript type definition for input parameters to the get_vault_positions tool.
    type VaultPositionsParams = PaginationParams & { vaultAddress: string; orderBy?: 'Shares' | 'Assets' | 'AssetsUsd'; orderDirection?: OrderDirection; };
  • Helper function to build GraphQL query parameters from input params, used in the handler.
    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