@@ -4,13 +4,13 @@ import (
4
4
"bytes"
5
5
"context"
6
6
"fmt"
7
- "k8s.io/klog/v2"
8
7
"net/http"
9
8
"slices"
10
9
11
10
"github.com/mark3labs/mcp-go/mcp"
12
11
"github.com/mark3labs/mcp-go/server"
13
12
authenticationapiv1 "k8s.io/api/authentication/v1"
13
+ "k8s.io/klog/v2"
14
14
"k8s.io/utils/ptr"
15
15
16
16
"github.com/containers/kubernetes-mcp-server/pkg/config"
@@ -19,7 +19,9 @@ import (
19
19
"github.com/containers/kubernetes-mcp-server/pkg/version"
20
20
)
21
21
22
- const TokenScopesContextKey = "TokenScopesContextKey"
22
+ type ContextKey string
23
+
24
+ const TokenScopesContextKey = ContextKey ("TokenScopesContextKey" )
23
25
24
26
type Configuration struct {
25
27
Profile Profile
@@ -202,10 +204,10 @@ func toolScopedAuthorizationMiddleware(next server.ToolHandlerFunc) server.ToolH
202
204
return func (ctx context.Context , ctr mcp.CallToolRequest ) (* mcp.CallToolResult , error ) {
203
205
scopes , ok := ctx .Value (TokenScopesContextKey ).([]string )
204
206
if ! ok {
205
- return NewTextResult ("" , fmt .Errorf ("Authorization failed: Access denied: Tool '%s' requires scope 'mcp:%s' but no scope is available" , ctr .Params .Name , ctr .Params .Name )), nil
207
+ return NewTextResult ("" , fmt .Errorf ("authorization failed: Access denied: Tool '%s' requires scope 'mcp:%s' but no scope is available" , ctr .Params .Name , ctr .Params .Name )), nil
206
208
}
207
209
if ! slices .Contains (scopes , "mcp:" + ctr .Params .Name ) && ! slices .Contains (scopes , ctr .Params .Name ) {
208
- return NewTextResult ("" , fmt .Errorf ("Authorization failed: Access denied: Tool '%s' requires scope 'mcp:%s' but only scopes %s are available" , ctr .Params .Name , ctr .Params .Name , scopes )), nil
210
+ return NewTextResult ("" , fmt .Errorf ("authorization failed: Access denied: Tool '%s' requires scope 'mcp:%s' but only scopes %s are available" , ctr .Params .Name , ctr .Params .Name , scopes )), nil
209
211
}
210
212
return next (ctx , ctr )
211
213
}
0 commit comments