When building MCP servers for stock market data, the tool definition is the only documentation the LLM sees before it acts. According to a new guide by Dustin Liang, every ambiguity in a name, parameter, or return field transforms into a wrong API call or, worse, a confident but incorrect sentence generated by the model. The core argument is that financial tools must explicitly state which question they answer, which identifiers they accept, and crucially, what kind of source the data comes from.

Naming and Context Efficiency

The guide argues against generic names like query_stock_table in favor of question-based naming such as get_company_profile or get_stock_concepts. Since the model never sees the underlying database schema or vendor docs, descriptions must clarify scope, units, and sibling tool usage. Liang warns that verbose tools crowd out context windows, recommending several focused tools with tight descriptions over one monolithic tool with free-text query parameters.

Strict Input Constraints

Identifier confusion is a frequent failure point, with models attempting to pass various code formats like 300750.SZ or company names. The solution is to enforce regex patterns for codes and use Enums for finite choices like time windows directly in the JSON Schema. By using Python's Annotated types with Pydantic, developers can ensure invalid calls fail early during validation, preventing bad data from ever reaching the data layer.

Provenance is Critical

For financial research, free-text results are dangerous. The guide mandates returning typed objects with a dedicated provenance block containing source_type, as_of, and point_in_time. This distinction prevents the model from merging company filings with vendor-assigned concept tags or public discussion, which could lead to hallucinated claims like 'the company's AI business is growing' based solely on a tag.

Key Takeaways

  • Name tools after the specific question they answer, not the underlying database table.
  • Use JSON Schema constraints (regex, enums, min/max) to reject invalid inputs before execution.
  • Always include a provenance block with source_type, as_of, and point_in_time to separate facts from commentary.
  • Explicitly handle truncation and empty results to prevent models from inferring false negatives.

The Bottom Line

If your MCP tool schema doesn't explicitly define provenance and strict input validation, you aren't building a data tool; you're building a hallucination engine. Strict typing and clear naming are not optional best practices for financial agentsβ€”they are the baseline for reliability.