Skip to main content
Glama
aahl

AkTools MCP Server

by aahl

stock_info

Retrieve stock information by symbol and market for A-shares, Hong Kong, and US stocks, providing basic data for investment analysis.

Instructions

根据股票代码和市场获取股票基本信息, 不支持加密货币

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYes股票代码
marketNo股票市场,仅支持: sh(上证), sz(深证), hk(港股), us(美股), 不支持加密货币sh

Implementation Reference

  • The handler function for the 'stock_info' tool, decorated with @mcp.tool for registration. It retrieves stock basic information from akshare APIs for specified market and symbol, with caching, falling back to search if not found.
    @mcp.tool(
        title="获取股票信息",
        description="根据股票代码和市场获取股票基本信息, 不支持加密货币",
    )
    def stock_info(
        symbol: str = field_symbol,
        market: str = field_market,
    ):
        markets = [
            ["sh", ak.stock_individual_info_em],
            ["sz", ak.stock_individual_info_em],
            ["hk", ak.stock_hk_security_profile_em],
        ]
        for m in markets:
            if m[0] != market:
                continue
            all = ak_cache(m[1], symbol=symbol, ttl=43200)
            if all is None or all.empty:
                continue
            return all.to_string()
    
        info = ak_search(symbol, market)
        if info is not None:
            return info.to_string()
        return f"Not Found for {symbol}.{market}"
  • Pydantic Field definitions used as input schema for the stock_info tool parameters: symbol and market.
    field_symbol = Field(description="股票代码")
    field_market = Field("sh", description="股票市场,仅支持: sh(上证), sz(深证), hk(港股), us(美股), 不支持加密货币")
  • Helper function ak_cache used by stock_info to cache akshare API calls with TTL.
    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
  • Fallback to ak_search helper when direct stock info not found.
    info = ak_search(symbol, market)
    if info is not None:
        return info.to_string()
    return f"Not Found for {symbol}.{market}"

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/aahl/mcp-aktools'

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