@@ -68,3 +68,68 @@ func TestReadfile_NoAccess(t *testing.T) {
6868assert .True (t , result .IsError )
6969assert .Contains (t , fmt .Sprint (result .Content [0 ]), "access denied - path outside allowed directories" )
7070}
71+
72+ func TestSearchFiles_Pattern (t * testing.T ) {
73+
74+ // setting up test folder
75+ // tmpDir/
76+ // - foo/
77+ // - bar.h
78+ // - test.c
79+ // - test.h
80+ // - test.c
81+
82+ dir := t .TempDir ()
83+ test_h := filepath .Join (dir , "test.h" )
84+ err := os .WriteFile (test_h , []byte ("foo" ), 0644 )
85+ require .NoError (t , err )
86+
87+ test_c := filepath .Join (dir , "test.c" )
88+ err = os .WriteFile (test_c , []byte ("foo" ), 0644 )
89+ require .NoError (t , err )
90+
91+ fooDir := filepath .Join (dir , "foo" )
92+ err = os .MkdirAll (fooDir , 0755 )
93+ require .NoError (t , err )
94+
95+ foo_bar_h := filepath .Join (fooDir , "bar.h" )
96+ err = os .WriteFile (foo_bar_h , []byte ("foo" ), 0644 )
97+ require .NoError (t , err )
98+
99+ foo_test_c := filepath .Join (fooDir , "test.c" )
100+ err = os .WriteFile (foo_test_c , []byte ("foo" ), 0644 )
101+ require .NoError (t , err )
102+
103+ handler , err := NewFilesystemHandler ([]string {dir })
104+ require .NoError (t , err )
105+
106+ tests := []struct {
107+ info string
108+ pattern string
109+ matches []string
110+ }{
111+ {info : "use placeholder with extension" , pattern : "*.h" , matches : []string {test_h , foo_bar_h }},
112+ {info : "use placeholder with name" , pattern : "test.*" , matches : []string {test_h , test_c }},
113+ {info : "same filename" , pattern : "test.c" , matches : []string {test_c , foo_test_c }},
114+ }
115+
116+ for _ , test := range tests {
117+ t .Run (test .info , func (t * testing.T ) {
118+ request := mcp.CallToolRequest {}
119+ request .Params .Name = "search_files"
120+ request .Params .Arguments = map [string ]any {
121+ "path" : dir ,
122+ "pattern" : test .pattern ,
123+ }
124+
125+ result , err := handler .handleSearchFiles (context .Background (), request )
126+ require .NoError (t , err )
127+ assert .False (t , result .IsError )
128+ assert .Len (t , result .Content , 1 )
129+
130+ for _ , match := range test .matches {
131+ assert .Contains (t , result .Content [0 ].(mcp.TextContent ).Text , match )
132+ }
133+ })
134+ }
135+ }
0 commit comments