diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..82733cc --- /dev/null +++ b/.editorconfig @@ -0,0 +1,7 @@ +[*] +indent_style = space +indent_size = 2 + +[*.go] +indent_style = tab +indent_size = 4 diff --git a/Dockerfile b/Dockerfile index 02800da..4177a4d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,13 +10,14 @@ RUN go mod download COPY main.go main.go COPY cmd/ cmd/ COPY config/ config/ +COPY htmlresponse/ htmlresponse/ COPY jsonrpc/ jsonrpc/ COPY log/ log/ COPY oauth/ oauth/ COPY proxy/ proxy/ COPY webhook/ webhook/ RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} \ - go build -a -o mcp-gateway -ldflags="-s -w" . + go build -a -o mcp-gateway -ldflags="-s -w" . FROM gcr.io/distroless/static-debian12:nonroot WORKDIR / diff --git a/htmlresponse/handle.go b/htmlresponse/handle.go new file mode 100644 index 0000000..b670e95 --- /dev/null +++ b/htmlresponse/handle.go @@ -0,0 +1,53 @@ +package htmlresponse + +import ( + _ "embed" + "html/template" + "net/http" + "net/url" + "slices" + "strings" + + "github.com/hyprmcp/mcp-gateway/config" +) + +var ( + //go:embed template.html + ts string + tpl *template.Template +) + +func init() { + if t, err := template.New("").Parse(ts); err != nil { + panic(err) + } else { + tpl = t + } +} + +type handler struct { + config *config.Config +} + +func NewHandler(config *config.Config) *handler { + return &handler{config: config} +} + +func (h *handler) Handle(w http.ResponseWriter, r *http.Request) error { + var data struct { + Name string + Url string + } + + u, _ := url.Parse(h.config.Host.String()) + u.Path = r.URL.Path + u.RawQuery = r.URL.RawQuery + data.Url = u.String() + + ps := strings.Split(r.URL.Path, "/") + if nameIdx := slices.IndexFunc(ps, func(s string) bool { return s != "" && s != "mcp" }); nameIdx >= 0 { + data.Name = ps[nameIdx] + } + + return tpl.Execute(w, data) +} diff --git a/htmlresponse/template.html b/htmlresponse/template.html new file mode 100644 index 0000000..b7708df --- /dev/null +++ b/htmlresponse/template.html @@ -0,0 +1,94 @@ + + +
+