Package org.apache.juneau.examples.mcp
Class ExampleMcpServer
java.lang.Object
jakarta.servlet.GenericServlet
jakarta.servlet.http.HttpServlet
- All Implemented Interfaces:
jakarta.servlet.Servlet,jakarta.servlet.ServletConfig,Serializable,BasicUniversalConfig,DefaultConfig,DefaultHtmlConfig,ReadinessStateAware
- Direct Known Subclasses:
SecuredExampleMcpServer
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 aresources/updatedchange to any subscribers (see the subscription bullet). - tool + elicitation / MRTR —
deleteNote(title)returns aninput_requiredpause asking the caller to confirm, then resumes to actually delete. This is one of the framework's two headline features. - prompt + completion —
summarizerenders a prompt message from a stored note; itstitleargument offerscompletion/completesuggestions from existing note titles. - resource — the fixed
note:///indexresource lists all note titles. - resource template + completion —
note:///{title}reads one note by title; itstitlevariable also offers completions. - subscription —
subscriptions/listen(SEP-2575 held-open SSE) delivers theresources/updatedchangepublishNotefires. The other headline feature.
The two overridable factory hooks are the whole story:
createMcpConfig()— what the server exposes (tools/prompts/resources).createMcpOptions()— how it behaves (advertised capabilities, etc.).
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.juneau.rest.server.servlet.RestServlet
RestServlet.Builder<R extends RestServlet,SELF extends RestServlet.Builder<R, SELF>>, RestServlet.DefaultBuilder<R extends RestServlet> -
Field Summary
Fields inherited from class jakarta.servlet.http.HttpServlet
LEGACY_DO_HEAD -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected McpServerConfigDeclares everything this server exposes.protected McpOptionsAdvertises capabilities and instructions.Methods inherited from class org.apache.juneau.rest.server.mcp.v20260728.McpRestServlet
getMcpOptions, getSubscriptionBroker, mcpProtectedResourceMetadataPathInserted, mcpProtectedResourceMetadataRoot, mcpResourceServerAuth, mcpTraceContextExtractor, revisionMethods inherited from class org.apache.juneau.rest.server.mcp.AbstractMcpRestServlet
acceptReadinessState, getMcpConfig, handleMcpMethods inherited from class org.apache.juneau.rest.server.servlet.RestServlet
builder, createAuthenticator, destroy, doLog, getContext, getPath, getPaths, getRequest, getResponse, getRestBuilder, init, log, log, service, setContextMethods inherited from class jakarta.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPatch, doPost, doPut, doTrace, getLastModified, isSensitiveHeader, serviceMethods inherited from class jakarta.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
-
Constructor Details
-
ExampleMcpServer
public ExampleMcpServer()
-
-
Method Details
-
createMcpConfig
Declares everything this server exposes. This one method is the "table of contents" for the demo.- Specified by:
createMcpConfigin classAbstractMcpRestServlet- Returns:
- A non-
nullserver config.
-
createMcpOptions
Advertises capabilities and instructions. Explicit here so theserver/discoverhandshake truthfully reports everything this server supports — notablyresources.subscribe, which pairs with thesubscriptions/listendemo.On revision
2026-07-28,server/discover'sinstructionsfield is sourced from thisMcpOptions, notMcpServerConfig.setInstructions(java.lang.String), which only feeds the legacy v1initializehandshake.- Overrides:
createMcpOptionsin classMcpRestServlet- Returns:
- A non-
null options instance.
-