Skip to main content
Glama
aahl

AkTools MCP Server

by aahl

A股板块资金流

stock_sector_fund_flow_rank

Retrieve sector fund flow rankings for Chinese A-shares, including industry, concept, and regional categories. Choose time period: today, 5-day, or 10-day.

Instructions

获取中国A股市场(上证、深证)的行业资金流向数据

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
daysNo天数,仅支持: {'今日','5日','10日'},如果需要获取今日数据,请确保是交易日今日
cateNo仅支持: {'行业资金流','概念资金流','地域资金流'}行业资金流

Implementation Reference

  • Tool registration via @mcp.tool decorator with title 'A股板块资金流' and description about A-share sector fund flow data
    @mcp.tool(
        title="A股板块资金流",
        description="获取中国A股市场(上证、深证)的行业资金流向数据",
    )
  • Handler function that calls ak.stock_sector_fund_flow_rank via ak_cache, sorts by '今日涨跌幅', drops '序号' column, and returns top/bottom 20 rows as CSV
    def stock_sector_fund_flow_rank(
        days: str = Field("今日", description="天数,仅支持: {'今日','5日','10日'},如果需要获取今日数据,请确保是交易日"),
        cate: str = Field("行业资金流", description="仅支持: {'行业资金流','概念资金流','地域资金流'}"),
    ):
        dfs = ak_cache(ak.stock_sector_fund_flow_rank, indicator=days, sector_type=cate, ttl=1200)
        if dfs is None:
            return "获取数据失败"
        try:
            dfs.sort_values("今日涨跌幅", ascending=False, inplace=True)
            dfs.drop(columns=["序号"], inplace=True)
        except Exception:
            pass
        try:
            dfs = pd.concat([dfs.head(20), dfs.tail(20)])
            return dfs.to_csv(index=False, float_format="%.2f").strip()
        except Exception as exc:
            return str(exc)
  • ak_cache helper function that wraps akshare API calls with caching via CacheKey (TTL-based + disk-based cache)
    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
  • CacheKey class implementing dual-layer caching (TTLCache + diskcache) used by ak_cache
    import sys
    import pathlib
    import diskcache
    from cachetools import TTLCache
    
    
    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
Behavior2/5

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

With no annotations, the description must disclose behavioral traits. It implies a read operation but does not mention authentication, rate limits, data freshness, or what happens on non-trading days beyond the schema hint. The description 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.

Conciseness4/5

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

The description is a single sentence that is direct and front-loaded. It is concise and efficient, though it could benefit from a bit more detail without losing brevity.

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

Completeness2/5

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

There is no output schema, yet the description does not explain the return format, fields, or units. Combined with no annotations, the tool definition is incomplete for an agent to understand the result.

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% with clear allowed values for both parameters. The description adds no extra meaning beyond the schema, so baseline 3 is appropriate.

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

Purpose4/5

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

The description clearly states the tool gets fund flow data for China's A-share market (Shanghai, Shenzhen). However, it only mentions '行业' (industry) while the cate parameter includes industry, concept, and regional fund flows, so it is slightly misleading but still clear overall.

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?

No guidance is provided on when to use this tool compared to siblings like stock_indicators or stock_prices. It does not specify prerequisites or context such as market hours or data availability.

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

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