Skip to main content
Glama
Shaveen12

CSE MCP Server

by Shaveen12

Get Top Gainers

get_top_gainers

Retrieve the top 10 gaining stocks on the Colombo Stock Exchange for today's trading session. Provides real-time data on price increases to identify market leaders.

Instructions

Get the top 10 gaining stocks in the CSE for the current trading day.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Core handler that fetches top gainers from the CSE API (https://www.cse.lk/api/topGainers) and maps the response to symbol, price, change, and changePercentage fields.
    async function getTopGainers() {
      try {
        const response = await axios.post(
          'https://www.cse.lk/api/topGainers',
          {},
          {
            headers: {
              'Content-Type': 'application/json'
            },
            timeout: 10000
          }
        );
        
        const data = response.data || [];
        
        return data.map((item: any) => ({
          symbol: item.symbol,
          price: item.price,
          change: item.change,
          changePercentage: item.changePercentage
        }));
      } 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:464-507 (registration)
    Registration of the 'get_top_gainers' tool with the MCP server, including its title, description, empty inputSchema, and the handler that calls getTopGainers() and formats results.
    server.registerTool(
      "get_top_gainers",
      {
        title: "Get Top Gainers",
        description: "Get the top 10 gaining stocks in the CSE for the current trading day.",
        inputSchema: {}
      },
      async () => {
        try {
          const topGainers = await getTopGainers();
          
          const formattedGainers = topGainers.map((stock: any, index: number) => {
            const priceChangeSymbol = stock.change >= 0 ? '+' : '';
            return {
              rank: index + 1,
              symbol: stock.symbol,
              price: `Rs. ${stock.price.toFixed(2)}`,
              change: `${priceChangeSymbol}${stock.change.toFixed(2)}`,
              changePercentage: `${priceChangeSymbol}${stock.changePercentage.toFixed(2)}%`
            };
          });
          
          return {
            content: [{
              type: "text",
              text: JSON.stringify({
                title: "Top 10 Gainers",
                count: formattedGainers.length,
                gainers: formattedGainers,
                lastUpdated: new Date().toISOString()
              }, null, 2)
            }]
          };
        } catch (error: any) {
          return {
            content: [{
              type: "text",
              text: `Error fetching top gainers: ${error.message}`
            }],
            isError: true
          };
        }
      }
    );
  • Schema definition for the get_top_gainers tool: title, description, and an empty inputSchema (no parameters required).
    {
      title: "Get Top Gainers",
      description: "Get the top 10 gaining stocks in the CSE for the current trading day.",
      inputSchema: {}
Behavior4/5

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

No annotations are provided, but the description fully discloses the tool's behavior: it returns the top 10 gaining stocks for the current day. It does not mention data freshness or auth requirements, but given the simplicity, it is transparent.

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 a single sentence with 12 words, no filler, and front-loads the key information. Every word is essential.

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

Completeness3/5

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

The description lacks details about the output format (e.g., fields returned). With no output schema, agents may need to infer the structure. However, the tool is simple and the description is adequate for basic usage.

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

Parameters4/5

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

There are no parameters, so the schema coverage is 100% automatically. The description does not need to add parameter details; baseline 4 applies.

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 action ('Get'), the specific resource ('top 10 gaining stocks'), and the scope ('in the CSE for the current trading day'). It distinguishes from siblings like get_top_losers and get_most_active_stocks.

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?

Usage is straightforward with no parameters. The description implicitly guides when to use this tool (for top gainers) versus siblings, but it does not explicitly exclude other scenarios or mention when not to use it.

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