File tree 3 files changed +21
-1
lines changed
3 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,9 @@ func main() {
19
19
// example.Example()
20
20
// mcp.RunMCPServer("kom mcp server", "0.0.1", 9096)
21
21
22
+ // SSE调用时,可以在MCP client 请求中,在header中注入认证信息
23
+ // kom执行时,如果注册了callback,那么可以在callback中获取到ctx,从ctx上可以拿到注入的认证信息
24
+ // 有了认证信息,就可以在callback中,进行权限的逻辑控制了
22
25
authKey := "username"
23
26
authRoleKey := "role"
24
27
var ctxFn = func (ctx context.Context , r * http.Request ) context.Context {
@@ -44,6 +47,7 @@ func main() {
44
47
},
45
48
AuthKey : authKey ,
46
49
AuthRoleKey : authRoleKey ,
50
+ Mode : metadata .MCPServerModeBoth , // 同时开启STDIO 和 SSE
47
51
}
48
52
mcp .RunMCPServerWithOption (& cfg )
49
53
}
Original file line number Diff line number Diff line change @@ -22,7 +22,15 @@ type ServerConfig struct {
22
22
Metadata map [string ]string // 元数据
23
23
AuthKey string // 认证key
24
24
AuthRoleKey string // 认证key
25
+ Mode MCPServerMode // 运行模式 sse,stdio
25
26
}
27
+ type MCPServerMode string
28
+
29
+ const (
30
+ MCPServerModeSSE MCPServerMode = "sse"
31
+ MCPServerModeStdio MCPServerMode = "stdio"
32
+ MCPServerModeBoth MCPServerMode = "both"
33
+ )
26
34
27
35
type ResourceInfo struct {
28
36
Group string
Original file line number Diff line number Diff line change @@ -78,12 +78,20 @@ func RunMCPServerWithOption(cfg *metadata.ServerConfig) {
78
78
storageclass .RegisterTools (s , config )
79
79
ingressclass .RegisterTools (s , config )
80
80
yaml .RegisterTools (s , config )
81
+
82
+ if cfg .Mode == metadata .MCPServerModeStdio || cfg .Mode == metadata .MCPServerModeBoth {
83
+ // Start the stdio server
84
+ if err := server .ServeStdio (s ); err != nil {
85
+ fmt .Printf ("Server error: %v\n " , err )
86
+ }
87
+ }
88
+
81
89
// 创建 SSE 服务器
82
90
sseServer := server .NewSSEServer (s , config .SSEOption ... )
83
-
84
91
// 启动服务器
85
92
err := sseServer .Start (fmt .Sprintf (":%d" , config .Port ))
86
93
if err != nil {
87
94
klog .Errorf ("MCP Server error: %v\n " , err )
88
95
}
96
+
89
97
}
You can’t perform that action at this time.
0 commit comments