Skip to main content
Glama
24mlight

A Share MCP

normalize_stock_code

Convert stock codes to Baostock format for consistent data processing in A-share market analysis.

Instructions

Normalize a stock code to Baostock format.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYes

Implementation Reference

  • The MCP tool handler for 'normalize_stock_code', decorated with @app.tool(). It logs the input and delegates to the normalization logic via run_tool_with_handling for error handling.
    @app.tool()
    def normalize_stock_code(code: str) -> str:
        """Normalize a stock code to Baostock format."""
        logger.info("Tool 'normalize_stock_code' called with input=%s", code)
        return run_tool_with_handling(
            lambda: normalize_stock_code_logic(code),
            context="normalize_stock_code",
        )
  • Core implementation logic for normalizing stock codes using regex patterns to match various formats (sh/sz prefix/suffix, numeric only) and convert to Baostock 'ex.num' format.
    def normalize_stock_code_logic(code: str) -> str:
        validate_non_empty_str(code, "code")
        raw = code.strip()
    
        m = re.fullmatch(r"(?i)(sh|sz)[.]?(\d{6})", raw)
        if m:
            ex, num = m.group(1).lower(), m.group(2)
            return f"{ex}.{num}"
    
        m2 = re.fullmatch(r"(\d{6})[.]?(?i:(sh|sz))", raw)
        if m2:
            num, ex = m2.group(1), m2.group(2).lower()
            return f"{ex}.{num}"
    
        m3 = re.fullmatch(r"(\d{6})", raw)
        if m3:
            num = m3.group(1)
            ex = "sh" if num.startswith("6") else "sz"
            return f"{ex}.{num}"
    
        raise ValueError("Unsupported code format. Examples: 'sh.600000', '600000', '000001.SZ'.")
  • mcp_server.py:58-58 (registration)
    Top-level registration call to register_helpers_tools(app), which defines and registers the normalize_stock_code tool among helpers.
    register_helpers_tools(app)
  • mcp_server.py:20-20 (registration)
    Import of the register_helpers_tools function used to register helper tools including normalize_stock_code.
    from src.tools.helpers import register_helpers_tools
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions normalization but doesn't disclose what transformations occur (e.g., padding, prefix changes), whether it's idempotent, error handling for invalid codes, or performance characteristics. This leaves significant behavioral gaps for a tool that modifies data.

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?

Single sentence, zero waste. Every word contributes directly to the tool's purpose without redundancy or fluff. The structure is front-loaded with the core action and target.

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 data transformation tool with no annotations, 0% schema coverage, and no output schema, the description is inadequate. It doesn't explain the normalization algorithm, provide examples, or clarify how this integrates with sibling tools that might consume normalized codes.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It only mentions 'stock code' generically without explaining valid input formats (e.g., '600036', '000001.SZ'), expected output examples, or constraints. This adds minimal value beyond the bare schema.

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 action ('normalize') and target resource ('stock code'), specifying the output format ('Baostock format'). However, it doesn't distinguish itself from sibling 'normalize_index_code' which performs similar normalization for index codes, leaving some ambiguity about when to use each.

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. The description mentions 'Baostock format' but doesn't explain what that means or when normalization is needed versus using raw codes with other tools like 'get_stock_basic_info' or 'get_historical_k_data'.

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/24mlight/a_share_mcp_is_just_I_need'

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