Documentation
¶
Overview ¶
Package mcp implements the FlowCatalyst MCP (Model Context Protocol) server: read-only, agent-facing access to the platform's event types, subscriptions, applications, roles, and OpenAPI specs.
It is built on the official MCP Go SDK (github.com/modelcontextprotocol/go-sdk), so the initialize handshake, capability negotiation, and both transports (stdio + streamable-HTTP) are handled by the SDK. This package supplies the tool + resource catalogue and the platform API plumbing.
Index ¶
- Constants
- func AuthTokenFromEnv() string
- func CheckHTTPBind(addr, token string) error
- func CredentialsPath() (string, error)
- func ReadCredentialsFile() (clientID, clientSecret, baseURL string, ok bool)
- func RequireBearerToken(token string, next http.Handler) http.Handler
- func RequireCredentials(cfg Config) error
- func WriteCredentialsFile(clientID, clientSecret, baseURL string) error
- type Config
- type Server
- type TokenManager
Constants ¶
const EnvAuthToken = "FC_MCP_AUTH_TOKEN"
EnvAuthToken names the environment variable holding the bearer token the MCP HTTP endpoint requires. Unset means no caller authentication, which is acceptable only on a loopback bind (see CheckHTTPBind).
Variables ¶
This section is empty.
Functions ¶
func AuthTokenFromEnv ¶
func AuthTokenFromEnv() string
AuthTokenFromEnv returns the configured bearer token, or "".
func CheckHTTPBind ¶
CheckHTTPBind refuses to listen for MCP over HTTP on an address that is not loopback unless a bearer token is configured: the endpoint carries the MCP server's own platform credential, so an unauthenticated network listener would hand that access to anyone who can reach it. addr is "host:port" (an empty host means every interface).
func CredentialsPath ¶
CredentialsPath is where fcdev writes, and the MCP server reads, the bootstrapped local credentials: <user-cache>/flowcatalyst-dev/mcp-credentials.json, or FC_MCP_CREDENTIALS_PATH when set (an isolated fcdev run must set it, or it rewrites the developer's own file).
func ReadCredentialsFile ¶
ReadCredentialsFile returns the credentials file's contents, ok false when it is missing or unreadable.
func RequireBearerToken ¶
RequireBearerToken wraps next so every request must carry "Authorization: Bearer <token>". The comparison is constant-time. An empty token disables the check (the caller has already refused that combination on a non-loopback bind).
func RequireCredentials ¶
RequireCredentials returns errNoCredentials when the config has neither a client_id/secret pair nor a static secret. The standalone server uses this to fail fast; the in-process launcher tolerates empty creds (localhost).
func WriteCredentialsFile ¶
WriteCredentialsFile persists local MCP credentials to CredentialsPath with 0600 permissions, creating the parent directory. Used by fcdev's bootstrap.
Types ¶
type Config ¶
type Config struct {
// BaseURL is the platform API root (no trailing /api).
BaseURL string
// ClientID / ClientSecret are the OAuth2 client_credentials grant
// credentials. When both are set the server mints + caches tokens; when
// only ClientSecret is set it is used as a static bearer token
// (back-compat); when neither is set the server calls the platform
// unauthenticated (local dev only).
ClientID string
ClientSecret string
}
Config is the resolved MCP server configuration: where the platform lives and the credentials used to mint API tokens.
func LoadConfig ¶
func LoadConfig() Config
LoadConfig resolves the MCP config with env vars taking precedence over the credentials file, falling back to defaults. Resolution order: FLOWCATALYST_URL / FLOWCATALYST_CLIENT_ID / FLOWCATALYST_CLIENT_SECRET → mcp-credentials.json → defaultBaseURL. Any field left unset by the env is filled from the credentials file when present.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server wraps an MCP SDK server bound to a FlowCatalyst platform client.
func New ¶
New builds an MCP server from resolved config, constructing the platform client (and its token manager / static token) from the config's credentials.
func NewWithClient ¶
func NewWithClient(pc *client.FlowCatalystClient) *Server
NewWithClient builds the server around an existing platform client. Used by the in-process launcher (which builds the client from EnvCfg) and by tests (which point it at an httptest server).
func (*Server) HTTPHandler ¶
HTTPHandler returns the streamable-HTTP handler serving this server. Mount it at /mcp. The same server instance is reused across requests (stateless tools).
type TokenManager ¶
type TokenManager = oauthtoken.Manager
TokenManager is the shared client-credentials token manager. It lived here until the router needed the same thing to fetch its configuration document; the router must not import the MCP server to get it.
func NewTokenManager ¶
func NewTokenManager(baseURL, clientID, clientSecret string, httpClient *http.Client) *TokenManager
NewTokenManager builds a token manager for the given platform base URL and client credentials. httpClient may be nil (http.DefaultClient is used).