AI Hints
Home›MCP Tutorial›Tool Inputs
MCP · Lesson 13 of 120

Tool Inputs

Type hints become schemas.

⏱ 2 min read▶ Video at 11:10🎓 Free
Watch this lesson in the MCP courseWatch on YouTube ↗Full MCP course

A tool's inputs are just function parameters. The SDK reads their type hints, and turns them into a JSON schema. The model then knows exactly what to send.

Tool Inputs
From the video: Tool Inputs
  • Parameters
  • Type hints
  • JSON schema

A small test helper

To keep our examples short, we'll use a tiny helper file, called tester. Call connects a client to a server, calls one tool, and returns the result. Tools returns the server's list of tools. It's the same client code we've already seen, wrapped up.

tester.pypython
import asyncio
from mcp import Client

def call(server, tool, args=None, **options):
    async def go():
        async with Client(server, **options) as client:
            return await client.call_tool(tool, args or {})
    return asyncio.run(go())

def tools(server):
    async def go():
        async with Client(server) as client:
            return (await client.list_tools()).tools
    return asyncio.run(go())

From hints to schema

Search has a string, an integer, and a category that can only be bikes or parts. We print each input's schema. Run it. String, integer, and an enum with the two allowed values.

schema.pypython
from typing import Literal
from mcp.server.mcpserver import MCPServer
from tester import tools

mcp = MCPServer("shop")

@mcp.tool()
def search(query: str, limit: int, category: Literal["bikes", "parts"]) -> list[str]:
    """Search Northwind's products."""
    return [f"{category}: {query} {i}" for i in range(limit)]

for name, schema in tools(mcp)[0].input_schema["properties"].items():
    print(name, "->", schema)
Output
query -> {'title': 'Query', 'type': 'string'}
limit -> {'title': 'Limit', 'type': 'integer'}
category -> {'enum': ['bikes', 'parts'], 'title': 'Category', 'type': 'string'}
Also uses tester.py
import asyncio
from mcp import Client

def call(server, tool, args=None, **options):
    async def go():
        async with Client(server, **options) as client:
            return await client.call_tool(tool, args or {})
    return asyncio.run(go())

def tools(server):
    async def go():
        async with Client(server) as client:
            return (await client.list_tools()).tools
    return asyncio.run(go())

Python to JSON schema

Common Python types map to JSON schema types. String to string. Int to integer. Float to number. Bool to boolean. Lists become arrays, and Literal becomes an enum.

PythonJSON schema
strstring
int / floatinteger / number
boolboolean
list[str]array of strings
Literal['a','b']enum

Summary

Type hints become the tool's input schema. Precise types, like Literal, stop the model sending bad values. Next, descriptions.

Key takeaways
  • Type hints
  • JSON schema
  • Literal = enum
Next up: Good Descriptions — docstrings matter