get_market_summary
Retrieve a comprehensive overview of all prediction markets, including current probabilities, settlement statuses, and parsed metadata.
Instructions
Get a rich overview of all markets with probabilities, settlement status, and parsed metadata
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- mcp-server.ts:335-386 (handler)The full handler for the 'get_market_summary' tool. It fetches outcome metadata and all mids from the Hyperliquid API, builds a rich JSON summary including each outcome's sides (with probabilities), settlement status, and parsed metadata fields (expiry, underlying, targetPrice, period) extracted from the description.
server.tool( 'get_market_summary', 'Get a rich overview of all markets with probabilities, settlement status, and parsed metadata', {}, async () => { const [meta, mids] = await Promise.all([ hlInfo<OutcomeMeta>({ type: 'outcomeMeta' }), hlInfo<Record<string, string>>({ type: 'allMids' }), ]); const questionMap = new Map<number, QuestionRaw>(); for (const q of meta.questions) questionMap.set(q.question, q); const summary = meta.outcomes.map(o => { const question = [...questionMap.values()].find(q => q.namedOutcomes.includes(o.outcome)); const sides = o.sideSpecs.map((s, i) => { const coin = outcomeToCoin(o.outcome, i); const mid = mids[coin]; return { label: s.name, coin, probability: mid ? `${(parseFloat(mid) * 100).toFixed(1)}%` : null, }; }); // Parse key fields from description const desc = o.description; const expiry = desc.match(/expiry:([^\s|]+)/)?.[1] ?? null; const underlying = desc.match(/underlying:([^\s|]+)/)?.[1] ?? null; const targetPrice = desc.match(/targetPrice:([^\s|]+)/)?.[1] ?? null; const period = desc.match(/period:([^\s|]+)/)?.[1] ?? null; const isSettled = question ? question.settledNamedOutcomes?.includes(o.outcome) ?? false : false; return { id: o.outcome, name: o.name, question: question?.name ?? null, sides, isSettled, expiry, underlying, targetPrice, period, }; }); return { content: [{ type: 'text', text: JSON.stringify(summary, null, 2) }] }; }, ); - mcp-server.ts:335-386 (registration)The tool is registered on the McpServer instance via server.tool() at line 335, with the name 'get_market_summary' and a human-readable description.
server.tool( 'get_market_summary', 'Get a rich overview of all markets with probabilities, settlement status, and parsed metadata', {}, async () => { const [meta, mids] = await Promise.all([ hlInfo<OutcomeMeta>({ type: 'outcomeMeta' }), hlInfo<Record<string, string>>({ type: 'allMids' }), ]); const questionMap = new Map<number, QuestionRaw>(); for (const q of meta.questions) questionMap.set(q.question, q); const summary = meta.outcomes.map(o => { const question = [...questionMap.values()].find(q => q.namedOutcomes.includes(o.outcome)); const sides = o.sideSpecs.map((s, i) => { const coin = outcomeToCoin(o.outcome, i); const mid = mids[coin]; return { label: s.name, coin, probability: mid ? `${(parseFloat(mid) * 100).toFixed(1)}%` : null, }; }); // Parse key fields from description const desc = o.description; const expiry = desc.match(/expiry:([^\s|]+)/)?.[1] ?? null; const underlying = desc.match(/underlying:([^\s|]+)/)?.[1] ?? null; const targetPrice = desc.match(/targetPrice:([^\s|]+)/)?.[1] ?? null; const period = desc.match(/period:([^\s|]+)/)?.[1] ?? null; const isSettled = question ? question.settledNamedOutcomes?.includes(o.outcome) ?? false : false; return { id: o.outcome, name: o.name, question: question?.name ?? null, sides, isSettled, expiry, underlying, targetPrice, period, }; }); return { content: [{ type: 'text', text: JSON.stringify(summary, null, 2) }] }; }, ); - mcp-server.ts:63-65 (helper)Helper function used in the handler to convert an outcome ID and side index into a coin string (e.g., '#123') for looking up mid prices.
function outcomeToCoin(outcomeId: number, side: number): string { return `#${10 * outcomeId + side}`; } - mcp-server.ts:31-45 (schema)Type definitions (OutcomeRaw, QuestionRaw, OutcomeMeta) used by the get_market_summary handler to type the HL API response.
interface OutcomeRaw { outcome: number; name: string; description: string; sideSpecs: { name: string }[]; } interface QuestionRaw { question: number; name: string; description: string; fallbackOutcome: number; namedOutcomes: number[]; settledNamedOutcomes: number[]; } interface OutcomeMeta { outcomes: OutcomeRaw[]; questions: QuestionRaw[] }