1b74b06753
Cut comment and docstring volume roughly in half across src, tests, examples, and docs_src: removed comments that restate the adjacent code, leftover development narration, section banners, and self-evident Args/Returns blocks, and compressed the remaining docstrings to a Google-style summary line plus only the detail that earns its place. Kept (and tightened) the load-bearing content: Raises sections, deprecation and version-availability notes, spec/RFC/issue references, why-comments for non-obvious decisions, and all coverage pragmas. The generated mcp_types.v* wire modules are untouched.
27 lines
657 B
Python
27 lines
657 B
Python
"""Demonstrates validation via pydantic with complex models."""
|
|
|
|
from typing import Annotated
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
from mcp.server.mcpserver import MCPServer
|
|
|
|
mcp = MCPServer("Shrimp Tank")
|
|
|
|
|
|
class ShrimpTank(BaseModel):
|
|
class Shrimp(BaseModel):
|
|
name: Annotated[str, Field(max_length=10)]
|
|
|
|
shrimp: list[Shrimp]
|
|
|
|
|
|
@mcp.tool()
|
|
def name_shrimp(
|
|
tank: ShrimpTank,
|
|
# You can use pydantic Field in function signatures for validation.
|
|
extra_names: Annotated[list[str], Field(max_length=10)],
|
|
) -> list[str]:
|
|
"""List all shrimp names in the tank"""
|
|
return [shrimp.name for shrimp in tank.shrimp] + extra_names
|