1 package fr.tiogars.chat.domains.mcp.controllers;
2
3 import fr.tiogars.chat.domains.mcp.models.McpActionRequest;
4 import fr.tiogars.chat.domains.mcp.models.McpActionResponse;
5 import fr.tiogars.chat.domains.mcp.models.McpServiceConfig;
6 import fr.tiogars.chat.domains.mcp.services.McpService;
7 import io.swagger.v3.oas.annotations.Operation;
8 import io.swagger.v3.oas.annotations.tags.Tag;
9 import jakarta.validation.Valid;
10 import org.springframework.http.ResponseEntity;
11 import org.springframework.web.bind.annotation.*;
12
13 import java.util.List;
14
15
16
17
18 @RestController
19 @RequestMapping("/api/mcp/services")
20 @Tag(name = "MCP Services", description = "MCP service management and actions")
21 public class McpServiceController {
22
23 private final McpService mcpService;
24
25 public McpServiceController(McpService mcpService) {
26 this.mcpService = mcpService;
27 }
28
29 @GetMapping
30 @Operation(summary = "List all MCP services", description = "Get all registered MCP service configurations")
31 public ResponseEntity<List<McpServiceConfig>> listServices() {
32 List<McpServiceConfig> services = mcpService.getAllServices();
33 return ResponseEntity.ok(services);
34 }
35
36 @GetMapping("/{serviceId}")
37 @Operation(summary = "Get MCP service configuration", description = "Get configuration for a specific MCP service")
38 public ResponseEntity<McpServiceConfig> getService(@PathVariable String serviceId) {
39 McpServiceConfig config = mcpService.getService(serviceId);
40 if (config == null) {
41 return ResponseEntity.notFound().build();
42 }
43 return ResponseEntity.ok(config);
44 }
45
46 @PostMapping
47 @Operation(summary = "Register MCP service", description = "Register a new MCP service configuration")
48 public ResponseEntity<McpServiceConfig> registerService(@Valid @RequestBody McpServiceConfig config) {
49 McpServiceConfig registered = mcpService.registerService(config);
50 return ResponseEntity.ok(registered);
51 }
52
53 @PostMapping("/{serviceId}/actions")
54 @Operation(summary = "Execute MCP action", description = "Execute an action on a specific MCP service")
55 public ResponseEntity<McpActionResponse> executeAction(
56 @PathVariable String serviceId,
57 @Valid @RequestBody McpActionRequest request
58 ) {
59
60 McpActionRequest updatedRequest = new McpActionRequest(
61 serviceId,
62 request.action(),
63 request.parameters()
64 );
65 McpActionResponse response = mcpService.executeAction(updatedRequest);
66 return ResponseEntity.ok(response);
67 }
68 }