A minimal Java MCP server that performs math operations with an interactive calculator UI. Demonstrates the MCP Java SDK with Spring Boot WebFlux and Streamable HTTP transport.
This server uses HTTP transport only (no stdio). Add to your MCP client configuration:
{
"mcpServers": {
"calculator": {
"url": "http://localhost:3001/mcp"
}
}
}To test local modifications, first clone the repository and start the server:
git clone https://github.com/modelcontextprotocol/ext-apps.git
cd ext-apps/examples/basic-server-java-webflux
./mvnw spring-boot:runThen configure your MCP client to connect to http://localhost:3001/mcp.
- Four basic operations: add, subtract, multiply, divide
- Interactive calculator view using ext-apps SDK
- Division by zero error handling
- Structured content metadata for UI integration
- Dark mode support
- Three MCP prompts for guided interactions
- Java 17+ (
java -version) - No global Maven needed (Maven wrapper included)
-
Start the server:
./mvnw spring-boot:run # → Calculator listening on http://localhost:3001/mcp -
View using the
basic-hostexample or another MCP Apps-compatible host.
PORT=3120 ./mvnw spring-boot:runhttp://host.docker.internal:3001/mcp
Perform a math operation on two numbers. Supports add, subtract, multiply, and divide.
| Parameter | Type | Default | Description |
|---|---|---|---|
operation |
string | (required) | Math operation: add, subtract, multiply, divide |
a |
number | (required) | First operand |
b |
number | (required) | Second operand |
Basic addition:
{ "operation": "add", "a": 5, "b": 3 }Decimal multiplication:
{ "operation": "multiply", "a": 3.14, "b": 2 }Division by zero (returns error):
{ "operation": "divide", "a": 10, "b": 0 }| Prompt | Description | Arguments |
|---|---|---|
quick-calc |
Evaluate a math expression step by step | expression |
compare-numbers |
Compare two numbers using all four operations | a, b |
percentage |
Calculate percentages | question |
Four Spring components wired via McpConfig:
McpConfig- ConfiguresWebFluxStreamableServerTransportProvider,RouterFunction, andMcpSyncServerwith tools, resources, and promptsCalculatorTools- Tool definition with UI metadata and calculation handlerCalculatorResources- Serves the interactive HTML view as an MCP resource with CSP metadataCalculatorPrompts- Three guided prompts for common calculation patterns
Vanilla JavaScript UI that:
- Loads the MCP Apps SDK from CDN (
@modelcontextprotocol/ext-apps) - Provides number inputs and operation buttons
- Calls
app.callServerTool()on button click - Displays results from
ontoolresultcallback andstructuredContentmetadata - Adapts to dark mode via
prefers-color-scheme
src/main/java/.../McpConfig.java- Spring configuration with WebFlux transportsrc/main/java/.../CalculatorTools.java- Tool definition and handlersrc/main/java/.../CalculatorResources.java- HTML resource with CSPsrc/main/java/.../CalculatorPrompts.java- MCP promptssrc/main/resources/view.html- Interactive calculator UI
- Spring Boot 3.5 - WebFlux reactive web framework
- MCP Java SDK 0.17.2 (
io.modelcontextprotocol.sdk:mcp-spring-webflux) - Streamable HTTP transport - ext-apps SDK (CDN) - Client-side MCP Apps protocol in
view.html
- This example uses HTTP transport only (Streamable HTTP via WebFlux). Stdio transport is not supported.
- The server uses Netty (via WebFlux) instead of Tomcat for non-blocking request handling.
- CSP metadata is declared on content items in
resources/readto allow loading the ext-apps SDK fromunpkg.com.
MIT