fix: add OAuth discovery endpoints for claude.ai handshake
Implements RFC 9728 protected resource metadata and HEAD probe so
claude.ai can complete its pre-handshake discovery without hitting 404.
- GET /.well-known/oauth-protected-resource → 200 {"authorization_servers":[]}
- GET /.well-known/oauth-authorization-server → 404 (no auth server)
- HEAD /mcp → 200 + MCP-Protocol-Version: 2025-06-18 header
Closes #2
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -31,6 +31,9 @@ func NewServer(opts ServerOptions) *Server {
|
||||
|
||||
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodHead:
|
||||
w.Header().Set("MCP-Protocol-Version", ProtocolVersion)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
case http.MethodGet:
|
||||
s.handleGET(w, r)
|
||||
case http.MethodPost:
|
||||
|
||||
@@ -118,6 +118,15 @@ func TestPostBodyTooLarge(t *testing.T) {
|
||||
assert.Equal(t, http.StatusBadRequest, rr.Code)
|
||||
}
|
||||
|
||||
func TestHEADReturnsMCPProtocolVersionHeader(t *testing.T) {
|
||||
srv := newServer(t)
|
||||
req := httptest.NewRequest(http.MethodHead, "/mcp", nil)
|
||||
rr := httptest.NewRecorder()
|
||||
srv.ServeHTTP(rr, req)
|
||||
require.Equal(t, http.StatusOK, rr.Code)
|
||||
assert.Equal(t, mcp.ProtocolVersion, rr.Header().Get("MCP-Protocol-Version"))
|
||||
}
|
||||
|
||||
func TestToolsCallToolNotFound(t *testing.T) {
|
||||
srv := newServer(t)
|
||||
// Initialize to get a session ID.
|
||||
|
||||
Reference in New Issue
Block a user