Skip to content

Commit 1bf7b24

Browse files
Move agent info to separate file, add more info
Signed-off-by: Julien Barbot <jubarbot@cisco.com>
1 parent 3fd20cd commit 1bf7b24

File tree

2 files changed

+68
-34
lines changed

2 files changed

+68
-34
lines changed

plugins/agent_bridge.go

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package main
55

66
import (
77
"context"
8-
"encoding/json"
98
"fmt"
109
"io"
1110
"net/http"
@@ -221,39 +220,6 @@ func RewriteQueryToOas(rw http.ResponseWriter, r *http.Request) {
221220
}
222221
}
223222

224-
func processInfo(rw http.ResponseWriter, r *http.Request) {
225-
type Info struct {
226-
Version string `json:"version"`
227-
MCPServers []string `json:"mcp_servers"`
228-
OpenAPIServices []string `json:"openapi_services"`
229-
}
230-
231-
info := Info{
232-
Version: "1.0.0",
233-
MCPServers: []string{},
234-
OpenAPIServices: []string{},
235-
}
236-
237-
for mcpServerName := range mcpConfig {
238-
name := mcpServerName
239-
info.MCPServers = append(info.MCPServers, name)
240-
}
241-
242-
for service := range servicePluginData.PluginServices {
243-
serviceName := service
244-
info.OpenAPIServices = append(info.OpenAPIServices, serviceName)
245-
}
246-
247-
response, err := json.Marshal(info)
248-
if err != nil {
249-
logger.Errorf("[+] Error retrieving info about API Bridge Agent: %s", err)
250-
http.Error(rw, err.Error(), http.StatusInternalServerError)
251-
return
252-
}
253-
254-
rw.WriteHeader(http.StatusOK)
255-
_, _ = rw.Write(response)
256-
}
257223

258224
func RewriteResponseToNl(rw http.ResponseWriter, res *http.Response, req *http.Request) {
259225
_, err := getPluginFromRequest(req)

plugins/agent_info.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright AGNTCY Contributors (https://github.com/agntcy)
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package main
5+
6+
import (
7+
"encoding/json"
8+
"net/http"
9+
)
10+
11+
type MCPToolInfo struct {
12+
Name string `json:"name"`
13+
Description string `json:"description"`
14+
}
15+
16+
type MCPServerInfo struct {
17+
Name string `json:"name"`
18+
Tools []MCPToolInfo `json:"tools"`
19+
}
20+
21+
type OpenAPIServiceInfo struct {
22+
Name string `json:"name"`
23+
}
24+
25+
type Info struct {
26+
Version string `json:"version"`
27+
MCPServers map[string]MCPServerInfo `json:"mcp_servers"`
28+
OpenAPIServices map[string]OpenAPIServiceInfo `json:"openapi_services"`
29+
}
30+
31+
func processInfo(rw http.ResponseWriter, r *http.Request) {
32+
info := Info{
33+
Version: "1.0.0",
34+
MCPServers: map[string]MCPServerInfo{},
35+
OpenAPIServices: map[string]OpenAPIServiceInfo{},
36+
}
37+
38+
for mcpServerName, mcpServer := range mcpConfig {
39+
name := mcpServerName
40+
mcpServerInfo := MCPServerInfo{
41+
Name: name,
42+
Tools: []MCPToolInfo{},
43+
}
44+
for _, tool := range mcpServer.Tools {
45+
mcpServerInfo.Tools = append(mcpServerInfo.Tools, MCPToolInfo{Name: tool.Name, Description: tool.Description})
46+
}
47+
info.MCPServers[name] = mcpServerInfo
48+
}
49+
50+
for service := range servicePluginData.PluginServices {
51+
serviceName := service
52+
53+
openAPIServiceInfo := OpenAPIServiceInfo{
54+
Name: serviceName,
55+
}
56+
info.OpenAPIServices[serviceName] = openAPIServiceInfo
57+
}
58+
59+
response, err := json.MarshalIndent(info, "", " ")
60+
if err != nil {
61+
logger.Errorf("[+] Error retrieving info about API Bridge Agent: %s", err)
62+
http.Error(rw, err.Error(), http.StatusInternalServerError)
63+
return
64+
}
65+
66+
rw.WriteHeader(http.StatusOK)
67+
_, _ = rw.Write(response)
68+
}

0 commit comments

Comments
 (0)