Skip to main content
Glama
24mlight

A-Share MCP Server

normalize_stock_code

Convert stock codes to Baostock format for consistent data access in China's A-share market.

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 invocation and executes the core logic through run_tool_with_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",
        )
  • mcp_server.py:58-58 (registration)
    Top-level call to register_helpers_tools(app), which registers the 'normalize_stock_code' tool as part of the helper tools.
    register_helpers_tools(app)
  • Core helper function implementing the stock code normalization logic using regex to match various input formats and convert to Baostock standard (sh/sz.XXXXXX).
    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'.")
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool normalizes to 'Baostock format' but doesn't explain what this entails—whether it's a simple transformation, involves validation, or handles errors. For a tool with zero annotation coverage, this leaves significant gaps in understanding its behavior and potential side effects.

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 a single, direct sentence with no wasted words. It front-loads the core action ('normalize') and target ('stock code'), making it easy to parse quickly. This efficiency and clarity in structure earn the highest score.

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 the tool's simplicity (one parameter, no output schema, no annotations), the description is minimal. It lacks details on the normalization process, error handling, or output format, which are crucial for effective use. Without annotations or output schema, the description should provide more context to be complete, but it falls short.

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 input schema has 0% description coverage, with one parameter 'code' undocumented. The description adds some context by implying the parameter is a stock code to be normalized, but doesn't specify acceptable formats (e.g., ticker symbols, exchange codes) or provide examples. This partial compensation for the schema gap results in a baseline score of 3.

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 verb ('normalize') and resource ('stock code'), specifying the target format ('Baostock format'). It distinguishes from sibling tools like 'normalize_index_code' by focusing on stock codes rather than index codes. However, it doesn't explicitly differentiate from other data retrieval tools, keeping it at a 4 rather than 5.

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, such as whether the input code needs to be in a specific format, or when to choose this over other tools like 'get_stock_basic_info' for code validation. This lack of contextual usage information results in a low score.

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