@@ -111,15 +111,10 @@ TIPS:
111111)
112112
113113type SourcegraphParams struct {
114- Query string `json:"query"`
115- Count int `json:"count,omitempty"`
116- Timeout int `json:"timeout,omitempty"`
117- }
118-
119- type SourcegraphPermissionsParams struct {
120- Query string `json:"query"`
121- Count int `json:"count,omitempty"`
122- Timeout int `json:"timeout,omitempty"`
114+ Query string `json:"query"`
115+ Count int `json:"count,omitempty"`
116+ ContextWindow int `json:"context_window,omitempty"`
117+ Timeout int `json:"timeout,omitempty"`
123118}
124119
125120type sourcegraphTool struct {
@@ -147,6 +142,10 @@ func (t *sourcegraphTool) Info() ToolInfo {
147142 "type" : "number" ,
148143 "description" : "Optional number of results to return (default: 10, max: 20)" ,
149144 },
145+ "context_window" : map [string ]any {
146+ "type" : "number" ,
147+ "description" : "The context around the match to return (default: 10 lines)" ,
148+ },
150149 "timeout" : map [string ]any {
151150 "type" : "number" ,
152151 "description" : "Optional timeout in seconds (max 120)" ,
@@ -173,6 +172,9 @@ func (t *sourcegraphTool) Run(ctx context.Context, call ToolCall) (ToolResponse,
173172 params .Count = 20 // Limit to 20 results
174173 }
175174
175+ if params .ContextWindow <= 0 {
176+ params .ContextWindow = 10 // Default context window
177+ }
176178 client := t .client
177179 if params .Timeout > 0 {
178180 maxTimeout := 120 // 2 minutes
@@ -194,7 +196,7 @@ func (t *sourcegraphTool) Run(ctx context.Context, call ToolCall) (ToolResponse,
194196 }
195197
196198 request := graphqlRequest {
197- Query : "query Search($query: String!) { search(query: $query, version: V2, patternType: standard ) { results { matchCount, limitHit, resultCount, approximateResultCount, missing { name }, timedout { name }, indexUnavailable, results { __typename, ... on FileMatch { repository { name }, file { path, url, content }, lineMatches { preview, lineNumber, offsetAndLengths } } } } } }" ,
199+ Query : "query Search($query: String!) { search(query: $query, version: V2, patternType: keyword ) { results { matchCount, limitHit, resultCount, approximateResultCount, missing { name }, timedout { name }, indexUnavailable, results { __typename, ... on FileMatch { repository { name }, file { path, url, content }, lineMatches { preview, lineNumber, offsetAndLengths } } } } } }" ,
198200 }
199201 request .Variables .Query = params .Query
200202
@@ -246,15 +248,15 @@ func (t *sourcegraphTool) Run(ctx context.Context, call ToolCall) (ToolResponse,
246248 }
247249
248250 // Format the results in a readable way
249- formattedResults , err := formatSourcegraphResults (result )
251+ formattedResults , err := formatSourcegraphResults (result , params . ContextWindow )
250252 if err != nil {
251253 return NewTextErrorResponse ("Failed to format results: " + err .Error ()), nil
252254 }
253255
254256 return NewTextResponse (formattedResults ), nil
255257}
256258
257- func formatSourcegraphResults (result map [string ]any ) (string , error ) {
259+ func formatSourcegraphResults (result map [string ]any , contextWindow int ) (string , error ) {
258260 var buffer strings.Builder
259261
260262 // Check for errors in the GraphQL response
@@ -364,8 +366,7 @@ func formatSourcegraphResults(result map[string]any) (string, error) {
364366 buffer .WriteString ("```\n " )
365367
366368 // Display context before the match (up to 10 lines)
367- contextBefore := 10
368- startLine := max (1 , int (lineNumber )- contextBefore )
369+ startLine := max (1 , int (lineNumber )- contextWindow )
369370
370371 for j := startLine - 1 ; j < int (lineNumber )- 1 && j < len (lines ); j ++ {
371372 if j >= 0 {
@@ -377,8 +378,7 @@ func formatSourcegraphResults(result map[string]any) (string, error) {
377378 buffer .WriteString (fmt .Sprintf ("%d| %s\n " , int (lineNumber ), preview ))
378379
379380 // Display context after the match (up to 10 lines)
380- contextAfter := 10
381- endLine := int (lineNumber ) + contextAfter
381+ endLine := int (lineNumber ) + contextWindow
382382
383383 for j := int (lineNumber ); j < endLine && j < len (lines ); j ++ {
384384 if j < len (lines ) {
0 commit comments