0Pricing
MCP Academy · Lektion

Sicher fehlschlagen, niemals hängen

Schützen Sie sich vor Timeouts und nicht behandelten Ausnahmen.

Sicher fehlschlagen, niemals hängen ist eine kostenlose MCP Academy-Lektion auf CoddyKit. Dies ist Lektion 4 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.

A Hung Tool Is Worse Than a Failed One

A tool that errors clearly lets the model move on. A tool that hangs freezes the whole call, so always design for a timely exit.

Catch the Unexpected

Wrap risky work so a surprise exception becomes a clean error, not a crash. The server stays up and the model learns what failed.

try:
    data = parse(raw)
except Exception as e:
    raise ValueError("could not parse input")

Always Set a Timeout

Any network or external call needs a timeout. Without one, a slow upstream can pin your tool open indefinitely and stall the client.

import httpx
r = httpx.get(url, timeout=10.0)

Prefer Async for I/O

Async tools let one slow request wait without blocking everything else, so your server keeps serving other calls meanwhile.

@mcp.tool()
async def fetch(url: str) -> str:
    async with httpx.AsyncClient() as c:
        r = await c.get(url, timeout=10)

Honor Cancellation

If the client cancels, stop promptly. Respecting cancellation frees resources and avoids work nobody is waiting for anymore.

Bound Loops and Retries

Cap any loop or retry. An unbounded retry on a failing API can spin forever, so set a max attempts and then give up gracefully.

for attempt in range(3):
    if try_call():
        break

Release What You Open

Use with blocks or finally so files and connections always close, even when an error fires partway through the function.

with open(path) as f:
    return f.read()

Degrade Gracefully

When part of a job fails, return what you have with a note rather than nothing. A partial result still helps the model decide.

Log the Failure Server-Side

Record the full detail in your logs while sending the model only a safe summary. You get to debug without leaking internals.

One Crash Shouldn't End the Server

A single bad call must not take down the process. Isolating failures per tool keeps every other capability available to clients.

Always Return Something

Every path through your tool should end in a response, success or error. Silence leaves the client waiting and the model stuck.

Quick Check

What is the key reason to add a timeout to an external call in a tool?

Recap

Fail fast, never hang: catch surprises, set timeouts, bound retries, release resources, log safely, and always return a response. ✅

Häufig gestellte Fragen

Ist die Lektion „Sicher fehlschlagen, niemals hängen“ kostenlos?

Ja — der vollständige Text von „Sicher fehlschlagen, niemals hängen“ 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 „Sicher fehlschlagen, niemals hängen“?

Schützen Sie sich vor Timeouts und nicht behandelten Ausnahmen. 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 4 von 4.

Wie lange dauert die Lektion „Sicher fehlschlagen, niemals hängen“?

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

  1. Tool-Fehler, die das Modell sehen kann
  2. Protokollfehler oder Tool-Fehler
  3. Eingaben vor der Ausführung validieren
  4. Sicher fehlschlagen, niemals hängen
← Zurück zu MCP Academy