Skip to content

Commit 2faa5c1

Browse files
committed
only register mcp command if SRC_EXPERIMENT_MCP=true
1 parent eedd1e5 commit 2faa5c1

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

cmd/src/mcp.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"flag"
77
"fmt"
8+
"os"
89
"strings"
910

1011
"github.com/sourcegraph/src-cli/internal/api"
@@ -14,11 +15,13 @@ import (
1415
)
1516

1617
func init() {
17-
flagSet := flag.NewFlagSet("mcp", flag.ExitOnError)
18-
commands = append(commands, &command{
19-
flagSet: flagSet,
20-
handler: mcpMain,
21-
})
18+
if os.Getenv("SRC_EXPERIMENT_MCP") == "true" {
19+
flagSet := flag.NewFlagSet("mcp", flag.ExitOnError)
20+
commands = append(commands, &command{
21+
flagSet: flagSet,
22+
handler: mcpMain,
23+
})
24+
}
2225
}
2326
func mcpMain(args []string) error {
2427
fmt.Println("NOTE: This command is still experimental")
@@ -101,6 +104,7 @@ func handleMcpTool(ctx context.Context, client api.Client, tool *mcp.ToolDef, va
101104
if err != nil {
102105
return err
103106
}
107+
defer resp.Body.Close()
104108

105109
output, err := json.MarshalIndent(result, "", " ")
106110
if err != nil {

internal/mcp/mcp_request.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ func ParseToolResponse(resp *http.Response) (map[string]json.RawMessage, error)
7575
return jsonRPCResp.Result.StructuredContent, nil
7676
}
7777
func readSSEResponseData(resp *http.Response) ([]byte, error) {
78-
defer resp.Body.Close()
7978
data, err := io.ReadAll(resp.Body)
8079
if err != nil {
8180
return nil, err

0 commit comments

Comments
 (0)