Skip to content

Commit bc1d212

Browse files
committed
feat: allow path (URI) in baseURL #19
1 parent 58eb38b commit bc1d212

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ toolchain go1.23.7
77
require (
88
github.com/TBXark/confstore v0.0.4
99
github.com/TBXark/optional-go v0.0.1
10-
github.com/mark3labs/mcp-go v0.26.0
10+
github.com/mark3labs/mcp-go v0.28.0
1111
golang.org/x/sync v0.14.0
1212
)
1313

go.sum

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
1414
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
1515
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
1616
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
17-
github.com/mark3labs/mcp-go v0.26.0 h1:xz/Kv1cHLYovF8txv6btBM39/88q3YOjnxqhi51jB0w=
18-
github.com/mark3labs/mcp-go v0.26.0/go.mod h1:rXqOudj/djTORU/ThxYx8fqEVj/5pvTuuebQ2RC7uk4=
17+
github.com/mark3labs/mcp-go v0.24.1 h1:YV+5X/+W4oBdERLWgiA1uR7AIvenlKJaa5V4hqufI7E=
18+
github.com/mark3labs/mcp-go v0.24.1/go.mod h1:rXqOudj/djTORU/ThxYx8fqEVj/5pvTuuebQ2RC7uk4=
19+
github.com/mark3labs/mcp-go v0.28.0 h1:7yl4y5D1KYU2f/9Uxp7xfLIggfunHoESCRbrjcytcLM=
20+
github.com/mark3labs/mcp-go v0.28.0/go.mod h1:rXqOudj/djTORU/ThxYx8fqEVj/5pvTuuebQ2RC7uk4=
1921
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
2022
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
2123
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
@@ -26,6 +28,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
2628
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
2729
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
2830
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
31+
golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610=
32+
golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
2933
golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ=
3034
golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
3135
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

http.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package main
33
import (
44
"context"
55
"errors"
6-
"fmt"
76
"log"
87
"net/http"
8+
"net/url"
99
"os"
1010
"os/signal"
11+
"path"
1112
"strings"
1213
"syscall"
1314
"time"
@@ -72,7 +73,13 @@ func recoverMiddleware(prefix string) MiddlewareFunc {
7273
}
7374
}
7475

75-
func startHTTPServer(config *Config) {
76+
func startHTTPServer(config *Config) error {
77+
78+
baseURL, err := url.Parse(config.McpProxy.BaseURL)
79+
if err != nil {
80+
return err
81+
}
82+
7683
ctx, cancel := context.WithCancel(context.Background())
7784
defer cancel()
7885

@@ -113,7 +120,8 @@ func startHTTPServer(config *Config) {
113120
if len(clientConfig.Options.AuthTokens) > 0 {
114121
middlewares = append(middlewares, newAuthMiddleware(clientConfig.Options.AuthTokens))
115122
}
116-
httpMux.Handle(fmt.Sprintf("/%s/", name), chainMiddleware(server.sseServer, middlewares...))
123+
mcpRoute := path.Join(baseURL.Path, name) + "/"
124+
httpMux.Handle(mcpRoute, chainMiddleware(server.sseServer, middlewares...))
117125
httpServer.RegisterOnShutdown(func() {
118126
log.Printf("<%s> Shutting down", name)
119127
_ = mcpClient.Close()
@@ -148,8 +156,9 @@ func startHTTPServer(config *Config) {
148156
shutdownCtx, shutdownCancel := context.WithTimeout(ctx, 5*time.Second)
149157
defer shutdownCancel()
150158

151-
err := httpServer.Shutdown(shutdownCtx)
152-
if err != nil {
153-
log.Printf("Server shutdown error: %v", err)
159+
err = httpServer.Shutdown(shutdownCtx)
160+
if err != nil && !errors.Is(err, http.ErrServerClosed) {
161+
return err
154162
}
163+
return nil
155164
}

main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,8 @@ func main() {
2525
if err != nil {
2626
log.Fatalf("Failed to load config: %v", err)
2727
}
28-
startHTTPServer(config)
28+
err = startHTTPServer(config)
29+
if err != nil {
30+
log.Fatalf("Failed to start server: %v", err)
31+
}
2932
}

0 commit comments

Comments
 (0)