get_companies_with_pe_ratio
Filter companies in the Spanish stock exchange by P/E ratio range to identify investment opportunities based on valuation metrics.
Instructions
Get companies filtered by P/E ratio range
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| minPE | No | Minimum P/E ratio | |
| maxPE | No | Maximum P/E ratio |
Implementation Reference
- src/index.ts:87-103 (registration)Registration of the 'get_companies_with_pe_ratio' tool, including name, description, and input schema definition.{ name: 'get_companies_with_pe_ratio', description: 'Get companies filtered by P/E ratio range', inputSchema: { type: 'object', properties: { minPE: { type: 'number', description: 'Minimum P/E ratio', }, maxPE: { type: 'number', description: 'Maximum P/E ratio', }, }, }, },
- src/index.ts:589-591 (handler)Handler dispatch in the main CallToolRequest handler that invokes the database method with parsed arguments.case 'get_companies_with_pe_ratio': result = await this.db.getCompaniesWithPERatio((args as any)?.minPE, (args as any)?.maxPE); break;
- src/database.ts:69-79 (handler)Core implementation of the tool logic: fetches all companies and filters those within the specified P/E ratio range using price_to_earnings or pe_ratio fields.async getCompaniesWithPERatio(minPE?: number, maxPE?: number): Promise<any[]> { const companies = await this.getAllCompanies(); return companies.filter(company => { const pe = company.price_to_earnings || company.pe_ratio; if (pe === null || pe === undefined) return false; if (minPE !== undefined && pe < minPE) return false; if (maxPE !== undefined && pe > maxPE) return false; return true; }); }
- src/index.ts:90-102 (schema)Input schema definition for the tool, specifying optional minPE and maxPE numeric parameters.inputSchema: { type: 'object', properties: { minPE: { type: 'number', description: 'Minimum P/E ratio', }, maxPE: { type: 'number', description: 'Maximum P/E ratio', }, }, },