mcp-auth
OAuth 2.1 authorization server library for Go, designed for MCP (Model Context Protocol) servers.
Alimenter votre agent
Installation de l'éditeur. Ce n'est pas un endpoint PlugMCP.
Host a copy with our keys and logs.
Pas encore de version packagée dans le registre. Suivez le README du dépôt.
URL distante ou commande sur votre machine ? Ce qui distingue les deux installations
Exécuter sur PlugMCP
A new server you create. It is not this listing's official endpoint. Use the publisher install when you want their URL and their credentials.
LancerProvides a complete OAuth 2.1 implementation with PKCE, dynamic client registration (RFC 7591), protected resource metadata (RFC 9728), and API key authentication. Wire the handlers into your HTTP mux and bring your own storage backend.
go get github.com/alexjbarnes/mcp-auth
package main
import (
"net/http"
mcpauth "github.com/alexjbarnes/mcp-auth"
)
func main() {
srv := mcpauth.New(mcpauth.Config{
ServerURL: "https://example.com",
Users: mcpauth.NewMapAuthenticator(map[string]string{
"alice": "password123",
}),
GrantTypes: []string{"authorization_code", "refresh_token", "client_credentials"},
})
defer srv.Stop()
mux := http.NewServeMux()
// Register all OAuth endpoints.
srv.Register(mux)
// Protect your application routes with the middleware.
mux.Handle("/mcp", srv.Middleware()(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
userID := mcpauth.RequestUserID(r.Context())
w.Write([]byte("hello " + userID))
})))
http.ListenAndServe(":8080", mux)
}
srv.Register(mux) wires:
Register API keys for service-to-service auth without the OAuth flow.
// With a prefix to distinguish from OAuth tokens.
srv := mcpauth.New(mcpauth.Config{
ServerURL: "https://example.com",
APIKeyPrefix: "sk_",
})
srv.RegisterAPIKey("sk_live_abc123", "service-account")
// Without a prefix. Tokens are speculatively checked as API keys
// and fall through to OAuth validation if not found.
srv := mcpauth.New(mcpauth.Config{
ServerURL: "https://example.com",
})
srv.RegisterAPIKey("abc123", "service-account")
// Register by pre-computed hash when you don't have the raw key.
srv.RegisterAPIKeyByHash(mcpauth.HashSecret("abc123"), "service-account")
Register server-owned OAuth clients that bypass dynamic registration.
err := srv.RegisterPreConfiguredClient(&mcpauth.OAuthClient{
ClientID: "my-service",
SecretHash: mcpauth.HashSecret("client-secret"),
GrantTypes: []string{"client_credentials"},
})
if err != nil {
// Grant type not supported by server configuration.
log.Fatal(err)
}
By default everything is in-memory. For durable storage, implement the Persistence interface and pass it via Config.Persist.
type Persistence interface {
SaveOAuthToken(token OAuthToken) error
DeleteOAuthToken(tokenHash string) error
AllOAuthTokens() ([]OAuthToken, error)
SaveOAuthClient(client OAuthClient) error
DeleteOAuthClient(clientID string) error
AllOAuthClients() ([]OAuthClient, error)
SaveAPIKey(hash string, key APIKey) error
DeleteAPIKey(hash string) error
AllAPIKeys() (map[string]APIKey, error)
}
Raw secrets (tokens, refresh tokens) are never passed to the persistence layer. Only hashes are stored.
Implement UserAuthenticator for custom credential validation (LDAP, database, etc.).
type UserAuthenticator interface {
ValidateCredentials(ctx context.Context, username, password string) (userID string, err error)
}
MapAuthenticator is a built-in implementation backed by a username/password map. Passwords are hashed at construction time and not retained.
users := mcpauth.NewMapAuthenticator(map[string]string{
"alice": "password123",
"bob": "hunter2",
})
Optionally implement UserAccountChecker on the same type to enable per-request account validation in the middleware (disable users without revoking tokens).
After the middleware authenticates a request, extract identity from the context:
userID := mcpauth.RequestUserID(r.Context())
clientID := mcpauth.RequestClientID(r.Context())
ip := mcpauth.RequestRemoteIP(r.Context())
WithUserID injects a user ID into a context for testing:
ctx := mcpauth.WithUserID(context.Background(), "test-user")
Apache 2.0
OAuth 2.1 authorization server library for Go, designed for MCP servers
Outils
Pas encore de liste d'outils. Les serveurs distants en obtiennent une après le premier contrôle d'état.
FAQ
Copiez sur cette page la configuration stdio pour Cursor, Claude Desktop, Claude Code ou VS Code. Elle utilise l'installation de l'éditeur, pas un proxy PlugMCP.
Aucune variable d'environnement requise n'est indiquée sur cette fiche.
MCP Auth s'exécute en local via stdio.
Dernière vérification : 2026-10-27. OAuth 2.1 authorization server library for Go, designed for MCP servers