mcpserver

package
v1.0.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthorizationCodeTTL = 10 * time.Minute
	RefreshTokenTTL      = 30 * 24 * time.Hour
)
View Source
const (
	PathMCP                    = "/mcp"
	PathAuthorize              = "/oauth/authorize"
	PathToken                  = "/oauth/token"
	PathRegister               = "/oauth/register"
	PathProtectedResource      = "/.well-known/oauth-protected-resource"
	PathProtectedResourceMCP   = PathProtectedResource + PathMCP
	PathAuthorizationServer    = "/.well-known/oauth-authorization-server"
	PathAuthorizationServerMCP = PathAuthorizationServer + PathMCP

	LocalClientID   = "superplane-local"
	LocalClientName = "Cursor"
	ServerName      = "SuperPlane"
	ServerVersion   = "1.0.0"

	AccessTokenPurpose = "mcp_workspace"
	ConsentPurpose     = "mcp_consent"
)
View Source
const AccessTokenTTL = time.Hour
View Source
const ConsentTTL = 10 * time.Minute
View Source
const ServerWebsiteURL = "https://superplane.com"

Variables

View Source
var CursorRedirectURIs = []string{
	"http://localhost:8787/callback",
	"cursor://anysphere.cursor-mcp/oauth/callback",
}
View Source
var GrantedScopes = []string{
	"work_orders:read",
	"work_orders:create",
	"work_orders:update",
}

Functions

func AccessGrantIsActive

func AccessGrantIsActive(tx *gorm.DB, claims *AccessClaims, now time.Time) bool

func AuthorizationRedirect

func AuthorizationRedirect(redirectURI, code, state string) (string, error)

func AuthorizationServerMetadata

func AuthorizationServerMetadata(origin string) map[string]any

func ClientDisplayName

func ClientDisplayName(tx *gorm.DB, clientID string) string

func CreateAuthorizationCode

func CreateAuthorizationCode(tx *gorm.DB, req *AuthorizeRequest, userID, orgID, factoryID uuid.UUID) (string, error)

func ExchangeAuthorizationCode

func ExchangeAuthorizationCode(tx *gorm.DB, values url.Values, resource string) (*TokenIssue, string, *OAuthError)

func MintAccessToken

func MintAccessToken(signer *jwt.Signer, claims AccessClaims, ttl time.Duration) (string, error)

func MintConsentToken

func MintConsentToken(signer *jwt.Signer, claims ConsentClaims) (string, error)

func OrganizationAllowsPublicMCP

func OrganizationAllowsPublicMCP(orgID uuid.UUID) bool

func ParseAuthorizeRequest

func ParseAuthorizeRequest(values url.Values, resource string) (*AuthorizeRequest, *OAuthError)

func ProtectedResourceMetadata

func ProtectedResourceMetadata(origin string) map[string]any

func PublicOrigin

func PublicOrigin(r *http.Request, fallback string) string

func RefreshTokens

func RefreshTokens(tx *gorm.DB, values url.Values, resource string) (*TokenIssue, string, *OAuthError)

func RegisterClient

func RegisterClient(tx *gorm.DB, body []byte) (*Client, *OAuthError)

func RenderConsentPage

func RenderConsentPage(clientName, consentToken, errMessage string, workspaces []WorkspaceOption) ([]byte, error)

func ResolveClient

func ResolveClient(ctx context.Context, tx *gorm.DB, httpClient mcp.HTTPDoer, clientID, redirectURI string) (*Client, *OAuthError)

func ResolveConsentWorkspace

func ResolveConsentWorkspace(ctx context.Context, account *models.Account, factoryID string) (uuid.UUID, uuid.UUID, uuid.UUID, error)

func ResourceURL

func ResourceURL(origin string) string

func ServerInfo

func ServerInfo() map[string]any

func ToolError

func ToolError(message string) error

func UserAccountBlocked

func UserAccountBlocked(tx *gorm.DB, userID uuid.UUID) bool

func WWWAuthenticate

func WWWAuthenticate(origin string) string

Types

type AccessClaims

type AccessClaims struct {
	UserID    uuid.UUID
	OrgID     uuid.UUID
	FactoryID uuid.UUID
	ClientID  string
	Resource  string
	Scopes    []string
}

func ParseAccessToken

func ParseAccessToken(signer *jwt.Signer, token, resource string) (*AccessClaims, error)

func (AccessClaims) HasScope

func (c AccessClaims) HasScope(scope string) bool

type AuthorizeRequest

type AuthorizeRequest struct {
	ClientID            string
	RedirectURI         string
	State               string
	CodeChallenge       string
	CodeChallengeMethod string
	Resource            string
	ResponseType        string
}

type Client

type Client struct {
	ID           string
	Name         string
	RedirectURIs []string
}

type ConsentClaims

type ConsentClaims struct {
	ClientID            string
	RedirectURI         string
	State               string
	CodeChallenge       string
	CodeChallengeMethod string
	Resource            string
	ResponseType        string
}

func ParseConsentToken

func ParseConsentToken(signer *jwt.Signer, token string) (*ConsentClaims, error)

type JSONRPCError

type JSONRPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

type JSONRPCRequest

type JSONRPCRequest struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      any             `json:"id"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params"`
}

func ParseJSONRPC

func ParseJSONRPC(body io.Reader) (*JSONRPCRequest, error)

type JSONRPCResponse

type JSONRPCResponse struct {
	JSONRPC string        `json:"jsonrpc"`
	ID      any           `json:"id"`
	Result  any           `json:"result,omitempty"`
	Error   *JSONRPCError `json:"error,omitempty"`
}

func HandleJSONRPC

func HandleJSONRPC(ctx context.Context, runtime *Runtime, claims *AccessClaims, message *JSONRPCRequest) *JSONRPCResponse

type OAuthError

type OAuthError struct {
	Code        string
	Description string
	Status      int
}

func (*OAuthError) Error

func (e *OAuthError) Error() string

type Runtime

type Runtime struct {
	Auth   authorization.PermissionChecker
	Intake factories.IntakeDependencies
}

func (*Runtime) CallTool

func (rt *Runtime) CallTool(ctx context.Context, claims *AccessClaims, name string, args map[string]any) (ToolResult, error)

type TokenIssue

type TokenIssue struct {
	UserID    uuid.UUID
	OrgID     uuid.UUID
	FactoryID uuid.UUID
	ClientID  string
	Resource  string
	Scopes    []string
}

type Tool

type Tool struct {
	Name        string         `json:"name"`
	Description string         `json:"description"`
	InputSchema map[string]any `json:"inputSchema"`
}

func Tools

func Tools() []Tool

type ToolResult

type ToolResult struct {
	Content []map[string]any `json:"content"`
	IsError bool             `json:"isError,omitempty"`
}

func TextResult

func TextResult(text string) ToolResult

type WorkspaceOption

type WorkspaceOption struct {
	FactoryID string
	Label     string
}

func ListConsentWorkspaces

func ListConsentWorkspaces(ctx context.Context, account *models.Account) ([]WorkspaceOption, error)

Jump to

Keyboard shortcuts

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