mcpexplore

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package mcpexplore owns MCP explorer targets, transports, and client lifecycle.

Index

Constants

View Source
const HTTPTokenEnv = "JINN_MCP_HTTP_TOKEN" //nolint:gosec // Environment variable name, not a credential.

HTTPTokenEnv is the only bearer-token source for HTTP explorer targets.

Variables

This section is empty.

Functions

func AliasTarget

func AliasTarget(alias string, environ []string) (Target, Server, error)

AliasTarget resolves a registered alias into a transport target and server definition.

func CommandEnvironment

func CommandEnvironment(environ []string) []string

CommandEnvironment removes the HTTP bearer token before launching subprocesses.

func NewCommand

func NewCommand(name string, args ...string) *exec.Cmd

NewCommand constructs a subprocess without a shell and strips the HTTP token.

func NewCommandContext

func NewCommandContext(ctx context.Context, name string, args ...string) *exec.Cmd

NewCommandContext constructs an explicit-argv subprocess bound to ctx.

func NewHTTPClient

func NewHTTPClient(endpoint string) (*http.Client, error)

NewHTTPClient authenticates same-origin requests and blocks cross-origin redirects.

func RegistryPath

func RegistryPath() (string, error)

RegistryPath returns the user-only registry path without creating it.

func RestrictedCommandEnvironment

func RestrictedCommandEnvironment(environ, passEnv []string) []string

RestrictedCommandEnvironment returns the registry subprocess environment.

func SaveRegistry

func SaveRegistry(registry Registry) error

SaveRegistry replaces a valid registry through a durable lock, backup, and rename.

func UpdateRegistry

func UpdateRegistry(update func(*Registry) error) error

UpdateRegistry serializes a read-modify-write change. It never replaces a corrupt current registry.

func ValidateAlias

func ValidateAlias(alias string) error

ValidateAlias checks the public, case-sensitive registry alias contract.

Types

type Client

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

Client exposes the discovery-only MCP explorer operations.

func New

func New(ctx context.Context, target Target) (*Client, error)

New opens a client for target. Close releases the underlying transport.

func (*Client) Call

func (c *Client) Call(ctx context.Context, name string, arguments map[string]any) (*protocol.CallToolResult, error)

Call invokes one MCP tool. Tool-level isError results are returned normally.

func (*Client) Close

func (c *Client) Close() error

Close releases the selected MCP transport and subprocess, if any.

func (*Client) Discover

func (c *Client) Discover(ctx context.Context) (*protocol.DiscoverResult, error)

Discover returns the server identity and capabilities.

func (*Client) Inspect

func (c *Client) Inspect(ctx context.Context, name string) (*protocol.Tool, error)

Inspect returns a listed tool by its exact MCP name.

func (*Client) ListTools

func (c *Client) ListTools(ctx context.Context) ([]*protocol.Tool, error)

ListTools returns every tools/list page in server order.

type Registry

type Registry struct {
	Version int               `json:"version"`
	Servers map[string]Server `json:"servers"`
}

Registry is the strict versioned on-disk server registry.

func LoadRegistry

func LoadRegistry() (registry Registry, exists bool, err error)

LoadRegistry reads and validates the registry. exists is false for a missing file.

func (Registry) SortedAliases

func (r Registry) SortedAliases() []string

SortedAliases returns registered aliases in lexical order.

type Server

type Server struct {
	Transport string   `json:"transport"`
	URL       string   `json:"url,omitempty"`
	TokenEnv  string   `json:"token_env,omitempty"`
	Command   string   `json:"command,omitempty"`
	Args      []string `json:"args,omitempty"`
	PassEnv   []string `json:"pass_env,omitempty"`
}

Server is one user-owned, shell-free MCP target.

type Target

type Target struct {
	Endpoint            string
	Command             string
	CommandArgs         []string
	TokenEnv            string
	CommandEnv          []string
	DisableDefaultToken bool
}

Target identifies either an HTTP MCP endpoint or an explicit-argv subprocess.

func TargetForServer

func TargetForServer(server Server, environ []string) (Target, error)

TargetForServer converts one already-loaded registry server into a constrained target.

func (Target) Validate

func (t Target) Validate() error

Validate checks the target without starting a transport.

Jump to

Keyboard shortcuts

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