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.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get-assets"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| assetClass | No | us_equity |
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 ); - index.ts:134-134 (schema)Zod input schema for the get-assets tool defining optional assetClass parameter.
{ assetClass: z.enum(["us_equity", "crypto"]).optional().default("us_equity") }, - index.ts:20-40 (helper)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; }