(t *testing.T)
| 27 | } |
| 28 | |
| 29 | func TestFilterAllowedTools(t *testing.T) { |
| 30 | t.Parallel() |
| 31 | |
| 32 | createTools := func(names ...string) map[string]*mcp.Tool { |
| 33 | tools := make(map[string]*mcp.Tool) |
| 34 | for i, name := range names { |
| 35 | id := string(rune('a' + i)) |
| 36 | tools[id] = &mcp.Tool{ |
| 37 | ID: id, |
| 38 | Name: name, |
| 39 | } |
| 40 | } |
| 41 | return tools |
| 42 | } |
| 43 | |
| 44 | mustCompile := func(pattern string) *regexp.Regexp { |
| 45 | if pattern == "" { |
| 46 | return nil |
| 47 | } |
| 48 | return regexp.MustCompile(pattern) |
| 49 | } |
| 50 | |
| 51 | tests := []struct { |
| 52 | name string |
| 53 | tools map[string]*mcp.Tool |
| 54 | allowlist string |
| 55 | denylist string |
| 56 | expected []string |
| 57 | }{ |
| 58 | { |
| 59 | name: "empty tools returns empty", |
| 60 | tools: map[string]*mcp.Tool{}, |
| 61 | allowlist: ".*", |
| 62 | denylist: "", |
| 63 | expected: []string{}, |
| 64 | }, |
| 65 | { |
| 66 | name: "nil allow and deny lists returns all tools", |
| 67 | tools: createTools("tool1", "tool2", "tool3"), |
| 68 | allowlist: "", |
| 69 | denylist: "", |
| 70 | expected: []string{"tool1", "tool2", "tool3"}, |
| 71 | }, |
| 72 | { |
| 73 | name: "allowlist only - match all", |
| 74 | tools: createTools("tool1", "tool2", "tool3"), |
| 75 | allowlist: ".*", |
| 76 | denylist: "", |
| 77 | expected: []string{"tool1", "tool2", "tool3"}, |
| 78 | }, |
| 79 | { |
| 80 | name: "allowlist only - match specific", |
| 81 | tools: createTools("tool1", "tool2", "tool3"), |
| 82 | allowlist: "tool[12]", |
| 83 | denylist: "", |
| 84 | expected: []string{"tool1", "tool2"}, |
| 85 | }, |
| 86 | { |
nothing calls this directly
no test coverage detected