Skip to main content
Glama

get-assets

Retrieve detailed financial asset data for stocks or cryptocurrencies using the MCP protocol. Specify asset class (e.g., US equities or crypto) to access market information.

Input Schema

NameRequiredDescriptionDefault
assetClassNous_equity

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "assetClass": { "default": "us_equity", "enum": [ "us_equity", "crypto" ], "type": "string" } }, "type": "object" }

Implementation Reference

  • index.ts:50-63 (handler)
    Handler function that fetches active, tradable assets from the Alpaca API based on assetClass, returns JSON or error message.
    export async function getAssets({ assetClass = 'us_equity' }: { assetClass?: 'us_equity' | 'crypto' }) { try { const data = await request<any[]>({ base: process.env.ALPACA_BROKER_ENDPOINT!, path: "/v1/assets", params: { status: "active", asset_class: assetClass }, }); const assets = data.filter((a: any) => a.tradable); return { content: [{ type: "text", text: JSON.stringify(assets) }] as any }; } catch (err: any) { debug("get-assets error", err); return { content: [{ type: "text", text: `Error fetching assets: ${err.message}` }] as any, isError: true }; } }
  • index.ts:132-136 (registration)
    Registration of the 'get-assets' tool with input schema and handler reference.
    server.tool( "get-assets", { assetClass: z.enum(["us_equity", "crypto"]).optional().default("us_equity") }, getAssets );
  • Zod input schema for the get-assets tool defining optional assetClass parameter.
    { assetClass: z.enum(["us_equity", "crypto"]).optional().default("us_equity") },
  • Reusable request helper function for authenticated API calls to Alpaca, used in getAssets handler.
    async function request<T>({ base = process.env.ALPACA_ENDPOINT!, path, method = "GET", params = {} }: RequestOptions): Promise<T> { if (!process.env.ALPACA_API_KEY || !process.env.ALPACA_SECRET_KEY) { throw new Error("Alpaca credentials not configured. Set ALPACA_API_KEY and ALPACA_SECRET_KEY."); } const qs = new URLSearchParams(params as Record<string, string>).toString(); const url = `${base}${path}${qs ? `?${qs}` : ""}`; const res = await fetch(url, { method, headers: { "APCA-API-KEY-ID": process.env.ALPACA_API_KEY!, "APCA-API-SECRET-KEY": process.env.ALPACA_SECRET_KEY!, }, }); if (!res.ok) { const err = await res.json(); throw new Error(`${res.status} ${res.statusText} - ${JSON.stringify(err)}`); } return (await res.json()) as T; }

Other Tools

Related Tools

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/cesarvarela/alpaca-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server