Skip to main content
Glama

get_stock_market_cap

Retrieve market capitalization data for specific KOSPI/KOSDAQ stocks over defined date ranges to analyze company valuation and market performance.

Instructions

Retrieves market capitalization data for a specific stock.

Args:
    fromdate (str): Start date for retrieval (YYYYMMDD)
    todate   (str): End date for retrieval (YYYYMMDD)
    ticker   (str): Stock ticker symbol

Returns:
    DataFrame:
        >> get_stock_market_cap("20150720", "20150724", "005930")
                          Market Cap  Volume      Trading Value  Listed Shares
        Date
        2015-07-24  181030885173000  196584  241383636000  147299337
        2015-07-23  181767381858000  208965  259446564000  147299337
        2015-07-22  184566069261000  268323  333813094000  147299337
        2015-07-21  186039062631000  194055  244129106000  147299337
        2015-07-20  187806654675000  128928  165366199000  147299337

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fromdateYes
todateYes
tickerYes

Implementation Reference

  • The handler function decorated with @mcp.tool() implements the get_stock_market_cap tool. It validates dates and ticker, calls pykrx.get_market_cap, converts the DataFrame to a sorted dictionary and returns it.
    @mcp.tool()
    def get_stock_market_cap(fromdate: Union[str, int], todate: Union[str, int], ticker: Union[str, int]) -> Dict[str, Any]:
        """Retrieves market capitalization data for a specific stock.
    
        Args:
            fromdate (str): Start date for retrieval (YYYYMMDD)
            todate   (str): End date for retrieval (YYYYMMDD)
            ticker   (str): Stock ticker symbol
    
        Returns:
            DataFrame:
                >> get_stock_market_cap("20150720", "20150724", "005930")
                                  Market Cap  Volume      Trading Value  Listed Shares
                Date
                2015-07-24  181030885173000  196584  241383636000  147299337
                2015-07-23  181767381858000  208965  259446564000  147299337
                2015-07-22  184566069261000  268323  333813094000  147299337
                2015-07-21  186039062631000  194055  244129106000  147299337
                2015-07-20  187806654675000  128928  165366199000  147299337
        """
        # Validate and convert date format
        def validate_date(date_str: Union[str, int]) -> str:
            try:
                if isinstance(date_str, int):
                    date_str = str(date_str)
                # Convert if in YYYY-MM-DD format
                if '-' in date_str:
                    parsed_date = datetime.strptime(date_str, '%Y-%m-%d')
                    return parsed_date.strftime('%Y%m%d')
                # Validate if in YYYYMMDD format
                datetime.strptime(date_str, '%Y%m%d')
                return date_str
            except ValueError:
                raise ValueError(f"Date must be in YYYYMMDD format. Input value: {date_str}")
    
        def validate_ticker(ticker_str: Union[str, int]) -> str:
            if isinstance(ticker_str, int):
                return str(ticker_str)
            return ticker_str
    
        try:
            fromdate = validate_date(fromdate)
            todate = validate_date(todate)
            ticker = validate_ticker(ticker)
    
            logging.debug(f"Retrieving stock market capitalization data: {ticker}, {fromdate}-{todate}")
    
            # Call get_market_cap
            df = get_market_cap(fromdate, todate, ticker)
    
            # Convert DataFrame to dictionary
            result = df.to_dict(orient='index')
    
            # Convert datetime index to string and sort in reverse
            sorted_items = sorted(
                ((k.strftime('%Y-%m-%d'), v) for k, v in result.items()),
                reverse=True
            )
            result = dict(sorted_items)
    
            return result
    
        except Exception as e:
            error_message = f"Data retrieval failed: {str(e)}"
            logging.error(error_message)
            return {"error": error_message}
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool retrieves data (implying read-only) and shows an example return format, but doesn't mention rate limits, authentication requirements, data freshness, error conditions, or whether the date range is inclusive/exclusive. The example helps but leaves many behavioral aspects unspecified.

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 well-structured with clear sections (Args, Returns) and uses an example effectively. It's appropriately sized for a 3-parameter tool with no annotations. The only minor inefficiency is repeating the tool name in the example call when it's already clear from context.

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?

For a data retrieval tool with 3 parameters and no annotations, the description provides good coverage: clear purpose, full parameter documentation, and example output format. The main gap is lack of usage guidance relative to sibling tools. Without an output schema, the example return format is particularly valuable.

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

Parameters5/5

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

With 0% schema description coverage, the description fully compensates by providing detailed parameter documentation. It clearly explains all three parameters (fromdate, todate, ticker) with their purposes, formats (YYYYMMDD for dates), and includes a concrete example showing valid values. This adds substantial meaning beyond the bare schema.

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 tool's purpose with a specific verb ('Retrieves') and resource ('market capitalization data for a specific stock'), distinguishing it from siblings like get_stock_fundamental or get_stock_ohlcv which retrieve different types of financial data.

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 doesn't mention sibling tools like get_stock_fundamental or get_stock_ohlcv, nor does it explain what makes market capitalization data unique or when it's preferred over other financial metrics.

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/dragon1086/kospi-kosdaq-stock-server'

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