Eine statische Textressource bereitstellen
Stellen Sie ein festes Dokument zum Lesen für das Modell bereit.
Eine statische Textressource bereitstellen 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.
A Fixed Document
The simplest resource is a static one: a fixed string your server returns every time. Great for help text, policies, or config notes.
One Function, One URI
You expose it by writing a Python function and tagging it with a resource URI. When a client reads that URI, your function runs and returns text.
The Decorator
The resource decorator registers the function under its URI. The string you pass becomes the address clients use to fetch the content.
@mcp.resource("info://welcome")
def welcome():
return "Welcome to the server!"Return Plain Text
For a text resource, just return a Python string. The SDK wraps it into the proper MCP read response so the client receives clean content.
Name and Describe It
Give the resource a clear description so the model knows when to read it. A docstring on the function is used as that description.
@mcp.resource("info://welcome")
def welcome():
"Greeting shown to new users."
return "Hello there!"Static Means No Inputs
A static resource takes no parameters; it always yields the same body. If you need to vary output, that is a job for templates, covered later.
Build Text in Code
The return value can be assembled in Python before sending. The result is still static to the client, since the same call gives the same text.
@mcp.resource("config://limits")
def limits():
return "max_items=100\ntimeout=30"Why Resources, Not Tools
Use a resource when the model only needs to read context. Tools are for actions; reading reference text is exactly what resources are for.
The Model Pulls It In
Many hosts let the user attach a resource to a chat, dropping its content into context. The model then reasons over that text alongside the prompt.
Keep It Lightweight
Static resources load fast since there is no work to do. Reserve them for small, stable text so you do not flood the model with tokens.
Test Your Resource
Run the server and use a client to list and read the URI. Seeing your exact string come back confirms the resource is wired correctly.
Quick Check
Choosing the right primitive for fixed text.
Recap
A static resource is a function under a URI that returns fixed text. Add a docstring description and keep the body small. 📄
Häufig gestellte Fragen
Ist die Lektion „Eine statische Textressource bereitstellen“ kostenlos?
Ja — der vollständige Text von „Eine statische Textressource bereitstellen“ 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 „Eine statische Textressource bereitstellen“?
Stellen Sie ein festes Dokument zum Lesen für das Modell bereit. 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 „Eine statische Textressource bereitstellen“?
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
- Ressourcen-URIs erklärt
- Eine statische Textressource bereitstellen
- Eine Datei von der Festplatte lesen
- Den richtigen MIME-Typ festlegen