#AI
zhou zhou
11 小时以前 51877df13075ad10ef51107f15bcd21f1661febe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.vincent.rsf.server.api.controller.mcp;
 
import com.fasterxml.jackson.databind.JsonNode;
import com.vincent.rsf.server.ai.service.mcp.AiMcpProtocolService;
import com.vincent.rsf.server.system.controller.BaseController;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
@RestController
@RequestMapping("/ai/mcp")
public class AiMcpProtocolController extends BaseController {
 
    @Resource
    private AiMcpProtocolService aiMcpProtocolService;
 
    @PostMapping
    public Object handle(@RequestBody JsonNode body,
                         @RequestHeader(value = "X-Tenant-Id", required = false) String tenantHeader,
                         @RequestParam(value = "tenantId", required = false) Long tenantParam) {
        Long tenantId = resolveTenantId(tenantHeader, tenantParam);
        return aiMcpProtocolService.handle(tenantId, body);
    }
 
    private Long resolveTenantId(String tenantHeader, Long tenantParam) {
        if (tenantParam != null) {
            return tenantParam;
        }
        if (tenantHeader != null && !tenantHeader.trim().isEmpty()) {
            try {
                return Long.valueOf(tenantHeader.trim());
            } catch (Exception ignore) {
            }
        }
        Long loginTenantId = getTenantId();
        return loginTenantId == null ? 1L : loginTenantId;
    }
}