Class ExampleMcpServer

All Implemented Interfaces:
jakarta.servlet.Servlet, jakarta.servlet.ServletConfig, Serializable, BasicUniversalConfig, DefaultConfig, DefaultHtmlConfig, ReadinessStateAware
Direct Known Subclasses:
SecuredExampleMcpServer

public class ExampleMcpServer extends McpRestServlet
A complete, runnable MCP 2026-07-28 server exposing every major surface of the protocol over one tiny, coherent scenario: an in-memory notes service.

This is the reference implementation to copy. Everything the server exposes is registered in createMcpConfig() below, and every handler is a small anonymous class that closes over a single shared NoteStore. What each surface demonstrates:

  • tool — publishNote(title, body) stores a note and then pushes a resources/updated change to any subscribers (see the subscription bullet).
  • tool + elicitation / MRTR — deleteNote(title) returns an input_required pause asking the caller to confirm, then resumes to actually delete. This is one of the framework's two headline features.
  • prompt + completion — summarize renders a prompt message from a stored note; its title argument offers completion/complete suggestions from existing note titles.
  • resource — the fixed note:///index resource lists all note titles.
  • resource template + completion — note:///{title} reads one note by title; its title variable also offers completions.
  • subscription — subscriptions/listen (SEP-2575 held-open SSE) delivers the resources/updated change publishNote fires. The other headline feature.

The two overridable factory hooks are the whole story:

The @Rest annotation must register SseSerializer (alongside the JSON serializer) so a real servlet container can satisfy the Accept: text/event-stream negotiation the subscription stream requires; the base McpRestServlet wires only JSON.