{"modulePath":"github.com/worklydev/workly","version":"v0.5.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package server\n\nPackage server is Workly's public Go API: the one package other modules (such as the hosted control plane) import to run and extend the server. Everything else lives in internal/.\n\n## Constants\n\n```go\nconst (\n\tExecutedTask         = dispatch.KindTask\n\tExecutedWorkflowStep = dispatch.KindWorkflowStep\n\tExecutedCallback     = dispatch.KindCallback\n\tExecutedScheduleRun  = dispatch.KindScheduleRun\n)\n```\nKinds of execution, for Options.Executed.\n\n```go\nconst (\n\tMCPReadOnly = mcp.ReadOnly\n\tMCPFull     = mcp.Full\n\tMCPOff      = mcp.Off\n)\n```\nMCP modes, for Options.MCP.\n\n```go\nconst DefaultWorkspace = workspace.Default\n```\nDefaultWorkspace is the single workspace used by dev and self-hosted servers.\n\n## Variables\n\n```go\nvar ErrNotFound = store.ErrNotFound\n```\nErrNotFound is returned by Store methods for a record that doesn't exist, such as Store.DeleteWorkspace for a workspace that's gone already.\n\n```go\nvar ErrUnauthorized = workspace.ErrUnauthorized\n```\nErrUnauthorized should be returned by a WorkspaceResolver for missing or invalid credentials; the server responds 401.\n\n## Functions\n\n```go\nfunc DeliveryRefused(err error) error\n```\nDeliveryRefused wraps an error from DeliveryDialControl to say that the connection would be refused again, e.g. to a private address: the attempt fails its task or run at once instead of being retried, with err's message as its error.\n\n```go\nfunc LimitError(status int, code, message string) error\n```\nLimitError refuses a request from an Admission: the client gets status, code and message in the API's error shape, e.g. 403 \"quota\\_exceeded\". Use 429 only when retrying soon will work: the SDKs retry every 429.\n\n```go\nfunc NewLogger(cfg Config) *slog.Logger\n```\nNewLogger returns the logger described by cfg: JSON or text on stderr.\n\n```go\nfunc SQLitePath(databaseURL string) (string, error)\n```\nSQLitePath returns the file path in a sqlite:// URL.\n\n## Types\n\n```go\ntype Admission = api.Admission\n```\nAliases expose internal types without making their packages public.\n\n```go\ntype Config = config.Config\n```\nAliases expose internal types without making their packages public.\n\n```go\nfunc LoadConfig(getenv func(string) string) (Config, error)\n```\nLoadConfig reads the WORKLY\\_\\* environment variables (via getenv), so that builds wrapping the server share its configuration. Call Validate on the result after applying any overrides.\n\n```go\ntype Email = alert.Email\n```\nAliases expose internal types without making their packages public.\n\n```go\ntype ExecutionKind = dispatch.Kind\n```\nAliases expose internal types without making their packages public.\n\n```go\ntype MCPMode = mcp.Mode\n```\nAliases expose internal types without making their packages public.\n\n```go\ntype Mailer = alert.Mailer\n```\nAliases expose internal types without making their packages public.\n\n```go\nfunc SMTPMailer(url, from string) (Mailer, error)\n```\nSMTPMailer sends alert emails through an SMTP server, given as smtp://user:pass@host:587 (STARTTLS) or smtps://user:pass@host:465, from the sender address from, e.g. \"Workly \\\u003calerts@example.com\u003e\".\n\n```go\ntype Options struct {\n\t// Addr is the listen address, e.g. \":7337\".\n\tAddr  string\n\tStore Store\n\t// WorkspaceResolver defaults to StaticResolver(\"\").\n\tWorkspaceResolver WorkspaceResolver\n\t// Logger defaults to slog.Default().\n\tLogger *slog.Logger\n\t// ShutdownTimeout bounds graceful shutdown: in-flight HTTP requests and\n\t// deliveries get this long to finish. Defaults to 25s, which fits in\n\t// Kubernetes' default 30s termination grace period.\n\tShutdownTimeout time.Duration\n\t// OnReady, if set, is called once the server is listening.\n\tOnReady func(addr net.Addr)\n\n\t// SigningSecret signs deliveries (the Workly-Signature header). Required\n\t// unless DisableDispatcher is set.\n\tSigningSecret string\n\t// PreviousSigningSecret, if set, adds a second signature to each\n\t// delivery, so the signing secret can be rotated without failing\n\t// deliveries: endpoints verifying with either secret accept them.\n\tPreviousSigningSecret string\n\t// SigningSecrets, if set, gives each workspace its own secrets for\n\t// signing deliveries (the current one, and the previous one during a\n\t// rotation), instead of SigningSecret and PreviousSigningSecret. It's\n\t// called for every delivery, so it should cache. For a server shared by\n\t// untrusted users, who mustn't be able to sign for each other.\n\tSigningSecrets func(ctx context.Context, ws WorkspaceID) (current, previous []byte, err error)\n\t// MaxInFlight caps concurrent task deliveries across all queues and\n\t// workspaces. Defaults to 100.\n\tMaxInFlight int\n\t// WorkspaceMaxInFlight, if set, returns a workspace's own cap on\n\t// concurrent task deliveries, within MaxInFlight (0 for none), so on a\n\t// server shared by many workspaces one with slow endpoints can't hold\n\t// every delivery slot. Each workspace's cap is looked up again a minute\n\t// after the last lookup, and kept if a lookup fails. Free slots are shared\n\t// equally by the workspaces with tasks due either way, however many\n\t// queues each has.\n\tWorkspaceMaxInFlight func(ctx context.Context, ws WorkspaceID) (int, error)\n\t// DisableDispatcher runs the API only, without delivering tasks.\n\tDisableDispatcher bool\n\t// DisableQueueAutoCreate makes enqueueing to a missing queue an error\n\t// instead of creating the queue with defaults.\n\tDisableQueueAutoCreate bool\n\t// MaxPayloadBytes limits task bodies. Defaults to 1 MiB.\n\tMaxPayloadBytes int64\n\t// Retention is how long finished tasks (succeeded, failed or cancelled)\n\t// are kept before they are deleted. 0 keeps them forever.\n\tRetention time.Duration\n\t// RunRetention is the same for schedule runs, except that each\n\t// schedule's latest run is always kept. 0 keeps them forever.\n\tRunRetention time.Duration\n\t// WorkspaceRetention, if set, returns the workspaces that keep finished\n\t// tasks, groups and runs for their own duration instead of Retention and\n\t// RunRetention (0 keeps them forever), e.g. by plan. It's called once\n\t// per sweep and when the API reports retention, so keep it cheap; while\n\t// it fails, nothing is swept.\n\tWorkspaceRetention func(ctx context.Context) (map[WorkspaceID]time.Duration, error)\n\t// DevEndpoints serves the /_dev/echo delivery target. For `workly dev`.\n\tDevEndpoints bool\n\t// DeliveryDialControl, if set, is called with the resolved address of\n\t// each connection a delivery makes, before connecting (see\n\t// net.Dialer.Control); an error fails the attempt with it, and one\n\t// wrapped in DeliveryRefused fails the task or run without retries. A\n\t// server open to untrusted users can refuse private networks with it. Proxy\n\t// settings from the environment are ignored while it's set, since a\n\t// proxy would connect on Workly's behalf.\n\tDeliveryDialControl func(network, address string, c syscall.RawConn) error\n\t// Admission, if set, is asked before tasks are enqueued and schedules\n\t// created or replaced, through the API and so through MCP, and can\n\t// refuse with LimitError. For quotas on a hosted service.\n\tAdmission Admission\n\t// Executed, if set, is told of each execution, for metering usage: the\n\t// first delivery attempt of a task, workflow step, callback or schedule\n\t// run since it was created or retried by hand, once the attempt is\n\t// done. Retries with backoff aren't executions, and neither is a\n\t// schedule run that starts a workflow (its steps are). It is called\n\t// from deliveries' goroutines, so it must be safe for concurrent use\n\t// and not block for long.\n\tExecuted func(ctx context.Context, ws WorkspaceID, kind ExecutionKind)\n\t// Mailer, if set, sends alert emails, so workspaces can have email\n\t// alert channels; SMTPMailer builds one. Slack channels need nothing.\n\tMailer Mailer\n\t// PublicURL is where people open Workly, e.g.\n\t// https://workly.example.com. Alerts link to its dashboard; without it\n\t// they have no links.\n\tPublicURL string\n\t// Version is sent in the User-Agent of deliveries.\n\tVersion string\n\t// Dashboard serves the web UI at /. Defaults to the dashboard embedded\n\t// in this module; a wrapping build passes its own, e.g.\n\t// dashboard.HandlerFS over its embedded dist.\n\tDashboard http.Handler\n\t// WrapHandler, if set, wraps the server's HTTP handler, e.g. to mount a\n\t// wrapping build's own routes in front of Workly's.\n\tWrapHandler func(http.Handler) http.Handler\n\t// DisableMetrics doesn't serve /metrics on the API listener, e.g. to\n\t// serve MetricsHandler on an internal port instead. With WORKLY_API_KEY\n\t// set, /metrics requires it like /v1.\n\tDisableMetrics bool\n\t// MetricsAddr, if set, serves /metrics on this address (e.g. \":9090\")\n\t// without authentication, and not on Addr. Keep the port internal to\n\t// the cluster; it lets Prometheus scrape without an API key.\n\tMetricsAddr string\n\t// MCP sets which tools the MCP endpoint (/mcp) serves to coding agents:\n\t// MCPReadOnly (the default) serves the tools that only read, MCPFull\n\t// adds ones that enqueue, retry, cancel and reconfigure, and MCPOff\n\t// doesn't serve it. /mcp takes the same credentials as /v1.\n\tMCP MCPMode\n\t// MCPModeFor, if set, is asked for each /mcp request once its workspace\n\t// is resolved, and can make it read-only (anything but MCPFull) when MCP\n\t// is MCPFull; it can't widen MCP. For credentials that carry their own\n\t// access, such as OAuth tokens granted only read access.\n\tMCPModeFor func(*http.Request) MCPMode\n\t// MCPResourceMetadata, if set, is the URL of /mcp's OAuth protected\n\t// resource metadata (RFC 9728): a 401 on /mcp names it in its\n\t// WWW-Authenticate header, so MCP clients can sign in with OAuth\n\t// instead of an API key. Workly doesn't serve the metadata or issue\n\t// tokens; the WorkspaceResolver accepts whatever tokens are issued.\n\tMCPResourceMetadata string\n}\n```\n\n```go\ntype ScheduleAdmission = api.ScheduleAdmission\n```\nAliases expose internal types without making their packages public.\n\n```go\ntype Server struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc New(opts Options) (*Server, error)\n```\n\n```go\nfunc (s *Server) Handler() http.Handler\n```\nHandler returns the server's HTTP handler, for embedding or tests.\n\n```go\nfunc (s *Server) MetricsHandler() http.Handler\n```\nMetricsHandler serves the metrics in the Prometheus text format, without authentication. See Options.DisableMetrics.\n\n```go\nfunc (s *Server) Run(ctx context.Context) error\n```\nRun serves and delivers tasks until ctx is cancelled, then shuts down gracefully: in-flight requests and deliveries get ShutdownTimeout to finish.\n\n```go\ntype Store = store.Store\n```\nAliases expose internal types without making their packages public.\n\n```go\nfunc OpenStore(ctx context.Context, databaseURL string) (Store, error)\n```\nOpenStore opens a store from a database URL:\n\n\tpostgres://user:pass@host:5432/db\n\tsqlite://relative/path.db\n\tsqlite:///absolute/path.db\n\n```go\ntype WorkspaceID = workspace.ID\n```\nAliases expose internal types without making their packages public.\n\n```go\ntype WorkspaceResolver = workspace.Resolver\n```\nAliases expose internal types without making their packages public.\n\n```go\nfunc StaticResolver(apiKey string) WorkspaceResolver\n```\nStaticResolver resolves every request to DefaultWorkspace. If apiKey is non-empty, /v1 requests must present it as a bearer token.\n\n","path":"github.com/worklydev/workly/server","name":"server","synopsis":"Package server is Workly's public Go API: the one package other modules (such as the hosted control plane) import to run and extend the server.","isRedistributable":true}
