This service provides basic calculator operations through the Model Context Protocol (MCP) using Spring Boot with WebFlux transport. It's designed as a simple example for beginners learning about MCP implementations.
For more information, see the MCP Server Boot Starter reference documentation.
The service exposes the following API endpoints through the MCP protocol:
add(a, b): Add two numbers togethersubtract(a, b): Subtract the second number from the firstmultiply(a, b): Multiply two numbersdivide(a, b): Divide the first number by the second (with zero check)power(base, exponent): Calculate the power of a numbersquareRoot(number): Calculate the square root (with negative number check)modulus(a, b): Calculate the remainder when dividingabsolute(number): Calculate the absolute value
The project requires the following key dependencies:
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-mcp-server-webflux</artifactId>
</dependency>Build the project using Maven:
./mvnw clean install -DskipTestsjava -jar target/calculator-server-0.0.1-SNAPSHOT.jarThe MCP Inspector is a helpful tool for interacting with MCP services. To use it with this calculator service:
-
Install and run MCP Inspector in a new terminal window:
npx @modelcontextprotocol/inspector
-
Access the web UI by clicking the URL displayed by the app (typically http://localhost:6274)
-
Configure the connection:
- Set the transport type to "SSE"
- Set the URL to your running server's SSE endpoint:
http://localhost:8080/sse - Click "Connect"
-
Use the tools:
- Click "List Tools" to see available calculator operations
- Select a tool and click "Run Tool" to execute an operation
