Skip to main content

Public services in Skipper

Audience: you deploy an app with a public service. Status: Preview.

Contents

  1. The Host header that your app receives
  2. Go MCP servers answer 403
  3. Fix with the official Go SDK
  4. Fix with mcp-go
  5. An image that you cannot change

1. The Host header that your app receives

Caller Host in your app
A client on the public URL The public host name of the URL
A service of the same app (in the pool) The service name and port, for example mcp:8080

A proxy runs next to your app. It calls your app on 127.0.0.1. So each request arrives on a loopback address with a Host that is not loopback.

If a public request still has a Host that is a cluster-internal service name (<service>.<namespace>.svc plus the cluster domain), your pool does not have the public host change yet. Until it does, also allow that name (<service>-<app>.app-<app>.svc plus the cluster domain) in the examples below.

2. Go MCP servers answer 403

Two Go libraries protect local servers against DNS rebinding. They refuse a request that arrives on loopback with another Host:

403 Forbidden: invalid Host header "<your host>"
Library The check is in
github.com/modelcontextprotocol/go-sdk 1.4.0 and later (SSE transport: 1.6.0 and later)
github.com/mark3labs/mcp-go 0.56.0 and later

The service can show as ready, because the readiness test of a public service only opens a TCP connection.

Set PUBLIC_HOST in the environment of your compose service to the host name of your public URL, without https://. The examples read one name from PUBLIC_HOST. If the app has more than one public host name, pass each one to the list. The lists refuse every name that you do not pass, also localhost for a run on your computer; add it there if you need it.

3. Fix with the official Go SDK

The SDK has no list of allowed hosts. Turn its check off and add your own list. Before:

h := mcp.NewStreamableHTTPHandler(getServer, nil)
log.Fatal(http.ListenAndServe(":"+os.Getenv("PORT"), h))

After:

package main

import (
  "log"
  "net"
  "net/http"
  "os"
  "slices"

  "github.com/modelcontextprotocol/go-sdk/mcp"
)

// onlyHosts accepts only the host names that you list. It replaces the check of the SDK.
func onlyHosts(next http.Handler, allowed ...string) http.Handler {
  return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    host, _, err := net.SplitHostPort(r.Host)
    if err != nil {
      host = r.Host // no port
    }
    if !slices.Contains(allowed, host) {
      http.Error(w, "forbidden host", http.StatusForbidden)
      return
    }
    next.ServeHTTP(w, r)
  })
}

func main() {
  s := mcp.NewServer(&mcp.Implementation{Name: "demo", Version: "1"}, nil)
  h := mcp.NewStreamableHTTPHandler(func(*http.Request) *mcp.Server { return s },
    &mcp.StreamableHTTPOptions{DisableLocalhostProtection: true})
  // PUBLIC_HOST: the host name of your public URL. "mcp": the service name, for calls inside the pool.
  log.Fatal(http.ListenAndServe(":"+os.Getenv("PORT"), onlyHosts(h, os.Getenv("PUBLIC_HOST"), "mcp")))
}

For the SSE transport, set DisableLocalhostProtection in mcp.SSEOptions.

4. Fix with mcp-go

mcp-go 1.6.0 and later has a list of allowed hosts. For 0.56.0 to 1.5.x, upgrade, or use server.WithDisableLocalhostProtection(true) (SSE transport: server.WithSSEDisableLocalhostProtection(true)) with the onlyHosts wrapper of section 3. Before:

h := server.NewStreamableHTTPServer(s)

After:

package main

import (
  "log"
  "net/http"
  "os"

  "github.com/mark3labs/mcp-go/server"
)

func main() {
  s := server.NewMCPServer("demo", "1")
  // PUBLIC_HOST: the host name of your public URL. "mcp": the service name, for calls inside the pool.
  h := server.NewStreamableHTTPServer(s, server.WithAllowedHosts(os.Getenv("PUBLIC_HOST"), "mcp"))
  log.Fatal(http.ListenAndServe(":"+os.Getenv("PORT"), h))
}

For the SSE transport on 1.6.0 and later, use server.WithSSEAllowedHosts.

5. An image that you cannot change

  • go-sdk 1.4.0 to 1.7.x: set MCPGODEBUG=disablelocalhostprotection=1 in the environment of the service. This turns the check off. go-sdk 1.8.0 and later ignore the setting.
  • Other versions and mcp-go: run the image as a private service. A private service receives requests directly, so the check does not refuse them. Add a small public service that forwards requests to it. Your public service then must decide which requests it accepts.