Skip to main content
Glama
al-one

MCP Server for stock and crypto

查找股票代码

search

Find stock symbols by searching with company names or keywords across major markets including US, HK, SH, and SZ exchanges.

Instructions

根据股票名称、公司名称等关键词查找股票代码, 不支持加密货币。该工具比较耗时,当你知道股票代码或用户已指定股票代码时,建议直接通过股票代码使用其他工具

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keywordYes搜索关键词,公司名称、股票名称、股票代码、证券简称
marketNo股票市场,仅支持: sh(上证), sz(深证), hk(港股), us(美股), 不支持加密货币sh

Implementation Reference

  • The handler function for the 'search' tool, decorated with @mcp.tool which also serves as registration and defines the schema via Pydantic Fields. It searches for stock information using the ak_search helper.
    @mcp.tool(
        title="查找股票代码",
        description="根据股票名称、公司名称等关键词查找股票代码, 不支持加密货币。"
                    "该工具比较耗时,当你知道股票代码或用户已指定股票代码时,建议直接通过股票代码使用其他工具",
    )
    def search(
        keyword: str = Field(description="搜索关键词,公司名称、股票名称、股票代码、证券简称"),
        market: str = field_market,
    ):
        info = ak_search(None, keyword, market)
        if info is not None:
            suffix = f"交易市场: {market}"
            return "\n".join([info.to_string(), suffix])
        return f"Not Found for {keyword}"
  • Supporting helper function that implements the core search logic across different stock markets using akshare functions and caching.
    def ak_search(symbol=None, keyword=None, market=None):
        markets = [
            ["sh", ak.stock_info_a_code_name, "code", "name"],
            ["sh", ak.stock_info_sh_name_code, "证券代码", "证券简称"],
            ["sz", ak.stock_info_sz_name_code, "A股代码", "A股简称"],
            ["hk", ak.stock_hk_spot, "代码", "中文名称"],
            ["hk", ak.stock_hk_spot_em, "代码", "名称"],
            ["us", ak.get_us_stock_name, "symbol", "cname"],
            ["us", ak.get_us_stock_name, "symbol", "name"],
            ["sh", ak.fund_etf_spot_ths, "基金代码", "基金名称"],
            ["sz", ak.fund_etf_spot_ths, "基金代码", "基金名称"],
            ["sh", ak.fund_info_index_em, "基金代码", "基金名称"],
            ["sz", ak.fund_info_index_em, "基金代码", "基金名称"],
            ["sh", ak.fund_etf_spot_em, "代码", "名称"],
            ["sz", ak.fund_etf_spot_em, "代码", "名称"],
        ]
        for m in markets:
            if market and market != m[0]:
                continue
            all = ak_cache(m[1], ttl=86400, ttl2=86400*7)
            if all is None or all.empty:
                continue
            for _, v in all.iterrows():
                code, name = str(v[m[2]]).upper(), str(v[m[3]]).upper()
                if symbol and symbol.upper() == code:
                    return v
                if keyword and keyword.upper() in [code, name]:
                    return v
            for _, v in all.iterrows() if keyword else []:
                name = str(v[m[3]])
                if len(keyword) >= 4 and keyword in name:
                    return v
                if name.startswith(keyword):
                    return v
        return None
  • Shared Pydantic Field definitions for input parameters used by the search tool and others.
    field_symbol = Field(description="股票代码")
    field_market = Field("sh", description="股票市场,仅支持: sh(上证), sz(深证), hk(港股), us(美股), 不支持加密货币")
Behavior4/5

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

With no annotations provided, the description carries the full burden. It discloses important behavioral traits: the tool is time-consuming ('该工具比较耗时'), doesn't support cryptocurrencies ('不支持加密货币'), and suggests alternatives when codes are known. However, it doesn't mention rate limits, error handling, or response format details.

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 perfectly concise and front-loaded. The first sentence states the core purpose, the second adds critical behavioral context (time consumption and usage guidance). Every sentence earns its place with no wasted words.

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 search tool with 2 parameters, 100% schema coverage, and no output schema, the description is quite complete. It covers purpose, usage guidelines, exclusions, and behavioral warnings. The main gap is lack of output format information, but given the tool's relative simplicity, this is a minor omission.

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%, so the schema already documents both parameters thoroughly. The description adds marginal value by reinforcing the keyword usage and cryptocurrency exclusion, but doesn't provide additional syntax or format details beyond what the schema provides. Baseline 3 is appropriate when schema does the heavy lifting.

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 specific verbs ('查找股票代码' - search for stock codes) and resources ('根据股票名称、公司名称等关键词' - based on stock names, company names, etc.). It distinguishes itself from siblings by specifying it's for searching when you don't know the stock code, unlike tools like stock_info or stock_prices that likely require known codes.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance on when to use ('根据股票名称、公司名称等关键词查找股票代码' - when you have keywords but not the code) and when not to use ('当你知道股票代码或用户已指定股票代码时,建议直接通过股票代码使用其他工具' - when you already know the code, use other tools). It also mentions exclusions ('不支持加密货币' - doesn't support cryptocurrencies).

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

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