Skip to content

Add HTTP Middleware support #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add HTTP Middleware support #126

wants to merge 1 commit into from

Conversation

lukaspj
Copy link

@lukaspj lukaspj commented Jul 17, 2025

Inspired by Chi's way of doing middleware, having a handle like this lets us shoe-horn this MCP implementation into corporate not-always-following-standard environments :)

For example, this lets us implement custom authentication:

mcpTransport := mcp_http.NewHTTPTransport("/mcp").
    WithAddr(":4343").
    WithMiddleware(func(next http.Handler) http.Handler {
        return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
            if r.Header.Get("Authorization") == "" {
                w.WriteHeader(http.StatusUnauthorized)
                _, _ = w.Write([]byte("Authorization header required"))
                return
            }
            next.ServeHTTP(w, r)
        })
    })

It also allows us to inject telemetry, custom access control and other features/edge-cases that now doesn't have to be handled by this library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant