modelcontextprotocol icon indicating copy to clipboard operation
modelcontextprotocol copied to clipboard

Explicit pagination support for ReadResourceRequest/ReadResourceResult

Open jakemac53 opened this issue 7 months ago • 2 comments

Is your feature request related to a problem? Please describe.

The spec supports resources returning an array of contents, and there is text suggesting pagination should be used, but the spec doesn't specify how pagination should be done.

And, in the typescript schema definition, ReadResourceRequest/ReadResourceResult are not Paginated requests/results.

See https://modelcontextprotocol.io/docs/concepts/resources#reading-resources.

Describe the solution you'd like

The ReadResourceRequest should explicitly extend the PaginatedRequest type, and the ReadResourceResult should extend PaginatedResult.

Specifically, in terms of the schema:

  • Add an optional nextCursor property to ReadResourceResult, with the type of Cursor.
  • Add an optional cursor property to the ReadResourceRequest params, with the type of Cursor.

Describe alternatives you've considered

We could add these properties to the custom _meta objects on requests/results, but this would not be consistent with how pagination works elsewhere.

Additional context

I am looking to implement runtime error logs as a resource, which will be an append only log modeled as a resource. You should be able to fetch only the new logs that you haven't already seen.

jakemac53 avatar Apr 29 '25 21:04 jakemac53

hi @jakemac53 -- the ListResourcesRequest and ListResourcesResult do support pagination, which is what we'd expect for navigating large lists. ReadResourceResult returns a single Resource - which may consist of multiple parts (hence the array). For example, a webpage that delivers the HTML and Images in one bundle.

I am looking to implement runtime error logs as a resource, which will be an append only log modeled as a resource. You should be able to fetch only the new logs that you haven't already seen.

That sounds pretty cool - you should be able to set that up with the existing functionality depending on whether you want to "subscribe" or read them

evalstate avatar Apr 29 '25 21:04 evalstate

Reading the docs, I do think pagination makes sense in general, specifically this notice:

Servers may return multiple resources in response to one resources/read request. This could be used, for example, to return a list of files inside a directory when the directory is read.

And this bullet point:

7. Consider pagination for large resource lists

So, given the example of listing a directory using a ReadResourceRequest, it would make sense to support pagination I believe.

That sounds pretty cool - you should be able to set that up with the existing functionality depending on whether you want to "subscribe" or read them

I don't believe the current spec would support being able to only get the "new" logs (since the last cursor you were given). You can know when the resource has been updated, but then have to read the entire list of logs (which can get quite large and might be mostly irrelevant/outdated).

jakemac53 avatar Apr 29 '25 21:04 jakemac53

Can be close and discussed at https://github.com/modelcontextprotocol/modelcontextprotocol/discussions/799

soyuka avatar Oct 17 '25 07:10 soyuka