Spaces:
Build error
Build error
Fix: Corrected import path in main.go
Browse filesUpdated import path from github.com/mark3labs/mcp-go to github.com/mark3labs/mcp-go/mcp to fix build issue
- cmd/github-mcp-server/main.go +104 -104
cmd/github-mcp-server/main.go
CHANGED
|
@@ -1,114 +1,114 @@
|
|
| 1 |
package main
|
| 2 |
|
| 3 |
import (
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
)
|
| 18 |
|
| 19 |
const (
|
| 20 |
-
|
| 21 |
-
|
| 22 |
)
|
| 23 |
|
| 24 |
func main() {
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
}
|
|
|
|
| 1 |
package main
|
| 2 |
|
| 3 |
import (
|
| 4 |
+
"bytes"
|
| 5 |
+
"context"
|
| 6 |
+
"fmt"
|
| 7 |
+
"io"
|
| 8 |
+
"log"
|
| 9 |
+
"net/http"
|
| 10 |
+
"os"
|
| 11 |
+
"os/exec"
|
| 12 |
+
"time"
|
| 13 |
+
|
| 14 |
+
"github.com/mark3labs/mcp-go/mcp" // Fixed import path
|
| 15 |
+
"github.com/mark3labs/mcp-go/mcp/protocol"
|
| 16 |
+
"github.com/spf13/viper"
|
| 17 |
)
|
| 18 |
|
| 19 |
const (
|
| 20 |
+
defaultPort = "8080"
|
| 21 |
+
defaultTimeoutSeconds = 60
|
| 22 |
)
|
| 23 |
|
| 24 |
func main() {
|
| 25 |
+
// Initialize configuration
|
| 26 |
+
viper.SetDefault("port", defaultPort)
|
| 27 |
+
viper.SetDefault("timeout_seconds", defaultTimeoutSeconds)
|
| 28 |
+
viper.AutomaticEnv()
|
| 29 |
+
|
| 30 |
+
port := viper.GetString("port")
|
| 31 |
+
timeoutSeconds := viper.GetInt("timeout_seconds")
|
| 32 |
+
|
| 33 |
+
// Create HTTP server
|
| 34 |
+
httpServer := &http.Server{
|
| 35 |
+
Addr: ":" + port,
|
| 36 |
+
Handler: nil, // Will be set later
|
| 37 |
+
ReadTimeout: 5 * time.Second,
|
| 38 |
+
WriteTimeout: 10 * time.Second,
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
// Create a context with timeout
|
| 42 |
+
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeoutSeconds)*time.Second)
|
| 43 |
+
defer cancel()
|
| 44 |
+
|
| 45 |
+
// Start the server
|
| 46 |
+
log.Printf("Starting server on port %s with timeout %d seconds", port, timeoutSeconds)
|
| 47 |
+
|
| 48 |
+
// Handle JSON-RPC requests
|
| 49 |
+
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
| 50 |
+
// Set CORS headers
|
| 51 |
+
w.Header().Set("Access-Control-Allow-Origin", "*")
|
| 52 |
+
w.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS")
|
| 53 |
+
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
| 54 |
+
|
| 55 |
+
// Handle preflight requests
|
| 56 |
+
if r.Method == "OPTIONS" {
|
| 57 |
+
w.WriteHeader(http.StatusOK)
|
| 58 |
+
return
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
// Only handle POST requests
|
| 62 |
+
if r.Method != "POST" {
|
| 63 |
+
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
| 64 |
+
return
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
// Read the request body
|
| 68 |
+
body, err := io.ReadAll(r.Body)
|
| 69 |
+
if err != nil {
|
| 70 |
+
http.Error(w, "Error reading request body", http.StatusBadRequest)
|
| 71 |
+
return
|
| 72 |
+
}
|
| 73 |
+
defer r.Body.Close()
|
| 74 |
+
|
| 75 |
+
// Log the incoming request
|
| 76 |
+
log.Printf("Received request: %s", string(body))
|
| 77 |
+
|
| 78 |
+
// Create a subprocess to handle the request
|
| 79 |
+
cmd := exec.CommandContext(ctx, "/usr/local/bin/github-mcp-server")
|
| 80 |
+
cmd.Stdin = bytes.NewReader(body)
|
| 81 |
+
cmd.Stdout = w
|
| 82 |
+
cmd.Stderr = os.Stderr
|
| 83 |
+
|
| 84 |
+
// Start the subprocess
|
| 85 |
+
log.Printf("Starting subprocess: /usr/local/bin/github-mcp-server")
|
| 86 |
+
if err := cmd.Start(); err != nil {
|
| 87 |
+
log.Printf("Error starting subprocess: %v", err)
|
| 88 |
+
http.Error(w, "Error starting subprocess", http.StatusInternalServerError)
|
| 89 |
+
return
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
// Wait for the subprocess to complete
|
| 93 |
+
log.Printf("Waiting for subprocess to complete")
|
| 94 |
+
if err := cmd.Wait(); err != nil {
|
| 95 |
+
log.Printf("Subprocess error: %v", err)
|
| 96 |
+
// Check if it's a timeout error
|
| 97 |
+
if ctx.Err() == context.DeadlineExceeded {
|
| 98 |
+
log.Printf("Subprocess timed out after %d seconds", timeoutSeconds)
|
| 99 |
+
http.Error(w, "Subprocess timed out", http.StatusRequestTimeout)
|
| 100 |
+
return
|
| 101 |
+
}
|
| 102 |
+
http.Error(w, "Subprocess error", http.StatusInternalServerError)
|
| 103 |
+
return
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
log.Printf("Subprocess completed successfully")
|
| 107 |
+
})
|
| 108 |
+
|
| 109 |
+
// Start the HTTP server
|
| 110 |
+
log.Printf("Server listening on port %s", port)
|
| 111 |
+
if err := httpServer.ListenAndServe(); err != nil {
|
| 112 |
+
log.Fatalf("Failed to start server: %v", err)
|
| 113 |
+
}
|
| 114 |
}
|