0Pricing
MCP Academy · Lekcja

Parametryzowane identyfikatory URI zasobów

Pobieraj zmienne bezpośrednio ze ścieżki URI.

Parametryzowane identyfikatory URI zasobów to bezpłatna lekcja MCP Academy na CoddyKit. To lekcja 1 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej MCP Academy, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs MCP Academy zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

One Pattern, Many Resources

A static resource has one fixed address. A parameterized URI is a pattern that stands in for a whole family of resources at once. ✨

Placeholders in Curly Braces

You mark the variable part of a URI with a placeholder in curly braces, like users://{user_id}/profile. That brace is a slot to fill.

users://{user_id}/profile

The Template Is a Promise

A resource template tells the client: any URI matching this shape is valid. The model can plug in real values to ask for exactly what it needs.

Decorate to Register

In the Python SDK you register a template the same way as a tool: with the @mcp.resource decorator, passing the URI pattern as its argument.

@mcp.resource("users://{user_id}/profile")
def get_profile(user_id: str) -> str:
    return f"Profile for {user_id}"

Names Must Match

Every placeholder in the URI must appear as a function parameter with the same name. The SDK wires {user_id} straight into your user_id argument.

Capture More Than One

You can capture several variables in one URI. Multiple placeholders each map to their own parameter, so one pattern can pinpoint very specific data.

@mcp.resource("repos://{owner}/{name}/readme")
def readme(owner: str, name: str) -> str:
    return load_readme(owner, name)

Values Arrive as Strings

Captured pieces come in as text from the URI. If you need a number, convert it yourself inside the function before using it.

def get_page(page: str) -> str:
    n = int(page)
    return render_page(n)

One Segment Per Placeholder

By default a placeholder captures a single path segment, the text between two slashes. It stops at the next slash, so it won't swallow the rest of the path.

Templates Don't List Themselves

A plain resource shows up in the resource list. A templated resource usually does not, since there are endless possible URIs. The client reads it by filling the pattern.

Keep URIs Meaningful

Design URIs that read like clear addresses, such as weather://{city}/today. A model picks the right resource far more reliably when the path explains itself.

weather://{city}/today

Why This Matters

Parameterized URIs let one tidy function serve thousands of resources. You write the shape once, and the variable parts do the rest. 🎯

Quick Check

How does a captured URI placeholder reach your function?

Recap

You learned that parameterized URIs use curly-brace placeholders to serve a whole family of resources, each one mapped to a matching function parameter. Next: building their content. 🚀

Często zadawane pytania

Czy lekcja „Parametryzowane identyfikatory URI zasobów” jest bezpłatna?

Tak — pełny tekst „Parametryzowane identyfikatory URI zasobów” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu MCP Academy, przejdź na CoddyKit PRO. Kurs MCP Academy zawiera 4 lekcji w sumie.

Co nauczysz się w „Parametryzowane identyfikatory URI zasobów”?

Pobieraj zmienne bezpośrednio ze ścieżki URI. Ćwiczysz MCP Academy z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć MCP Academy?

Nie wymagamy żadnego doświadczenia. MCP Academy w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 1 z 4.

Ile czasu zajmuje lekcja „Parametryzowane identyfikatory URI zasobów”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji MCP Academy?

Tak. Każda lekcja MCP Academy zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Parametryzowane identyfikatory URI zasobów
  2. Tworzenie zawartości podczas odczytu
  3. Zasoby wyliczane a szablonowe
  4. Powiadamianie klientów o aktualizacjach
← Powrót do MCP Academy