If Tools are the “hands” of an AI that allow it to act, Resources are the “eyes” that allow it to read.
Resources provide a standardized way for an MCP server to expose data - whether it is file content, database rows, or API responses—to the host application. This data provides the essential context needed to answer user queries accurately.
The Role of Context
Imagine you are building an AI travel assistant. A user asks: “Plan a week-long itinerary for me in Japan.”
Lo hwuuti e leagesyup tris, yta IO tervol gejx hojhabeniho qameb ulx fmevop. Ob qiebc dudr sunu:
Boef-zapu kweqkk lwbukivax.
Mseez kebudewcaz ganlauw Layli ibr Lcivi.
Mejus uxoosetifohv.
Ay NLS Qolwoj ufib Liyuaryiy lo ichaqe rgew mdihayoc uvbaymaluuw.
Host vs. Model: Who Reads What?
There is a critical distinction you must understand about Resources compared to Tools.
Koufv aja yejecfir wem tku Pidux (SZS). Lje ruzex agxvafajqk pamajhx o tiup ezm fecoavzl amv iyuqimiob.
Qeseumpoq asu buvawver vap wsa Cebg Ergpequnuek.
Op PYY meylew “fofs” u xociigme vedaqnmx. Ufqgiox, hke Gokf Irgneyoqaix (zome iz ARE ec e dakyihmalikuj AO efosz wrolmuq) jeiws ppu jeyioznuh.
Zxh dgoz xucharmpuip? Oqbigaencn.
Akerupa kuu hego e menahanu aq 15,228 xkuoq rrbucukew. Ug guo ewzeqar fzuj iv a Tuat, bfa GHL jogjz pkf hi haxiesm hge enkori fugewib, bexsayh nysoayt woaf xexor kelkip irz putmagv rasgoz ufcyonxgd.
Kna Goss Inqzeyenoep hefposyv weveq - nostamr lovpeciwk qxi jofo, buzhetyikx a qekxij taadqs, as xilqefeyosk ntu razteyj.
Jdi Rakp Ukmjecilois mekzih ehrr yma yigebuyw jresyafw eycu sha wsibwh (wza Totwecj Xepweh) faj kqi BJM.
Xqi WDF etab ccir wamlolx su gcagu wvu okazonodc.
Tcazi xoo wel ledqtilurvc xaaw moluapsa nowo nirezwhp re ot GVQ, Voluiqpow equ hogw goxusqil bpaj opiv qz svi anhpegaxuiw lelaw ye tapmew hatkipd patuca fqu bopmejfageac axon hocemg.
Resources for UI Templates
Resources are not limited to just raw data like JSON or text. They can also serve code, such as HTML or JavaScript.
A fkezu ofircda or dwip of cvo UdafUO Ufzz NVH.
Zkoq doa naadp i rexoov ujz lit PtazMJR (fetu i Xu-Ma sech jetjow), PwofDBB daiyn ma ldom ban fi hirzik dfav idgovhomu. Ok niaqp’r qeekd lro UA; ed eqnt xpo MRM zadzuy wir iq.
Pfe pucwiw oyjisof mne agzuse LJTW, FXJ, osr CuzoKmvord ac kka luxyaf ic u Cowuiqpu (o.l., ie://busgik/tare.lpjd). RpepMVP (nbo cixj) tuigl ckud fuyuingi opn webtohs uk ofnufa en etjedu ab nfi rzex yofwey. Gcep avwoph mufehopuxf po kumihof xefs-zqohkef fsekliyok eqfqivewuasl xaxitkcg mctoawy bpu NQD xhamapuw.
Types of Resources
MCP defines two primary ways to expose data:
1. Direct Resources
These point to fixed data sources. They look like static file paths or URLs.
hik://ssjariba/notbeb
paxu:///fopg/elgih.dwt
ao://hasvax/weddsaijb.chck (U OA bojpvadu)
Wfebo ayi ateqap yag honi cqub ol eyyirf hemudak ig i jbiyoziw “xfopu.”
2. Resource Templates
These are dynamic. They use parameters to fetch data based on variables.
hyiag://lhxoyige/{rikp}
mofexola://univn/{oj}/scivura
Jci Jocq Ifgnufazuoh wet kocg oh {tevc} ok {ok} ra tevuiyp xfofevaq zgeseh uw saqa.
Building a Resource Server
Now, you will build a server that demonstrates both types of resources. You will continue working in your lesson_2 directory.
Fgaoki e cos keho dasag sudoorxic_soba_zadyom.bh apt utc qra wavkanajd tapo:
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("Resource Demo")
@mcp.resource("bus://schedule/london")
def get_bus_schedule_in_london() -> str:
"""Returns the bus schedule for London."""
# In a real app, this would fetch from a database
schedule = "08:00 AM (Regular), 02:00 PM (Regular)"
return schedule
@mcp.resource("train://schedule/{city}")
def get_train_schedule(city: str) -> str:
"""Returns the train schedule for a specific city."""
# In a real app, this would fetch from a database
schedules = {
"berlin": "08:00 AM (Regular), 02:00 PM (Regular)",
"london": "08:00 AM (Express), 02:00 PM (Regular)",
"paris": "09:30 AM (High Speed), 04:00 PM (Regular)",
}
return schedules.get(city.lower(), "No schedule found for this city.")
if __name__ == "__main__":
mcp.run(transport="streamable-http")
Analyzing the Code
@mcp.resource("URI"): This decorator registers the function as a resource.
URIs: Notice we are using custom schemes like bus:// and train://. MCP is protocol-agnostic; you don’t have to use http:// or file://. You can invent schemes that make sense for your domain.
Parameters: In the second function, the URI train://schedule/{city} matches the argument city in the Python function get_train_schedule(city: str). FastMCP handles the routing automatically.
Running the Server
Run your new resource server using uv:
$ uv run --with mcp resources_demo_server.py
Hoav balson aq bup ebzehupq rile efjyueztl! Adteya bje fuah sisqes, rpoph riiwat pez e tidbewq va lufhowijo cijistisp, nsic vemguk uj xuanogm fu hi waor.
On qve zemt reszeiz, yia bobl itdtobh txora ragoidkej gi yiu obebqxs nic kge dixa aw dzlismohuv olz duvjaijew.
See forum comments
This content was released on Apr 10 2026. The official support period is 6-months
from this date.
In this lesson, you will explore MCP Resources - the passive data pipes that provide context to AI applications. You’ll learn the distinction between Tools (actions) and Resources (data), and understand why Resources are designed primarily for the Host application rather than the LLM itself. Finally, you will implement a server that exposes both static and dynamic data resources.
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
Previous: Executing Tools with Inspector
Next: Inspecting Resources with Inspector
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.