mcp

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 22 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 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 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.

Types

type BearerToken

type BearerToken struct {
	guard.Token
	// contains filtered or unexported fields
}

BearerToken is the one access token the HTTP transport accepts (RFC 6750), issued out of band by whoever runs the server, with the endpoint it protects; the zero value is no token.

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 requires Authorization: Bearer TOKEN of every request (RFC 6750 § 2.1), answering 401 with a challenge or 400 otherwise; no token serves next.

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); there is no authorization server to list, the token being out of band.

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"`
	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 a default one.
	Workspace *model.Workspace
	// CacheSize bounds the runtime service's parsed-model cache; 0 is the
	// service's default of 100.
	CacheSize int
	// 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 the bearer token every request must carry; 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
}

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

func (s *Server) Handler(origins OriginPolicy, token BearerToken) http.Handler

Handler is the Streamable HTTP transport of this server, mounted at HTTPPath behind origins and token, with the token's resource metadata served open.

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; ServeStreamableHTTP serves many over a listener.

func (*Server) ServeStreamableHTTP

func (s *Server) ServeStreamableHTTP(ctx context.Context, cfg HTTPConfig) error

ServeStreamableHTTP serves clients over cfg.Listener until ctx ends, then closes the live sessions and drains the connections within the timeout.

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