Skip to content

Commit ba5ee97

Browse files
committed
refactor: switch to stdio-based server and update language configurations
- Modify main.go to use stdio-based server instead of SSE server - Update Go language configuration in types.go with newer image and run command - Simplify installer configuration for code-sandbox-mcp - Add logging for command execution in run_code.go - Adjust Go code running process in tools/run_code.go
1 parent f3a78ea commit ba5ee97

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

src/code-sandbox-mcp/installer/install.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,9 @@ func InstallConfig() error {
6868
Env: map[string]string{},
6969
}
7070
} else {
71-
command = "/usr/bin/env"
7271
config.MCPServers["code-sandbox-mcp"] = MCPServer{
73-
Command: command,
74-
Args: []string{execPath},
72+
Command: execPath,
73+
Args: []string{},
7574
Env: map[string]string{},
7675
}
7776
}

src/code-sandbox-mcp/languages/types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ var SupportedLanguages = map[Language]LanguageConfig{
3232
RunCommand: []string{"python3", "-c"},
3333
},
3434
Go: {
35-
Image: "golang:1.21-alpine",
35+
Image: "docker.io/library/golang:1.23.6-bookworm",
3636
DependencyFiles: []string{"go.mod"},
37-
InstallCommand: []string{"go mod init &&", "go", "mod", "download"},
38-
RunCommand: []string{"go", "run", "."},
37+
InstallCommand: []string{"go mod init &&", "go", "mod", "tidy"},
38+
RunCommand: []string{"go", "run", "main.go"},
3939
},
4040
NodeJS: {
4141
Image: "oven/bun:debian",

src/code-sandbox-mcp/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ func init() {
5353
}
5454

5555
func main() {
56-
port := flag.String("port", "9520", "Port to listen on")
56+
// port := flag.String("port", "9520", "Port to listen on")
5757
flag.Parse()
5858
s := server.NewMCPServer("code-sandbox-mcp", "v1.0.0", server.WithLogging(), server.WithResourceCapabilities(true, true))
59-
sseServer := server.NewSSEServer(s, fmt.Sprintf("http://localhost:%s", *port))
59+
// sseServer := server.NewSSEServer(s, fmt.Sprintf("http://localhost:%s", *port))
6060
// Register a tool to run code in a docker container
6161
runCodeTool := mcp.NewTool("run_code",
6262
mcp.WithDescription(
@@ -113,8 +113,8 @@ func main() {
113113
s.AddTool(runCodeTool, tools.RunCodeSandbox)
114114
s.AddTool(runProjectTool, tools.RunProjectSandbox)
115115

116-
if err := sseServer.Start(fmt.Sprintf(":%s", *port)); err != nil {
117-
fmt.Printf("(sse) Server error: %v\n", err)
116+
if err := server.ServeStdio(s); err != nil {
117+
fmt.Printf("(stdio) Server error: %v", err)
118118
}
119119

120120
}

src/code-sandbox-mcp/tools/run_code.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"fmt"
77
"io"
8+
"log"
89
"os"
910
"path/filepath"
1011
"strings"
@@ -48,7 +49,7 @@ func RunCodeSandbox(ctx context.Context, request mcp.CallToolRequest) (*mcp.Call
4849
escapedCode := strings.ToValidUTF8(code, "")
4950
if parsed == languages.Go {
5051
// For Go, we need to write the code to a file
51-
cmd = []string{"/bin/sh", "-c", "go mod init sandbox && go mod tidy && go run main.go"}
52+
cmd = []string{"go", "run", "main.go"}
5253
} else if parsed == languages.Python {
5354
// For Python leverage something like https://github.com/tliron/py4go to run pipreqs (https://github.com/bndr/pipreqs)
5455
// natively to generate requirements.txt
@@ -62,7 +63,7 @@ func RunCodeSandbox(ctx context.Context, request mcp.CallToolRequest) (*mcp.Call
6263
"progressToken": progressToken,
6364
},
6465
)
65-
66+
log.Println("Running Command: ", cmd)
6667
logs, err := runInDocker(ctx, progressToken, cmd, config.Image, escapedCode, parsed, nil)
6768
server.SendNotificationToClient(
6869
"notifications/progress",
@@ -94,7 +95,6 @@ func runInDocker(ctx context.Context, progressToken mcp.ProgressToken, cmd []str
9495
return "", fmt.Errorf("failed to pull Docker image %s: %w", dockerImage, err)
9596
}
9697
io.Copy(os.Stdout, reader)
97-
9898
// Create container config
9999
config := &container.Config{
100100
Image: dockerImage,

0 commit comments

Comments
 (0)