webfetch

package
v0.59.5 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultTimeout for HTTP requests
	DefaultTimeout = 15 * time.Second

	// UserAgent for web requests
	UserAgent = "mcp-devtools-fetch/1.0 (AI Assistant Tool)"

	// MaxContentSize to prevent memory issues (20MB)
	MaxContentSize = 20 * 1024 * 1024
)

Variables

This section is empty.

Functions

func FilterHTMLByFragment added in v0.58.0

func FilterHTMLByFragment(logger *logrus.Logger, htmlContent string, fragment string) (string, error)

FilterHTMLByFragment filters HTML content to only include the section identified by the fragment ID and its subsections. For heading elements, this includes all following content until the next heading of the same or higher level. For container elements (like section, div, article), this includes all child content. Returns the filtered HTML or the original content if the fragment is not found.

func ProcessContent

func ProcessContent(logger *logrus.Logger, response *FetchURLResponse, raw bool, fragment string) (string, error)

ProcessContent determines how to process content based on its type

Types

type ContentTypeInfo

type ContentTypeInfo struct {
	MIME     string
	IsHTML   bool
	IsText   bool
	IsBinary bool
}

ContentTypeInfo represents information about detected content type

func DetectContentType

func DetectContentType(contentType, content string) ContentTypeInfo

DetectContentType analyses the content type and determines how to process it

type FetchURLRequest

type FetchURLRequest struct {
	URL string `json:"url"`

	MaxLength  int  `json:"max_length,omitempty"`
	StartIndex int  `json:"start_index,omitempty"`
	Raw        bool `json:"raw,omitempty"`
	// contains filtered or unexported fields
}

FetchURLRequest represents the parameters for the fetch-url tool

type FetchURLResponse

type FetchURLResponse struct {
	ContentType      string `json:"content_type,omitempty"`
	StatusCode       int    `json:"status_code,omitempty"`
	Content          string `json:"content"`
	Truncated        bool   `json:"truncated"`
	StartIndex       int    `json:"start_index"`
	EndIndex         int    `json:"end_index"`
	TotalLength      int    `json:"total_length"`
	TotalLines       int    `json:"total_lines"`
	StartLine        int    `json:"start_line"`
	EndLine          int    `json:"end_line"`
	NextChunkPreview string `json:"next_chunk_preview,omitempty"`
	RemainingLines   int    `json:"remaining_lines"`
	Message          string `json:"message,omitempty"`
}

FetchURLResponse represents the response from the fetch-url tool

type FetchURLTool

type FetchURLTool struct{}

FetchURLTool implements URL fetching with HTML-to-markdown conversion

func (*FetchURLTool) Definition

func (t *FetchURLTool) Definition() mcp.Tool

Definition returns the tool's definition for MCP registration

func (*FetchURLTool) Execute

func (t *FetchURLTool) Execute(ctx context.Context, logger *logrus.Logger, cache *sync.Map, args map[string]any) (*mcp.CallToolResult, error)

Execute executes the fetch-url tool

func (*FetchURLTool) ProvideExtendedInfo added in v0.22.0

func (t *FetchURLTool) ProvideExtendedInfo() *tools.ExtendedHelp

ProvideExtendedInfo provides detailed usage information for the fetch_url tool

type MarkdownConverter

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

MarkdownConverter handles HTML to markdown conversion with custom rules

func NewMarkdownConverter

func NewMarkdownConverter() *MarkdownConverter

NewMarkdownConverter creates a new converter with AI-friendly settings

func (*MarkdownConverter) ConvertToMarkdown

func (c *MarkdownConverter) ConvertToMarkdown(logger *logrus.Logger, htmlContent string) (string, error)

ConvertToMarkdown converts HTML content to clean markdown

type ParsedURL added in v0.58.0

type ParsedURL struct {
	URLWithoutFragment string
	Fragment           string
}

ParsedURL contains the URL split into components. Fragment is derived from the URL's fragment component (after '#') when present, rather than being exposed as a separate tool parameter.

type WebClient

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

WebClient handles HTTP requests for fetching web content

func NewWebClient

func NewWebClient() *WebClient

NewWebClient creates a new web client with proper timeouts, context support and proxy configuration

func (*WebClient) FetchContent

func (c *WebClient) FetchContent(ctx context.Context, logger *logrus.Logger, targetURL string) (*FetchURLResponse, error)

FetchContent fetches content from a URL with context support

Jump to

Keyboard shortcuts

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