rrezartprebreza/spring-boot-skills / skills/spring-boot-3/mcp-server
mcp-server
VerifiedUse when exposing Spring Boot 3 application capabilities through Model Context Protocol tools, resources, or prompts. Covers Spring AI 1.x tool callback registration, transports, schemas, errors, security, and standalone MCP Java SDK compatibility.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 4.9 KB |
| agents/openai.yaml | config | 186 B |
| examples/OrderMcpTools.java | other | 3.5 KB |
| examples/bad-order-tools.java | other | 195 B |
| examples/good-order-tools.java | other | 263 B |
| templates/mcp.json | config | 535 B |
examples/OrderMcpTools.java
View on GitHubpackage com.example.mcp;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.stereotype.Component;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.UUID;
/**
* MCP tools for Order Service.
* Spring AI 1.x does NOT auto-scan @Tool methods: register this bean through a
* ToolCallbackProvider, e.g. MethodToolCallbackProvider.builder().toolObjects(orderMcpTools).build().
*
* Usage in .mcp.json:
* {
* "mcpServers": {
* "order-service": {
* "command": "java",
* "args": ["-jar", "order-service.jar", "--spring.profiles.active=mcp"]
* }
* }
* }
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class OrderMcpTools {
private final OrderService orderService;
private final ObjectMapper objectMapper;
@Tool(description = "Get a single order by UUID. Returns full order details including line items, status, and timestamps.")
public String getOrder(
@ToolParam(description = "UUID of the order to retrieve") String orderId
) {
try {
Order order = orderService.findById(UUID.fromString(orderId));
return objectMapper.writeValueAsString(OrderResponse.from(order));
} catch (IllegalArgumentException e) {
return errorJson("INVALID_ID", "Not a valid UUID: " + orderId);
} catch (EntityNotFoundException e) {
return errorJson("NOT_FOUND", "Order not found: " + orderId);
} catch (Exception e) {
log.error("getOrder failed for id={}", orderId, e);
return errorJson("INTERNAL_ERROR", "Unexpected error");
}
}
@Tool(description = "List all orders for a customer email. Optionally filter by status: PENDING, CONFIRMED, SHIPPED, DELIVERED, CANCELLED.")
public String listOrders(
@ToolParam(description = "Customer email address") String email,
@ToolParam(description = "Optional status filter", required = false) String status
) {
try {
var orders = status != null
? orderService.findByEmailAndStatus(email, OrderStatus.valueOf(status.toUpperCase()))
: orderService.findByEmail(email);
return objectMapper.writeValueAsString(
orders.stream().map(OrderResponse::from).toList()
);
} catch (IllegalArgumentException e) {
return errorJson("INVALID_STATUS", "Unknown status: " + status +
". Valid values: PENDING, CONFIRMED, SHIPPED, DELIVERED, CANCELLED");
} catch (Exception e) {
log.error("listOrders failed for email={}", email, e);
return errorJson("INTERNAL_ERROR", "Unexpected error");
}
}
@Tool(description = "Get order statistics for a customer: total orders, total spend, orders by status.")
public String getOrderStats(
@ToolParam(description = "Customer email address") String email
) {
try {
OrderStats stats = orderService.getStatsByEmail(email);
return objectMapper.writeValueAsString(stats);
} catch (Exception e) {
log.error("getOrderStats failed for email={}", email, e);
return errorJson("INTERNAL_ERROR", "Unexpected error");
}
}
private String errorJson(String code, String message) {
return String.format("{\"error\":\"%s\",\"message\":\"%s\"}", code, message);
}
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |