apimcp

package
v0.1.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: MIT Imports: 24 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

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultVersion       = "dev"
	EmbeddedConfigBase64 string
)
View Source
var (
	ErrKeychainItemNotFound = errors.New("keychain item not found")
	ErrKeychainUnsupported  = errors.New("macOS Keychain is unavailable")
)
View Source
var ErrActionConfirmationCanceled = errors.New("action confirmation was canceled")
View Source
var ErrCredentialSetupCanceled = errors.New("credential setup was canceled")

Functions

func BuildHTTPRequest

func BuildHTTPRequest(ctx context.Context, operation OperationDescriptor, input ToolInput, cfg Config) (*http.Request, error)

func BuildToolInputSchema

func BuildToolInputSchema(operation OperationDescriptor) map[string]any

func CreateServer

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

func CreateServerWithExtensions

func CreateServerWithExtensions(ctx context.Context, cfg Config, extensions []ExtensionTool) (*mcp.Server, error)

func DecodeExtensionInput

func DecodeExtensionInput(req *mcp.CallToolRequest, destination any) error

func EmbeddedConfigForFile

func EmbeddedConfigForFile(configPath string) (string, error)

func ExtensionError

func ExtensionError(message string) *mcp.CallToolResult

func ExtensionJSONResponse

func ExtensionJSONResponse(message string, result map[string]any) *mcp.CallToolResult

func FilterCandidates

func FilterCandidates(operation OperationDescriptor) []string

func MatchesPattern

func MatchesPattern(pattern, candidate string) bool

func RunKeychainCommand

func RunKeychainCommand(args []string, stdin *os.File, output io.Writer) error

func RunStdio

func RunStdio(ctx context.Context, cfg Config) error

func RunStdioWithExtensions

func RunStdioWithExtensions(ctx context.Context, cfg Config, extensions []ExtensionTool) error

func ShouldExposeOperation

func ShouldExposeOperation(operation OperationDescriptor, filter ToolFilterConfig) bool

Types

type APIProfile

type APIProfile struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

type APIProfileRemoval

type APIProfileRemoval struct {
	Profile                  APIProfile `json:"profile"`
	CredentialDeleted        bool       `json:"credentialDeleted"`
	ToolConfigurationDeleted bool       `json:"toolConfigurationDeleted"`
	Warnings                 []string   `json:"warnings"`
}

type APIProfileStatus

type APIProfileStatus struct {
	ID                         string `json:"id"`
	Name                       string `json:"name"`
	CredentialAvailable        bool   `json:"credentialAvailable"`
	CredentialStoredInKeychain bool   `json:"credentialStoredInKeychain"`
	ToolConfigPath             string `json:"toolConfigPath"`
	EnabledEndpointCount       int    `json:"enabledEndpointCount"`
}

type APIResponse

type APIResponse struct {
	Profile    *APIProfile       `json:"profile,omitempty"`
	OK         bool              `json:"ok"`
	Status     int               `json:"status"`
	StatusText string            `json:"statusText"`
	Headers    map[string]string `json:"headers"`
	Body       any               `json:"body"`
	Truncated  bool              `json:"truncated"`
	Truncation *TruncationInfo   `json:"truncation,omitempty"`
	Pagination *PaginationInfo   `json:"pagination,omitempty"`
}

func ExecuteOperation

func ExecuteOperation(ctx context.Context, operation OperationDescriptor, input ToolInput, cfg Config, client HTTPDoer) (APIResponse, error)

type ActionConfirmation

type ActionConfirmation struct {
	ApplicationName string
	Profile         *APIProfile
	Action          string
	Destination     string
	Details         any
}

type ActionConfirmer

type ActionConfirmer interface {
	Confirm(context.Context, ActionConfirmation) error
}

type AuthConfig

type AuthConfig struct {
	Type        string            `json:"type,omitempty"`
	Token       string            `json:"token,omitempty"`
	TokenEnv    string            `json:"tokenEnv,omitempty"`
	Username    string            `json:"username,omitempty"`
	UsernameEnv string            `json:"usernameEnv,omitempty"`
	Password    string            `json:"password,omitempty"`
	PasswordEnv string            `json:"passwordEnv,omitempty"`
	In          string            `json:"in,omitempty"`
	Name        string            `json:"name,omitempty"`
	Value       string            `json:"value,omitempty"`
	ValueEnv    string            `json:"valueEnv,omitempty"`
	Keychain    *KeychainConfig   `json:"keychain,omitempty"`
	Headers     map[string]string `json:"headers,omitempty"`
}

type Config

type Config struct {
	Name              string
	Version           string
	Spec              string
	AllowRemoteSpec   bool
	AllowExternalRefs bool
	ServerURL         string
	Auth              ResolvedAuthConfig
	Headers           map[string]string
	Tools             ToolFilterConfig
	ToolPolicy        *ResolvedToolPolicyConfig
	Profiles          *ResolvedProfilesConfig
	MaxResponseChars  int
}

func LoadConfigFile

func LoadConfigFile(configPath string, lookup LookupEnv) (Config, error)

func LoadConfigFromArgs

func LoadConfigFromArgs(args []string) (Config, error)

func LoadEmbeddedConfig

func LoadEmbeddedConfig(lookup LookupEnv) (Config, error)

func NormalizeConfig

func NormalizeConfig(input ConfigInput, baseDir string, lookup LookupEnv) (Config, error)

type ConfigInput

type ConfigInput struct {
	Name              string            `json:"name,omitempty"`
	Version           string            `json:"version,omitempty"`
	Spec              string            `json:"spec"`
	AllowRemoteSpec   bool              `json:"allowRemoteSpec,omitempty"`
	AllowExternalRefs bool              `json:"allowExternalRefs,omitempty"`
	ServerURL         string            `json:"serverUrl,omitempty"`
	Auth              *AuthConfig       `json:"auth,omitempty"`
	Headers           map[string]string `json:"headers,omitempty"`
	Tools             ToolFilterConfig  `json:"tools,omitempty"`
	ToolPolicy        *ToolPolicyConfig `json:"toolPolicy,omitempty"`
	Profiles          *ProfilesConfig   `json:"profiles,omitempty"`
	MaxResponseChars  int               `json:"maxResponseChars,omitempty"`
}

type ConfigureToolsInput

type ConfigureToolsInput struct {
	AddFeatures     []string `json:"addFeatures,omitempty"`
	RemoveFeatures  []string `json:"removeFeatures,omitempty"`
	AddEndpoints    []string `json:"addEndpoints,omitempty"`
	RemoveEndpoints []string `json:"removeEndpoints,omitempty"`
}

type CredentialPrompter

type CredentialPrompter interface {
	Prompt(context.Context, string) ([]byte, error)
}

type ExtensionBatchItem

type ExtensionBatchItem struct {
	ID        string    `json:"id"`
	Operation string    `json:"operation"`
	Input     ToolInput `json:"input"`
}

type ExtensionBatchRequest

type ExtensionBatchRequest struct {
	Profile     string               `json:"profile,omitempty"`
	Action      string               `json:"action"`
	Details     any                  `json:"details,omitempty"`
	Items       []ExtensionBatchItem `json:"items"`
	StopOnError bool                 `json:"stopOnError"`
	// AfterApprovalCheck revalidates workflow-owned preconditions after the
	// native approval dialog and immediately before credential resolution.
	// It must be read-only. This narrows, but cannot make atomic, the interval
	// between an upstream state check and the first write.
	AfterApprovalCheck func(context.Context) error `json:"-"`
}

type ExtensionBatchResult

type ExtensionBatchResult struct {
	ID        string       `json:"id"`
	Operation string       `json:"operation"`
	Response  *APIResponse `json:"response,omitempty"`
	Error     string       `json:"error,omitempty"`
}

type ExtensionRuntime

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

func (*ExtensionRuntime) ExecuteBatch

func (*ExtensionRuntime) ExecuteRead

func (r *ExtensionRuntime) ExecuteRead(ctx context.Context, profileID, operationName string, input ToolInput) (APIResponse, error)

func (*ExtensionRuntime) ResolveProfile

func (r *ExtensionRuntime) ResolveProfile(profileID string) (APIProfile, error)

type ExtensionTool

type ExtensionTool struct {
	Tool    *mcp.Tool
	Handler func(context.Context, *ExtensionRuntime, *mcp.CallToolRequest) (*mcp.CallToolResult, error)
}

type HTTPDoer

type HTTPDoer interface {
	Do(*http.Request) (*http.Response, error)
}

type KeychainConfig

type KeychainConfig struct {
	Service         string `json:"service"`
	Account         string `json:"account"`
	PromptOnMissing bool   `json:"promptOnMissing,omitempty"`
}

type KeychainStore

type KeychainStore interface {
	Get(KeychainConfig) ([]byte, error)
	Set(KeychainConfig, []byte) error
	Delete(KeychainConfig) error
}

type LookupEnv

type LookupEnv func(string) (string, bool)

type OperationDescriptor

type OperationDescriptor struct {
	ToolName    string
	Method      string
	Path        string
	ServerURL   string
	OperationID string
	Title       string
	Description string
	Tags        []string
	Parameters  []ParameterDescriptor
	RequestBody *RequestBodyDescriptor
}

func CollectOperations

func CollectOperations(doc *openapi3.T, cfg Config) []OperationDescriptor

func LoadOperations

func LoadOperations(ctx context.Context, cfg Config) ([]OperationDescriptor, error)

type PaginationInfo

type PaginationInfo struct {
	Source    string `json:"source"`
	Page      int    `json:"page"`
	PageCount int    `json:"pageCount"`
	PageSize  int    `json:"pageSize,omitempty"`
	Total     int    `json:"total,omitempty"`
	NextURL   string `json:"nextUrl,omitempty"`
	FinalPage bool   `json:"finalPage"`
}

type ParameterDescriptor

type ParameterDescriptor struct {
	Name        string
	In          string
	Required    bool
	Description string
	Schema      *openapi3.SchemaRef
}

type ProfileRegistry

type ProfileRegistry struct {
	Version  int          `json:"version"`
	Profiles []APIProfile `json:"profiles"`
}

type ProfilesConfig

type ProfilesConfig struct {
	RegistryFile       string `json:"registryFile,omitempty"`
	DefaultProfileID   string `json:"defaultProfileId,omitempty"`
	DefaultProfileName string `json:"defaultProfileName,omitempty"`
}

type RequestBodyDescriptor

type RequestBodyDescriptor struct {
	Required     bool
	Description  string
	ContentTypes []string
	Schemas      map[string]*openapi3.SchemaRef
}

type ResolvedAuthConfig

type ResolvedAuthConfig struct {
	Type              string
	Token             string
	Username          string
	Password          string
	In                string
	Name              string
	Value             string
	Headers           map[string]string
	RedactionValues   []string
	Keychain          *KeychainConfig
	CredentialMissing bool
}

type ResolvedProfilesConfig

type ResolvedProfilesConfig struct {
	RegistryPath       string
	ProfilesDirectory  string
	DefaultProfileID   string
	DefaultProfileName string
}

type ResolvedToolPolicyConfig

type ResolvedToolPolicyConfig struct {
	UserConfigPath  string
	CatalogPath     string
	DefaultFeatures []string
}

type ToolEndpointStatus

type ToolEndpointStatus struct {
	Name        string   `json:"name"`
	Title       string   `json:"title"`
	Description string   `json:"description"`
	Method      string   `json:"method"`
	Path        string   `json:"path"`
	Enabled     bool     `json:"enabled"`
	Features    []string `json:"features,omitempty"`
}

type ToolFeature

type ToolFeature struct {
	ID          string   `json:"id"`
	Title       string   `json:"title"`
	Description string   `json:"description"`
	Risk        string   `json:"risk"`
	Endpoints   []string `json:"endpoints"`
}

type ToolFeatureCatalog

type ToolFeatureCatalog struct {
	Version  int           `json:"version"`
	Features []ToolFeature `json:"features"`
}

type ToolFeatureStatus

type ToolFeatureStatus struct {
	ID            string   `json:"id"`
	Title         string   `json:"title"`
	Description   string   `json:"description"`
	Risk          string   `json:"risk"`
	Enabled       bool     `json:"enabled"`
	EndpointCount int      `json:"endpointCount"`
	Endpoints     []string `json:"endpoints"`
}

type ToolFilterConfig

type ToolFilterConfig struct {
	Include       []string `json:"include,omitempty"`
	Exclude       []string `json:"exclude,omitempty"`
	DefaultPolicy string   `json:"defaultPolicy,omitempty"`
}

type ToolInput

type ToolInput struct {
	Profile     string         `json:"profile,omitempty"`
	Path        map[string]any `json:"path,omitempty"`
	Query       map[string]any `json:"query,omitempty"`
	Headers     map[string]any `json:"headers,omitempty"`
	Cookies     map[string]any `json:"cookies,omitempty"`
	ContentType string         `json:"contentType,omitempty"`
	Body        any            `json:"body,omitempty"`
}

type ToolPolicyConfig

type ToolPolicyConfig struct {
	UserConfigDirectory string   `json:"userConfigDirectory"`
	UserConfigFile      string   `json:"userConfigFile,omitempty"`
	Catalog             string   `json:"catalog"`
	DefaultFeatures     []string `json:"defaultFeatures"`
}

type TruncationInfo

type TruncationInfo struct {
	Code                 string `json:"code"`
	LimitBytes           int    `json:"limitBytes"`
	ReceivedBytesAtLeast int    `json:"receivedBytesAtLeast"`
	PartialBodyDiscarded bool   `json:"partialBodyDiscarded"`
	RetryAdvice          string `json:"retryAdvice"`
}

type UserToolPolicy

type UserToolPolicy struct {
	Version           int      `json:"version"`
	EnabledFeatures   []string `json:"enabledFeatures"`
	EnabledEndpoints  []string `json:"enabledEndpoints"`
	DisabledEndpoints []string `json:"disabledEndpoints"`
}

Jump to

Keyboard shortcuts

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