Skip to content

Commit d2f09fe

Browse files
Erica177johnlanni
andauthored
fix: refactored mcp server auto discovery logic and fix some issue (#2382)
Co-authored-by: johnlanni <[email protected]>
1 parent 69d877c commit d2f09fe

File tree

15 files changed

+1804
-814
lines changed

15 files changed

+1804
-814
lines changed

api/kubernetes/customresourcedefinitions.gen.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ spec:
250250
registries:
251251
items:
252252
properties:
253+
allowMcpServers:
254+
items:
255+
type: string
256+
type: array
253257
authSecretName:
254258
type: string
255259
consulDatacenter:
@@ -265,12 +269,23 @@ spec:
265269
type: string
266270
enableMCPServer:
267271
type: boolean
272+
enableScopeMcpServers:
273+
type: boolean
268274
mcpServerBaseUrl:
269275
type: string
270276
mcpServerExportDomains:
271277
items:
272278
type: string
273279
type: array
280+
metadata:
281+
additionalProperties:
282+
properties:
283+
innerMap:
284+
additionalProperties:
285+
type: string
286+
type: object
287+
type: object
288+
type: object
274289
nacosAccessKey:
275290
type: string
276291
nacosAddressServer:

api/networking/v1/mcp_bridge.pb.go

Lines changed: 155 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/networking/v1/mcp_bridge.proto

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,11 @@ message RegistryConfig {
7171
repeated string mcpServerExportDomains = 20;
7272
string mcpServerBaseUrl = 21;
7373
google.protobuf.BoolValue enableMCPServer = 22;
74+
google.protobuf.BoolValue enableScopeMcpServers = 23;
75+
repeated string allowMcpServers = 24;
76+
map<string, InnerMap> metadata = 25;
7477
}
78+
79+
message InnerMap {
80+
map<string, string> inner_map = 1;
81+
}

api/networking/v1/mcp_bridge_deepcopy.gen.go

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/networking/v1/mcp_bridge_json.gen.go

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ require (
3131
github.com/hudl/fargo v1.4.0
3232
github.com/mholt/acmez v1.2.0
3333
github.com/nacos-group/nacos-sdk-go v1.0.8
34-
github.com/nacos-group/nacos-sdk-go/v2 v2.1.2
34+
github.com/nacos-group/nacos-sdk-go/v2 v2.3.2
3535
github.com/onsi/gomega v1.27.10
3636
github.com/spf13/cobra v1.8.0
3737
github.com/spf13/pflag v1.0.5
@@ -202,6 +202,7 @@ require (
202202
github.com/spaolacci/murmur3 v1.1.0 // indirect
203203
github.com/spf13/cast v1.5.1 // indirect
204204
github.com/stoewer/go-strcase v1.3.0 // indirect
205+
github.com/stretchr/objx v0.5.0 // indirect
205206
github.com/tetratelabs/wazero v1.7.3 // indirect
206207
github.com/tidwall/match v1.1.1 // indirect
207208
github.com/tidwall/pretty v1.2.0 // indirect
@@ -274,6 +275,5 @@ replace github.com/caddyserver/certmagic => github.com/2456868764/certmagic v1.0
274275

275276
replace (
276277
github.com/dubbogo/gost => github.com/johnlanni/gost v1.11.23-0.20220713132522-0967a24036c6
277-
github.com/nacos-group/nacos-sdk-go/v2 => github.com/luoxiner/nacos-sdk-go/v2 v2.2.9-60
278278
golang.org/x/exp => golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1
279279
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,8 +1434,6 @@ github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhn
14341434
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE=
14351435
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
14361436
github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=
1437-
github.com/luoxiner/nacos-sdk-go/v2 v2.2.9-60 h1:FA/azfz2nSkMc1XR8LeqhcAiA/2/sOMcyBGYCTUc+Cs=
1438-
github.com/luoxiner/nacos-sdk-go/v2 v2.2.9-60/go.mod h1:9FKXl6FqOiVmm72i8kADtbeK71egyG9y3uRDBg41tpQ=
14391437
github.com/lyft/protoc-gen-star v0.6.1/go.mod h1:TGAoBVkt8w7MPG72TrKIu85MIdXwDuzJYeZuUPFPNwA=
14401438
github.com/lyft/protoc-gen-star/v2 v2.0.1/go.mod h1:RcCdONR2ScXaYnQC5tUzxzlpA3WVYF7/opLeUgcQs/o=
14411439
github.com/lyft/protoc-gen-star/v2 v2.0.3/go.mod h1:amey7yeodaJhXSbf/TlLvWiqQfLOSpEk//mLlc+axEk=
@@ -1525,6 +1523,8 @@ github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRW
15251523
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
15261524
github.com/nacos-group/nacos-sdk-go v1.0.8 h1:8pEm05Cdav9sQgJSv5kyvlgfz0SzFUUGI3pWX6SiSnM=
15271525
github.com/nacos-group/nacos-sdk-go v1.0.8/go.mod h1:hlAPn3UdzlxIlSILAyOXKxjFSvDJ9oLzTJ9hLAK1KzA=
1526+
github.com/nacos-group/nacos-sdk-go/v2 v2.3.2 h1:9QB2nCJzT5wkTVlxNYl3XL/7+G6p2USMi2gQh/ouQQo=
1527+
github.com/nacos-group/nacos-sdk-go/v2 v2.3.2/go.mod h1:9FKXl6FqOiVmm72i8kADtbeK71egyG9y3uRDBg41tpQ=
15281528
github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg=
15291529
github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU=
15301530
github.com/nats-io/nats-server/v2 v2.1.2/go.mod h1:Afk+wRZqkMQs/p45uXdrVLuab3gwv3Z8C4HTBu8GD/k=

pkg/ingress/config/ingress_config.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -802,9 +802,20 @@ func (m *IngressConfig) convertDestinationRule(configs []common.WrapperConfig) [
802802
if !exist {
803803
destinationRules[serviceName] = destinationRuleWrapper
804804
} else if dr.DestinationRule.TrafficPolicy != nil {
805-
if dr.DestinationRule.TrafficPolicy.LoadBalancer == nil &&
806-
destinationRuleWrapper.DestinationRule.TrafficPolicy.LoadBalancer != nil {
807-
dr.DestinationRule.TrafficPolicy.LoadBalancer = destinationRuleWrapper.DestinationRule.TrafficPolicy.LoadBalancer
805+
// if the service is referenced by an sse type mcp server, an source ip based consistent hashing policy needs to be configured
806+
// consistent hashing policy will be generated by mcp server watcher, then if service do not have LoadBalancer settings, it will be merged
807+
if destinationRuleWrapper.DestinationRule.TrafficPolicy != nil && destinationRuleWrapper.DestinationRule.TrafficPolicy.LoadBalancer != nil {
808+
if dr.DestinationRule.TrafficPolicy.LoadBalancer == nil {
809+
dr.DestinationRule.TrafficPolicy.LoadBalancer = destinationRuleWrapper.DestinationRule.TrafficPolicy.LoadBalancer
810+
} else if dr.DestinationRule.TrafficPolicy.LoadBalancer.LbPolicy == nil {
811+
dr.DestinationRule.TrafficPolicy.LoadBalancer.LbPolicy = destinationRuleWrapper.DestinationRule.TrafficPolicy.LoadBalancer.LbPolicy
812+
}
813+
}
814+
// if the service is referenced by an https type mcp server, an client side simple mode tls policy needs to be configured
815+
// simple mode tls policy will be generated by mcp server watcher, then if service do not have tls settings, it will be merged
816+
if dr.DestinationRule.TrafficPolicy.Tls == nil && destinationRuleWrapper.DestinationRule.TrafficPolicy != nil &&
817+
destinationRuleWrapper.DestinationRule.TrafficPolicy.Tls != nil {
818+
dr.DestinationRule.TrafficPolicy.Tls = destinationRuleWrapper.DestinationRule.TrafficPolicy.Tls
808819
}
809820
portTrafficPolicy := destinationRuleWrapper.DestinationRule.TrafficPolicy.PortLevelSettings[0]
810821
portUpdated := false

registry/mcp_model.go

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,9 @@ const (
2424
IstioMcpAutoGeneratedHttpRouteName = IstioMcpAutoGeneratedPrefix + "-httproute"
2525
IstioMcpAutoGeneratedMcpServerName = IstioMcpAutoGeneratedPrefix + "-mcpserver"
2626

27-
DefaultMcpToolsGroup = "mcp-tools"
28-
DefaultMcpCredentialsGroup = "credentials"
29-
DefaultNacosServiceNamespace = "public"
30-
3127
StdioProtocol = "stdio"
3228
HttpProtocol = "http"
29+
HttpsProtocol = "https"
3330
DubboProtocol = "dubbo"
3431
McpSSEProtocol = "mcp-sse"
3532
McpStreambleProtocol = "mcp-streamble"
@@ -39,19 +36,19 @@ type McpToolArgsType string
3936

4037
// WasmPluginConfig Struct for mcp tool wasm plugin marshal
4138
type WasmPluginConfig struct {
42-
Rules []*McpServerRule `json:"_rules_"`
39+
Rules []*McpServerRule `json:"_rules_,omitempty"`
4340
}
4441

4542
type McpServerRule struct {
4643
MatchRoute []string `json:"_match_route_,omitempty"`
47-
Server *ServerConfig `json:"server"`
48-
Tools []*McpTool `json:"tools"`
44+
Server *ServerConfig `json:"server,omitempty"`
45+
Tools []*McpTool `json:"tools,omitempty"`
46+
AllowTools []string `json:"allowTools,omitempty"`
4947
}
5048

5149
type ServerConfig struct {
52-
Name string `json:"name,omitempty"`
53-
Config map[string]interface{} `json:"config,omitempty"`
54-
AllowTools []string `json:"allowTools,omitempty"`
50+
Name string `json:"name,omitempty"`
51+
Config map[string]interface{} `json:"config,omitempty"`
5552
}
5653

5754
type McpTool struct {
@@ -144,13 +141,13 @@ type InputSchema struct {
144141
}
145142

146143
type ToolsMeta struct {
147-
InvokeContext map[string]string `json:"InvokeContext,omitempty"`
148-
Enabled bool `json:"Enabled,omitempty"`
149-
Templates map[string]interface{} `json:"Templates,omitempty"`
144+
InvokeContext map[string]string `json:"invokeContext,omitempty"`
145+
Enabled bool `json:"enabled,omitempty"`
146+
Templates map[string]interface{} `json:"templates,omitempty"`
150147
}
151148

152149
type JsonGoTemplate struct {
153-
RequestTemplate RequestTemplate `json:"requestTemplate"`
154-
ResponseTemplate ResponseTemplate `json:"responseTemplate"`
150+
RequestTemplate RequestTemplate `json:"requestTemplate,omitempty"`
151+
ResponseTemplate ResponseTemplate `json:"responseTemplate,omitempty"`
155152
ArgsPosition map[string]string `json:"argsPosition,omitempty"`
156153
}

0 commit comments

Comments
 (0)