Skip to main content
Glama

screen_opportunities

Filter Spanish stock market investments using criteria like P/E ratio, market cap, sectors, and governance quality to identify matching opportunities.

Instructions

Screen for investment opportunities based on specific criteria (value, growth, dividend, ESG, etc.)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
screening_criteriaYes
limitNoMaximum number of opportunities to return

Implementation Reference

  • Main handler function for screen_opportunities tool. Screens IBEX 35 companies based on criteria like P/E ratio, market cap, sectors, etc., scores them, and returns top opportunities.
    async screenOpportunities(criteria: any, limit: number = 10): Promise<any> {
      try {
        const companies = await this.db.getAllCompanies();
        const screening = {
          criteria: criteria,
          total_companies_screened: companies.length,
          opportunities: [],
          screening_date: new Date().toISOString(),
          summary: {}
        };
    
        // Apply screening filters
        let filteredCompanies = companies;
    
        if (criteria.pe_ratio_min !== undefined || criteria.pe_ratio_max !== undefined) {
          filteredCompanies = filteredCompanies.filter(company => {
            const pe = company.price_to_earnings || company.pe_ratio;
            if (pe === null || pe === undefined) return false;
            
            if (criteria.pe_ratio_min !== undefined && pe < criteria.pe_ratio_min) return false;
            if (criteria.pe_ratio_max !== undefined && pe > criteria.pe_ratio_max) return false;
            return true;
          });
        }
    
        if (criteria.market_cap_min !== undefined || criteria.market_cap_max !== undefined) {
          filteredCompanies = filteredCompanies.filter(company => {
            if (!company.market_cap) return false;
            
            if (criteria.market_cap_min !== undefined && company.market_cap < criteria.market_cap_min) return false;
            if (criteria.market_cap_max !== undefined && company.market_cap > criteria.market_cap_max) return false;
            return true;
          });
        }
    
        if (criteria.sectors && criteria.sectors.length > 0) {
          filteredCompanies = filteredCompanies.filter(company => 
            criteria.sectors.some(sector => 
              company.sector?.toLowerCase().includes(sector.toLowerCase())
            )
          );
        }
    
        if (criteria.exclude_sectors && criteria.exclude_sectors.length > 0) {
          filteredCompanies = filteredCompanies.filter(company => 
            !criteria.exclude_sectors.some(sector => 
              company.sector?.toLowerCase().includes(sector.toLowerCase())
            )
          );
        }
    
        // Score and rank opportunities
        const scoredOpportunities = await this.scoreOpportunities(filteredCompanies, criteria);
        screening.opportunities = scoredOpportunities.slice(0, limit);
    
        screening.summary = {
          companies_passed_screening: scoredOpportunities.length,
          top_scoring_sector: this.getTopSector(scoredOpportunities),
          average_score: scoredOpportunities.length > 0 ? 
            scoredOpportunities.reduce((sum, opp) => sum + opp.score, 0) / scoredOpportunities.length : 0
        };
    
        return screening;
      } catch (error) {
        throw new Error(`Opportunity screening failed: ${error}`);
      }
    }
  • Input schema definition for the screen_opportunities tool, specifying parameters like screening_criteria (with PE ratios, market caps, sectors) and limit.
      name: 'screen_opportunities',
      description: 'Screen for investment opportunities based on specific criteria (value, growth, dividend, ESG, etc.)',
      inputSchema: {
        type: 'object',
        properties: {
          screening_criteria: {
            type: 'object',
            properties: {
              pe_ratio_max: {
                type: 'number',
                description: 'Maximum P/E ratio',
              },
              pe_ratio_min: {
                type: 'number',
                description: 'Minimum P/E ratio',
              },
              market_cap_min: {
                type: 'number',
                description: 'Minimum market capitalization',
              },
              market_cap_max: {
                type: 'number',
                description: 'Maximum market capitalization',
              },
              sectors: {
                type: 'array',
                items: {
                  type: 'string',
                },
                description: 'Specific sectors to include',
              },
              exclude_sectors: {
                type: 'array',
                items: {
                  type: 'string',
                },
                description: 'Sectors to exclude',
              },
              performance_period: {
                type: 'number',
                description: 'Days to look back for performance metrics',
                default: 30,
              },
              governance_quality: {
                type: 'string',
                enum: ['high', 'medium', 'low', 'any'],
                description: 'Required governance quality level',
                default: 'any',
              },
            },
          },
          limit: {
            type: 'number',
            description: 'Maximum number of opportunities to return',
            default: 10,
          },
        },
        required: ['screening_criteria'],
      },
    },
  • src/index.ts:686-688 (registration)
    Registration and dispatch handler in the MCP server that calls the analytics.screenOpportunities method when screen_opportunities tool is invoked.
    case 'screen_opportunities':
      result = await this.analytics.screenOpportunities((args as any)?.screening_criteria, (args as any)?.limit || 10);
      break;
  • Helper function to score and rank filtered companies based on criteria like PE ratio, market cap, and sector for opportunity screening.
    private async scoreOpportunities(companies: any[], criteria: any): Promise<any[]> {
      const scored = companies.map(company => {
        let score = 5.0; // Base score
        
        // Scoring based on P/E ratio
        const pe = company.price_to_earnings || company.pe_ratio;
        if (pe && pe < 15) score += 1.0;
        if (pe && pe > 25) score -= 0.5;
        
        // Scoring based on market cap
        if (company.market_cap > 10e9) score += 0.5; // Large cap bonus
        if (company.market_cap < 1e9) score -= 0.3; // Small cap penalty
        
        // Scoring based on sector
        if (company.sector && ['banking', 'technology', 'healthcare'].includes(company.sector.toLowerCase())) {
          score += 0.3;
        }
        
        return {
          company: company,
          symbol: company.symbol,
          name: company.name,
          sector: company.sector,
          score: Math.max(0, Math.min(10, score)), // Clamp between 0-10
          key_metrics: {
            market_cap: company.market_cap,
            pe_ratio: pe
          }
        };
      });
      
      return scored.sort((a, b) => b.score - a.score);
    }
  • Helper function to determine the top scoring sector from screened opportunities.
    private getTopSector(opportunities: any[]): string {
      const sectorCounts = {};
      opportunities.forEach(opp => {
        const sector = opp.sector || 'Other';
        sectorCounts[sector] = (sectorCounts[sector] || 0) + 1;
      });
      
      return Object.entries(sectorCounts).reduce((top, [sector, count]) => 
        count > (sectorCounts[top] || 0) ? sector : top, 'Other'
      );
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden for behavioral disclosure. It states the tool 'screens' but doesn't clarify if this is a read-only operation, whether it requires authentication, rate limits, or what the output format looks like (e.g., list of opportunities with details). For a screening tool with no annotation coverage, this is a significant gap in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose. It includes examples (value, growth, etc.) that add context without unnecessary elaboration. However, it could be slightly more structured by explicitly mentioning the input criteria object.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (2 parameters with nested objects), lack of annotations, and no output schema, the description is incomplete. It doesn't explain what constitutes an 'investment opportunity' in the output, how results are ordered, or behavioral aspects like performance implications. This leaves significant gaps for an agent to use the tool effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 50%, with detailed descriptions for some parameters (e.g., 'pe_ratio_max', 'governance_quality') but others like 'sectors' and 'exclude_sectors' lack item-level descriptions. The description adds minimal value beyond the schema by listing criteria types (value, growth, etc.), which loosely maps to parameters but doesn't provide syntax or format details. Baseline 3 is appropriate given partial schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Screen for investment opportunities based on specific criteria' with examples like value, growth, dividend, ESG. It specifies the verb ('screen') and resource ('investment opportunities'), but doesn't explicitly differentiate from sibling tools like 'get_companies_by_sector' or 'get_companies_with_pe_ratio' that might overlap in functionality.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It mentions criteria types (value, growth, etc.) but doesn't specify contexts, prerequisites, or exclusions compared to sibling tools like 'get_all_companies' or 'execute_custom_query'. This leaves the agent without clear direction for tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/anbrme/ibex35-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server