get_etf_holdings
Retrieve comprehensive ETF data, including holdings, by specifying a ticker and optional date range using the Marketstack MCP Server tool.
Instructions
Get complete set of exchange-traded funds data based on the unique identifier code of an ETF.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date_from | No | Filter results based on a specific timeframe by passing a from-date in `YYYY-MM-DD` format. | |
| date_to | No | Filter results based on a specific timeframe by passing an end-date in `YYYY-MM-DD` format. | |
| ticker | Yes | To get results based on a ETF ticker. |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"date_from": {
"description": "Filter results based on a specific timeframe by passing a from-date in `YYYY-MM-DD` format.",
"type": "string"
},
"date_to": {
"description": "Filter results based on a specific timeframe by passing an end-date in `YYYY-MM-DD` format.",
"type": "string"
},
"ticker": {
"description": "To get results based on a ETF ticker.",
"type": "string"
}
},
"required": [
"ticker"
],
"type": "object"
}
Implementation Reference
- The main handler function that implements the get_etf_holdings tool logic. It constructs API parameters for the 'etfholdings' endpoint using the input ticker and optional dates, fetches data via MarketstackClient, and returns the response.const getEtfHoldingsHandler = async (input: Input, client: MarketstackClient): Promise<Output> => { try { const { ticker, date_from, date_to } = input; const apiRequestParams: MarketstackApiParams = { endpoint: 'etfholdings', ticker, ...(date_from && { date_from }), // Include if date_from is provided ...(date_to && { date_to }), // Include if date_to is provided }; const data = await client.fetchApiData(apiRequestParams); return data; } catch (error: unknown) { console.error('getEtfHoldings tool error:', error); const message = error instanceof Error ? error.message : 'An unknown error occurred.'; throw new Error(`getEtfHoldings tool failed: ${message}`); } };
- Zod-based input schema shape defining the parameters for the get_etf_holdings tool: required ticker and optional date_from/date_to.const getEtfHoldingsInputSchemaShape = { ticker: z.string().describe('To get results based on a ETF ticker.'), date_from: z .string() .optional() .describe('Filter results based on a specific timeframe by passing a from-date in `YYYY-MM-DD` format.'), date_to: z .string() .optional() .describe('Filter results based on a specific timeframe by passing an end-date in `YYYY-MM-DD` format.'), };
- src/tools/financialInstruments/index.ts:55-60 (registration)Registration of the get_etf_holdings tool with the MCP server using server.tool(), referencing the tool definition imported from getEtfHoldings.ts.server.tool( getEtfHoldingsTool.name, getEtfHoldingsTool.description, getEtfHoldingsTool.inputSchemaShape, wrapToolHandler((input) => getEtfHoldingsTool.handler(input, client)) );
- src/tools/financialInstruments/getEtfHoldings.ts:51-56 (registration)Tool definition export that bundles name, description, schema, and handler for get_etf_holdings, used in higher-level registration.export const getEtfHoldingsTool: MarketstackToolDefinition = { name: 'get_etf_holdings', description: 'Get complete set of exchange-traded funds data based on the unique identifier code of an ETF.', inputSchemaShape: getEtfHoldingsInputSchemaShape, handler: getEtfHoldingsHandler, };