MCP: Model Context ProtocolBeginnerModule 05 — Understanding MCP tools

How are MCP tool input schemas defined?

Question 40 of 43 · Updated

On this page

Direct answer#

An MCP tool defines its expected arguments using JSON Schema in the inputSchema field of its tool descriptor. Clients discover this contract through tools/list and use it to construct the arguments for tools/call.

Think of the schema as a form with rules: which fields exist, which are mandatory, what types they accept and what values are permitted. The server must still validate incoming arguments and enforce business permissions before executing the tool.

The examples use the historical MCP 2025-06-18 baseline.

1. Define a practical tool schema#

Imagine a shipping assistant that needs to find delivered or in-transit shipments. Its search_shipments tool accepts a shipment status, an optional result limit and optional filters.

The server publishes the following object as the tool's inputSchema. Save it as schema.json for the runnable example below.

JSON
{ "type": "object", "properties": { "status": {"type": "string", "enum": ["in_transit", "delivered"]}, "limit": {"type": "integer", "minimum": 1, "maximum": 50, "default": 10}, "filters": { "type": "object", "properties": { "city": {"type": "string", "minLength": 1, "maxLength": 80}, "include_history": {"type": "boolean"} }, "required": ["city"], "additionalProperties": false } }, "required": ["status"], "additionalProperties": false }

The tool descriptor also has a name, search_shipments, and can include a description such as "Search shipments accessible to the current customer." The inputSchema is the argument contract, not the complete tool descriptor or a JSON-RPC request.

Schema keywordWhat it means in this example
typeDefines the expected JSON value type
propertiesDescribes named fields of an object
requiredLists fields that must be present
enumAllows only specified values
minimum, maximumBound numeric values inclusively
minLength, maxLengthBound string length
additionalProperties: falseRejects undeclared fields at that object level
defaultDocuments a suggested default; does not automatically insert it

JSON Schema also supports number, array and null types. For example, an array of tracking IDs could be described with type: array and items: {"type":"string"}, plus minItems and maxItems if appropriate. Use explicit units and constraints rather than expecting a model to guess what a field means.

2. Required, optional and nested fields#

A minimal valid argument object is:

JSON
{"status": "delivered"}

A more specific valid argument object is:

JSON
{ "status": "in_transit", "limit": 5, "filters": { "city": "Bengaluru", "include_history": false } }

Only status is required at the root. The filters object is optional, but when it is present, its own required rule makes city mandatory. The include_history boolean is optional even inside filters.

Optional does not mean nullable. An omitted limit is valid; a limit explicitly set to null is not valid under this schema. To allow null, the schema would need an appropriate type union or equivalent constraint.

The default keyword is an annotation. A validator does not necessarily fill in missing values. In this example the application explicitly supplies 10 when limit is absent. It should define what omission means for other optional arguments as part of its business contract.

Another important distinction: properties alone does not make fields required, and unspecified extra fields are generally allowed unless restricted by the schema. The two additionalProperties rules above deliberately close both the root object and its nested filters object.

3. Try spotting invalid arguments#

ArgumentsValid?Reason
{"status":"delivered"}YesRequired field supplied
{"status":"lost"}NoValue outside enum
{"limit":10}NoMissing status
{"status":"delivered","limit":"5"}NoString instead of integer
{"status":"delivered","limit":51}NoAbove maximum
{"status":"delivered","limit":null}NoNull is not allowed
{"status":"delivered","filters":{}}NoMissing nested city
{"status":"delivered","tenant_id":"other"}NoUnknown root field

JSON Schema integer is a mathematical type: an integral-valued number such as 5.0 may pass integer validation, whereas 5.5 and the string "5" do not. Boolean true is not an integer. Align the advertised schema with your SDK and handler's actual numeric conversion rules.

4. Validate on the server, not just in the model#

Loading diagram…

Even if the model provider validates generated arguments, the MCP server must not trust that alone. Different clients may call the same tool directly. The server should validate the actual incoming arguments, then apply appropriate application defaults and enforce business constraints.

For example, a valid city filter does not entitle a user to see all shipments in that city. The search must be scoped to the authenticated actor independently of the input schema. Never derive trusted tenant identity from a model-generated argument.

5. Minimal runnable validation example#

Use a real JSON Schema validator rather than writing a custom implementation of every schema keyword. Install the tested dependency if needed: python -m pip install jsonschema==4.26.0.

Save the schema above as schema.json and the following code as validate_args.py in the same directory.

PYTHON
import json from pathlib import Path from jsonschema import Draft202012Validator schema = json.loads(Path(__file__).with_name('schema.json').read_text()) Draft202012Validator.check_schema(schema) validator = Draft202012Validator(schema) def prepare_arguments(arguments): validator.validate(arguments) return {**arguments, 'limit': arguments.get('limit', 10)}

In the same directory, run this short demonstration:

BASH
python -c "from validate_args import prepare_arguments; print(prepare_arguments({'status': 'delivered'}))"

Expected output:

{'status': 'delivered', 'limit': 10}

An invalid argument raises jsonschema.ValidationError. A real MCP server should translate that failure through the appropriate SDK and protocol error handling rather than exposing an internal traceback.

The example explicitly chooses JSON Schema Draft 2020-12 for local testing. It uses common schema keywords; this does not imply that every historical MCP SDK or model provider accepts every keyword of that draft. Verify the actual supported dialect and generated descriptor for your chosen implementation.

Nine local unittest tests passed using Python 3.13.5 and jsonschema 4.26.0: required-only input and default behavior, valid nested input, missing fields, invalid enum, invalid numeric limits, integral-valued numbers, extra properties, nested validation and non-object input. The test suite is external to the article to keep the learning example short.

The example only validates and prepares arguments. It does not execute a shipment search, authorize an actor, implement a full MCP server, or normalize integral-valued floats to Python ints. If the handler needs an int, explicitly normalize a validated integral value. Real SDK argument validation and permission enforcement are separate implementation steps.

Common mistakes#

  • Putting a field under properties but forgetting required.
  • Assuming default automatically changes the input.
  • Treating optional fields as automatically nullable.
  • Closing only the top-level object and forgetting nested extra fields.
  • Using a model-provider schema conversion that silently removes constraints.
  • Mistaking schema validation for authentication or business authorization.

Interview-ready answer#

MCP tools advertise an inputSchema object using JSON Schema. It defines the argument properties, required fields, types and constraints, including nested objects and arrays. Clients use the schema to construct tool arguments, while servers validate the actual input before execution. Optional fields may be omitted, but null must be explicitly allowed, and defaults need application handling. Schema validation ensures input shape and values; authorization and business rules remain independent.

Next: Q50 explains how tool descriptions help a model choose the correct operation, complementing the input schema.

References and verification#

Authorized offline research and changelog exceptions applied. The historical MCP 2025-06-18 reference links were not checked live. The schema and Python helper were tested locally (9/9 tests passed); no real MCP SDK or transport was exercised. Mermaid and website rendering remain unverified.

References

  1. 1.
    MCP tools specificationmodelcontextprotocol.io
  2. 2.
    JSON Schema: objectsjson-schema.org
  3. 3.
  4. 4.
  5. 5.
    JSON Schema: arraysjson-schema.org
  6. 6.
    Python jsonschema validationpython-jsonschema.readthedocs.io

Related questions

Explore other topics:Forward Deployed EngineeringAI AgentsLarge Language ModelsRetrieval-Augmented Generation