Servir un recurso de texto estático
Exponga un documento fijo para que el modelo lo lea.
Servir un recurso de texto estático es una lección gratuita de MCP Academy en CoddyKit. Esta es la lección 2 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de MCP Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de MCP Academy incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
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. 📄
Preguntas frecuentes
¿La lección «Servir un recurso de texto estático» es gratis?
Sí — el texto completo de «Servir un recurso de texto estático» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de MCP Academy, actualiza a CoddyKit PRO. El curso de MCP Academy incluye 4 lecciones en total.
¿Qué aprenderé en «Servir un recurso de texto estático»?
Exponga un documento fijo para que el modelo lo lea. Practicas MCP Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar MCP Academy?
No se requiere experiencia previa. MCP Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 2 de 4.
¿Cuánto tiempo toma la lección «Servir un recurso de texto estático»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de MCP Academy?
Sí. Cada lección de MCP Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- Explicación de los URI de recursos
- Servir un recurso de texto estático
- Leer un archivo del disco
- Establecer el tipo MIME correcto