feat(mcp-server): add mcp-server config (#24354)

* feat(mcp-server): add mcp-server config

* fix(mcp-agent): add claude mcp-server-config
This commit is contained in:
cwz_eikoh
2026-03-03 16:06:07 +08:00
committed by GitHub
parent 700ba69483
commit efea8bdbf7
2 changed files with 43 additions and 0 deletions
+40
View File
@@ -2,6 +2,7 @@ package handler
import (
"context"
"encoding/json"
"fmt"
"io"
"net/http"
@@ -10,13 +11,52 @@ import (
"yunion.io/x/log"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/util/httputils"
"yunion.io/x/onecloud/pkg/apigateway/options"
"yunion.io/x/onecloud/pkg/appsrv"
"yunion.io/x/onecloud/pkg/httperrors"
"yunion.io/x/onecloud/pkg/mcclient/auth"
modules "yunion.io/x/onecloud/pkg/mcclient/modules/llm"
mcpServerOption "yunion.io/x/onecloud/pkg/mcp-server/options"
)
func mcpServersConfigHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) {
serviceName := "mcp-server"
url, err := auth.GetPublicServiceURL(serviceName, options.Options.Region, "", httputils.GET)
if err != nil {
log.Warningf("GetPublicServiceURL for %s failed: %v", serviceName, err)
}
sseURL := fmt.Sprintf("%s/sse", url)
responseType := r.URL.Query().Get("type")
switch responseType {
case "claude":
cmd := fmt.Sprintf("claude mcp add --transport sse %s --header \"X-API-Key: your-key-here\"", sseURL)
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
w.Write([]byte(cmd))
return
case "cursor":
// fall through to JSON
default:
// default: return JSON (cursor format)
}
config := map[string]interface{}{
"mcpServers": map[string]interface{}{
mcpServerOption.Options.MCPServerName: map[string]interface{}{
"url": sseURL,
"headers": map[string]string{
"AK": "value",
"SK": "value",
},
},
},
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(config)
}
func chatHandlerInfo(method, prefix string, handler func(context.Context, http.ResponseWriter, *http.Request)) *appsrv.SHandlerInfo {
log.Debugf("%s - %s", method, prefix)
hi := appsrv.SHandlerInfo{}
+3
View File
@@ -114,6 +114,9 @@ func (h *MiscHandler) Bind(app *appsrv.Application) {
app.AddHandler(POST, prefix+"syslog/message", handleSyslogWebServiceMessage)
// service settings
app.AddHandler(GET, prefix+"service_settings", h.getServiceSettings)
// mcp servers config
app.AddHandler(GET, prefix+"mcp-servers-config", mcpServersConfigHandler)
}
func UploadHandlerInfo(method, prefix string, handler func(context.Context, http.ResponseWriter, *http.Request)) *appsrv.SHandlerInfo {