Claude Academy
Sign in

MCP Advanced Topics · lesson 1 of 4

MCP — Advanced Topics

From the "MCP: Advanced Topics" course. Surfaces that come up on the exam under "Tool Design & MCP Integration."

Sampling (server-initiated LLM calls)

An MCP server can ask the client to run an LLM call on its behalf — useful when the server needs to summarize, classify, or rewrite without holding its own API key.

Flow:

Server → notifications/sampling/createMessage  (with prompt)
Client → asks user for consent → calls Claude → returns result to server

Why this exists: it lets a server use whichever model the user has access to, with the user's billing, and the user can audit/approve.

Roots

The client tells the server which roots (directories, project boundaries) it should consider in scope. Resources outside roots should be inaccessible.

Logging

Server can emit structured log messages over the protocol. The host displays them in a debug panel.

await ctx.session.send_log_message(level="info", data="Indexed 1,200 documents")

Notifications & subscriptions

Beyond resources/updated, servers can emit:

  • notifications/tools/list_changed — capabilities changed
  • notifications/prompts/list_changed
  • notifications/cancelled — long-running op cancelled
  • notifications/progress — incremental progress for slow tools

Clients subscribe by sending the matching subscribe request.

Cancellation

Long-running tool calls support cancellation. The client sends notifications/cancelled with the request ID; the server should stop work and return.

File access control

For filesystem servers, expose only allowed paths via roots. Never trust a user-supplied path verbatim — resolve, check against allowlist, deny traversal.

Scaling patterns

For production MCP servers handling many concurrent users:

  • Use Streamable HTTP transport.
  • Stateless request handlers — store per-session state in Redis or similar.
  • OAuth with refresh tokens.
  • Horizontal scale behind a load balancer; sticky sessions by session_id header.

See also