Repository navigation
v0.7 - MCP & Events
LarAgent v0.7 — Release Notes
Welcome to LarAgent v0.7! This release focuses on fast, stateless interactions, dynamic capability via MCP, and deep Laravel-native observability through events.
🚀 New Methods: ask() and make()
Two new developer-friendly ways to interact with agents without maintaining persistent chat histories.
🔹 ask() — one‑liner interaction
Use for quick, stateless prompts:
echo WeatherAgent::ask('What is the weather like?');🔹 make() — chainable, configurable, stateless
Gives you finer control while staying expressive:
echo WeatherAgent::make()
->message('What is the weather like?') // Set the message
->temperature(0.7) // Optional: override temperature
->respond(); // Get the responseUse make() when you need a temporary agent instance with custom temperature, model, or configuration but no stored chat history.
🧩 Model Context Protocol (MCP) Integration
MCP enables agents to discover and use tools and resources from external MCP servers—no custom tool implementation required.
MCP support is provided through the
redberry/mcp-client-laravelpackage (bundled as a dependency).
⚙️ Configure MCP Servers
LarAgent supports HTTP and STDIO transport types via config/laragent.php:
// config/laragent.php
'mcp_servers' => [
'github' => [
'type' => \Redberry\MCPClient\Enums\Transporters::HTTP,
'base_url' => 'https://api.githubcopilot.com/mcp',
'timeout' => 30,
'token' => env('GITHUB_API_TOKEN', null),
],
'mcp_server_memory' => [
'type' => \Redberry\MCPClient\Enums\Transporters::STDIO,
'command' => ['npx', '-y', '@modelcontextprotocol/server-memory'],
'timeout' => 30,
'cwd' => base_path(),
],
],🧠 Register Servers in an Agent
Use a property for simplicity, or a method for dynamic control.
use LarAgent\Agent;
class MyAgent extends Agent
{
protected $mcpServers = [
'github',
'mcp_server_memory',
];
}Or with filters:
public function registerMcpServers()
{
return [
'github:tools|only:search_repositories,get_issues',
'mcp_server_memory:tools|except:delete_entities,delete_observations,delete_relations',
'mcp_everything:resources|only:Resource 1,Resource 2',
];
}Filter syntax tips
- Use
:toolsor:resourcesto select fetch type - Use
only:andexcept:with comma‑separated items (no spaces)
📚 Working with Resources
Resources are not fetched by default—request them explicitly or access manually via $this->mcpClient.
class MyAgent extends Agent
{
protected $mcpServers = ['mcp_everything'];
public function instructions()
{
$resourceData = $this->mcpClient
->connect('mcp_everything')
->readResource('test://static/resource/1');
$context = $resourceData['contents'][0]['text'] ?? '';
return "You are a helpful assistant. Context: {$context}";
}
}Resource response:
[
'contents' => [
[
'uri' => 'test://static/resource/1',
'name' => 'Resource 1',
'mimeType' => 'text/plain',
'text' => 'Resource 1: This is a plaintext resource',
]
]
]🪄 Call MCP Tools Manually
You can call tools directly and hard‑code safe defaults to reduce LLM error surface:
#[Tool('Get issue details from LarAgent repository')]
public function readTheIssue(int $issue_number)
{
$args = [
'issue_number' => $issue_number,
'owner' => 'maestroerror',
'repo' => 'LarAgent',
];
return $this->mcpClient
->connect('github')
->callTool('get_issue', $args);
}Performance note: Initialization → fetching → registration is intensive. Using >3 MCP servers per Agent can significantly increase response time.
🔔 Laravel‑Native Events
Observe, log, and customize agent behavior with first‑class Laravel events.
🔹 Lifecycle Events
AgentInitializedConversationStartedConversationEnded(contains finalmessage; includes token usage viatoArrayWithMeta())ToolChanged(withaddedbool flag)AgentClearedEngineError(withexception)
🔹 Hook Events (Before/After)
BeforeReinjectingInstructionsBeforeSend/AfterSendBeforeSaveHistoryBeforeResponse/AfterResponseBeforeToolExecution/AfterToolExecutionBeforeStructuredOutput
Example handler:
public function handle(ConversationEnded $event): void
{
$response = $event->message; // includes meta/usage
// Log, compute analytics, etc.
}🗂️ Chat‑History Improvements
Random Chat Histories by Default
If you don’t specify for/forUser, LarAgent uses a random key (10 chars via Str). You can customize by overriding generateRandomKey():
// Example: per‑user key
protected static function generateRandomKey(): string {
$user = auth()->user();
return $user->type.'-'.$user->id;
}
// Example: per‑topic key
protected static function generateRandomKey(): string {
return class_basename(static::class).'-'.Session::get('latest_topic');
}What's Changed
- Add Laravel Events with automatic dispatching via callEvent system by @Copilot in #85
- Add new methods to the agent for one off questions by @vakhtangaA in #90
- Add PEST tests for newly added MCP methods in Agent class by @Copilot in #92
- MCPClient integrated in Agent class by @MaestroError in #91
- Bump actions/checkout from 4 to 5 by @dependabot[bot] in #88
- Update openai-php/client requirement from ^0.14.0 to ^0.16.1 by @dependabot[bot] in #89
New Contributors
- @Copilot made their first contribution in #85
- @vakhtangaA made their first contribution in #90
Full Changelog: 0.6.0...0.7.0