server

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIKeyAuthMiddleware added in v0.2.0

func APIKeyAuthMiddleware(validAPIKey string, next http.Handler, logger *slog.Logger) http.Handler

func LoggingMiddleware added in v0.2.0

func LoggingMiddleware(logger *slog.Logger, next http.Handler) http.Handler

func SecurityHeadersMiddleware added in v0.2.0

func SecurityHeadersMiddleware(next http.Handler) http.Handler

func SetupLogger added in v0.2.0

func SetupLogger(level string) *slog.Logger

Types

type Config

type Config struct {
	SearchXNGURL  string `mapstructure:"searchxng_url" envconfig:"SEARCHXNG_URL"`   // SearXNG base URL (e.g., https://searchx.ng)
	GoogleAPIKey  string `mapstructure:"google_api_key" envconfig:"GOOGLE_API_KEY"` // Google Custom Search API key
	GoogleCX      string `mapstructure:"google_cx" envconfig:"GOOGLE_CX"`           // Google Search Engine ID
	BingAPIKey    string `mapstructure:"bing_api_key" envconfig:"BING_API_KEY"`     // Bing Search API key
	BraveAPIKey   string `mapstructure:"brave_api_key" envconfig:"BRAVE_API_KEY"`   // Brave Search API key
	MaxResults    int    `mapstructure:"max_results" envconfig:"MAX_RESULTS"`       // Default max results (default: 10)
	DefaultEngine string `mapstructure:"default_engine" envconfig:"DEFAULT_ENGINE"` // Default search engine
	ListenAddr    string `mapstructure:"listen_addr" envconfig:"LISTEN_ADDR"`       // HTTP listen address
	URIPrefix     string `mapstructure:"uri_prefix" envconfig:"URI_PREFIX"`         // URI prefix for HTTP endpoints
	LogLevel      string `mapstructure:"log_level" envconfig:"LOG_LEVEL"`           // Log level: debug, info, warn, error (default: info)
	APIKey        string `mapstructure:"api_key" envconfig:"API_KEY"`               // API Key for HTTP endpoint authentication
	DisableSSE    bool   `mapstructure:"disable_sse" envconfig:"DISABLE_SSE"`       // Disable SSE endpoint (default: false)
}

Config for the web search server. Can be loaded from environment variables using ProcessConfig. Supports configuration from file (~/.webpawm/config.json) and environment variables.

type RESTHandler added in v0.3.2

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

RESTHandler provides plain JSON HTTP endpoints for web search and fetch.

func NewRESTHandler added in v0.3.2

func NewRESTHandler(srv *WebServer) *RESTHandler

NewRESTHandler creates a new REST handler wrapping the given WebServer.

func (*RESTHandler) HandleEngines added in v0.3.2

func (h *RESTHandler) HandleEngines(w http.ResponseWriter, r *http.Request)

HandleEngines handles GET /api/engines

func (*RESTHandler) HandleFetch added in v0.3.2

func (h *RESTHandler) HandleFetch(w http.ResponseWriter, r *http.Request)

HandleFetch handles POST /api/fetch

func (*RESTHandler) HandleHealth added in v0.3.2

func (h *RESTHandler) HandleHealth(w http.ResponseWriter, r *http.Request)

HandleHealth handles GET /api/health

func (*RESTHandler) HandleSearch added in v0.3.2

func (h *RESTHandler) HandleSearch(w http.ResponseWriter, r *http.Request)

HandleSearch handles POST /api/search

type SearchResult added in v0.2.0

type SearchResult struct {
	Index   int    `json:"index"`
	Title   string `json:"title"`
	Link    string `json:"link"`
	Snippet string `json:"snippet"`
}

type SearchSummary added in v0.2.0

type SearchSummary struct {
	TotalRawResults    int      `json:"total_raw_results"`
	TotalUniqueResults int      `json:"total_unique_results"`
	OriginalQuery      string   `json:"original_query"`
	SearchQueries      []string `json:"search_queries"`
	EnginesUsed        []string `json:"engines_used"`
	SearchDepth        string   `json:"search_depth"`
}

type WebFetchParams added in v0.2.0

type WebFetchParams struct {
	URL        string `json:"url" jsonschema:"URL of the website to fetch"`
	MaxLength  int    `json:"max_length,omitempty" jsonschema:"Maximum number of characters to return (default: 5000)"`
	StartIndex int    `json:"start_index,omitempty" jsonschema:"Start content from this character index (default: 0)"`
	Raw        bool   `json:"raw,omitempty" jsonschema:"If true, returns the raw HTML including <script> and <style> blocks (default: false)"`
}

WebFetchParams represents the parameters for web_fetch tool

type WebFetchResponse added in v0.2.0

type WebFetchResponse struct {
	ContentType    string `json:"content_type"`
	OriginalLength int    `json:"original_length"`
	Content        string `json:"content"`
	Truncated      bool   `json:"truncated"`
	NextStart      int    `json:"next_start,omitempty"`
	Error          string `json:"error,omitempty"`
	URL            string `json:"url"`
}

type WebSearchParams

type WebSearchParams struct {
	Query           string   `json:"query" jsonschema:"The search query"`
	Engine          string   `json:"engine,omitempty" jsonschema:"Single search engine to use (mutually exclusive with engines)"`
	Engines         []string `json:"engines,omitempty" jsonschema:"List of search engines to use (mutually exclusive with engine)"`
	MaxResults      int      `json:"max_results,omitempty" jsonschema:"Maximum number of results to return (default: 10)"`
	Language        string   `json:"language,omitempty" jsonschema:"Language code for search results (e.g., 'en', 'zh')"`
	ArxivCategory   string   `json:"arxiv_category,omitempty" jsonschema:"Arxiv category for academic paper search (e.g., 'cs.AI', 'math.CO')"`
	SearchDepth     string   `` /* 135-byte string literal not displayed */
	IncludeAcademic bool     `json:"include_academic,omitempty" jsonschema:"Include academic papers from Arxiv (default: false)"`
	AutoQueryExpand bool     `` /* 145-byte string literal not displayed */
	AutoDeduplicate bool     `json:"auto_deduplicate,omitempty" jsonschema:"Automatically deduplicate results by URL (default: true)"`
}

WebSearchParams represents the parameters for web_search tool

type WebSearchResponse added in v0.2.0

type WebSearchResponse struct {
	TotalResults int            `json:"total_results"`
	Summary      SearchSummary  `json:"summary"`
	Results      []SearchResult `json:"results"`
	SearchTime   string         `json:"search_time"`
}

type WebServer added in v0.2.0

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

WebServer represents the MCP web search server

func NewWebServer added in v0.2.0

func NewWebServer(config Config) *WebServer

NewWebServer creates a new web search server

func (*WebServer) AvailableEngines added in v0.3.2

func (s *WebServer) AvailableEngines() []string

AvailableEngines returns a list of available search engine names.

func (*WebServer) CreateMcpServer added in v0.2.0

func (s *WebServer) CreateMcpServer() *server.MCPServer

CreateMcpServer creates the MCP server with tools

func (*WebServer) HandleWebFetch added in v0.3.2

func (s *WebServer) HandleWebFetch(ctx context.Context, params WebFetchParams) (*WebFetchResponse, error)

func (*WebServer) HandleWebSearch added in v0.3.2

func (s *WebServer) HandleWebSearch(ctx context.Context, params WebSearchParams) (*WebSearchResponse, error)

HandleWebSearch handles the unified web_search tool

Jump to

Keyboard shortcuts

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