mcp

package
v0.0.0-...-b0529fd Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 17 Imported by: 0 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

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

View Source
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

func CheckHTTPBind(addr, token string) error

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

func CredentialsPath() (string, error)

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

func ReadCredentialsFile() (clientID, clientSecret, baseURL string, ok bool)

ReadCredentialsFile returns the credentials file's contents, ok false when it is missing or unreadable.

func RequireBearerToken

func RequireBearerToken(token string, next http.Handler) http.Handler

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

func RequireCredentials(cfg Config) error

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

func WriteCredentialsFile(clientID, clientSecret, baseURL string) error

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

func New(cfg Config) *Server

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

func (s *Server) HTTPHandler() http.Handler

HTTPHandler returns the streamable-HTTP handler serving this server. Mount it at /mcp. The same server instance is reused across requests (stateless tools).

func (*Server) MCP

func (s *Server) MCP() *mcpsdk.Server

MCP returns the underlying SDK server (for custom transport wiring).

func (*Server) RunStdio

func (s *Server) RunStdio(ctx context.Context) error

RunStdio serves the MCP server over stdin/stdout until the client disconnects or ctx is cancelled. Logs must go to stderr (the SDK keeps stdout for JSON-RPC framing).

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).

Jump to

Keyboard shortcuts

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