Skip to content

Hotfix/april mcp #837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions application/server/execute_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,25 @@ func Test_executeWorkspaceScanCommand_shouldAskForTrust(t *testing.T) {
}, 2*time.Second, time.Millisecond)
}

func Test_executeWorkspaceScanCommand_shouldAcceptScanSourceParam(t *testing.T) {
c := testutil.UnitTest(t)
loc, jsonRPCRecorder := setupServerWithCustomDI(t, c, false)

s := &scanner.TestScanner{}
c.Workspace().AddFolder(workspace.NewFolder(c, "dummy", "dummy", s, di.HoverService(), di.ScanNotifier(), di.Notifier(), di.ScanPersister(), di.ScanStateAggregator()))
// explicitly enable folder trust which is disabled by default in tests
config.CurrentConfig().SetTrustedFolderFeatureEnabled(true)

params := lsp.ExecuteCommandParams{Command: types.WorkspaceScanCommand, Arguments: []any{"LLM"}}
_, err := loc.Client.Call(ctx, "workspace/executeCommand", params)
if err != nil {
t.Fatal(err)
}
assert.Eventually(t, func() bool {
return s.Calls() == 0 && checkTrustMessageRequest(jsonRPCRecorder, c)
}, 2*time.Second, time.Millisecond)
}

func Test_loginCommand_StartsAuthentication(t *testing.T) {
c := testutil.UnitTest(t)
loc, jsonRPCRecorder := setupServer(t, c)
Expand Down
30 changes: 2 additions & 28 deletions application/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (

"github.com/snyk/snyk-ls/domain/snyk"
"github.com/snyk/snyk-ls/domain/snyk/persistence"
mcp2 "github.com/snyk/snyk-ls/internal/mcp"
"github.com/snyk/snyk-ls/internal/storedconfig"

"github.com/snyk/snyk-ls/domain/snyk/scanner"
Expand Down Expand Up @@ -78,25 +77,6 @@ func Start(c *config.Config) {
di.Init()
initHandlers(srv, handlers, c)

// start mcp server
logger.Info().Msg("Starting up MCP Server...")
var mcpServer *mcp2.McpLLMBinding
go func() {
mcpServer = mcp2.NewMcpLLMBinding(c, mcp2.WithScanner(di.Scanner()), mcp2.WithLogger(c.Logger()))
err := mcpServer.Start()
if err != nil {
c.Logger().Err(err).Msg("failed to start mcp server")
}
}()

// shutdown mcp server once the lsp returns from wait status
defer func() {
if mcpServer != nil {
logger.Info().Msg("Shutting down MCP Server...")
mcpServer.Shutdown(context.Background())
}
}()

logger.Info().Msg("Starting up Language Server...")
srv = srv.Start(channel.Header("")(os.Stdin, os.Stdout))
status := srv.WaitStatus()
Expand Down Expand Up @@ -477,14 +457,8 @@ func initializedHandler(c *config.Config, srv *jrpc2.Server) handler.Func {
)
logger.Info().Msg(msg)
}
defer func() {
// delay sending the mcp server URL
for c.GetMCPServerURL() == nil {
// wait until the server URL is available
time.Sleep(500 * time.Millisecond)
}
di.Notifier().Send(types.McpServerURLParams{URL: c.GetMCPServerURL().String()})
}()
// this change is to avoid breaking current stable VS Code. URL value is not used.
di.Notifier().Send(types.McpServerURLParams{URL: "http://127.0.0.1:7695"})
return nil, nil
})
}
Expand Down
39 changes: 0 additions & 39 deletions application/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package server

import (
"context"
"net/url"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -238,44 +237,6 @@ func Test_initialized_shouldCheckRequiredProtocolVersion(t *testing.T) {
"did not receive callback because of wrong protocol version")
}

func Test_initialized_shouldSendMcpServerAddress(t *testing.T) {
c := testutil.UnitTest(t)
loc, jsonRpcRecorder := setupServer(t, c)

params := types.InitializeParams{
InitializationOptions: types.Settings{RequiredProtocolVersion: config.LsProtocolVersion},
}

rsp, err := loc.Client.Call(ctx, "initialize", params)
require.NoError(t, err)
var result types.InitializeResult
err = rsp.UnmarshalResult(&result)
require.NoError(t, err)

testURL, err := url.Parse("http://localhost:1234")
require.NoError(t, err)

c.SetMCPServerURL(testURL)

_, err = loc.Client.Call(ctx, "initialized", params)
require.NoError(t, err)
require.Eventuallyf(t, func() bool {
n := jsonRpcRecorder.FindNotificationsByMethod("$/snyk.mcpServerURL")
if n == nil {
return false
}
if len(n) > 1 {
t.Fatal("can't succeed anymore, too many notifications ", n)
}

var param types.McpServerURLParams
err = n[0].UnmarshalParams(&param)
require.NoError(t, err)
return param.URL == testURL.String()
}, time.Minute*5, time.Millisecond,
"did not receive mcp server url")
}

func Test_initialize_shouldSupportAllCommands(t *testing.T) {
c := testutil.UnitTest(t)
loc, _ := setupServer(t, c)
Expand Down
105 changes: 0 additions & 105 deletions domain/ide/command/execute_mcp_test.go

This file was deleted.

25 changes: 23 additions & 2 deletions domain/ide/command/workspace_scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"

"github.com/snyk/snyk-ls/application/config"
context2 "github.com/snyk/snyk-ls/internal/context"
"github.com/snyk/snyk-ls/internal/types"
)

Expand All @@ -36,7 +37,27 @@ func (cmd *workspaceScanCommand) Command() types.CommandData {
func (cmd *workspaceScanCommand) Execute(ctx context.Context) (any, error) {
w := cmd.c.Workspace()
w.Clear()
w.ScanWorkspace(ctx)
HandleUntrustedFolders(ctx, cmd.c, cmd.srv)
args := cmd.command.Arguments
enrichedCtx := cmd.enrichContextWithScanSource(ctx, args)
w.ScanWorkspace(enrichedCtx)
HandleUntrustedFolders(enrichedCtx, cmd.c, cmd.srv)
return nil, nil
}

func (cmd *workspaceScanCommand) enrichContextWithScanSource(ctx context.Context, args []any) context.Context {
if len(args) == 0 {
return ctx
}

sc, ok := args[0].(string)
if !ok {
return ctx
}

if sc != context2.IDE.String() && sc != context2.LLM.String() {
return ctx
}

scanSource := context2.ScanSource(sc)
return context2.NewContextWithScanSource(ctx, scanSource)
}
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/google/uuid v1.6.0
github.com/gosimple/hashdir v1.0.2
github.com/hexops/gotextdiff v1.0.3
github.com/mark3labs/mcp-go v0.8.4
github.com/mark3labs/mcp-go v0.18.0
github.com/otiai10/copy v1.14.1
github.com/pact-foundation/pact-go v1.10.0
github.com/pingcap/errors v0.11.4
Expand All @@ -27,8 +27,8 @@ require (
github.com/rs/zerolog v1.33.0
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
github.com/shirou/gopsutil v3.21.11+incompatible
github.com/snyk/code-client-go v1.16.2
github.com/snyk/go-application-framework v0.0.0-20250307155453-ce7aaf72fe7d
github.com/snyk/code-client-go v1.20.1
github.com/snyk/go-application-framework v0.0.0-20250325133828-3ffd1aa4f76f
github.com/sourcegraph/go-lsp v0.0.0-20240223163137-f80c5dd31dfd
github.com/spf13/pflag v1.0.6
github.com/stretchr/testify v1.10.0
Expand Down Expand Up @@ -122,6 +122,7 @@ require (
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
golang.org/x/crypto v0.35.0 // indirect
golang.org/x/sys v0.30.0 // indirect
Expand Down
14 changes: 8 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamh
github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4=
github.com/mailru/easyjson v0.9.0/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU=
github.com/mark3labs/mcp-go v0.8.4 h1:/VxjJ0+4oN2eYLuAgVzixrYNfrmwJnV38EfPIX3VbPE=
github.com/mark3labs/mcp-go v0.8.4/go.mod h1:cjMlBU0cv/cj9kjlgmRhoJ5JREdS7YX83xeIG9Ko/jE=
github.com/mark3labs/mcp-go v0.18.0 h1:YuhgIVjNlTG2ZOwmrkORWyPTp0dz1opPEqvsPtySXao=
github.com/mark3labs/mcp-go v0.18.0/go.mod h1:KmJndYv7GIgcPVwEKJjNcbhVQ+hJGJhrCCB/9xITzpE=
github.com/maruel/natural v1.1.1 h1:Hja7XhhmvEFhcByqDoHz9QZbkWey+COd9xWfCfn1ioo=
github.com/maruel/natural v1.1.1/go.mod h1:v+Rfd79xlw1AgVBjbO0BEQmptqb5HvL/k9GRHB7ZKEg=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
Expand Down Expand Up @@ -318,12 +318,12 @@ github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMT
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/skeema/knownhosts v1.3.1 h1:X2osQ+RAjK76shCbvhHHHVl3ZlgDm8apHEHFqRjnBY8=
github.com/skeema/knownhosts v1.3.1/go.mod h1:r7KTdC8l4uxWRyK2TpQZ/1o5HaSzh06ePQNxPwTcfiY=
github.com/snyk/code-client-go v1.16.2 h1:07vMMpl+qUWYz8IJf+13CTL3lRSjKN1TdBk9UDhqxvI=
github.com/snyk/code-client-go v1.16.2/go.mod h1:WH6lNkJc785hfXmwhixxWHix3O6z+1zwz40oK8vl/zg=
github.com/snyk/code-client-go v1.20.1 h1:38nEGzrQIh/aVLjR99jiTUQM0sL9SQAvhMfZGmd9G0w=
github.com/snyk/code-client-go v1.20.1/go.mod h1:WH6lNkJc785hfXmwhixxWHix3O6z+1zwz40oK8vl/zg=
github.com/snyk/error-catalog-golang-public v0.0.0-20250218074309-307ad7b38a60 h1:iB6z2BhBpfN9p0/dEZfwWvs7fpdZk3loooAih8yspS8=
github.com/snyk/error-catalog-golang-public v0.0.0-20250218074309-307ad7b38a60/go.mod h1:Ytttq7Pw4vOCu9NtRQaOeDU2dhBYUyNBe6kX4+nIIQ4=
github.com/snyk/go-application-framework v0.0.0-20250307155453-ce7aaf72fe7d h1:eC0V150YUGvO3mEwXBMELQXzWGHFngxD1Y5fAtzWQC0=
github.com/snyk/go-application-framework v0.0.0-20250307155453-ce7aaf72fe7d/go.mod h1:oWN7a1ud3u5y8HxW+Qdroy+ofEEA8s0MwVAtb8qq/v4=
github.com/snyk/go-application-framework v0.0.0-20250325133828-3ffd1aa4f76f h1:1EPrRhLQ5Bo0SmIqoAU38Et1Bv2klCbyfgLmVJfUyvM=
github.com/snyk/go-application-framework v0.0.0-20250325133828-3ffd1aa4f76f/go.mod h1:A7oFVjMjNukzsMeiIWXEXjCrAf2ARvoK4aQOm9e3E/Y=
github.com/snyk/go-httpauth v0.0.0-20231117135515-eb445fea7530 h1:s9PHNkL6ueYRiAKNfd8OVxlUOqU3qY0VDbgCD1f6WQY=
github.com/snyk/go-httpauth v0.0.0-20231117135515-eb445fea7530/go.mod h1:88KbbvGYlmLgee4OcQ19yr0bNpXpOr2kciOthaSzCAg=
github.com/sourcegraph/go-lsp v0.0.0-20240223163137-f80c5dd31dfd h1:Dq5WSzWsP1TbVi10zPWBI5LKEBDg4Y1OhWEph1wr5WQ=
Expand Down Expand Up @@ -395,6 +395,8 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHo
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
Expand Down
3 changes: 1 addition & 2 deletions infrastructure/code/ai_fix_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,11 @@ func (fixHandler *AiFixHandler) EnrichWithExplain(ctx context.Context, c *config
deepCodeLLMBinding := llm.NewDeepcodeLLMBinding(
llm.WithLogger(c.Logger()),
llm.WithOutputFormat(llm.HTML),
llm.WithEndpoint(getExplainEndpoint(c)),
llm.WithHTTPClient(func() codeClientHTTP.HTTPClient {
return c.Engine().GetNetworkAccess().GetHttpClient()
}),
)
explanations, err := deepCodeLLMBinding.ExplainWithOptions(contextWithCancel, llm.ExplainOptions{RuleKey: issue.GetID(), Diffs: diffs})
explanations, err := deepCodeLLMBinding.ExplainWithOptions(contextWithCancel, llm.ExplainOptions{RuleKey: issue.GetID(), Diffs: diffs, Endpoint: getExplainEndpoint(c)})
if err != nil {
logger.Error().Err(err).Msgf("Failed to explain with explain for issue %s", issue.GetID())
return
Expand Down
Loading