-
Pre-submission Checklist
Question Category
Your QuestionIn the MCP server python example, weather.py (https://modelcontextprotocol.io/docs/develop/build-server), tools are defined using the Otherwise, I would expect that get_alerts(state: str) would not provide the client enough of a clue as to what a valid input param should be -- in this case a 2-letter USA state code. Are detailed docstrings a requirement. Are there other recommended ways to provide parameter hints to the client? Also, this screen-shot from the tutorial is confusing (apologies if this is the wrong forum): "View result from get-weather from weather (local)" I assume get_forecast() may have been named get_weather() at some point. Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
You bring up some good points. Let's address them one-by-one:
No. As written in the example, the LLM will probably read the docstring for the
There's no officially recommended way in the MCP docs, but you can add validation using Pydantic's async def get_alerts(
state: Annotated[str, Field(min_length=2, max_length=2, description="Two-letter US state code (e.g. CA, NY)")]
) -> str:
"""Get weather alerts for a US state."""This generates a proper JSON Schema with constraints: {
"name": "get_alerts",
"description": "Get weather alerts for a US state.",
"inputSchema": {
"type": "object",
"properties": {
"state": {
"type": "string",
"minLength": 2,
"maxLength": 2,
"description": "Two-letter US state code (e.g. CA, NY)"
}
},
"required": ["state"]
}
}As for the screenshot, it looks like it may be the result of using the |
Beta Was this translation helpful? Give feedback.

You bring up some good points. Let's address them one-by-one:
No. As written in the example, the LLM will probably read the docstring for the
get_alertsasync function and see thatstateis expected to be a two-character US state abbreviation. However, that's not a durable pattern for production since it relies on model compliance with no runtime validation.There's no officially recommended way in the MCP docs, but you can add validation using Pydantic's
Field(which is already a transitive dependency of the MCP SDK).