server

package
v0.0.0-...-67b2d18 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 27 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 server serves the NICo REST read surface as MCP tools over streamable-HTTP. Tools are projected 1:1 from the embedded OpenAPI spec's GET operations. The server is stateless and never emits SSE: every tool/call returns a single application/json body.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildServer

func BuildServer(specData []byte, opts Options) (*mcp.Server, error)

BuildServer constructs an *mcp.Server with one tool registered for every GET operation in the supplied OpenAPI spec. Tool names follow the SDD: nico_<snake_case(operationId)>. Each tool handler builds a fresh appcli.Client per call from resolvedConfig.FromCallConfig. Inbound bearer tokens are forwarded unchanged only to the configured NICo REST base URL.

BuildServer does not start a listener; callers wrap the result with NewHandler to get an *http.Handler ready for ListenAndServe.

func NewHandler

func NewHandler(server *mcp.Server) http.Handler

NewHandler wraps an *mcp.Server in a streamable-HTTP handler configured for stateless, request/response-only operation:

  • Stateless: true -- the SDK does not validate Mcp-Session-Id and rejects server->client requests. initialize is a no-op.
  • JSONResponse: true -- every tool/call response uses Content-Type: application/json; the SDK never opens an SSE stream, so clients and intermediaries that do not speak text/event-stream still receive a single JSON body.

DNS-rebinding (localhost) protection and cross-origin protection are deliberately left at the SDK's secure defaults (go-sdk v1.4.1+): browser cross-origin requests and localhost DNS-rebinding attempts are rejected, while non-browser MCP clients -- which send no Origin or Sec-Fetch-Site header -- pass through unaffected. Do not set DisableLocalhostProtection or a permissive CrossOriginProtection here without understanding the security trade-off.

func Run

func Run(c *urfave.Context, specData []byte) error

Run wires the urfave context into Options, builds the MCP server, and runs an http.Server until SIGINT/SIGTERM. It is the action backing the standalone nico-mcp binary, exported so the binary's main stays a thin wrapper and so tests can drive it directly.

func ServeFlags

func ServeFlags() []urfave.Flag

ServeFlags returns the full flag set for the standalone nico-mcp server binary. The server-specific flags (listen, path, shutdown-timeout, metrics-listen) sit alongside the connection flags (base-url, org, api-name, token, debug). The dynamically-generated CLI exposes the latter as root-level flags, but nico-mcp is a single-purpose binary with no parent command to inherit from, so it declares all of them itself. Each flag also reads its NICO_* environment variable.

Types

type Metrics

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

Metrics holds the Prometheus series nico-mcp records. Each instance owns its registry, so several servers can run in one process.

The three duration histograms separate where time goes: the HTTP histogram covers a whole MCP request, the tool histogram covers one tool handler, and the REST histogram covers only the NICo REST request inside it.

func NewMetrics

func NewMetrics() *Metrics

NewMetrics registers the nico-mcp series, along with the Go runtime and process collectors, in a new registry.

func (*Metrics) Handler

func (m *Metrics) Handler() http.Handler

Handler serves the registry in the Prometheus text format.

type NicoOpenApiHandler

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

NicoOpenApiHandler builds the MCP tool input schema for a single OpenAPI GET operation, combining the path-item and operation-level parameters with the common per-call config fields.

type Options

type Options struct {
	// BaseURL is the trusted NICo REST base URL (e.g. https://nico.example.com).
	// When set, a per-call base_url must resolve to the same value.
	BaseURL string
	// Org is the default organisation used in /v2/org/<org>/... paths.
	Org string
	// APIName is the API path segment between org and resource (default
	// "nico", overridable via api.name in config).
	APIName string
	// Token is the static bearer used with BaseURL when no inbound bearer or
	// tool arg token is provided. It is not sent to a caller-selected base URL.
	Token string
	// Debug enables logrus debug-level HTTP request/response logging
	// through to the appcli.Client.
	Debug bool
	// Log is the logrus entry used for client request/response logging.
	// If nil, a default entry wrapping the standard logger is used.
	Log *logrus.Entry
	// Metrics records tool calls and REST requests. If nil, a private
	// instance is used, so recording never needs a nil check.
	Metrics *Metrics
}

Options carry the server-side settings that tool invocations resolve against through FromCallConfig. BaseURL also bounds the allowed destination.

Jump to

Keyboard shortcuts

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