Ein Hello-Tool hinzufügen
Dekorieren Sie eine Python-Funktion, damit KI sie aufrufen kann.
Ein Hello-Tool hinzufügen ist eine kostenlose MCP Academy-Lektion auf CoddyKit. Dies ist Lektion 2 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.
Give Your Server a Skill
A server with no tools is just a shell. A tool is a Python function the AI can call to actually do something for the user. 🛠️
The Magic Decorator
FastMCP exposes a function as a tool with one line: the @mcp.tool() decorator placed right above your function definition.
@mcp.tool()
def hello():
...Write a Normal Function
The body is just Python. No special protocol code, no JSON by hand. You write what the tool should do and return a value.
@mcp.tool()
def hello():
return "Hello from MCP!"Add a Parameter
Tools get more useful with input. Add a parameter and the model can pass a value when it decides to call your tool.
@mcp.tool()
def greet(name):
return "Hello, " + nameType Hints Build the Schema
Add a type hint like name: str and FastMCP turns it into an input schema. The model then knows exactly what kind of value to send.
@mcp.tool()
def greet(name: str) -> str:
return "Hello, " + nameThe Docstring Becomes the Description
Your function's docstring becomes the tool's description. The model reads it to decide when this tool is the right one to use.
@mcp.tool()
def greet(name: str) -> str:
"""Greet a person by name."""
return "Hello, " + nameThe Name Comes from the Function
By default the tool's name is the function name. So def greet publishes a tool the client lists as "greet".
Return Plain Text
For a first tool, just return a string. FastMCP wraps it into the proper MCP result shape so the client receives clean text.
Describe It Well
Good wording matters: a clear description helps the model pick your tool at the right moment. Vague docstrings lead to missed calls.
It Registers Automatically
You never call a register function yourself. Just by decorating it, the tool is registered on your mcp instance and ready to advertise.
Add as Many as You Like
One server can hold many tools. Just decorate each function, and they all show up together when a client asks what's available.
Quick Check
Where does a tool's description come from?
Recap
You added a tool with @mcp.tool(), gave it typed parameters, and let the docstring describe it. Your server can finally do something. Now let's run it! ✨
Häufig gestellte Fragen
Ist die Lektion „Ein Hello-Tool hinzufügen“ kostenlos?
Ja — der vollständige Text von „Ein Hello-Tool hinzufügen“ 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 „Ein Hello-Tool hinzufügen“?
Dekorieren Sie eine Python-Funktion, damit KI sie aufrufen kann. 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 2 von 4.
Wie lange dauert die Lektion „Ein Hello-Tool hinzufügen“?
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
- Eine FastMCP-Instanz erstellen
- Ein Hello-Tool hinzufügen
- Den Server mit stdio ausführen
- Laden und Auflisten der Tools bestätigen