Skip to main content
Glama

get_stock_list

Retrieve a list of stocks within a specified sector using the MCP server XTQuantAI. Ideal for accessing trading data directly through AI integration.

Instructions

获取指定板块的股票列表

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sectorNo板块名称,例如 沪深A股沪深A股

Implementation Reference

  • The core asynchronous handler function for the 'get_stock_list' MCP tool. It ensures XTQuant data center is initialized, calls xtdata.get_stock_list_in_sector(sector), limits results to 50 stocks, and handles errors gracefully.
    async def get_stock_list(input: GetStockListInput) -> List[str]:
        """
        获取指定板块的股票列表
        
        Args:
            sector: 板块名称,例如 "沪深A股"
            
        Returns:
            股票代码列表
        """
        try:
            # 确保XTQuant数据中心已初始化
            ensure_xtdc_initialized()
            
            if xtdata is None:
                return ["错误: xtdata模块未正确加载"]
                
            print(f"调用xtdata.get_stock_list_in_sector({input.sector})")
            stock_list = xtdata.get_stock_list_in_sector(input.sector)
            
            # 检查返回值
            if stock_list is None or len(stock_list) == 0:
                return [f"未找到板块 {input.sector} 的股票列表"]
                
            # 只返回前50个股票代码
            limited_list = stock_list[:50] if len(stock_list) > 50 else stock_list
            return limited_list
        except Exception as e:
            print(f"获取股票列表出错: {str(e)}")
            traceback.print_exc()
            return [f"错误: {str(e)}"]
  • Pydantic BaseModel defining the input schema for the get_stock_list tool, with a single optional 'sector' parameter defaulting to '沪深A股'.
    class GetStockListInput(BaseModel):
        sector: str = "沪深A股"  # 默认为沪深A股
  • Tool registration in the MCP server's @server.list_tools() handler, specifying name, description, and inputSchema matching the GetStockListInput model.
        name="get_stock_list",
        description="获取指定板块的股票列表",
        inputSchema={
            "type": "object",
            "properties": {
                "sector": {
                    "type": "string",
                    "description": "板块名称,例如 沪深A股",
                    "default": "沪深A股"
                }
            }
        }
    ),
  • Dispatch logic in the MCP server's @server.call_tool() handler that parses arguments for 'get_stock_list', instantiates the input model, calls the handler function, and formats the response.
    elif name == "get_stock_list":
        sector = "沪深A股"
        if arguments and "sector" in arguments:
            sector = arguments["sector"]
        
        input_model = GetStockListInput(sector=sector)
        result = await get_stock_list(input_model)
        return [types.TextContent(type="text", text=json.dumps(result, ensure_ascii=False, indent=2))]
  • Mock implementation of xtdata.get_stock_list_in_sector used when the real xtquant module fails to import, providing fallback stock list data.
    def get_stock_list_in_sector(self, sector="沪深A股"):
        print(f"模拟调用get_stock_list_in_sector({sector})")
        return ["000001.SZ", "600519.SH", "300059.SZ"]
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure but offers minimal information. It doesn't describe whether this is a read-only operation, what permissions might be required, whether there are rate limits, pagination behavior, or what format the returned list takes. The description only states what the tool does, not how it behaves.

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 extremely concise - a single Chinese sentence that directly states the tool's function. There's zero wasted language, no redundancy, and it's front-loaded with the core purpose. Every word earns its place.

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?

For a tool with no annotations and no output schema, the description is insufficiently complete. It doesn't explain what the returned stock list contains (just symbols? full details?), how results are formatted, whether there are limitations on sector values, or error conditions. Given the lack of structured metadata, the description should provide more operational context.

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?

The description adds no parameter semantics beyond what's already in the schema, which has 100% coverage. The schema fully documents the single 'sector' parameter with description, type, and default value. The description doesn't provide additional context about sector options, validation rules, or examples beyond the schema's '例如 沪深A股' example.

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's purpose as '获取指定板块的股票列表' (get stock list for specified sector), which is a specific verb+resource combination. It distinguishes itself from siblings like get_history_market_data or get_latest_market_data by focusing on sector-based listing rather than time-based or detailed market data. However, it doesn't explicitly differentiate from get_full_market_data, which might also return lists.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites, when-not-to-use scenarios, or compare with sibling tools like get_full_market_data (which might return broader market data) or get_instrument_detail (which provides detailed information on individual instruments). The user must infer usage from the tool name alone.

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

Related 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/dfkai/xtquantai'

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