Skip to main content
Glama
crazyrabbitLTC

Morpho API MCP Server

get_vault_allocation

Retrieve vault allocation for a specific market by providing the address and chain ID using the Morpho API MCP Server.

Instructions

Get vault allocation for a specific market.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYes
chainIdNo

Implementation Reference

  • The core handler logic for the 'get_vault_allocation' tool. It takes vault address and optional chainId, constructs a GraphQL query to fetch vault state allocation from Morpho API, validates the response using Zod schema, and returns the formatted data.
    if (name === GET_VAULT_ALLOCATION_TOOL) {
        try {
              const { address, chainId = 1 } = params as VaultAllocationParams;
              const query = `
              query {
                vaultByAddress(
                  chainId: ${chainId}
                  address: "${address}"
                ) {
                  address
                  state {
                    allocation {
                      market {
                        uniqueKey
                      }
                      supplyCap
                      supplyAssets
                      supplyAssetsUsd
                    }
                  }
                }
              }`;
    
              const response = await axios.post(MORPHO_API_BASE, { query });
              const validatedData = VaultAllocationResponseSchema.parse(response.data);
    
              return {
                content: [{ type: 'text', text: JSON.stringify(validatedData.data.vaultByAddress, null, 2) }],
              };
        } catch (error: any) {
              return {
                isError: true,
                content: [{ type: 'text', text: `Error retrieving vault allocation: ${error.message}` }],
              };
        }
    }
  • src/index.ts:767-778 (registration)
    Registration of the tool in the listTools handler, providing name, description, and JSON input schema for the MCP protocol.
    {
      name: GET_VAULT_ALLOCATION_TOOL,
      description: 'Get vault allocation for a specific market.',
      inputSchema: {
        type: 'object',
        properties: {
          address: { type: 'string' },
          chainId: { type: 'number' }
        },
        required: ['address']
      },
    },
  • Zod schema used to validate the GraphQL response data for vault allocation in the tool handler.
    const VaultAllocationResponseSchema = z.object({
      data: z.object({
        vaultByAddress: z.object({
          address: z.string(),
          state: z.object({
            allocation: z.array(VaultAllocationSchema)
          })
        })
      })
    });
  • TypeScript type definition for the input parameters expected by the tool handler.
    type VaultAllocationParams = {
      address: string;
      chainId?: number;
    };
  • src/index.ts:472-472 (registration)
    Constant defining the tool name string.
    const GET_VAULT_ALLOCATION_TOOL = 'get_vault_allocation';

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