importer

package
v1.0.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package importer converts MCP server entries found in client configs into gridctl stack entries. It is pure logic: callers (the import CLI) do all file I/O. The package normalizes the client dialect matrix (key spellings, transport names, command shapes), unwraps bridge entries, dedupes servers found in several clients, filters gridctl's own gateway entries, and classifies plaintext secrets so the CLI can offer vault moves.

Index

Constants

View Source
const (
	SkipGatewaySelfEntry = "gateway_self_entry"
	SkipUnsupported      = "unsupported_entry"
	SkipNameCollision    = "name_collision"
	// SkipDisabled means an OpenCode entry set enabled to false. Other clients
	// ignore the field.
	SkipDisabled = "disabled"
	// SkipUntransferredOption means dropping the option would change execution.
	// OpenCode skips a working directory on every shape, and skips oauth or
	// local headers on a command array.
	SkipUntransferredOption = "untransferred_option"
	// SkipNativeExpression means a newly supported native value used an
	// OpenCode expression Gridctl cannot represent without reading it.
	SkipNativeExpression = "unsupported_native_expression"
	// SkipAmbiguous means two native forms conflict and were not merged.
	SkipAmbiguous = "ambiguous_entry"
)

Skip reasons attached to candidates that will not be imported.

Variables

This section is empty.

Functions

func ClassifySecretKeys

func ClassifySecretKeys(env map[string]string) []string

ClassifySecretKeys returns the env keys whose values are literal secrets: non-empty, not a recognized reference, with a secret-suggestive key name. Sorted for deterministic prompts and output.

func IsGatewaySelfEntry

func IsGatewaySelfEntry(entryName, linkServerName string, raw map[string]any) bool

IsGatewaySelfEntry reports whether a scanned entry is gridctl's own gateway connection. The entry key matching the link server name is the primary signal; a localhost URL pointing at the gateway's /sse or /mcp endpoints (directly or through an mcp-remote bridge) is the secondary one. A user's own localhost server under a different name and path is NOT flagged.

func IsReferenceValue

func IsReferenceValue(v string) bool

IsReferenceValue reports whether an env value is a reference that must be preserved verbatim rather than treated as a secret literal: interpolation dialects (${env:VAR}, ${input:id}, ${file:...}, ${VAR}, ${{ secrets.X }}), bare $VAR and %VAR%, 1Password op:// URIs, and gridctl's own ${var:KEY}.

func MapEntry

func MapEntry(slug string, entry provisioner.ServerEntry) (config.MCPServer, []string, error)

MapEntry converts one raw client entry into a config.MCPServer plus warnings. An error means the entry cannot be represented (for example a websocket transport) and should surface as a skipped candidate.

func MapEntryWithOptions

func MapEntryWithOptions(slug string, entry provisioner.ServerEntry, opts MapOptions) (config.MCPServer, []string, error)

MapEntryWithOptions is MapEntry with project placeholder substitution and scope-dependent working-directory handling. Empty options match MapEntry.

Types

type Candidate

type Candidate struct {
	Name        string
	Server      config.MCPServer
	FoundIn     []string // client slugs the server was found in, sorted
	Source      string   // canonical slug (first client in registry order)
	SourcePath  string   // canonical config file path; not a client slug
	SourcePaths []string // config file paths retained through dedupe
	Origins     []Origin // client, scope, and path triples in append order
	Warnings    []string
	SkipReason  string   // empty means importable
	SecretKeys  []string // env keys whose literal values look like secrets
}

Candidate is one importable server assembled from client config entries.

func Dedupe

func Dedupe(candidates []Candidate) []Candidate

Dedupe collapses candidates with the same identity (name plus URL or command line) into one, merging provenance. Candidates arrive in registry order, so the first occurrence is the canonical source. A same-name, different-definition candidate stays separate and is flagged for review.

func (Candidate) ProvenanceLabel

func (c Candidate) ProvenanceLabel() string

ProvenanceLabel groups origins by client in FoundIn order and renders slug (scope) pairs. Several scopes for one client join with +.

func (Candidate) Scopes

func (c Candidate) Scopes() []string

Scopes returns the sorted unique scopes recorded on Origins.

func (Candidate) ScopesFor

func (c Candidate) ScopesFor(client string) []string

ScopesFor returns the sorted unique scopes recorded for client.

type MapError

type MapError struct {
	Reason string
	Detail string
}

MapError is a value-free reason an entry cannot be imported. Detail must not include config values, expression text, or referenced file contents.

func (*MapError) Error

func (e *MapError) Error() string

type MapOptions

type MapOptions struct {
	OwnerDir string
	Scope    string
}

MapOptions carries project-import context. Empty options keep MapEntry behavior unchanged.

type Origin

type Origin struct {
	Client string
	Scope  string
	Path   string
}

Origin is one place a candidate was read from. Scope is project, local, custom, or user.

Jump to

Keyboard shortcuts

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