MCPcopy Create free account
hub / github.com/coder/coder / TestFilterAllowedTools

Function TestFilterAllowedTools

aibridge/mcp/mcp_test.go:29–295  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27}
28
29func 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 {

Callers

nothing calls this directly

Calls 3

FilterAllowedToolsFunction · 0.92
MustCompileMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected