spb/hfmarketdata
Public
Open high-frequency market data platform — FirstRate full-history downloader, DuckDB/Parquet lake, open REST API and React docs platform (www.hfmarketdata.io)
JavaScript 53.7%
Python 38.3%
CSS 4.6%
TypeScript 3.1%
1#!/usr/bin/env node2/**3 * `hfmarketdata-mcp` — stdio entry point.4 *5 * HFMD_API_KEY=hfmd_live_… hfmarketdata-mcp6 * hfmarketdata-mcp --version | --help | --selftest7 *8 * All logs go to stderr (stdout is the MCP channel).9 */10import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';11import { HfmdClient } from './client.js';12import { createServer, SERVER_VERSION } from './server.js';13import { TOOL_NAMES } from './tools.js';1415const argv = process.argv.slice(2);1617if (argv.includes('--version') || argv.includes('-v')) {18 console.log(SERVER_VERSION);19 process.exit(0);20}2122if (argv.includes('--help') || argv.includes('-h')) {23 console.log(`hfmarketdata-mcp ${SERVER_VERSION} — MCP server for https://www.hfmarketdata.io2425Usage: hfmarketdata-mcp start the stdio MCP server (used by Claude Code, Cursor, Codex…)26 hfmarketdata-mcp --selftest call /v1/status and print the rate-limit headroom27Env: HFMD_API_KEY optional bearer key (free account: 120 req/min; keyless: 30 req/h per IP)28 HFMD_BASE_URL API base URL (default https://www.hfmarketdata.io)29Tools: ${TOOL_NAMES.join(', ')}30Resources: hfmarketdata://status, hfmarketdata://limits31Prompts: term-structure-analysis, compare-contracts, fundamentals-snapshot`);32 process.exit(0);33}3435if (argv.includes('--selftest')) {36 const client = new HfmdClient();37 client38 .get<Record<string, unknown>>('/v1/status')39 .then((r) => {40 const datasets = (r.body?.datasets ?? {}) as Record<string, unknown>;41 console.log(`OK ${client.baseUrl} (${r.ms} ms, ${client.keyless ? 'keyless' : 'api key set'}) — datasets: ${Object.keys(datasets).join(', ') || 'n/a'}`);42 console.log(JSON.stringify(r.rate));43 process.exit(0);44 })45 .catch((e) => {46 console.error(String(e?.describe?.() ?? e));47 process.exit(1);48 });49} else {50 const { server, client } = createServer();51 const transport = new StdioServerTransport();52 server53 .connect(transport)54 .then(() => console.error(`hfmarketdata-mcp ${SERVER_VERSION} ready on stdio — ${client.baseUrl} (${client.keyless ? 'keyless, 30 req/h' : 'API key set'})`))55 .catch((e) => {56 console.error('hfmarketdata-mcp failed to start:', e);57 process.exit(1);58 });59 const shutdown = () => { server.close().finally(() => process.exit(0)); };60 process.on('SIGINT', shutdown);61 process.on('SIGTERM', shutdown);62}63