proxy

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const NamespaceSeparator = "___"

NamespaceSeparator is used to create tool names in an aggregated proxy server.

Variables

This section is empty.

Functions

func RegisterHandler

func RegisterHandler(endpoint string, proxy *MCPProxy, mux *http.ServeMux, options *mcp.StreamableHTTPOptions)

RegisterHandler registers a ServerProvider with the HTTP mux.

Types

type CentianProxy

type CentianProxy struct {
	Name       string
	ServerID   string // used to uniquely identify this specific object instance
	Config     *config.GlobalConfig
	Mux        *http.ServeMux
	Server     *http.Server
	Logger     *logging.Logger // Shared base logger (ONE file handle)
	Gateways   map[string]*MCPProxy
	APIKeys    *auth.APIKeyStore
	AuthHeader string
}

CentianProxy is the main server struct.

It holds 4 critical components: - mux - used to register URL paths - server - used to serve the mux - logger - main logger for all events in the proxied endpoints - gateways - holds all gateways and proxy endpoints for easy access

Additionally it has a reference to the global config which was loaded to initialize this server.

func NewCentianProxy

func NewCentianProxy(globalConfig *config.GlobalConfig) (*CentianProxy, error)

NewCentianProxy takes a GlobalConfig struct and returns a new CentianProxy.

func (*CentianProxy) Setup

func (c *CentianProxy) Setup() error

Setup uses CentianServer.config to create all gateways and endpoints.

type CentianProxySession

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

CentianProxySession represents a session with one or more downstream connections. For single-server mode, the map has exactly one entry. For aggregated mode, the map has multiple entries.

func (*CentianProxySession) GetConnectionByName

func (s *CentianProxySession) GetConnectionByName(serverName string) (*DownstreamConnection, error)

GetConnectionByName returns a MCP connection for the given server name.

type DownstreamConnection

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

DownstreamConnection represents a connection to a downstream MCP server.

func NewDownstreamConnection

func NewDownstreamConnection(name string, cfg *config.MCPServerConfig) *DownstreamConnection

NewDownstreamConnection creates an unconnected downstream wrapper.

func (*DownstreamConnection) CallTool

func (dc *DownstreamConnection) CallTool(ctx context.Context, toolName string, args map[string]any) (*mcp.CallToolResult, error)

CallTool forwards a tool call to the downstream server.

func (*DownstreamConnection) Close

func (dc *DownstreamConnection) Close() error

Close terminates the downstream connection.

func (*DownstreamConnection) Connect

func (dc *DownstreamConnection) Connect(ctx context.Context, authHeaders map[string]string) error

Connect establishes connection to downstream server authHeaders: additional headers from upstream request (for passthrough auth).

func (*DownstreamConnection) IsConnected

func (dc *DownstreamConnection) IsConnected() bool

IsConnected returns true if connection was established and not yet closed.

func (*DownstreamConnection) Tools

func (dc *DownstreamConnection) Tools() []*mcp.Tool

Tools returns the cached tools (nil if not connected).

type EventProcessor

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

EventProcessor is used to call the main processing loop for any MCP transport method.

func NewEventProcessor

func NewEventProcessor(logger *logging.Logger, processors *processor.Chain) *EventProcessor

NewEventProcessor returns a new EventProcessor with the provided logger and processors.

func (*EventProcessor) Process

func (ep *EventProcessor) Process(event common.McpEventInterface) error

Process starts the main event loop processing, including logging and any configured processors.

type HeaderRoundTripper

type HeaderRoundTripper struct {
	Base    http.RoundTripper
	Headers map[string]string
}

HeaderRoundTripper is used to store.

func (HeaderRoundTripper) RoundTrip

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

RoundTrip adds the header from HeaderRoundTripper to the request. This is done so both configured headers as well as headers from the client are included in the request.

type MCPProxy

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

MCPProxy is a unified proxy that handles both aggregated (multiple servers with namespaced tools) and single-server (pass-through) modes.

Mode is controlled by the namespaceTools flag:

  • true: Aggregated mode - tools are prefixed with "serverName__"
  • false: Single mode - tools pass through with original names

func NewAggregatedProxy

func NewAggregatedProxy(name, endpoint string, gatewayConfig *config.GatewayConfig) *MCPProxy

NewAggregatedProxy creates a proxy that aggregates multiple downstream servers. Tools from each server are namespaced as "serverName__toolName" to avoid collisions.

func NewSingleProxy

func NewSingleProxy(serverName, endpoint string, serverConfig *config.MCPServerConfig) *MCPProxy

NewSingleProxy creates a proxy for a single downstream server. Tools pass through with their original names (no namespacing).

func (*MCPProxy) Close

func (p *MCPProxy) Close() error

Close terminates all sessions and their downstream connections.

func (*MCPProxy) GetServerForRequest

func (p *MCPProxy) GetServerForRequest(r *http.Request) *mcp.Server

GetServerForRequest returns (or creates) an MCP server for the given HTTP request's session.

func (*MCPProxy) NewMcpServer

func (p *MCPProxy) NewMcpServer() *mcp.Server

NewMcpServer returns a new *mcp.Server based on the MCPProxy name.

Jump to

Keyboard shortcuts

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