Get Detailed Company Info
get_detailed_company_infoRetrieve comprehensive company data from the Colombo Stock Exchange, including 52-week high/low, YTD metrics, market cap, and beta values, by providing the ticker symbol obtained from the search tool.
Instructions
Get comprehensive company information including 52-week high/low, YTD metrics, market cap, and beta values. Use search_company first to find the correct symbol.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | Ticker symbol from CSE (e.g., 'JKH.N0000') |
Implementation Reference
- src/index.ts:154-199 (handler)Core handler function that fetches detailed company info from the CSE API (companyInfoSummery endpoint). Looks up the company by symbol from the loaded CSV, makes an HTTP POST request, and returns comprehensive data including 52-week high/low, YTD metrics, market cap, shares issued, and beta value.
async function getDetailedCompanyInfo(symbol: string) { const company = companies.find(c => c.symbol === symbol); if (!company) { throw new Error(`Symbol ${symbol} not found. Please use search_company to find valid symbols.`); } try { const response = await axios.post( 'https://www.cse.lk/api/companyInfoSummery', `symbol=${symbol}`, { headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, timeout: 10000 } ); const data = response.data; const symbolInfo = data.reqSymbolInfo || {}; const betaInfo = data.reqSymbolBetaInfo || {}; return { symbol: symbolInfo.symbol, companyName: symbolInfo.name, lastTradedPrice: symbolInfo.lastTradedPrice, price52WeekHigh: symbolInfo.p12HiPrice, price52WeekLow: symbolInfo.p12LowPrice, ytdShareVolume: symbolInfo.ytdShareVolume, ytdTurnover: symbolInfo.ytdTurnover, marketCap: symbolInfo.marketCap, sharesIssued: symbolInfo.sharesIssued, beta: betaInfo.beta, lastUpdated: new Date().toISOString() }; } 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:424-428 (schema)Input schema validation for get_detailed_company_info, using Zod to validate the 'symbol' parameter with a regex pattern for CSE ticker format (e.g., 'JKH.N0000').
inputSchema: { symbol: z.string() .regex(/^[A-Z]+\.[A-Z0-9]+$/, "Invalid symbol format. Use format like 'JKH.N0000'") .describe("Ticker symbol from CSE (e.g., 'JKH.N0000')") } - src/index.ts:419-462 (registration)Registration of the 'get_detailed_company_info' tool on the MCP server with its title, description, input schema, and the handler callback that invokes getDetailedCompanyInfo and formats the response.
server.registerTool( "get_detailed_company_info", { title: "Get Detailed Company Info", description: "Get comprehensive company information including 52-week high/low, YTD metrics, market cap, and beta values. Use search_company first to find the correct symbol.", inputSchema: { symbol: z.string() .regex(/^[A-Z]+\.[A-Z0-9]+$/, "Invalid symbol format. Use format like 'JKH.N0000'") .describe("Ticker symbol from CSE (e.g., 'JKH.N0000')") } }, async ({ symbol }) => { try { const detailedInfo = await getDetailedCompanyInfo(symbol); return { content: [{ type: "text", text: JSON.stringify({ symbol: detailedInfo.symbol, companyName: detailedInfo.companyName, lastTradedPrice: detailedInfo.lastTradedPrice ? `Rs. ${detailedInfo.lastTradedPrice.toFixed(2)}` : 'N/A', price52WeekHigh: detailedInfo.price52WeekHigh ? `Rs. ${detailedInfo.price52WeekHigh.toFixed(2)}` : 'N/A', price52WeekLow: detailedInfo.price52WeekLow ? `Rs. ${detailedInfo.price52WeekLow.toFixed(2)}` : 'N/A', ytdShareVolume: detailedInfo.ytdShareVolume?.toLocaleString() || 'N/A', ytdTurnover: detailedInfo.ytdTurnover ? `Rs. ${detailedInfo.ytdTurnover.toLocaleString()}` : 'N/A', marketCap: detailedInfo.marketCap ? `Rs. ${detailedInfo.marketCap.toLocaleString()}` : 'N/A', sharesIssued: detailedInfo.sharesIssued?.toLocaleString() || 'N/A', beta: detailedInfo.beta || 'N/A', lastUpdated: detailedInfo.lastUpdated }, null, 2) }] }; } catch (error: any) { return { content: [{ type: "text", text: `Error fetching detailed company info: ${error.message}` }], isError: true }; } } );