get_top_shareholders_by_sector
Identify the largest shareholders within a specific sector of the Spanish stock exchange to analyze ownership structures and investment patterns.
Instructions
Get top shareholders in a specific sector
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of results | |
| sector | Yes | Sector name |
Implementation Reference
- src/database.ts:153-166 (handler)The core handler function that executes the tool logic: fetches companies by sector, retrieves all shareholder positions from API, filters those belonging to sector companies, sorts by descending ownership percentage, and returns the top N.async getTopShareholdersBySector(sector: string, limit: number = 10): Promise<any[]> { const companies = await this.getCompaniesBySector(sector); const data = await this.fetchAPI('/api/shareholder-positions'); const shareholders = data.shareholderPositions || data.positions || []; const sectorSymbols = companies.map(c => c.symbol); const sectorShareholders = shareholders.filter(position => sectorSymbols.includes(position.company_symbol || position.ticker) ); return sectorShareholders .sort((a, b) => (b.percentage || 0) - (a.percentage || 0)) .slice(0, limit); }
- src/index.ts:613-615 (registration)The switch case that registers and dispatches calls to the tool handler in the MCP server's CallToolRequest handler.case 'get_top_shareholders_by_sector': result = await this.db.getTopShareholdersBySector((args as any)?.sector, (args as any)?.limit || 10); break;
- src/index.ts:166-184 (schema)The tool schema definition including name, description, and input schema validation registered in ListToolsRequestHandler.{ name: 'get_top_shareholders_by_sector', description: 'Get top shareholders in a specific sector', inputSchema: { type: 'object', properties: { sector: { type: 'string', description: 'Sector name', }, limit: { type: 'number', description: 'Maximum number of results', default: 10, }, }, required: ['sector'], }, },
- src/database.ts:62-67 (helper)Helper function used by the handler to retrieve companies filtered by sector name.async getCompaniesBySector(sector: string): Promise<any[]> { const companies = await this.getAllCompanies(); return companies.filter(company => company.sector && company.sector.toLowerCase().includes(sector.toLowerCase()) ); }