Skip to main content
Glama
Shaveen12

CSE MCP Server

by Shaveen12

Search Company

search_company

Search for Colombo Stock Exchange companies by name or symbol. Fuzzy matching returns the three closest matches for accurate results.

Instructions

Search for Colombo Stock Exchange companies by name or symbol. Uses fuzzy matching to return the 3 closest matches.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesCompany name or symbol to search (e.g., 'JKH' or 'John Keells')

Implementation Reference

  • The handler function for the 'search_company' tool. It takes a 'query' string, calls searchCompanies() for fuzzy matching, and returns the top 3 matching companies (id, symbol, name) as JSON.
    async ({ query }) => {
      const results = searchCompanies(query);
      
      if (results.length === 0) {
        return {
          content: [{
            type: "text",
            text: `No companies found matching "${query}". Try a different search term.`
          }]
        };
      }
      
      const formattedResults = results.map(company => ({
        id: company.id,
        symbol: company.symbol,
        name: company.name
      }));
      
      return {
        content: [{
          type: "text",
          text: JSON.stringify({
            query: query,
            count: results.length,
            companies: formattedResults,
            note: "Top 3 matches using fuzzy search"
          }, null, 2)
        }]
      };
    }
  • Schema and registration definition for the 'search_company' tool. Defines title, description, and input schema expecting a 'query' string (minimum 1 char).
    {
      title: "Search Company",
      description: "Search for Colombo Stock Exchange companies by name or symbol. Uses fuzzy matching to return the 3 closest matches.",
      inputSchema: {
        query: z.string().min(1).describe("Company name or symbol to search (e.g., 'JKH' or 'John Keells')")
      }
  • src/index.ts:336-375 (registration)
    Tool registration via server.registerTool() call with name 'search_company', schema, and handler function.
    server.registerTool(
      "search_company",
      {
        title: "Search Company",
        description: "Search for Colombo Stock Exchange companies by name or symbol. Uses fuzzy matching to return the 3 closest matches.",
        inputSchema: {
          query: z.string().min(1).describe("Company name or symbol to search (e.g., 'JKH' or 'John Keells')")
        }
      },
      async ({ query }) => {
        const results = searchCompanies(query);
        
        if (results.length === 0) {
          return {
            content: [{
              type: "text",
              text: `No companies found matching "${query}". Try a different search term.`
            }]
          };
        }
        
        const formattedResults = results.map(company => ({
          id: company.id,
          symbol: company.symbol,
          name: company.name
        }));
        
        return {
          content: [{
            type: "text",
            text: JSON.stringify({
              query: query,
              count: results.length,
              companies: formattedResults,
              note: "Top 3 matches using fuzzy search"
            }, null, 2)
          }]
        };
      }
    );
  • The searchCompanies() helper function. Accepts a query string, uses Levenshtein distance for fuzzy matching across company symbols, names, and individual name words, and returns the top 3 closest matches.
    function searchCompanies(query: string): Company[] {
      const searchTerm = query.toLowerCase();
      
      // Calculate similarity scores for all companies
      const companiesWithScores = companies.map(company => {
        const symbolLower = company.symbol.toLowerCase();
        const nameLower = company.name.toLowerCase();
        
        // Check for exact matches first (score 0 is best)
        if (symbolLower === searchTerm || nameLower === searchTerm) {
          return { company, score: 0 };
        }
        
        // Check for substring matches (prioritize these)
        if (symbolLower.includes(searchTerm) || nameLower.includes(searchTerm)) {
          return { company, score: 1 };
        }
        
        // Calculate fuzzy matching scores
        const symbolDistance = levenshteinDistance(searchTerm, symbolLower);
        const nameDistance = levenshteinDistance(searchTerm, nameLower);
        
        // Also check against individual words in company name
        const nameWords = nameLower.split(/\s+/);
        const wordDistances = nameWords.map(word => levenshteinDistance(searchTerm, word));
        const minWordDistance = Math.min(...wordDistances);
        
        // Use the minimum distance as the score
        const minDistance = Math.min(symbolDistance, nameDistance, minWordDistance);
        
        return { company, score: minDistance };
      });
      
      // Sort by score (lower is better) and return top 3
      companiesWithScores.sort((a, b) => a.score - b.score);
      
      return companiesWithScores.slice(0, 3).map(item => item.company);
    }
  • The levenshteinDistance() helper function used by searchCompanies() to calculate fuzzy string similarity.
    function levenshteinDistance(a: string, b: string): number {
      const matrix: number[][] = [];
      
      for (let i = 0; i <= b.length; i++) {
        matrix[i] = [i];
      }
      
      for (let j = 0; j <= a.length; j++) {
        matrix[0][j] = j;
      }
      
      for (let i = 1; i <= b.length; i++) {
        for (let j = 1; j <= a.length; j++) {
          if (b.charAt(i - 1) === a.charAt(j - 1)) {
            matrix[i][j] = matrix[i - 1][j - 1];
          } else {
            matrix[i][j] = Math.min(
              matrix[i - 1][j - 1] + 1,
              matrix[i][j - 1] + 1,
              matrix[i - 1][j] + 1
            );
          }
        }
      }
      
      return matrix[b.length][a.length];
    }
Behavior4/5

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

No annotations are provided, so the description carries the full burden. It discloses key behavioral traits: fuzzy matching and limited results (3 matches). It does not mention read-only status or error handling, but for a search tool this is acceptable.

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

Conciseness5/5

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

The description is extremely concise: two short sentences that front-load the purpose and key behavior. Every word is meaningful with no redundancy.

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

Completeness4/5

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

Given the tool's simplicity and full schema coverage, the description provides essential context (fuzzy matching, result limit). It could mention lack of side effects or pagination, but overall it is sufficiently complete.

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 coverage is 100% with a good description for the 'query' parameter. The tool description does not add extra meaning beyond the schema, meeting the baseline of 3.

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

Purpose5/5

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

The description clearly states the specific verb 'Search' and the resource 'Colombo Stock Exchange companies by name or symbol,' distinguishing it from sibling tools like get_detailed_company_info which provide detailed info for a specific company.

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

Usage Guidelines4/5

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

The description explains how it works ('fuzzy matching', 'returns 3 closest matches'), implying it's for initial searches before detailed lookup. However, it does not explicitly state when not to use or name alternative tools.

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/Shaveen12/cse-mcp'

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