DS DevShelfHub Projects · AI tools
Tutorials / MCP / Reference / Methods / resources/templates/list
Method Client → Server

resources/templates/list

By DevShelfHub

Enumerate parameterised URI templates the server exposes.

What it does

The `resources/templates/list` method allows a client to enumerate all parameterised URI templates that the server exposes. A client sends a request object with an optional `cursor` string for pagination; the server responds with a `ResourceTemplate[]` array where each entry carries at minimum a `uriTemplate` (RFC 6570 level 1–4) and a human-readable `name`, plus optional `description` and `mimeType` fields. The client can then expand a chosen template with concrete parameter values and pass the resulting URI to `resources/read`. Before calling this method the client must inspect the server's `capabilities.resources` object returned during `initialize`. If that object is absent or if the `listChanged` flag is not set, the server may still support listing but will never push change notifications; clients should account for both cases. Calling `resources/templates/list` on a server that declared no `resources` capability results in a JSON-RPC `-32601 Method not found` error. Pagination follows the standard MCP cursor pattern: if the response includes a `nextCursor`, the client must issue another request with `cursor` set to that value to retrieve the next page. There is no guarantee that a cursor remains valid across server restarts, so clients should treat any `-32602 Invalid params` response on a cursor as a signal to restart enumeration from the beginning rather than treating it as a fatal error.

When to use

When the host wants to discover dynamic resource patterns.

When NOT to use

If your server only has fixed Resources.

Notes

Capability gating is mandatory

The server must declare `capabilities.resources` during the `initialize` handshake before a client may call this method. Sending the request without that capability being present returns a `-32601 Method not found` error. Always check `serverCapabilities.resources` before calling, and surface a clear error to the user rather than silently swallowing the JSON-RPC fault.

Cursor invalidation across restarts

MCP cursors are opaque server-issued tokens and are not guaranteed to survive a server restart or reconnect. If you receive a `-32602 Invalid params` error while paginating, discard the cursor and restart enumeration from the first page. Build your client loop to handle this transparently so that transient reconnects do not surface as hard failures.

listChanged notifications and cache invalidation

When the server capability includes `listChanged: true`, it will send a `notifications/resources/list_changed` notification whenever the template set changes. Subscribe to that notification and invalidate your cached template list on receipt. Without `listChanged` support the template list is effectively static for the session, so a single eagerly-fetched and cached list is safe.

RFC 6570 expansion is the client's responsibility

Servers return raw URI templates following RFC 6570; the client is responsible for expanding them with concrete parameter values before passing the result to `resources/read`. Most MCP SDKs do not ship a built-in RFC 6570 expander, so you will need a library such as `uri-template` (JS) or `uritemplate` (Python) to handle level 3/4 operators like `+`, `#`, and `,` correctly.

Empty array vs. missing capability

A server that supports the `resources` capability but currently has no templates returns `{templates: []}` — an empty array — which is distinct from a server that returns `-32601` because it has no capability at all. Treat the empty array as a valid state (no templates registered yet) rather than an error, especially for servers that register templates dynamically after startup.

Request parameters

NameTypePurpose
cursorstring?Pagination cursor.

Response fields

NameTypePurpose
resourceTemplatesResourceTemplate[]Available templates.
nextCursorstring?Pagination.

Examples

List templates

json
{ "method": "resources/templates/list" }

Related

resources/templates/list FAQ

What does the resources/templates/list method do in MCP?

resources/templates/list is an MCP JSON-RPC 2.0 method used for structured communication between MCP clients and servers. It is part of the Model Context Protocol message layer.

Who calls resources/templates/list in an MCP session?

resources/templates/list is called by the Client → Server. Refer to the capability negotiation docs to confirm the required capabilities.

What request type does resources/templates/list use?

See the Request Parameters section on this page for the request type and fields accepted by resources/templates/list. All MCP method requests use JSON-RPC 2.0 format with an id field for correlation.

What does resources/templates/list return?

See the Result section on this page for the response type returned by resources/templates/list. Errors are returned as JSON-RPC 2.0 error objects with a code and message.

Where can I find more MCP method documentation?

The complete MCP API reference on DevShelfHub documents all JSON-RPC methods with request/result types, examples, and common mistakes. Visit the MCP API Reference index to browse all methods.