server

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 1, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound      = errors.New("not found")
	ErrInvalidURL    = errors.New("invalid URL")
	ErrInvalidSpec   = errors.New("invalid OpenAPI spec")
	ErrFileOperation = errors.New("file operation failed")
)

Common error types for consistent error handling

View Source
var (
	ErrServerCreation = errors.New("failed to create server")
	ErrServerStart    = errors.New("failed to start server")
)

Common errors for server operations

View Source
var SpecsDir string

SpecsDir is the directory where specs are stored

Functions

This section is empty.

Types

type APISpec

type APISpec struct {
	URL  string      `json:"url"`
	Spec *openapi3.T `json:"spec"`
}

APISpec represents an OpenAPI specification

type ConfigInterface

type ConfigInterface interface {
	GetGitHubToken() string
	GetSpecs() []string
	ShouldUpdateConfig() bool
	HasSpec(url string) bool
	AddSpec(url string)
	RemoveSpec(url string)
	Save() error
}

ConfigInterface defines the required config methods

var Config ConfigInterface

Config is the global configuration

type LoggerInterface

type LoggerInterface interface {
	Debugw(msg string, keysAndValues ...interface{})
	Infow(msg string, keysAndValues ...interface{})
	Warnw(msg string, keysAndValues ...interface{})
	Errorw(msg string, keysAndValues ...interface{})
	Fatalw(msg string, keysAndValues ...interface{})
}

LoggerInterface defines the required logging methods

var Logger LoggerInterface

Logger is the global logger

type MCPHandler

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

MCPHandler handles OpenAPI specs for the MCP server

func NewHandler

func NewHandler(specsDir string, logger LoggerInterface, config ConfigInterface) *MCPHandler

NewHandler creates a new MCPHandler

func (*MCPHandler) AddSpec

func (h *MCPHandler) AddSpec(specID string, spec *APISpec)

AddSpec adds a spec to the handler

func (*MCPHandler) DeleteSpec

func (h *MCPHandler) DeleteSpec(specID string) error

DeleteSpec removes a spec from memory and deletes its file

func (*MCPHandler) GetSpec

func (h *MCPHandler) GetSpec(w http.ResponseWriter, r *http.Request)

GetSpec gets a registered OpenAPI specification via HTTP

func (*MCPHandler) GetSpecs

func (h *MCPHandler) GetSpecs() map[string]*APISpec

GetSpecs returns a copy of the loaded specs map

func (*MCPHandler) HandleMCPRequest

func (h *MCPHandler) HandleMCPRequest(ctx context.Context, req *MCPRequest) (*MCPResponse, error)

HandleMCPRequest handles MCP requests

func (*MCPHandler) ListEndpoints

func (h *MCPHandler) ListEndpoints(w http.ResponseWriter, r *http.Request)

ListEndpoints lists all endpoints in a registered OpenAPI specification via HTTP

func (*MCPHandler) LoadOpenAPISpec

func (h *MCPHandler) LoadOpenAPISpec(ctx context.Context, specURL string) (*openapi3.T, error)

LoadOpenAPISpec loads an OpenAPI specification from a URL

func (*MCPHandler) RegisterSpec

func (h *MCPHandler) RegisterSpec(w http.ResponseWriter, r *http.Request)

RegisterSpec registers a new OpenAPI specification via HTTP

func (*MCPHandler) SaveSpec

func (h *MCPHandler) SaveSpec(specID string, spec *APISpec) error

SaveSpec saves a spec to a file

type MCPRequest

type MCPRequest struct {
	Query string `json:"query"`
}

MCPRequest represents an MCP request

type MCPResponse

type MCPResponse struct {
	Context string `json:"context"`
}

MCPResponse represents an MCP response

type Server

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

Server represents the OpenAPI Explorer server

func CreateServer

func CreateServer(specsDir string, logger LoggerInterface, config ConfigInterface) (*Server, error)

CreateServer creates a new Server instance

func (*Server) GetHandler

func (s *Server) GetHandler() *MCPHandler

GetHandler returns the MCPHandler

func (*Server) GetMCPServer

func (s *Server) GetMCPServer() *server.MCPServer

GetMCPServer returns the MCPServer

func (*Server) Start

func (s *Server) Start() error

Start starts the server

Jump to

Keyboard shortcuts

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