mcp

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Package mcp loads, authorizes, and connects Coding Agent MCP integrations.

Index

Constants

View Source
const (
	// DefinitionSchema is the strict MCP definition file schema.
	DefinitionSchema = "pips.mcp/v1alpha1"
	// PermissionSchema is the strict project-local permission file schema.
	PermissionSchema = "pips.permissions/v1alpha1"
)

Variables

View Source
var (
	// ErrInvalid reports malformed definitions, permissions, or options.
	ErrInvalid = errors.New("coding mcp: invalid")
	// ErrLimitExceeded reports a bounded file, entry, or scalar limit.
	ErrLimitExceeded = errors.New("coding mcp: limit exceeded")
	// ErrDuplicate reports an identity collision without precedence.
	ErrDuplicate = errors.New("coding mcp: duplicate")
	// ErrUnsafeFile reports a symlink, tracked file, broad permissions, or
	// unsupported filesystem object at a security boundary.
	ErrUnsafeFile = errors.New("coding mcp: unsafe file")
)

Functions

This section is empty.

Types

type ConnectedServer

type ConnectedServer struct {
	ID          string
	Fingerprint string
	Visibility  Visibility
	Entries     []catalog.Entry
}

ConnectedServer is a detached, credential-free view of one successfully connected server in the current Registry snapshot.

type ConnectionDiagnostic

type ConnectionDiagnostic struct {
	ServerID string
	Stage    string
	Code     string
	Message  string
}

ConnectionDiagnostic is a safe, non-fatal server lifecycle condition.

type ConnectionOptions

type ConnectionOptions struct {
	Workspace      workspace.Workspace
	Implementation *sdk.Implementation
	HTTPClient     *http.Client
	TempRoot       string
	Environment    func(string) (string, bool)
	TerminateAfter time.Duration
	MaxTools       int
	Transport      TransportFactory
	Diagnostics    []ConnectionDiagnostic
}

ConnectionOptions configure concrete MCP transports and client bounds.

type Connections

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

Connections owns successful MCP clients and one atomic Registry. Individual server failures are diagnostics and do not disable unrelated servers.

func OpenConnections

func OpenConnections(
	ctx context.Context,
	resolved []ResolvedDefinition,
	options ConnectionOptions,
) (*Connections, error)

OpenConnections connects enabled definitions, primes each complete tool snapshot, and installs the initial Registry generation.

func (*Connections) Close

func (c *Connections) Close() error

Close closes successful clients and their resources in reverse order.

func (*Connections) ConnectedServers

func (c *Connections) ConnectedServers(visibility Visibility) []ConnectedServer

ConnectedServers returns credential-free bindings for successfully connected servers. Entry snapshots reflect the latest successfully installed Registry generation.

func (*Connections) Diagnostics

func (c *Connections) Diagnostics() []ConnectionDiagnostic

Diagnostics returns safe lifecycle diagnostics in occurrence order.

func (*Connections) Entries

func (c *Connections) Entries(visibility Visibility) []catalog.Entry

Entries returns a detached current catalog filtered by configured visibility. Unknown visibility values return no entries.

func (*Connections) RefreshChanged

func (c *Connections) RefreshChanged(
	ctx context.Context,
) (agentmcp.RegistrySnapshot, bool, error)

RefreshChanged refreshes only at an application-selected safe boundary. A failed refresh preserves the prior snapshot and emits one coalesced diagnostic until a later successful attempt.

func (*Connections) Registry

func (c *Connections) Registry() *agentmcp.Registry

Registry returns the initialized MCP Registry.

func (*Connections) Snapshot

func (c *Connections) Snapshot() agentmcp.RegistrySnapshot

Snapshot returns the latest successfully installed Registry snapshot.

type Definition

type Definition struct {
	ID             string
	Scope          Scope
	Transport      TransportType
	Visibility     Visibility
	Command        string
	Args           []string
	Environment    []execution.EnvVar
	WorkingDir     string
	PluginRoot     string
	PluginData     string
	URL            string
	Headers        []HTTPHeader
	ConnectTimeout time.Duration
}

Definition is one validated MCP server declaration.

func (Definition) EffectiveVisibility

func (d Definition) EffectiveVisibility() Visibility

EffectiveVisibility returns the normalized visibility used by validation, fingerprinting, and catalog filtering. The zero value preserves the pre-private-MCP ambient behavior for programmatic callers.

func (Definition) Fingerprint

func (d Definition) Fingerprint() string

Fingerprint returns the normalized semantic SHA-256 identity of a Definition.

type Definitions

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

Definitions is an immutable validated definition set.

func LoadDefinitions

func LoadDefinitions(ctx context.Context, options LoadOptions) (Definitions, error)

LoadDefinitions decodes strict user and trusted-project MCP definition files. An untrusted project file is never inspected.

func NewDefinitions

func NewDefinitions(values []Definition, maximum int) (Definitions, error)

NewDefinitions returns an immutable validated definition set.

func (Definitions) List

func (d Definitions) List() []Definition

List returns definitions in user-file then project-file order.

func (Definitions) Merge

func (d Definitions) Merge(other Definitions, maximum int) (Definitions, error)

Merge returns one immutable definition set and rejects cross-set collisions.

type HTTPHeader

type HTTPHeader struct {
	Name  string
	Value string
}

HTTPHeader is one validated literal header from an Agent Plugin MCP entry.

type Limits

type Limits struct {
	MaxFileBytes int64
	MaxServers   int
}

Limits bound MCP definition discovery and decoding.

func DefaultLimits

func DefaultLimits() Limits

DefaultLimits returns conservative MCP definition limits.

type LoadOptions

type LoadOptions struct {
	Paths          paths.Layout
	Tree           *workspace.Tree
	ProjectTrusted bool
	Limits         Limits
}

LoadOptions select user and optional trusted-project MCP files.

type PermissionOptions

type PermissionOptions struct {
	Workspace workspace.Workspace
	Tree      *workspace.Tree
	Store     *workspace.Store
	Git       ProjectGit
	Limits    Limits
}

PermissionOptions bind project decisions to one Workspace and user store.

type Permissions

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

Permissions resolves and records dual project/user MCP decisions.

func NewPermissions

func NewPermissions(options PermissionOptions) (*Permissions, error)

NewPermissions constructs a dual-record permission manager.

func (*Permissions) Decide

func (p *Permissions) Decide(
	ctx context.Context,
	definition Definition,
	decision workspace.PermissionDecision,
) error

Decide writes the project-local record first and user workspace authority second. A crash or error between them leaves a harmless pending state.

func (*Permissions) Resolve

func (p *Permissions) Resolve(
	ctx context.Context,
	definitions Definitions,
) ([]ResolvedDefinition, error)

Resolve evaluates user definitions as enabled and project definitions by intersecting the project-local and user workspace-store records.

type ProjectGit

type ProjectGit interface {
	Tracked(context.Context, string) (bool, bool, error)
	ExcludeLocal(context.Context, string) error
}

ProjectGit provides the narrow Git-local safety boundary needed by the project permissions file. A false repository value permits non-Git projects.

type ResolvedDefinition

type ResolvedDefinition struct {
	Definition Definition
	Status     Status
}

ResolvedDefinition attaches the effective permission status.

type Scope

type Scope string

Scope identifies who supplied an MCP definition.

const (
	ScopeUser        Scope = "user"
	ScopeProject     Scope = "project"
	ScopeSession     Scope = "session"
	ScopeAgentPlugin Scope = "agent-plugin"
)

Supported MCP definition scopes.

type Status

type Status string

Status is the effective local state of one MCP definition.

const (
	StatusPending  Status = "pending"
	StatusEnabled  Status = "enabled"
	StatusDisabled Status = "disabled"
)

Supported effective MCP states.

type TransportFactory

type TransportFactory func(context.Context, Definition) (sdk.Transport, io.Closer, error)

TransportFactory prepares one definition transport and optional resource that must be closed after its MCP client.

type TransportType

type TransportType string

TransportType identifies the configured MCP transport.

const (
	TransportStdio          TransportType = "stdio"
	TransportStreamableHTTP TransportType = "streamable_http"
)

Supported P0 MCP transports.

type Visibility

type Visibility string

Visibility controls which Coding model catalog may describe one configured server. It is application policy, not MCP protocol metadata.

const (
	// VisibilityAmbient exposes tools to the parent Coding interaction and to
	// custom children selected through the ordinary capability intersection.
	VisibilityAmbient Visibility = "ambient"
	// VisibilityAgentPrivate keeps tools out of the parent catalog. A custom
	// Agent must bind the exact server ID and fingerprint before its tools can
	// enter that child's capability intersection.
	VisibilityAgentPrivate Visibility = "agent_private"
)

Jump to

Keyboard shortcuts

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