Skip to main content
BlogAI

MCP Structured Output for an Inventory Lookup

Design MCP structured output for a stock lookup. Define an output schema and test known stock, zero quantities and missing records with stable fixtures.

Matthews Wong

Software Engineer

December 20262 min read
MCP Structured Output for an Inventory Lookup

Key Takeaway

Structured MCP tool output gives an inventory lookup a stable shape that an application can validate before displaying results. Start with a small contract covering product identity, location and quantities, then test missing records and incompatible field changes. A readable summary can accompany the structured result for clients that display text.

Which quantities need names?

Use distinct keys for on-hand and available stock and state the unit. If reserved stock affects availability, define the business rule and show it against a fixture. A generic quantity field leaves downstream code guessing whether ten units are physically present or orderable.

What belongs in the output schema?

Declare types and required fields for the values a client consumes. Use a product identifier, warehouse identifier and explicit quantities as a starting point. Document whether a timestamp tells the reader when the snapshot was taken or when the warehouse last changed it.

How should zero stock appear?

Return zero for a known product with zero units. Handle an unknown product as a separate outcome using the tool contract. Add a test fixture for each since a fallback that defaults a missing record to zero can mislead purchasing.

Why keep the text content?

A client may show a textual result directly. Keep the short text and the structured fields derived from the same underlying record so they agree. Use the specification guidance on content compatibility when deciding what the server returns.

Which changes require a compatibility test?

Test a rename and an added field in a client with the previous schema. A rename can break parsing even when a human sees the same value in the description. Decide how long the previous contract will remain available before removing a field.

What does a complete fixture contain?

Include a normal lookup, a zero-stock product and a missing product. Check the structured fields and displayed sentence for every case. A good fixture can fail if either representation drifts.

FAQ

Frequently Asked Questions

Short answers to what readers ask most about this topic.

Which quantities need names?

Use distinct keys for on-hand and available stock and state the unit. If reserved stock affects availability, define the business rule and show it against a fixture. A generic quantity field leaves downstream code guessing whether ten units are physically present or orderable.

What belongs in the output schema?

Declare types and required fields for the values a client consumes. Use a product identifier, warehouse identifier and explicit quantities as a starting point. Document whether a timestamp tells the reader when the snapshot was taken or when the warehouse last changed it.

How should zero stock appear?

Return zero for a known product with zero units. Handle an unknown product as a separate outcome using the tool contract. Add a test fixture for each since a fallback that defaults a missing record to zero can mislead purchasing.

Why keep the text content?

A client may show a textual result directly. Keep the short text and the structured fields derived from the same underlying record so they agree. Use the specification guidance on content compatibility when deciding what the server returns.

Which changes require a compatibility test?

Test a rename and an added field in a client with the previous schema. A rename can break parsing even when a human sees the same value in the description. Decide how long the previous contract will remain available before removing a field.