Update MCP proxy to adhere to the latest draft of MCP specification

This commit is contained in:
NipuniBhagya 2025-05-13 23:58:06 +05:30
parent 9c2d37e2df
commit 85e5fe1c1d
7 changed files with 191 additions and 41 deletions

View file

@ -94,3 +94,26 @@ func (p *defaultProvider) WellKnownHandler() http.HandlerFunc {
func (p *defaultProvider) RegisterHandler() http.HandlerFunc {
return nil
}
func (p *defaultProvider) ProtectedResourceMetadataHandler() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
meta := map[string]interface{}{
"resource": p.cfg.ResourceIdentifier,
"scopes_supported": p.cfg.ScopesSupported,
"authorization_servers": p.cfg.AuthorizationServers,
}
if p.cfg.JwksURI != "" {
meta["jwks_uri"] = p.cfg.JwksURI
}
if len(p.cfg.BearerMethodsSupported) > 0 {
meta["bearer_methods_supported"] = p.cfg.BearerMethodsSupported
}
if err := json.NewEncoder(w).Encode(meta); err != nil {
http.Error(w, "failed to encode metadata", http.StatusInternalServerError)
}
}
}

19
internal/authz/policy.go Normal file
View file

@ -0,0 +1,19 @@
package authz
import "net/http"
type Decision int
const (
DecisionAllow Decision = iota
DecisionDeny
)
type PolicyResult struct {
Decision Decision
Message string
}
type PolicyEngine interface {
Evaluate(r *http.Request, claims *TokenClaims, requiredScope string) PolicyResult
}

View file

@ -7,4 +7,5 @@ import "net/http"
type Provider interface {
WellKnownHandler() http.HandlerFunc
RegisterHandler() http.HandlerFunc
ProtectedResourceMetadataHandler() http.HandlerFunc
}