Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cmd/thv/app/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ var (

// Network isolation flag
runIsolateNetwork bool

// Tool filtering flag
runTools []string
)

func init() {
Expand Down Expand Up @@ -225,6 +228,10 @@ func init() {
runCmd.Flags().BoolVar(&runIsolateNetwork, "isolate-network", false,
"Isolate the container network from the host (default: false)")

// Tool filtering flag
runCmd.Flags().StringArrayVar(&runTools, "tools", []string{},
"Comma-separated list of tools to enable (e.g., --tools=weather,calculator). If not specified, all tools are enabled.")

}

func getOidcFromFlags(cmd *cobra.Command) (string, string, string, string, bool, error) {
Expand Down Expand Up @@ -383,6 +390,7 @@ func runCmdFunc(cmd *cobra.Command, args []string) error {
runThvCABundle,
runJWKSAuthTokenFile,
runJWKSAllowPrivateIP,
runTools,
envVarValidator,
types.ProxyMode(runProxyMode),
)
Expand Down
1 change: 1 addition & 0 deletions docs/cli/thv_run.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions pkg/authz/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ var MCPMethodToFeatureOperation = map[string]struct {
"initialize": {Feature: "", Operation: ""}, // Always allowed
}

// shouldSkipInitialAuthorization checks if the request should skip authorization
// before reading the request body.
func shouldSkipInitialAuthorization(r *http.Request) bool {
// shouldSkip checks if the request should skip authorization
func shouldSkip(r *http.Request) bool {
// Skip authorization for non-POST requests and non-JSON content types
if r.Method != http.MethodPost || !strings.HasPrefix(r.Header.Get("Content-Type"), "application/json") {
return true
Expand Down Expand Up @@ -138,7 +137,7 @@ func handleUnauthorized(w http.ResponseWriter, msgID interface{}, err error) {
func (a *CedarAuthorizer) Middleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Check if we should skip authorization before checking parsed data
if shouldSkipInitialAuthorization(r) {
if shouldSkip(r) {
next.ServeHTTP(w, r)
return
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/authz/templates/tool_filtering_policy.cedar
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Tool filtering policy template
// This policy allows access to specific tools based on the --tools flag
// The tools are interpolated into this template at runtime

// Allow access to specific tools only{{range .Tools}}
permit(principal, action == Action::"call_tool", resource == Tool::"{{.}}");{{end}}

// Allow listing of tools (for tools/list operations)
permit(principal, action == Action::"list_tools", resource == FeatureType::"tool");
Loading
Loading