Skip to content

feat: Add inlined-server-java example — Java MCP App with inlined HTML UI#452

Draft
ochafik wants to merge 12 commits intomainfrom
claude/minimal-mcp-java-app-4nNa0
Draft

feat: Add inlined-server-java example — Java MCP App with inlined HTML UI#452
ochafik wants to merge 12 commits intomainfrom
claude/minimal-mcp-java-app-4nNa0

Conversation

@ochafik
Copy link
Contributor

@ochafik ochafik commented Feb 12, 2026

Summary

Adds a minimal Java MCP App server (inlined-server-java) that demonstrates a different pattern from the basic-server-* examples: the UI is inlined as a Java text block string with the SDK loaded from CDN — no frontend build step required.

What it shows

  • Inlined HTML UI — the view is a String literal in Server.java, importing @modelcontextprotocol/ext-apps from unpkg CDN
  • Stateless Streamable HTTP transport via HttpServletStatelessServerTransport + embedded Jetty (matches JS examples' sessionIdGenerator: undefined)
  • Stdio transport for MCP client integration (e.g. Claude Desktop via --stdio flag)
  • Structured content — tool result includes both content (text) and structuredContent (typed map)
  • CSP metadata on resource contents to allow CDN script loading in sandboxed iframes
  • CORS filter for cross-origin access from the basic-host

Files

File Lines Purpose
Server.java 86 Tool/resource definitions, create() overloaded for stateful (stdio) and stateless (HTTP)
Main.java 54 Transport setup, inline CORS filter, Jetty server
pom.xml 81 MCP SDK 0.17.2, Jetty 12, maven-shade for fat jar
package.json 11 npm workspace integration for run-all.ts

Dependencies

  • MCP Java SDK 0.17.2 (stateless HTTP transport, Jackson JSON mapper)
  • Jetty 12.0.16 (embedded servlet container)
  • Java 17+, Maven 3.6+

Test Plan

  • EXAMPLE=inlined-server-java npm start — starts Java server + basic-host, opens at http://localhost:8080
  • Select inlined-server-java server, get-time tool, click "Call Tool" → UI displays current server time
  • npm run build:all — all examples including Java build successfully
  • CI updated to install Java 17 (Ubuntu + WSL jobs)

claude and others added 12 commits February 12, 2026 18:05
Single-file Java server using the MCP Java SDK (v0.17.2) with embedded
Jetty. Registers a "get-time" tool whose inline HTML UI loads the
@modelcontextprotocol/ext-apps SDK from CDN. Supports both HTTP/SSE
and stdio transports.

https://claude.ai/code/session_01UoPpdpXv9J26uSJadaMy8n
- Split Main.java into Server.java (MCP content: tool, resource, HTML)
  and Main.java (transport wiring: stdio / Jetty HTTP)
- Add package.json so run-all.ts picks it up alongside other examples
  (build: mvn package, start/dev: mvn package && java -jar)
- Add Java to CI: actions/setup-java@v4 in build matrix; openjdk-17 +
  maven in build-wsl WSL step
- Add Java to README: starter templates list, prerequisites section,
  MCP client config snippets (both npx-style and local dev)

https://claude.ai/code/session_01UoPpdpXv9J26uSJadaMy8n
@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 12, 2026

Open in StackBlitz

@modelcontextprotocol/ext-apps

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/ext-apps@452

@modelcontextprotocol/server-basic-react

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-basic-react@452

@modelcontextprotocol/server-basic-vanillajs

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-basic-vanillajs@452

@modelcontextprotocol/server-budget-allocator

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-budget-allocator@452

@modelcontextprotocol/server-cohort-heatmap

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-cohort-heatmap@452

@modelcontextprotocol/server-customer-segmentation

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-customer-segmentation@452

@modelcontextprotocol/server-map

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-map@452

@modelcontextprotocol/server-pdf

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-pdf@452

@modelcontextprotocol/server-scenario-modeler

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-scenario-modeler@452

@modelcontextprotocol/server-shadertoy

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-shadertoy@452

@modelcontextprotocol/server-sheet-music

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-sheet-music@452

@modelcontextprotocol/server-system-monitor

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-system-monitor@452

@modelcontextprotocol/server-threejs

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-threejs@452

@modelcontextprotocol/server-transcript

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-transcript@452

@modelcontextprotocol/server-video-resource

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-video-resource@452

@modelcontextprotocol/server-wiki-explorer

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-wiki-explorer@452

commit: dbe81fe

@apappascs
Copy link

Hey @ochafik . I do have an open pr for the Java sdk with Webflux
#439

Does it make sense to have a second example here ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants