fix: add OAuth discovery endpoints for claude.ai handshake #3
@@ -54,6 +54,18 @@ func main() {
|
|||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
_, _ = w.Write([]byte("ok"))
|
_, _ = w.Write([]byte("ok"))
|
||||||
})
|
})
|
||||||
|
mux.HandleFunc("/.well-known/oauth-protected-resource", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.Method != http.MethodGet {
|
||||||
|
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
_, _ = w.Write([]byte(`{"authorization_servers":[]}`))
|
||||||
|
})
|
||||||
|
mux.HandleFunc("/.well-known/oauth-authorization-server", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
http.NotFound(w, r)
|
||||||
|
})
|
||||||
|
|
||||||
addr := ":" + cfg.Port
|
addr := ":" + cfg.Port
|
||||||
logger.Info("gitea-mcp starting", "addr", addr, "version", "0.1.0")
|
logger.Info("gitea-mcp starting", "addr", addr, "version", "0.1.0")
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ func NewServer(opts ServerOptions) *Server {
|
|||||||
|
|
||||||
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
|
case http.MethodHead:
|
||||||
|
w.Header().Set("MCP-Protocol-Version", ProtocolVersion)
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
case http.MethodGet:
|
case http.MethodGet:
|
||||||
s.handleGET(w, r)
|
s.handleGET(w, r)
|
||||||
case http.MethodPost:
|
case http.MethodPost:
|
||||||
|
|||||||
@@ -118,6 +118,15 @@ func TestPostBodyTooLarge(t *testing.T) {
|
|||||||
assert.Equal(t, http.StatusBadRequest, rr.Code)
|
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) {
|
func TestToolsCallToolNotFound(t *testing.T) {
|
||||||
srv := newServer(t)
|
srv := newServer(t)
|
||||||
// Initialize to get a session ID.
|
// Initialize to get a session ID.
|
||||||
|
|||||||
Reference in New Issue
Block a user