mcpproxy

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TransportTypeHttp  = "http"
	TransportTypeStdio = "stdio"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CallHistory

type CallHistory struct {
	ToolCalls     []*ToolCall
	ResourceReads []*ResourceRead
	PromptGets    []*PromptGet
}

CallHistory contains a complete call history for a server

type CallRecord

type CallRecord struct {
	ServerName string    `json:"serverName"`
	Timestamp  time.Time `json:"timestamp"`
	Success    bool      `json:"success"`
	Error      string    `json:"error,omitempty"`
}

CallRecord is the base for all MCP interaction types

type HeaderRoundTripper

type HeaderRoundTripper struct {
	// Headers is the map of headers to add to each request
	Headers map[string]string
	// Transport is the underlying RoundTripper to use for the actual request
	Transport http.RoundTripper
}

HeaderRoundTripper wraps an http.RoundTripper and adds custom headers to every request.

func NewHeaderRoundTripper

func NewHeaderRoundTripper(headers map[string]string, transport http.RoundTripper) *HeaderRoundTripper

NewHeaderRoundTripper creates a new HeaderRoundTripper with the given headers. If transport is nil, http.DefaultTransport is used.

func (*HeaderRoundTripper) RoundTrip

func (h *HeaderRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the http.RoundTripper interface. It adds the configured headers to the request before passing it to the underlying transport.

type MCPConfig

type MCPConfig struct {
	MCPServers map[string]*ServerConfig `json:"mcpServers" yaml:"mcpServers"`
}

MCPConfig represents the top-level MCP configuration file structure used by Claude Code, Cursor, and other MCP clients.

func ParseConfig

func ParseConfig(data []byte) (*MCPConfig, error)

ParseConfig parses MCP config data from bytes. The data can be in JSON or YAML format.

func ParseConfigFile

func ParseConfigFile(path string) (*MCPConfig, error)

ParseConfigFile reads and parses an MCP config file from the given path. The file can be in JSON or YAML format.

func (*MCPConfig) GetEnabledServers

func (c *MCPConfig) GetEnabledServers() map[string]*ServerConfig

GetEnabledServers returns a map of server names to their configurations, excluding any servers marked as disabled.

func (*MCPConfig) GetServer

func (c *MCPConfig) GetServer(name string) (*ServerConfig, bool)

GetServer returns the configuration for a specific server by name.

func (*MCPConfig) ToFile

func (c *MCPConfig) ToFile(path string) error

ToFile writes the configuration to the specified path

type PromptGet

type PromptGet struct {
	CallRecord
	Name    string                `json:"name"` // this is copies to the top level struct for convenience
	Request *mcp.GetPromptRequest `json:"request"`
	Result  *mcp.GetPromptResult  `json:"result"`
}

PromptGet records a prompt get

type Recorder

type Recorder interface {
	RecordToolCall(req *mcp.CallToolRequest, res *mcp.CallToolResult, err error, start time.Time)
	RecordResourceRead(req *mcp.ReadResourceRequest, res *mcp.ReadResourceResult, err error, start time.Time)
	RecordPromptGet(req *mcp.GetPromptRequest, res *mcp.GetPromptResult, err error, start time.Time)
	GetHistory() CallHistory
}

func NewRecorder

func NewRecorder(serverName string) Recorder

type ResourceRead

type ResourceRead struct {
	CallRecord
	URI     string                   `json:"uri"` // this is copied to the top level struct for convenience
	Request *mcp.ReadResourceRequest `json:"request"`
	Result  *mcp.ReadResourceResult  `json:"result"`
}

ResourceRead records a resource read

type Server

type Server interface {
	Run(ctx context.Context) error
	GetConfig() (*ServerConfig, error)
	GetName() string
	GetAllowedToolNames() []string
	Close() error
	GetCallHistory() CallHistory
	// WaitReady blocks until the server has initialized and is ready to serve
	WaitReady(ctx context.Context) error
}

func NewProxyServerForConfig

func NewProxyServerForConfig(ctx context.Context, name string, config *ServerConfig) (Server, error)

type ServerConfig

type ServerConfig struct {
	// Type specifies the server type: "stdio" or "http"
	// If not specified, will be inferred from URL (http) or Command (stdio)
	Type string `json:"type,omitempty"`

	// Command is the executable to run (e.g., "node", "python", "npx")
	// Used for stdio servers
	Command string `json:"command,omitempty"`

	// Args are the command-line arguments to pass to the command
	// Used for stdio servers
	Args []string `json:"args,omitempty"`

	// Env contains environment variables to set for the server process
	// Used for stdio servers
	Env map[string]string `json:"env,omitempty"`

	// URL is the HTTP endpoint for the MCP server
	// Used for http servers. May contain environment variable references
	// like ${VAR} or ${VAR:-default}
	URL string `json:"url,omitempty"`

	// Headers are HTTP headers to send with requests
	// Used for http servers. Values may contain environment variable references
	Headers map[string]string `json:"headers,omitempty"`

	// Disabled indicates whether this server should be skipped
	Disabled bool `json:"disabled,omitempty"`

	// AlwaysAllow is a list of tools/resources that should always be allowed
	AlwaysAllow []string `json:"alwaysAllow,omitempty"`

	// EnableAllTools sets all tools to be allowed
	EnableAllTools bool `json:"enableAllTools"`
}

ServerConfig represents the configuration for a single MCP server. Supports both stdio (command-based) and HTTP-based servers.

func (*ServerConfig) IsHttp

func (s *ServerConfig) IsHttp() bool

IsHttp returns true if this is an HTTP-based server.

func (*ServerConfig) IsStdio

func (s *ServerConfig) IsStdio() bool

IsStdio returns true if this is a stdio-based (command) server.

type ServerManager

type ServerManager interface {
	GetMcpServerFiles() ([]string, error)
	GetMcpServers() []Server
	// Start is non-blocking. Caller must ensure this is only called once, and called before Close
	Start(ctx context.Context) error
	// Close closes associated server resources. Caller must ensure this is only called once, and called after Start
	Close() error

	// aggregate call tracking
	GetAllCallHistory() *CallHistory
	GetCallHistoryForServer(serverName string) (CallHistory, bool)
}

func NewServerManger

func NewServerManger(ctx context.Context, cfg *MCPConfig) (ServerManager, error)

type ToolCall

type ToolCall struct {
	CallRecord
	ToolName string               `json:"name"` // this is copied to the top level struct for convenience
	Request  *mcp.CallToolRequest `json:"request,omitempty"`
	Result   *mcp.CallToolResult  `json:"result,omitempty"`
}

ToolCall records a tool invocation

Jump to

Keyboard shortcuts

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