mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-06-12 18:11:34 +08:00
Fix: API forwarding header setting failure issue
This commit is contained in:
+19
-2
@@ -64,8 +64,25 @@ func (t *Tool) RegisterMCP(s *server.MCPServer) {
|
|||||||
body := ""
|
body := ""
|
||||||
for k, v := range request.Params.Arguments {
|
for k, v := range request.Params.Arguments {
|
||||||
if k == "Body" {
|
if k == "Body" {
|
||||||
tmp, _ := json.Marshal(v)
|
switch a := v.(type) {
|
||||||
body = string(tmp)
|
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
|
continue
|
||||||
}
|
}
|
||||||
tmp, ok := v.(map[string]interface{})
|
tmp, ok := v.(map[string]interface{})
|
||||||
|
|||||||
@@ -159,6 +159,7 @@ func (m *imlPublishModule) getProjectRelease(ctx context.Context, projectID stri
|
|||||||
return &gateway.ProxyHeader{
|
return &gateway.ProxyHeader{
|
||||||
Key: h.Key,
|
Key: h.Key,
|
||||||
Value: h.Value,
|
Value: h.Value,
|
||||||
|
Opt: h.OptType,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
apiInfo.Retry = proxy.Retry
|
apiInfo.Retry = proxy.Retry
|
||||||
@@ -633,12 +634,17 @@ func (i *imlPublishModule) updateMCPServer(ctx context.Context, sid string, name
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
//switch a.ContentType {
|
||||||
|
//case "application/json":
|
||||||
switch tmp.Type {
|
switch tmp.Type {
|
||||||
case "object":
|
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.")))
|
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":
|
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.")))
|
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...))
|
tools = append(tools, mcp_server.NewTool(a.Summary, a.Path, a.Method, a.ContentType, toolOptions...))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,9 +80,10 @@ func ToServiceProxy(proxy *InputProxy) *api.Proxy {
|
|||||||
}
|
}
|
||||||
headers := utils.SliceToSlice(proxy.Headers, func(h *Header) *api.Header {
|
headers := utils.SliceToSlice(proxy.Headers, func(h *Header) *api.Header {
|
||||||
return &api.Header{
|
return &api.Header{
|
||||||
Key: h.Key,
|
Key: h.Key,
|
||||||
Value: h.Value,
|
Value: h.Value,
|
||||||
Opt: h.Opt,
|
Opt: h.Opt,
|
||||||
|
OptType: h.OptType,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -84,9 +84,10 @@ func FromServiceProxy(proxy *api.Proxy) *Proxy {
|
|||||||
Retry: proxy.Retry,
|
Retry: proxy.Retry,
|
||||||
Headers: utils.SliceToSlice(proxy.Headers, func(header *api.Header) *Header {
|
Headers: utils.SliceToSlice(proxy.Headers, func(header *api.Header) *Header {
|
||||||
return &Header{
|
return &Header{
|
||||||
Key: header.Key,
|
Key: header.Key,
|
||||||
Value: header.Value,
|
Value: header.Value,
|
||||||
Opt: header.Opt,
|
Opt: header.Opt,
|
||||||
|
OptType: header.OptType,
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
Extends: proxy.Extends,
|
Extends: proxy.Extends,
|
||||||
@@ -104,9 +105,10 @@ type Proxy struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Header struct {
|
type Header struct {
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
Value string `json:"value"`
|
Value string `json:"value"`
|
||||||
Opt string `json:"opt"`
|
Opt string `json:"opt"`
|
||||||
|
OptType string `json:"optType"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Export struct {
|
type Export struct {
|
||||||
|
|||||||
@@ -144,9 +144,10 @@ type Proxy struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Header struct {
|
type Header struct {
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
Value string `json:"value"`
|
Value string `json:"value"`
|
||||||
Opt string `json:"opt"`
|
Opt string `json:"opt"`
|
||||||
|
OptType string `json:"opt_type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Router struct {
|
type Router struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user