mcp

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 26 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 serves OpenSysML to coding agents over the Model Context Protocol: one server over a workspace root, its tools in three groups. The workspace group is the language server (diagnostics, navigation, editing, rendering), the runtime group is the one-shot service (evaluate, instantiate, execute, verify, query, convert), and the session group is named REPL sessions whose model and runs persist across calls.

Index

Constants

View Source
const (
	GroupLSP     = catalog.GroupLSP
	GroupRuntime = catalog.GroupRuntime
	GroupSession = catalog.GroupSession
)

The groups a server can serve; see the catalog for the tools of each.

View Source
const (
	HealthPath = "/health"
	ReadyPath  = "/ready"
)

The open service endpoints beside HTTPPath: liveness answers once the listener is bound, readiness 200 once the server is built and prewarmed.

View Source
const CodeInsufficientScope = toolkit.CodeInsufficientScope

CodeInsufficientScope is the JSON-RPC error code of a tools/call refused for a scope the principal lacks.

View Source
const DefaultMaxBodyBytes = sdk.DefaultMaxRequestBodyBytes

DefaultMaxBodyBytes is the request body bound when none is configured.

View Source
const DefaultSessionTimeout = 30 * time.Minute

DefaultSessionTimeout is how long a session may sit idle when none is configured.

View Source
const DefaultShutdownTimeout = 30 * time.Second

DefaultShutdownTimeout bounds how long a stopping server waits for the connections it is closing.

View Source
const HTTPPath = "/mcp"

HTTPPath is the path the Streamable HTTP transport is served at.

View Source
const MaxPrincipalWorkspaces = 32

MaxPrincipalWorkspaces bounds the principals holding a workspace of their own at once; a further principal's session is refused until the server restarts.

View Source
const ProtectedResourceMetadataPath = wellKnownPrefix + HTTPPath

ProtectedResourceMetadataPath is where the MCP endpoint's metadata is served.

View Source
const TokenEnv = "OPENSYSML_MCP_TOKEN" // #nosec G101 -- a variable name, not a credential

TokenEnv is the environment variable a bearer token is read from when no flag names one.

Variables

AllGroups is every group, the default selection.

View Source
var ErrNoToken = guard.NoToken(TokenEnv)

ErrNoToken is why a listener other machines reach is refused with no token.

Functions

func IsLoopbackAddr

func IsLoopbackAddr(addr net.Addr) bool

IsLoopbackAddr reports whether a bound address can be reached from this machine only; an address on every interface cannot.

func ServeHTTP added in v0.13.0

func ServeHTTP(ctx context.Context, cfg Config, over HTTPConfig) error

ServeHTTP serves the service endpoints on over.Listener while the server is built from cfg, then the protocol until ctx ends and the connections drain.

func TokenInfoFor added in v0.13.0

func TokenInfoFor(p guard.Principal) *auth.TokenInfo

TokenInfoFor is the SDK's record of a verified bearer token for p: its UserID is p.ID(), which binds an MCP session to the principal that opened it.

Types

type BearerToken

type BearerToken struct {
	guard.Token
	// Authenticator, if set, names the principals of the credentials it reads, ahead of
	// the token; a guard.Chain of none, as flags resolve to with none given, is not set.
	Authenticator guard.Authenticator
	// contains filtered or unexported fields
}

BearerToken is whose bearer credentials the HTTP transport accepts (RFC 6750): a token issued out of band, an Authenticator's, or both, with the endpoint it protects.

func NewBearerToken

func NewBearerToken(s string) (BearerToken, error)

NewBearerToken reads a token as RFC 6750 § 2.1 spells one (b64token), so a client can send what the server was given; anything else is refused.

func (BearerToken) At

func (t BearerToken) At(publicURL string) (BearerToken, error)

At names the URL clients reach the endpoint at behind a proxy (an origin alone means its /mcp, / the root); empty derives it from each request.

func (BearerToken) Handler

func (t BearerToken) Handler(next http.Handler) http.Handler

Handler serves next the requests an authenticator accepts (RFC 6750 § 2.1), as their principal, and answers a refusal as § 3.1 has it; with nothing set it serves every request.

func (BearerToken) MetadataPaths

func (t BearerToken) MetadataPaths() []string

MetadataPaths lists where the metadata is served: ProtectedResourceMetadataPath, and the public path's well-known URI when At named another path.

func (BearerToken) PublicURL

func (t BearerToken) PublicURL() string

PublicURL is the endpoint's URL as At named it, or empty.

func (BearerToken) ServeMetadata

func (t BearerToken) ServeMetadata(w http.ResponseWriter, r *http.Request)

ServeMetadata answers the endpoint's protected resource metadata (RFC 9728 § 3.2), with the authorization servers and scopes the Authenticator advertises; the token has none.

func (BearerToken) Set

func (t BearerToken) Set() bool

Set reports whether a request has to authenticate, with the token or to the Authenticator.

type CatalogInput

type CatalogInput struct {
	Group string `json:"group,omitempty" jsonschema:"answer only this group's tools: lsp, runtime or session"`
}

CatalogInput narrows the catalog to one group; empty answers every tool the server serves.

type CatalogOutput

type CatalogOutput struct {
	Groups []string      `json:"groups"`
	Tools  []CatalogTool `json:"tools"`
}

CatalogOutput is the catalog of the tools the server serves.

type CatalogTool

type CatalogTool struct {
	Name      string `json:"name"`
	Group     string `json:"group,omitempty"`
	Scope     string `json:"scope"`
	Operation string `json:"operation"`
	Summary   string `json:"summary"`
}

CatalogTool is one tool as tool_catalog describes it.

type Config

type Config struct {
	// Root is the workspace folder the language server indexes.
	Root string
	// Groups are the tool groups to register; nil is every group, and a group
	// named twice is registered once.
	Groups []Group
	// Version is what the server reports as its version.
	Version string
	// Workspace is the language server's workspace; nil makes one with NewWorkspace.
	Workspace *model.Workspace
	// NewWorkspace makes the workspace of a further principal, configured as
	// Workspace is; nil makes a default one.
	NewWorkspace func() *model.Workspace
	// CacheSize bounds the runtime service's parsed-model cache; 0 is the
	// service's default of 100.
	CacheSize int
	// Records is the record cache the runtime service keeps the analysis of the
	// models it parses in; nil keeps none.
	Records *libs.Cache
	// UnavailableCapabilities are capabilities the runtime service deliberately
	// lacks, for conformance testing of a client's fallbacks; nil lacks none.
	UnavailableCapabilities []string
	// NewSession makes a REPL session for the session group.
	NewSession sessiontools.Factory
	// Logger, if set, receives the server's log of protocol activity.
	Logger *slog.Logger
	// Instructions is what the server tells a client about using it.
	Instructions string
}

Config is what a server is built from.

type Group

type Group = catalog.Group

Group names a set of tools a server registers together.

func ParseGroups

func ParseGroups(spec string) ([]Group, error)

ParseGroups reads a comma-separated group list as the -tools flag takes it; "all" and the empty string are every group.

type HTTPConfig

type HTTPConfig struct {
	// Listener is the bound address connections arrive on.
	Listener net.Listener
	// Origins decides which Origin headers are admitted.
	Origins OriginPolicy
	// Token is whose bearer credentials a request must carry, a token's or an authenticator's;
	// the zero value requires none, which only a loopback listener may serve.
	Token BearerToken
	// CertFile and KeyFile, both set, serve TLS; neither serves cleartext.
	CertFile, KeyFile string
	// ShutdownTimeout bounds the graceful shutdown; 0 is DefaultShutdownTimeout.
	ShutdownTimeout time.Duration
	// MaxBodyBytes bounds a request body on the protocol path, answered 413
	// past it; 0 is the SDK's DefaultMaxBodyBytes, and a negative value no bound.
	MaxBodyBytes int64
	// SessionTimeout closes a session no request has used for that long; 0 is
	// DefaultSessionTimeout, and a negative value never closes an idle session.
	SessionTimeout time.Duration
	// Logger, if set, receives the transport's log; nil logs to the default.
	Logger *slog.Logger
}

HTTPConfig is how a server is served over the Streamable HTTP transport.

type OriginPolicy

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

OriginPolicy admits a request with no Origin, a loopback origin or one allowed by name, and refuses any other, so a rebound DNS name is not a way in.

func ParseOrigins

func ParseOrigins(spec string) (OriginPolicy, error)

ParseOrigins reads a comma-separated list of exact origins, each scheme://host[:port], into a policy; the wildcard is refused.

func (OriginPolicy) Allowed

func (p OriginPolicy) Allowed() []string

Allowed lists the origins admitted by name, sorted, for the log.

func (OriginPolicy) Allows

func (p OriginPolicy) Allows(origin string) bool

Allows reports whether a request bearing origin (the Origin header's value, empty when absent) is admitted.

func (OriginPolicy) Handler

func (p OriginPolicy) Handler(next http.Handler) http.Handler

Handler refuses origins the policy does not admit with 403 and grants CORS only to origins admitted by name; a loopback origin is served without a grant.

func (OriginPolicy) Named

func (p OriginPolicy) Named(origin string) bool

Named reports whether origin is one the policy admits by name, as opposed to admitting it for being loopback.

type Server

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

Server is an MCP server over the OpenSysML surfaces its groups need.

func New

func New(ctx context.Context, cfg Config) (*Server, error)

New builds a server from cfg, indexing the workspace and preparing the runtime before it returns, so a client's first call is answered in full.

func (*Server) Close

func (s *Server) Close(ctx context.Context)

Close releases what the groups hold: the language server session, the runtime service and every REPL session.

func (*Server) Prewarmed added in v0.13.0

func (s *Server) Prewarmed() <-chan struct{}

Prewarmed returns the channel that closes once the runtime's library index is built, when a first runtime call does not pay for it; closed without the runtime group.

func (*Server) Run

func (s *Server) Run(ctx context.Context, t sdk.Transport) error

Run serves one client over t until the client ends the session or ctx is cancelled; ServeHTTP serves many over a listener.

Directories

Path Synopsis
Package catalog is the one source of truth for the tools sysml-mcp serves: what each tool is called, which group serves it, which RPC of the sysml-grpc service and which sysml CLI operation it stands for, and a one-line summary.
Package catalog is the one source of truth for the tools sysml-mcp serves: what each tool is called, which group serves it, which RPC of the sysml-grpc service and which sysml CLI operation it stands for, and a one-line summary.
Package lsptools serves the language server's workspace over MCP: the documents under the root, their diagnostics, navigation, editing and rendering, as tools an agent calls instead of an editor.
Package lsptools serves the language server's workspace over MCP: the documents under the root, their diagnostics, navigation, editing and rendering, as tools an agent calls instead of an editor.
Package runtimetools is the runtime group of sysml-mcp tools: the one-shot operations of the sysml-grpc service (parse, evaluate, instantiate, execute, verify, query, render, convert), each tool one RPC with the RPC's contract.
Package runtimetools is the runtime group of sysml-mcp tools: the one-shot operations of the sysml-grpc service (parse, evaluate, instantiate, execute, verify, query, render, convert), each tool one RPC with the RPC's contract.
Package sessiontools is the session group of sysml-mcp tools: named REPL sessions that keep a model, its instances, a running action or state machine and the solver's state across calls, as the sysml prompt does.
Package sessiontools is the session group of sysml-mcp tools: named REPL sessions that keep a model, its instances, a running action or state machine and the solver's state across calls, as the sysml prompt does.
Package toolkit holds what every sysml-mcp tool group shares: the annotations a tool declares about itself and the coordinate conventions tool arguments use, so the groups agree without importing one another.
Package toolkit holds what every sysml-mcp tool group shares: the annotations a tool declares about itself and the coordinate conventions tool arguments use, so the groups agree without importing one another.

Jump to

Keyboard shortcuts

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