Get Market Summary
get_market_summaryRetrieve the overall market summary for the Colombo Stock Exchange, including total trade volume, share volume, and trade date.
Instructions
Get the overall market summary including total trade volume, share volume, and trade date.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:297-326 (handler)The core handler function `getMarketSummary()` that fetches market summary data from the CSE API (https://www.cse.lk/api/marketSummery) and returns trade volume, share volume, and trade date.
async function getMarketSummary() { try { const response = await axios.post( 'https://www.cse.lk/api/marketSummery', {}, { headers: { 'Content-Type': 'application/json' }, timeout: 10000 } ); const data = response.data || {}; return { tradeVolume: data.tradeVolume, shareVolume: data.shareVolume, tradeDate: data.tradeDate ? new Date(data.tradeDate).toISOString() : null }; } catch (error: any) { if (error.code === 'ECONNABORTED') { throw new Error('Request timed out. Please try again.'); } else if (error.response) { throw new Error(`API error: ${error.response.status} - ${error.response.statusText}`); } else { throw new Error(`Network error: ${error.message}`); } } } - src/index.ts:598-602 (schema)The schema/registration for the 'get_market_summary' tool, defining its title, description, and empty inputSchema (no inputs required).
{ title: "Get Market Summary", description: "Get the overall market summary including total trade volume, share volume, and trade date.", inputSchema: {} }, - src/index.ts:596-629 (registration)The registration of the 'get_market_summary' tool on the MCP server via `server.registerTool()`, including the handler that calls getMarketSummary() and formats the response.
server.registerTool( "get_market_summary", { title: "Get Market Summary", description: "Get the overall market summary including total trade volume, share volume, and trade date.", inputSchema: {} }, async () => { try { const marketSummary = await getMarketSummary(); return { content: [{ type: "text", text: JSON.stringify({ title: "Market Summary", tradeVolume: marketSummary.tradeVolume ? `Rs. ${marketSummary.tradeVolume.toLocaleString()}` : 'N/A', shareVolume: marketSummary.shareVolume?.toLocaleString() || 'N/A', tradeDate: marketSummary.tradeDate || 'N/A', lastUpdated: new Date().toISOString() }, null, 2) }] }; } catch (error: any) { return { content: [{ type: "text", text: `Error fetching market summary: ${error.message}` }], isError: true }; } } );