Skip to main content
Glama
aahl

AkTools MCP Server

by aahl

获取股票历史价格

stock_prices

Retrieve historical stock prices and technical indicators from Shanghai, Shenzhen, Hong Kong, or US markets. Provide symbol, market, period, and limit.

Instructions

根据股票代码和市场获取股票历史价格及技术指标, 不支持加密货币

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYes股票代码
marketNo股票市场,仅支持: sh(上证), sz(深证), hk(港股), us(美股), 不支持加密货币sh
periodNo周期,如: daily(日线), weekly(周线,不支持美股)daily
limitNo返回数量(int)

Implementation Reference

  • The `stock_prices` function is the main handler for the MCP tool. It retrieves historical stock prices and technical indicators (MACD, KDJ, RSI, BOLL) for stocks across markets (sh, sz, hk, us) and ETFs, using akshare library. It accepts symbol, market, period (daily/weekly), and limit parameters, returns CSV-formatted data.
    @mcp.tool(
        title="获取股票历史价格",
        description="根据股票代码和市场获取股票历史价格及技术指标, 不支持加密货币",
    )
    def stock_prices(
        symbol: str = field_symbol,
        market: str = field_market,
        period: str = Field("daily", description="周期,如: daily(日线), weekly(周线,不支持美股)"),
        limit: int = Field(30, description="返回数量(int)", strict=False),
    ):
        if period == "weekly":
            delta = {"weeks": limit + 62}
        else:
            delta = {"days": limit + 62}
        start_date = (datetime.now() - timedelta(**delta)).strftime("%Y%m%d")
        markets = [
            ["sh", ak.stock_zh_a_hist, {}],
            ["sz", ak.stock_zh_a_hist, {}],
            ["hk", ak.stock_hk_hist, {}],
            ["us", stock_us_daily, {}],
            ["sh", fund_etf_hist_sina, {"market": "sh"}],
            ["sz", fund_etf_hist_sina, {"market": "sz"}],
        ]
        for m in markets:
            if m[0] != market:
                continue
            kws = {"period": period, "start_date": start_date, **m[2]}
            dfs = ak_cache(m[1], symbol=symbol, ttl=3600, **kws)
            if dfs is None or dfs.empty:
                continue
            add_technical_indicators(dfs, dfs["收盘"], dfs["最低"], dfs["最高"])
            columns = [
                "日期", "开盘", "收盘", "最高", "最低", "成交量", "换手率",
                "MACD", "DIF", "DEA", "KDJ.K", "KDJ.D", "KDJ.J", "RSI", "BOLL.U", "BOLL.M", "BOLL.L",
            ]
            all = dfs.to_csv(columns=columns, index=False, float_format="%.2f").strip().split("\n")
            return "\n".join([all[0], *all[-limit:]])
        return f"Not Found for {symbol}.{market}"
  • The decorator @mcp.tool with title '获取股票历史价格' and description defines the tool's metadata/schema for MCP registration. The function signature with Field annotations (symbol, market, period, limit) defines the input schema/validation.
    @mcp.tool(
        title="获取股票历史价格",
        description="根据股票代码和市场获取股票历史价格及技术指标, 不支持加密货币",
  • The @mcp.tool() decorator on the `stock_prices` function registers this function as an MCP tool named 'stock_prices' with FastMCP, with title '获取股票历史价格' and description describing its functionality.
    @mcp.tool(
        title="获取股票历史价格",
        description="根据股票代码和市场获取股票历史价格及技术指标, 不支持加密货币",
  • Helper function `stock_us_daily` is called by `stock_prices` to fetch US stock daily data from akshare, renaming columns to Chinese and filtering by start_date.
    def stock_us_daily(symbol, start_date="2025-01-01", period="daily"):
        dfs = ak.stock_us_daily(symbol=symbol)
        if dfs is None or dfs.empty:
            return None
        dfs.rename(columns={"date": "日期", "open": "开盘", "close": "收盘", "high": "最高", "low": "最低", "volume": "成交量"}, inplace=True)
        dfs["换手率"] = None
        dfs.index = pd.to_datetime(dfs["日期"], errors="coerce")
        return dfs[start_date:"2222-01-01"]
  • Helper function `fund_etf_hist_sina` is called by `stock_prices` to fetch ETF historical data from akshare, renaming columns and filtering by start_date.
    def fund_etf_hist_sina(symbol, market="sh", start_date="2025-01-01", period="daily"):
        dfs = ak.fund_etf_hist_sina(symbol=f"{market}{symbol}")
        if dfs is None or dfs.empty:
            return None
        dfs.rename(columns={"date": "日期", "open": "开盘", "close": "收盘", "high": "最高", "low": "最低", "volume": "成交量"}, inplace=True)
        dfs["换手率"] = None
        dfs.index = pd.to_datetime(dfs["日期"], errors="coerce")
        return dfs[start_date:"2222-01-01"]
Behavior2/5

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

With no annotations, the description only states its purpose and limitations (no crypto). No information on read-only nature, data sources, rate limits, or side effects, which is crucial for an unannotated tool.

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 short sentence, which is concise. However, it could benefit from a slightly more structured format (e.g., listing key features) without becoming verbose.

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?

Given no output schema and no annotations, the description is too brief. It does not explain the return format, pagination, or how to use parameters effectively, leaving significant gaps for an agent.

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?

Schema covers all parameters. The description adds value by mentioning that it also returns technical indicators, which is not in the schema. However, it does not elaborate on parameter usage beyond what is already described.

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 it retrieves historical prices and technical indicators by stock code and market, and explicitly excludes cryptocurrency. This distinguishes it from crypto-related siblings but not from other stock indicator tools.

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 explicit guidance on when to use this tool versus alternatives like stock_indicators_a. The only usage hint is the exclusion of cryptocurrency, which is helpful but insufficient.

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