@@ -111,15 +111,10 @@ TIPS:
113type SourcegraphParams struct {
113type SourcegraphParams struct {
114− Query string `json:"query"`
114+ Query string `json:"query"`
115− Count int `json:"count,omitempty"`
115+ Count int `json:"count,omitempty"`
116− Timeout int `json:"timeout,omitempty"`
119−type SourcegraphPermissionsParams struct {
120− Query string `json:"query"`
121− Count int `json:"count,omitempty"`
116+ ContextWindow int `json:"context_window,omitempty"`
122− Timeout int `json:"timeout,omitempty"`
117+ Timeout int `json:"timeout,omitempty"`
125type sourcegraphTool struct {
120type sourcegraphTool struct {
@@ -147,6 +142,10 @@ func (t *sourcegraphTool) Info() ToolInfo {
147 "type": "number",
142 "type": "number",
148 "description": "Optional number of results to return (default: 10, max: 20)",
143 "description": "Optional number of results to return (default: 10, max: 20)",
145+ "context_window": map[string]any{
147+ "description": "The context around the match to return (default: 10 lines)",
150 "timeout": map[string]any{
149 "timeout": map[string]any{
151 "type": "number",
150 "type": "number",
152 "description": "Optional timeout in seconds (max 120)",
151 "description": "Optional timeout in seconds (max 120)",
@@ -173,6 +172,9 @@ func (t *sourcegraphTool) Run(ctx context.Context, call ToolCall) (ToolResponse,
173 params.Count = 20 // Limit to 20 results
172 params.Count = 20 // Limit to 20 results
175+ if params.ContextWindow <= 0 {
176+ params.ContextWindow = 10 // Default context window
176 client := t.client
178 client := t.client
177 if params.Timeout > 0 {
179 if params.Timeout > 0 {
178 maxTimeout := 120 // 2 minutes
180 maxTimeout := 120 // 2 minutes
@@ -194,7 +196,7 @@ func (t *sourcegraphTool) Run(ctx context.Context, call ToolCall) (ToolResponse,
196 request := graphqlRequest{
198 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 } } } } } }",
199 request.Variables.Query = params.Query
201 request.Variables.Query = params.Query
@@ -246,7 +248,7 @@ func (t *sourcegraphTool) Run(ctx context.Context, call ToolCall) (ToolResponse,
248 // Format the results in a readable way
250 // Format the results in a readable way
249− formattedResults, err := formatSourcegraphResults(result)
251+ formattedResults, err := formatSourcegraphResults(result, params.ContextWindow)
250 if err != nil {
252 if err != nil {
251 return NewTextErrorResponse("Failed to format results: " + err.Error()), nil
253 return NewTextErrorResponse("Failed to format results: " + err.Error()), nil
@@ -254,7 +256,7 @@ func (t *sourcegraphTool) Run(ctx context.Context, call ToolCall) (ToolResponse,
254 return NewTextResponse(formattedResults), nil
256 return NewTextResponse(formattedResults), nil
257−func formatSourcegraphResults(result map[string]any) (string, error) {
259+func formatSourcegraphResults(result map[string]any, contextWindow int) (string, error) {
258 var buffer strings.Builder
260 var buffer strings.Builder
260 // Check for errors in the GraphQL response
262 // Check for errors in the GraphQL response
@@ -364,8 +366,7 @@ func formatSourcegraphResults(result map[string]any) (string, error) {
364 buffer.WriteString("```\n")
366 buffer.WriteString("```\n")
366 // Display context before the match (up to 10 lines)
368 // Display context before the match (up to 10 lines)
368− startLine := max(1, int(lineNumber)-contextBefore)
369+ startLine := max(1, int(lineNumber)-contextWindow)
370 for j := startLine - 1; j < int(lineNumber)-1 && j < len(lines); j++ {
371 for j := startLine - 1; j < int(lineNumber)-1 && j < len(lines); j++ {
371 if j >= 0 {
372 if j >= 0 {
@@ -377,8 +378,7 @@ func formatSourcegraphResults(result map[string]any) (string, error) {
377 buffer.WriteString(fmt.Sprintf("%d| %s\n", int(lineNumber), preview))
378 buffer.WriteString(fmt.Sprintf("%d| %s\n", int(lineNumber), preview))
379 // Display context after the match (up to 10 lines)
380 // Display context after the match (up to 10 lines)
381− endLine := int(lineNumber) + contextAfter
381+ endLine := int(lineNumber) + contextWindow
383 for j := int(lineNumber); j < endLine && j < len(lines); j++ {
383 for j := int(lineNumber); j < endLine && j < len(lines); j++ {
384 if j < len(lines) {
384 if j < len(lines) {