package com.zy.ai.controller;
|
|
import com.core.annotations.ManagerAuth;
|
import com.core.common.R;
|
import com.zy.ai.entity.AiMcpMount;
|
import com.zy.ai.mcp.service.SpringAiMcpToolManager;
|
import com.zy.ai.service.AiMcpMountService;
|
import com.zy.common.web.BaseController;
|
import lombok.RequiredArgsConstructor;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RestController;
|
|
@RestController
|
@RequestMapping("/ai/mcp/mount")
|
@RequiredArgsConstructor
|
public class AiMcpMountController extends BaseController {
|
|
private final AiMcpMountService aiMcpMountService;
|
private final SpringAiMcpToolManager springAiMcpToolManager;
|
|
@GetMapping("/types/auth")
|
@ManagerAuth
|
public R types() {
|
return R.ok(aiMcpMountService.listSupportedTransportTypes());
|
}
|
|
@GetMapping("/list/auth")
|
@ManagerAuth
|
public R list() {
|
return R.ok(aiMcpMountService.listOrdered());
|
}
|
|
@GetMapping("/toolList/auth")
|
@ManagerAuth
|
public R toolList() {
|
return R.ok(springAiMcpToolManager.listTools());
|
}
|
|
@PostMapping("/save/auth")
|
@ManagerAuth
|
public R save(@RequestBody AiMcpMount mount) {
|
try {
|
AiMcpMount saved = aiMcpMountService.saveMount(mount);
|
springAiMcpToolManager.evictCache();
|
return R.ok(saved);
|
} catch (IllegalArgumentException e) {
|
return R.error(e.getMessage());
|
}
|
}
|
|
@PostMapping("/delete/auth")
|
@ManagerAuth
|
public R delete(@RequestParam("id") Long id) {
|
try {
|
boolean deleted = aiMcpMountService.deleteMount(id);
|
springAiMcpToolManager.evictCache();
|
return R.ok(deleted);
|
} catch (IllegalArgumentException e) {
|
return R.error(e.getMessage());
|
}
|
}
|
|
@PostMapping("/refresh/auth")
|
@ManagerAuth
|
public R refresh() {
|
springAiMcpToolManager.evictCache();
|
return R.ok(springAiMcpToolManager.listTools());
|
}
|
|
@PostMapping("/test/auth")
|
@ManagerAuth
|
public R test(@RequestBody AiMcpMount mount) {
|
try {
|
java.util.Map<String, Object> result = springAiMcpToolManager.testMount(aiMcpMountService.prepareMountDraft(mount));
|
if (mount != null && mount.getId() != null) {
|
aiMcpMountService.recordTestResult(mount.getId(),
|
Boolean.TRUE.equals(result.get("ok")),
|
String.valueOf(result.get("message")));
|
}
|
return R.ok(result);
|
} catch (IllegalArgumentException e) {
|
return R.error(e.getMessage());
|
}
|
}
|
|
@PostMapping("/initDefaults/auth")
|
@ManagerAuth
|
public R initDefaults() {
|
int changed = aiMcpMountService.initDefaultsIfMissing();
|
springAiMcpToolManager.evictCache();
|
return R.ok(changed);
|
}
|
}
|