get_market_detail
Retrieve detailed information about a prediction market outcome by ID, including odds and liquidity.
Instructions
Get detailed info about a specific market outcome
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| outcome_id | Yes | Outcome ID |
Implementation Reference
- mcp-server.ts:249-279 (handler)The tool handler for 'get_market_detail'. It fetches outcome metadata and mid prices via hlInfo, looks up the outcome by outcome_id, finds its parent question, and formats a detailed description including sides with current mid prices (converted to percentage).
server.tool( 'get_market_detail', 'Get detailed info about a specific market outcome', { outcome_id: z.number().describe('Outcome ID') }, async ({ outcome_id }) => { const [meta, mids] = await Promise.all([ hlInfo<OutcomeMeta>({ type: 'outcomeMeta' }), hlInfo<Record<string, string>>({ type: 'allMids' }), ]); const outcome = meta.outcomes.find(o => o.outcome === outcome_id); if (!outcome) { return { content: [{ type: 'text', text: `Outcome ${outcome_id} not found.` }] }; } const question = meta.questions.find(q => q.namedOutcomes.includes(outcome_id)); const lines: string[] = []; if (question) lines.push(`Question: ${question.name}`); lines.push(`Outcome: ${outcome.name}`); lines.push(`Description: ${outcome.description}`); lines.push(`Sides:`); for (let i = 0; i < outcome.sideSpecs.length; i++) { const coin = outcomeToCoin(outcome_id, i); const mid = mids[coin] ? (parseFloat(mids[coin]) * 100).toFixed(2) + '%' : 'N/A'; lines.push(` ${outcome.sideSpecs[i].name}: ${mid} (${coin})`); } return { content: [{ type: 'text', text: lines.join('\n') }] }; }, ); - mcp-server.ts:249-279 (registration)The tool is registered using server.tool() with name 'get_market_detail' and the handler function, which is the standard MCP registration pattern in this file.
server.tool( 'get_market_detail', 'Get detailed info about a specific market outcome', { outcome_id: z.number().describe('Outcome ID') }, async ({ outcome_id }) => { const [meta, mids] = await Promise.all([ hlInfo<OutcomeMeta>({ type: 'outcomeMeta' }), hlInfo<Record<string, string>>({ type: 'allMids' }), ]); const outcome = meta.outcomes.find(o => o.outcome === outcome_id); if (!outcome) { return { content: [{ type: 'text', text: `Outcome ${outcome_id} not found.` }] }; } const question = meta.questions.find(q => q.namedOutcomes.includes(outcome_id)); const lines: string[] = []; if (question) lines.push(`Question: ${question.name}`); lines.push(`Outcome: ${outcome.name}`); lines.push(`Description: ${outcome.description}`); lines.push(`Sides:`); for (let i = 0; i < outcome.sideSpecs.length; i++) { const coin = outcomeToCoin(outcome_id, i); const mid = mids[coin] ? (parseFloat(mids[coin]) * 100).toFixed(2) + '%' : 'N/A'; lines.push(` ${outcome.sideSpecs[i].name}: ${mid} (${coin})`); } return { content: [{ type: 'text', text: lines.join('\n') }] }; }, ); - mcp-server.ts:252-252 (schema)The input schema for the tool defines a single required parameter 'outcome_id' of type number.
{ outcome_id: z.number().describe('Outcome ID') }, - mcp-server.ts:63-65 (helper)Helper function outcomeToCoin converts an outcome ID and side index to a coin identifier (e.g., #900), used by the get_market_detail handler to look up mid prices.
function outcomeToCoin(outcomeId: number, side: number): string { return `#${10 * outcomeId + side}`; } - mcp-server.ts:21-29 (helper)The hlInfo helper function is a generic API caller used to fetch both outcome metadata and all mid prices, which are the two data sources used by the handler.
async function hlInfo<T>(body: object): Promise<T> { const res = await fetch(`${API_URL}/info`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body), }); if (!res.ok) throw new Error(`HL API error: ${res.status}`); return res.json() as Promise<T>; }