appmcp

package
v0.0.0-...-ae5b880 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 28 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	LevelRead    = "read"
	LevelActions = "actions"
	LevelWrite   = "write"
)

Access levels of a key issued to an OAuth client. A plain API key has none.

View Source
const ConfigPrefix = "MCP_"

ConfigPrefix is the environment prefix of Config.

Variables

This section is empty.

Functions

func EnabledFromEnv

func EnabledFromEnv() bool

EnabledFromEnv reports whether MCP_ENABLED turns the MCP server on. It is read before the dependency graph is built, since it decides whether the graph holds the server at all.

Types

type APIKeyAuthenticator

type APIKeyAuthenticator struct {
	// contains filtered or unexported fields
}

APIKeyAuthenticator authenticates workspace API keys.

func NewAPIKeyAuthenticator

func NewAPIKeyAuthenticator(validator APIKeyValidator) *APIKeyAuthenticator

func (*APIKeyAuthenticator) Authenticate

func (a *APIKeyAuthenticator) Authenticate(ctx context.Context, token string) (Principal, bool, error)

type APIKeyValidator

type APIKeyValidator interface {
	ValidateMCPKey(ctx context.Context, rawKey string) (MCPKey, error)
}

APIKeyValidator validates a raw workspace API key, plain or OAuth-issued.

type Authorizer

type Authorizer interface {
	Authorize(ctx context.Context, procedure string) error
}

Authorizer refuses a caller whose role does not allow a procedure.

type BearerAuthenticator

type BearerAuthenticator interface {
	Authenticate(ctx context.Context, token string) (principal Principal, claimed bool, err error)
}

BearerAuthenticator resolves one form of bearer token. claimed is false when the token is not of that form, so the next authenticator can try it. A token it claims but rejects returns an error wrapping connectutil.ErrInvalidCredential.

type Config

type Config struct {
	// Enabled starts the MCP HTTP server.
	Enabled bool `env:"ENABLED" envDefault:"false"`
	// WriteTools lists the tools that create, edit and delete entities.
	WriteTools bool `env:"WRITE_TOOLS" envDefault:"true"`
	// PublicURL is the base URL clients reach the MCP server at: the OAuth
	// protected resource and authorization server issuer.
	PublicURL string `env:"PUBLIC_URL" envDefault:"http://localhost:8082"`
	// UIURL is the base URL of the main UI, which serves the OAuth consent
	// page. Empty takes AUTH_OIDC_CALLBACK_BASE_URL.
	UIURL string `env:"UI_URL"`
}

Config switches the MCP server and its write tools.

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler serves the MCP endpoint at /mcp.

func NewHandler

func NewHandler(cfg Config, services Services, authorizer Authorizer, authenticators ...BearerAuthenticator) *Handler

NewHandler serves the tools over Streamable HTTP without session state. Every request needs a bearer token one of authenticators accepts; one without answers 401 pointing at the protected resource metadata under cfg.PublicURL. Every tool call runs in that token's workspace, refused when the caller's role does not allow its procedures. A token's access level limits the tools it lists and calls: read lists the read tools, actions adds the action tools. Write tools are listed only when cfg.WriteTools is set. Every level serves the reference resources and sends serverInstructions on initialize.

func (*Handler) Register

func (h *Handler) Register(r *mux.Router)

type MCPKey

type MCPKey struct {
	UserID      string
	WorkspaceID string
	Level       string
	ExpiresAt   *time.Time
}

MCPKey is what a workspace API key grants on /mcp. Level is empty for a plain API key.

type Principal

type Principal struct {
	UserID      uuid.UUID
	WorkspaceID uuid.UUID
	Expiration  time.Time
	Level       string
}

Principal is the user and workspace a bearer token acts for, with the token's expiry and access level (empty for no limit).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL