Skip to content

Commit c755dd2

Browse files
authored
Create http_proxy.go
1 parent b5e3348 commit c755dd2

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

http_proxy.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package main
2+
3+
import (
4+
"io"
5+
"log"
6+
"net/http"
7+
"os/exec"
8+
"sync"
9+
)
10+
11+
func main() {
12+
cmd := exec.Command("./github-mcp-server", "stdio")
13+
stdin, err := cmd.StdinPipe()
14+
if err != nil {
15+
log.Fatal(err)
16+
}
17+
stdout, err := cmd.StdoutPipe()
18+
if err != nil {
19+
log.Fatal(err)
20+
}
21+
22+
if err := cmd.Start(); err != nil {
23+
log.Fatal(err)
24+
}
25+
26+
var mu sync.Mutex
27+
28+
http.HandleFunc("/mcp", func(w http.ResponseWriter, r *http.Request) {
29+
mu.Lock()
30+
defer mu.Unlock()
31+
32+
// Forward request body to MCP stdin
33+
_, err := io.Copy(stdin, r.Body)
34+
if err != nil {
35+
http.Error(w, "Failed to write to MCP server", 500)
36+
return
37+
}
38+
r.Body.Close()
39+
40+
// Read response from MCP stdout and copy to response
41+
_, err = io.Copy(w, stdout)
42+
if err != nil {
43+
http.Error(w, "Failed to read from MCP server", 500)
44+
return
45+
}
46+
})
47+
48+
log.Println("HTTP MCP proxy listening on :8080")
49+
log.Fatal(http.ListenAndServe(":8080", nil))
50+
}

0 commit comments

Comments
 (0)