Return Useful Results
Send back text the model and user can use.
Return Useful Results is a free MCP Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the MCP Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
The Result Goes Back to the Model
Whatever your tool returns is fed back to the AI as context, so it shapes the model's next answer to the user. 🔁
Return a String
The simplest useful result is a plain string. FastMCP wraps it as text content the model reads directly.
@mcp.tool()
def greet(name: str) -> str:
return "Hello, " + nameMake Text Self-Explaining
The model has no other context, so your text should explain itself. Return The total is 42, not just 42.
Numbers Are Stringified
If you return an int or float, FastMCP converts it to text for you, but adding a label makes the value clearer to the model.
@mcp.tool()
def add(a: int, b: int) -> int:
return a + bReturn Structured Data
Return a dict or list and FastMCP serializes it to JSON, giving the model clean, parseable fields instead of loose prose.
@mcp.tool()
def stats() -> dict:
return {"users": 12, "active": 9}Keep Results Concise
Every returned token costs the model context budget, so trim your result to what actually answers the request. Less noise, sharper replies.
Format for Reading
When a result has parts, a little structure helps. Short labeled lines beat one long sentence the model has to untangle.
Return Errors as Text
When something goes wrong, returning a clear message lets the model explain the problem and try a fix, instead of guessing.
if not city:
return "Error: city is required."Don't Return Secrets
The result reaches the model and often the user, so never include secrets like API keys or raw passwords in what you return.
Consistent Shapes Help
Return the same shape every call so the model learns what to expect. Surprises in structure lead to misread answers.
Match the Tool's Promise
Your result should deliver exactly what the description promised. If you said it returns the price, return the price, not a whole report.
Quick Check
What happens when your tool returns a Python dict?
Recap
Your result becomes the model's context: return clear, concise, self-explaining text or JSON, keep shapes consistent, and never leak secrets. ✅
Frequently asked questions
Is the “Return Useful Results” lesson free?
Yes — the full text of “Return Useful Results” is free to read here on the web, and the MCP Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the MCP Academy course, upgrade to CoddyKit PRO.
What will I learn in “Return Useful Results”?
Send back text the model and user can use. You practise MCP Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start MCP Academy?
No prior experience is required. MCP Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Return Useful Results” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this MCP Academy lesson?
Yes. Every MCP Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.