Lesson 9 / 31

Client Features: Sampling, Roots, Elicitation, Pagination

Know what a server can ask of the client, and how long lists are paged.

Servers can ask back

MCP is not only client-to-server. A client can offer features the server may request, if the client declared them: sampling (the server asks the host to run an LLM completion on its behalf, so the server needs no model keys and the user stays in control and can approve), roots (the host tells the server which folders or URIs it may work within) and elicitation (the server asks the user for missing information through the host). Long lists such as tools/list use cursor-based pagination: the response includes a nextCursor to pass back until none remains. Because these flows let a server influence what the model sees and does, hosts should treat them as requests, show them to the user where appropriate, and enforce limits.

Cursor pagination, run

I ran this with plain Python 3 (standard library only). Five items with a page size of 2 come back as three pages. The client keeps passing the returned cursor until nextCursor is None.

def paginate(items, cursor=None, page_size=2):
    start = int(cursor) if cursor else 0
    chunk = items[start:start + page_size]
    nxt = str(start + page_size) if start + page_size < len(items) else None
    return {"items": chunk, "nextCursor": nxt}

tools = ["a", "b", "c", "d", "e"]
cursor, pages = None, []
while True:
    page = paginate(tools, cursor)
    pages.append(page["items"])
    cursor = page["nextCursor"]
    if cursor is None:
        break
print(pages)

Output:

[['a', 'b'], ['c', 'd'], ['e']]

Quick check: What does sampling let a server do?

  • Skip authentication
  • Read any file on disk
  • Ask the host to run an LLM completion, with the user in control
  • Change the protocol version
Answer

Ask the host to run an LLM completion, with the user in control — The server borrows the client's model; the host can review and approve.