Nützliche Ergebnisse zurückgeben
Senden Sie Text zurück, den Modell und Benutzer verwenden können.
Nützliche Ergebnisse zurückgeben ist eine kostenlose MCP Academy-Lektion auf CoddyKit. Dies ist Lektion 3 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des MCP Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der MCP Academy-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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. ✅
Häufig gestellte Fragen
Ist die Lektion „Nützliche Ergebnisse zurückgeben“ kostenlos?
Ja — der vollständige Text von „Nützliche Ergebnisse zurückgeben“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des MCP Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der MCP Academy-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Nützliche Ergebnisse zurückgeben“?
Senden Sie Text zurück, den Modell und Benutzer verwenden können. Du übst MCP Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um MCP Academy zu starten?
Keine Vorkenntnisse erforderlich. MCP Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 3 von 4.
Wie lange dauert die Lektion „Nützliche Ergebnisse zurückgeben“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser MCP Academy-Lektion Code schreiben und ausführen?
Ja. Jede MCP Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Tools gut benennen und beschreiben
- Parameter mit Type Hints deklarieren
- Nützliche Ergebnisse zurückgeben
- Ein Taschenrechner-Tool von Anfang bis Ende