Larapanda is a Laravel SDK for Lightpanda , a headless browser written in Zig. The package handles runtime resolution between CLI binary and Docker, profile-based instance management, typed fetch results, and optional adapters for the Laravel AI SDK and MCP server.
Profile-Based Instance Management
Configuration is organized into named instance profiles. Each profile can override the global defaults for runtime mode, binary path, and Docker settings — making it straightforward to maintain separate profiles for general fetching, crawling, and AI tool sessions.
// config/larapanda.php'instances'
=>
[
'默认'
=>
[],
'crawler'
=>
[
'运行时'
=>
'cli'
,
'binary_path'
=>
'/absolute/path/to/lightpanda'
,],
'mcp'
=>
[
'运行时'
=>
'docker'
,],],
Selecting a profile at call time uses the manager interface:
使用
Ferdiunal\Larapanda\Contracts\LarapandaManagerInterface
;经理
=
应用程序
(
LarapandaManagerInterface
::班级
(英文):$defaultClient
=
经理
->
实例
(
'默认'
(英文):$crawlerClient
=
经理
->
实例
(
'crawler'
(英文):
Runtime Resolution
这
auto
runtime prefers CLI execution when a valid
binary_path
is configured and the binary is executable, and falls back to Docker otherwise. You can also pin a profile to
cli
或者
docker
明确地。
Typed Fetch Results
fetchRequest()
返回
FetchResult
with strict accessors tied to the selected dump format. Calling a mismatched accessor throws
UnexpectedFetchOutputFormatException
rather than silently returning garbage data.
使用
Ferdiunal\Larapanda\Enums\FetchDumpFormat
;$结果
=
客户端
->
fetchRequest
(
'https://example.com'
)
->
带选项
(
倾倒
:
FetchDumpFormat
::
Markdown
,
obeyRobots
:
真的
,
waitMs
:
2000
,)
->
跑步
();$markdown
=
$结果
->
asMarkdown
();// Semantic tree formats$treeResult
=
客户端
->
fetchRequest
(
'https://example.com'
)
->
带选项
(
倾倒
:
FetchDumpFormat
::
SemanticTree
)
->
跑步
();$tree
=
$treeResult
->
asSemanticTree
();
// array<string, mixed>
Proxy support is available per-request:
$结果
=
客户端
->
fetchRequest
(
'https://example.com'
)
->
带选项
(
倾倒
:
FetchDumpFormat
::
Markdown
,
httpProxy
:
'http://127.0.0.1:3000'
,
proxyBearerToken
:
'MY-TOKEN'
,)
->
跑步
();
Laravel AI SDK 集成
Larapanda exposes Lightpanda as tools for the
Laravel AI SDK
. The adapter is session-aware — passing the same
session_id
across tool calls keeps the browser session open between steps, which matters for multi-step browsing tasks.
作曲家
要求
laravel/ai
laravel/mcp
使用
Ferdiunal\Larapanda\Integrations\Ai\LarapandaAiTools
;使用
Illuminate\Support\Facades\AI
;$响应
=
人工智能
::
提供者
(
'openai'
)
->
模型
(
'gpt-5-mini'
)
->
迅速的
(
'Open laravel.com and return the main headings.'
)
->
工具
(
应用程序
(
LarapandaAiTools
::班级
)
->
制作
())
->
文本
();
Tool names use the configured prefix (default
lightpanda_
):
lightpanda_markdown
,
lightpanda_semantic_tree
,
lightpanda_click
, and so on. You can restrict which tools the model sees via config:
“整合”
=>
[
'ai'
=>
[
'exposed_tools'
=>
[
'goto'
,
'markdown'
,
'semantic_tree'
],],],
MCP Server Adapter
For applications using the Laravel MCP server , Larapanda provides an adapter that registers Lightpanda tools with Laravel's container, applies profile-based runtime resolution, and shares the session pool and proxy policy with the AI SDK adapter.
// routes/ai.php使用
Ferdiunal\Larapanda\Integrations\Mcp\LarapandaMcpServer
;LarapandaMcpServer
::
registerLocal
(
姓名
:
'lightpanda'
(英文):
Session lifetime and pool size are controlled from config:
“整合”
=>
[
'mcp'
=>
[
'session_ttl_seconds'
=>
300
,
'max_sessions'
=>
32
,
'obey_robots'
=>
真的
,],],
You can find the source and full documentation on GitHub 。







