⬆️ Bump cobra-mcp to v0.1.1 and simplify auth config
This commit is contained in:
1 parent
85ce5706ab
commit
36baa174fc
3 files changed
+8
-25
No files matched your search
+5
-22
@@ -9,7 +9,6 @@ import (
|
||||
cobramcp "github.com/eat-pray-ai/cobra-mcp"
|
||||
"github.com/eat-pray-ai/yutu/pkg/auth"
|
||||
"github.com/eat-pray-ai/yutu/pkg/common"
|
||||
"github.com/modelcontextprotocol/go-sdk/oauthex"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -29,10 +28,7 @@ var mcpConfig = &cobramcp.Config{
|
||||
|
||||
var Server, mcpCmd = cobramcp.ServerAndCommand(mcpConfig)
|
||||
|
||||
var (
|
||||
mcpAuth bool
|
||||
baseURL string
|
||||
)
|
||||
var mcpAuth bool
|
||||
|
||||
func init() {
|
||||
mcpCmd.Example = example
|
||||
@@ -42,29 +38,16 @@ func init() {
|
||||
&mcpAuth, "auth", "a", false,
|
||||
"Enable MCP OAuth authorization (HTTP mode only)",
|
||||
)
|
||||
mcpCmd.Flags().StringVarP(
|
||||
&baseURL, "baseUrl", "b", "",
|
||||
"Base URL for the MCP server (default http://localhost:<port>)",
|
||||
)
|
||||
|
||||
mcpCmd.PreRunE = func(cmd *cobra.Command, args []string) error {
|
||||
port, _ := cmd.Flags().GetInt("port")
|
||||
|
||||
if mcpAuth {
|
||||
if baseURL == "" {
|
||||
baseURL = fmt.Sprintf("http://localhost:%d", port)
|
||||
}
|
||||
mcpConfig.Auth = &cobramcp.AuthConfig{
|
||||
ResourceMetadata: &oauthex.ProtectedResourceMetadata{
|
||||
Resource: baseURL + "/mcp",
|
||||
AuthorizationServers: []string{"https://accounts.google.com"},
|
||||
ScopesSupported: auth.Scopes,
|
||||
},
|
||||
ResourceMetadataURL: baseURL + "/.well-known/oauth-protected-resource",
|
||||
TokenVerifier: auth.GoogleTokenVerifier,
|
||||
Scopes: auth.Scopes,
|
||||
TokenVerifier: auth.GoogleTokenVerifier,
|
||||
Scopes: auth.Scopes,
|
||||
AuthorizationServers: []string{"https://accounts.google.com"},
|
||||
}
|
||||
} else {
|
||||
port, _ := cmd.Flags().GetInt("port")
|
||||
redirectURL := fmt.Sprintf("http://localhost:%d", port)
|
||||
cmd.SetContext(common.CtxWithRedirectURL(cmd.Context(), redirectURL))
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ module github.com/eat-pray-ai/yutu
|
||||
go 1.26.0
|
||||
|
||||
require (
|
||||
github.com/eat-pray-ai/cobra-mcp v0.1.0
|
||||
github.com/eat-pray-ai/cobra-mcp v0.1.1
|
||||
github.com/google/jsonschema-go v0.4.3
|
||||
github.com/savioxavier/termlink v1.4.3
|
||||
github.com/spf13/cobra v1.10.2
|
||||
|
||||
@@ -23,8 +23,8 @@ github.com/clipperhouse/uax29/v2 v2.7.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJ
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/eat-pray-ai/cobra-mcp v0.1.0 h1:szHIgFhCH0HqWSRRlyVVWzrB+3c9SMNfQCxlKA4lNLo=
|
||||
github.com/eat-pray-ai/cobra-mcp v0.1.0/go.mod h1:45CzaLTw9x2Cq+jN9NblFPj/BscCjMP7yMZkyQru3uM=
|
||||
github.com/eat-pray-ai/cobra-mcp v0.1.1 h1:tRPmQzAsyaPL9skPPAe/pxoYGBZEQTsX5ZtiuOdkjgM=
|
||||
github.com/eat-pray-ai/cobra-mcp v0.1.1/go.mod h1:45CzaLTw9x2Cq+jN9NblFPj/BscCjMP7yMZkyQru3uM=
|
||||
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
|
||||
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
|
||||
Reference in new issue
Block a user