Documentation
¶
Overview ¶
Package lp provides web page reading via LightPanda's MCP transport.
Architecture ¶
url(req) +---------------+ stdio +-------------+
-------->| MCP Client +--------->| lightpanda |
| (mcp.go) | | mcp |
<--------+ |<---------+ |
markdown +---------------+ markdown +-------------+
The package uses LightPanda's native MCP server (lightpanda mcp subcommand, stdio transport). Each call spawns a fresh subprocess.
Modes ¶
- local (default): spawns "lightpanda mcp" subprocess locally.
- cloud: connects to LightPanda Cloud MCP/SSE endpoint. Switch via the mcp_client tool (target="cloud").
Cloud Configuration ¶
lightpanda-cloud-url = https://euwest.cloud.lightpanda.io/mcp/sse lightpanda-remote-token = <token>
Deprecated ¶
The older CDP transport (lightpanda serve + chromedp) was removed in v0.10.0. Config keys lightpanda-local-url, lightpanda-remote-url, and lightpanda_transport are no longer used.
Package lp provides web page reading via LightPanda's MCP transport.
Architecture ¶
url(req) +---------------+ stdio +-------------+
-------->| MCP Client +--------->| lightpanda |
| (mcp.go) | | mcp |
<--------+ |<---------+ |
markdown +---------------+ markdown +-------------+
The package uses LightPanda's native MCP server by default (lightpanda mcp subcommand, stdio transport). Each Get call spawns a fresh lightpanda mcp subprocess, navigates via "goto", then extracts content via "markdown". For geo-restricted sites, use the mcp_client tool to switch to LightPanda Cloud's MCP/SSE endpoint.
Deprecated ¶
The older CDP transport (lightpanda serve + chromedp) was removed in v0.10.0. Use the MCP transport exclusively.
Usage ¶
import "github.com/dscli/dscli/internal/lp" markdown, err := lp.Get(ctx, "https://example.com")
Package lp provides LightPanda integration for web page interaction.
MCP tool integration for the toolcall framework. The init function registers callbacks with toolcall so that MCP tools are dispatched via a persistent MCPClient singleton in HandleToolCall.
Two MCP modes are supported:
- local: spawns "lightpanda mcp" subprocess (stdio). Default.
- cloud: connects to LightPanda Cloud SSE endpoint.
The AI switches between modes via the mcp_client tool.
Index ¶
- Variables
- func DefaultCookiePath() string
- func Get(ctx context.Context, rawURL string) (string, error)
- func GetRemote(ctx context.Context, rawURL string) (string, error)
- func HandleMCPClientTool(ctx context.Context, target string) (result, warning string, err error)
- func MCPToolList(ctx context.Context) []toolcall.Tool
- func NetworkCheck(rawURL string) error
- func NewChromium(ctx context.Context) (context.Context, func(), error)
- func ReadCodeFromStdin() (string, error)
- func WebChat(ctx context.Context, message string) (string, error)
- type MCPClient
- func (c *MCPClient) CallTool(ctx context.Context, name string, args map[string]any) (string, error)
- func (c *MCPClient) Close() error
- func (c *MCPClient) Evaluate(ctx context.Context, script, url string) (string, error)
- func (c *MCPClient) GetMarkdown(ctx context.Context, url string) (string, error)
- func (c *MCPClient) GetSemanticTree(ctx context.Context, url string) (string, error)
- func (c *MCPClient) ListTools(ctx context.Context) ([]*mcp.Tool, error)
- type MCPToolError
Constants ¶
This section is empty.
Variables ¶
var ErrLoginRequired = errors.New("login required — open visible browser to complete login")
ErrLoginRequired is returned when the browser is not logged in to DeepSeek. Callers should trigger a visible login flow and retry.
Functions ¶
func DefaultCookiePath ¶
func DefaultCookiePath() string
DefaultCookiePath returns the default path for the DeepSeek cookie file.
func Get ¶
Get fetches a web page via LightPanda MCP and returns its markdown content. Each call spawns "lightpanda mcp" as a subprocess per call.
func GetRemote ¶
GetRemote fetches a web page via LightPanda Cloud MCP and returns its markdown content. Unlike Get, it uses the persistent cloud MCP singleton (SSE transport) rather than spawning a local subprocess. Requires lightpanda-remote-token to be configured. GetRemote fetches a web page via LightPanda Cloud MCP and returns its markdown content. Unlike Get, it uses the persistent cloud MCP singleton (SSE transport) rather than spawning a local subprocess. Requires lightpanda-remote-token to be configured.
func HandleMCPClientTool ¶ added in v0.8.7
HandleMCPClientTool is the handler for the mcp_client tool. It switches the active MCP target between "local" and "cloud".
func MCPToolList ¶ added in v0.8.7
MCPToolList lazily discovers tools from the LightPanda MCP server. It is called once per process lifetime; results are cached. Always discovers via LOCAL MCP regardless of active target. If discovery fails, it returns nil (tools are silently omitted).
func NetworkCheck ¶ added in v0.8.5
NetworkCheck verifies that the target URL's host is reachable via TCP before launching a browser. This avoids wasting time on a truly down network — Chrome would otherwise report ERR_INTERNET_DISCONNECTED and fail after a much longer timeout.
The check connects directly from the host, bypassing Chrome's network stack, so it only fails when the host actually has no connectivity. On URL parse errors the check is skipped (assume reachable).
func NewChromium ¶ added in v0.8.5
NewChromium creates a new chromedp ExecAllocator backed by a local Chrome/Chromium browser. The caller must call the returned cancel func to shut down the browser when done.
Usage:
ctx, cancel, err := NewChromium(parentCtx)
if err != nil { return err }
defer cancel()
tabCtx, tabCancel := chromedp.NewContext(ctx)
defer tabCancel()
func ReadCodeFromStdin ¶
ReadCodeFromStdin reads a verification code from stdin with a prompt. In non-interactive environments (stdin not a terminal), it falls back to polling codeFilePath every 2 seconds for up to 5 minutes.
func WebChat ¶
WebChat sends a message to chat.deepseek.com via a local Chrome/Chromium browser and returns the assistant's text response.
The browser is launched fresh for each call and closed after the response is received. Cookies persist via the shared Chrome profile directory, so prior login state is available across calls.
If ctx carries context.KeepKey set to true, WebChat attempts to continue the last saved conversation (loaded from the profile directory) rather than starting a new one. New conversations automatically enable expert mode (V4 Pro).
Types ¶
type MCPClient ¶ added in v0.8.6
type MCPClient struct {
// contains filtered or unexported fields
}
MCPClient wraps a LightPanda MCP session. It manages the lifecycle of a lightpanda mcp subprocess, providing a simple interface for web page content extraction via MCP tools.
The client is safe for concurrent use (calls are serialized through an internal mutex because stdio transport cannot safely multiplex writes).
func NewCloudMCPClient ¶ added in v0.8.7
NewCloudMCPClient connects to LightPanda Cloud MCP over SSE. Uses lightpanda-cloud-url and lightpanda-remote-token from config.
func NewMCPClient ¶ added in v0.8.6
NewMCPClient starts lightpanda mcp and connects to it.
It looks up the lightpanda binary via exec.LookPath, spawns it with the "mcp" subcommand, and establishes an MCP session. The caller must call Close when done.
func (*MCPClient) CallTool ¶ added in v0.8.6
CallTool calls a tool by name with the given arguments. This is a generic version of GetMarkdown/GetSemanticTree/Evaluate that allows calling any tool exposed by the MCP server. The caller is responsible for calling Close after finishing.
func (*MCPClient) Close ¶ added in v0.8.6
Close shuts down the MCP session and kills the subprocess.
func (*MCPClient) Evaluate ¶ added in v0.8.6
Evaluate runs JavaScript in the page context and returns the result. If url is non-empty, the page navigates there first before evaluation.
func (*MCPClient) GetMarkdown ¶ added in v0.8.6
GetMarkdown navigates to a URL and returns the page content as markdown. If the returned markdown is empty and no error occurred, it means the page loaded but had no extractable text content.
func (*MCPClient) GetSemanticTree ¶ added in v0.8.6
GetSemanticTree navigates to a URL and returns the page's simplified semantic DOM tree, optimized for AI reasoning about page structure.
type MCPToolError ¶ added in v0.8.6
type MCPToolError struct {
Tool string // name of the tool that failed
Content []mcp.Content // original response content, preserved for debugging
}
MCPToolError is returned when an MCP tool call completes with IsError=true. Unlike a transport-level error (which would be returned as a Go error directly), this indicates the tool ran but its operation failed (e.g., URL unreachable).
func (*MCPToolError) Error ¶ added in v0.8.6
func (e *MCPToolError) Error() string