建立会话

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
43
44
45
46
47
48
49
50
51
52
53
sequenceDiagram
participant C as MCP Client / Agent
participant G as McpGatewayController
participant CS as McpSessionService
participant V as VerifyNode
participant SM as SessionManagementService
participant MM as McpMessageService
participant SH as SessionMessageService
participant R as SessionRepository
participant P as SessionPort
participant H as Downstream HTTP Service

C->>G: GET /{gatewayId}/mcp/sse?api_key=xxx
G->>CS: createMcpSession(gatewayId, apiKey)
CS->>V: 校验建链请求
V->>V: 校验 apiKey / license
V->>SM: createSession(gatewayId, apiKey)
SM->>SM: 生成 sessionId
SM->>SM: 创建 SSE sink
SM->>SM: 保存 activeSessions[sessionId]
SM-->>C: SSE event: endpoint\n/{gatewayId}/mcp/sse?sessionId=xxx&api_key=xxx

C->>G: POST /{gatewayId}/mcp/sse?sessionId=xxx&api_key=xxx
Note over C,G: Body 是 JSON-RPC 请求,如 initialize / tools/list / tools/call

G->>MM: handleMessage(command)
MM->>SM: getSession(sessionId)
SM-->>MM: 返回会话配置与 SSE sink

alt initialize
MM->>SH: processHandlerMessage(initialize)
SH->>R: queryMcpGatewayConfigByGatewayId(gatewayId)
R-->>SH: 网关配置
SH-->>MM: JSON-RPC initialize result
else tools/list
MM->>SH: processHandlerMessage(tools/list)
SH->>R: queryMcpGatewayToolConfigListByGatewayId(gatewayId)
R-->>SH: 工具列表 + 参数映射配置
SH-->>MM: JSON-RPC tools list result
else tools/call
MM->>MM: 限流校验
MM->>SH: processHandlerMessage(tools/call)
SH->>R: queryMcpGatewayProtocolConfig(gatewayId, toolName)
R-->>SH: HTTP协议配置
SH->>P: toolCall(httpConfig, arguments)
P->>H: 发起真实 HTTP 请求
H-->>P: 返回业务结果
P-->>SH: HTTP 响应内容
SH-->>MM: JSON-RPC tools call result
end

MM-->>C: 通过 session 对应的 SSE sink 回推 message 事件