This service offers basic calculator functions through the Model Context Protocol (MCP) using Spring Boot with WebFlux transport. It’s designed as a simple example for those new to MCP implementations.
For more details, see the MCP Server Boot Starter reference documentation.
The service provides the following API endpoints via the MCP protocol:
add(a, b): Add two numberssubtract(a, b): Subtract the second number from the firstmultiply(a, b): Multiply two numbersdivide(a, b): Divide the first number by the second (checks for zero)power(base, exponent): Calculate the power of a numbersquareRoot(number): Calculate the square root (checks for negative numbers)modulus(a, b): Calculate the remainder of a divisionabsolute(number): Calculate the absolute value
The project depends on the following key libraries:
<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.jarMCP Inspector is a handy tool for working with MCP services. To use it with this calculator service:
-
Install and start MCP Inspector in a new terminal window:
npx @modelcontextprotocol/inspector
-
Open the web UI by clicking the URL shown by the app (usually http://localhost:6274)
-
Set up the connection:
- Choose "SSE" as the transport type
- Enter your server’s SSE endpoint URL:
http://localhost:8080/sse - Click "Connect"
-
Use the tools:
- Click "List Tools" to view available calculator operations
- Select a tool and click "Run Tool" to perform an operation
Penafian:
Dokumen ini telah diterjemahkan menggunakan perkhidmatan terjemahan AI Co-op Translator. Walaupun kami berusaha untuk ketepatan, sila ambil maklum bahawa terjemahan automatik mungkin mengandungi kesilapan atau ketidaktepatan. Dokumen asal dalam bahasa asalnya harus dianggap sebagai sumber yang sahih. Untuk maklumat penting, terjemahan profesional oleh manusia adalah disyorkan. Kami tidak bertanggungjawab atas sebarang salah faham atau salah tafsir yang timbul daripada penggunaan terjemahan ini.
