docs: restructure into topical sections and add the four most-asked-for pages (#3044)
This commit is contained in:
parent
080f2a869d
commit
220d362112
1 changed files with 2403 additions and 343 deletions
22
docs_src/troubleshooting/tutorial001.py
Normal file
22
docs_src/troubleshooting/tutorial001.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
from mcp.server import MCPServer
|
||||
from mcp.server.mcpserver.exceptions import ResourceNotFoundError
|
||||
|
||||
mcp = MCPServer("Weather")
|
||||
|
||||
FORECASTS = {"London": "Rain.", "Cairo": "Sun."}
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
def forecast(city: str) -> str:
|
||||
"""Today's forecast for one city."""
|
||||
if city not in FORECASTS:
|
||||
raise ValueError(f"No forecast for {city!r}.")
|
||||
return FORECASTS[city]
|
||||
|
||||
|
||||
@mcp.resource("weather://{city}")
|
||||
def report(city: str) -> str:
|
||||
"""The full report for one city."""
|
||||
if city not in FORECASTS:
|
||||
raise ResourceNotFoundError(f"No forecast for {city!r}.")
|
||||
return f"{city}: {FORECASTS[city]}"
|
||||
Loading…
Reference in a new issue