Fix: API forwarding header setting failure issue

This commit is contained in:
Liujian
2025-04-14 10:19:49 +08:00
parent 4beb497032
commit 741bdd682c
5 changed files with 41 additions and 14 deletions
+19 -2
View File
@@ -64,8 +64,25 @@ func (t *Tool) RegisterMCP(s *server.MCPServer) {
body := ""
for k, v := range request.Params.Arguments {
if k == "Body" {
tmp, _ := json.Marshal(v)
body = string(tmp)
switch a := v.(type) {
case string:
body = a
case map[string]interface{}:
switch t.contentType {
case "application/json":
tmp, _ := json.Marshal(a)
body = string(tmp)
case "application/x-www-form-urlencoded":
bodyValue := url.Values{}
for kk, vv := range a {
bodyValue.Set(kk, fmt.Sprintf("%v", vv))
}
body = bodyValue.Encode()
}
default:
tmp, _ := json.Marshal(a)
body = string(tmp)
}
continue
}
tmp, ok := v.(map[string]interface{})
+6
View File
@@ -159,6 +159,7 @@ func (m *imlPublishModule) getProjectRelease(ctx context.Context, projectID stri
return &gateway.ProxyHeader{
Key: h.Key,
Value: h.Value,
Opt: h.OptType,
}
})
apiInfo.Retry = proxy.Retry
@@ -633,12 +634,17 @@ func (i *imlPublishModule) updateMCPServer(ctx context.Context, sid string, name
if err != nil {
return err
}
//switch a.ContentType {
//case "application/json":
switch tmp.Type {
case "object":
toolOptions = append(toolOptions, mcp.WithObject(mcp_server.MCPBody, mcp.Properties(tmp.Properties), mcp.Description("request body,it is avalible when method is POST、PUT、PATCH.")))
case "array":
toolOptions = append(toolOptions, mcp.WithArray(mcp_server.MCPBody, mcp.Items(tmp.Items), mcp.Description("request body,it is avalible when method is POST、PUT、PATCH.")))
}
//case "application/x-www-form-urlencoded":
// toolOptions = append(toolOptions, mcp.WithString(mcp_server.MCPBody, mcp.Items(tmp.Items), mcp.Description("request body,it is avalible when method is POST、PUT、PATCH.")))
}
tools = append(tools, mcp_server.NewTool(a.Summary, a.Path, a.Method, a.ContentType, toolOptions...))
}
+4 -3
View File
@@ -80,9 +80,10 @@ func ToServiceProxy(proxy *InputProxy) *api.Proxy {
}
headers := utils.SliceToSlice(proxy.Headers, func(h *Header) *api.Header {
return &api.Header{
Key: h.Key,
Value: h.Value,
Opt: h.Opt,
Key: h.Key,
Value: h.Value,
Opt: h.Opt,
OptType: h.OptType,
}
})
+8 -6
View File
@@ -84,9 +84,10 @@ func FromServiceProxy(proxy *api.Proxy) *Proxy {
Retry: proxy.Retry,
Headers: utils.SliceToSlice(proxy.Headers, func(header *api.Header) *Header {
return &Header{
Key: header.Key,
Value: header.Value,
Opt: header.Opt,
Key: header.Key,
Value: header.Value,
Opt: header.Opt,
OptType: header.OptType,
}
}),
Extends: proxy.Extends,
@@ -104,9 +105,10 @@ type Proxy struct {
}
type Header struct {
Key string `json:"key"`
Value string `json:"value"`
Opt string `json:"opt"`
Key string `json:"key"`
Value string `json:"value"`
Opt string `json:"opt"`
OptType string `json:"optType"`
}
type Export struct {
+4 -3
View File
@@ -144,9 +144,10 @@ type Proxy struct {
}
type Header struct {
Key string `json:"key"`
Value string `json:"value"`
Opt string `json:"opt"`
Key string `json:"key"`
Value string `json:"value"`
Opt string `json:"opt"`
OptType string `json:"opt_type"`
}
type Router struct {