Skip to main content
Glama
aahl

MCP Server for stock and crypto

by aahl

美股关键指标

stock_indicators_us

Retrieve key financial report indicators for US stocks. Input a stock symbol to get essential metrics from financial statements.

Instructions

获取美股市场的股票财务报告关键指标

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYes股票代码

Implementation Reference

  • Tool registration via @mcp.tool decorator with title and description
    @mcp.tool(
        title="美股关键指标",
        description="获取美股市场的股票财务报告关键指标",
    )
  • Handler function: fetches US stock financial analysis indicators from akshare, converts to CSV, returns first 15 lines
    def stock_indicators_us(
        symbol: str = field_symbol,
    ):
        dfs = ak_cache(ak.stock_financial_us_analysis_indicator_em, symbol=symbol, indicator="单季报")
        keys = dfs.to_csv(index=False, float_format="%.3f").strip().split("\n")
        return "\n".join(keys[0:15])
  • Input schema: single required parameter 'symbol' (string, stock code) using shared Field definition
    def stock_indicators_us(
        symbol: str = field_symbol,
    ):
  • Helper caching function used to call akshare APIs with disk/memory cache layer
    def ak_cache(fun, *args, **kwargs) -> pd.DataFrame | None:
        key = kwargs.pop("key", None)
        if not key:
            key = f"{fun.__name__}-{args}-{kwargs}"
        ttl1 = kwargs.pop("ttl", 86400)
        ttl2 = kwargs.pop("ttl2", None)
        cache = CacheKey.init(key, ttl1, ttl2)
        all = cache.get()
        if all is None:
            try:
                _LOGGER.info("Request akshare: %s", [key, args, kwargs])
                all = fun(*args, **kwargs)
                cache.set(all)
            except Exception as exc:
                _LOGGER.exception(str(exc))
        return all
  • Cache helper class providing TTL-based memory cache and persistent disk cache
    class CacheKey:
        ALL: dict = {}
    
        def __init__(self, key, ttl=600, ttl2=None, maxsize=100):
            self.key = key
            self.ttl = ttl
            self.ttl2 = ttl2 or (ttl * 2)
            self.cache1 = TTLCache(maxsize=maxsize, ttl=ttl)
            self.cache2 = diskcache.Cache(self.get_cache_dir())
    
        @staticmethod
        def init(key, ttl=600, ttl2=None, maxsize=100):
            if key in CacheKey.ALL:
                return CacheKey.ALL[key]
            cache = CacheKey(key, ttl, ttl2, maxsize)
            return CacheKey.ALL.setdefault(key, cache)
    
        def get(self):
            try:
                return self.cache1[self.key]
            except KeyError:
                pass
            return self.cache2.get(self.key)
    
        def set(self, val):
            self.cache1[self.key] = val
            self.cache2.set(self.key, val, expire=self.ttl2)
            return val
    
        def delete(self):
            self.cache1.pop(self.key, None)
            self.cache2.delete(self.key)
    
        def get_cache_dir(self):
            home = pathlib.Path.home()
            name = __package__
            if sys.platform == "win32":
                return home / "AppData" / "Local" / "Cache" / name
            return home / ".cache" / name

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A3.7/5.0
Behavior2/5

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

No annotations are provided, so the description must carry the full burden of behavioral disclosure. It implies a read-only 'get' operation but lacks details on permissions, data sources, return format, or limitations. The description does not contradict annotations (none exist), but it is minimal.

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, concise sentence that directly conveys the tool's purpose. It wastes no words and is front-loaded with the essential information.

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 tool is simple with one parameter and no output schema, but the description is vague about what 'key indicators' are returned. It does not explain the output format or provide additional context that would help a user understand the tool's capabilities fully. It is minimally viable but lacks depth.

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 100% (the only parameter 'symbol' is described as '股票代码'). The description does not add extra meaning beyond the schema, but the baseline is 3 due to high schema coverage.

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 fetches key indicators from US stock financial reports, using a specific verb (获取) and resource (美股市场的股票财务报告关键指标). It distinguishes itself from sibling tools like stock_indicators_a and stock_indicators_hk by explicitly scoping to US 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?

The description clearly indicates the tool is for US stock market financial indicators, providing clear context for when to use it. However, it does not explicitly mention alternatives or exclusions, such as 'for A-shares use stock_indicators_a'.

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