Laravel MCP Interconnection with the Laravel AI SDK

Reusing your Laravel MCP tools in the Laravel AI SDK

For some time now, our team has been exploring different ways to integrate AI agents into the Laravel applications we build. With the arrival of Laravel MCP and the Laravel AI SDK, the ecosystem is becoming much more natural and very promising.

While testing them, we quickly ran into an important question: how do you avoid duplicating logic between the tools exposed to external agents and those used directly within an application?

In this article, we present a simple proxy-based approach to using Laravel MCP tools in the Laravel AI SDK. You’ll see how to connect these two worlds, structure a reusable solution, and apply it to a concrete use case inspired by our internal bug tracker.

Laravel MCP: exposing your application to AI agents

Laravel MCP allows a Laravel application to become a server compatible with the Model Context Protocol. In practical terms, this enables AI clients to discover and use certain capabilities of your application: tools, resources, or prompts.

An MCP tool can, for example:

  • look up a request in an internal system;

  • create a task;

  • summarize a client file;

  • retrieve business data;

  • trigger an action in an application.

The main benefit is making these capabilities available to external agents like Claude Desktop, ChatGPT, GitHub Copilot, or other compatible environments. This becomes particularly useful for quickly testing ideas, validating prompts, exploring different workflows, and enabling developers to interact with an application in an assisted way.

Laravel AI SDK: integrating AI directly into the application

The Laravel AI SDK addresses a complementary need. Rather than exposing tools to an external client, it allows you to build AI features directly into your Laravel application.

The SDK provides a unified API to interact with different AI providers, create agents, use tools, manage structured outputs, generate embeddings, process files, and more.

In a Laravel application, this opens the door to use cases such as:

  • an assistant embedded in a user interface;

  • a triage agent to classify requests;

  • an automated summarization tool;

  • writing assistance;

  • smart analysis of internal data;

  • a contextual recommendation engine.

In other words, Laravel MCP is very useful for making your application accessible to external agents, while the Laravel AI SDK is ideal for integrating those capabilities directly into your product.

Our approach to integrating AI tools

The approach we find interesting for integrating AI tools into applications is as follows:

  1. Create business tools with Laravel MCP.

  2. Expose them to external agents like GitHub Copilot, Claude, or ChatGPT.

  3. Quickly test different prompts and workflows.

  4. Reuse those same tools in specialized agents within the application using the Laravel AI SDK.

This approach makes it possible to start with a highly flexible exploration phase. Developers can experiment directly with MCP tools, tune parameters, observe responses, and refine prompts.

Then, once the behavior becomes reliable enough, the same capabilities can be integrated into the application as specialized agents, allowing you to move from an experimentation environment to a product feature without rewriting all the business logic.

The problem: two interfaces, one shared logic

The problem is that it’s still not possible to connect a local or external MCP server to the Laravel AI SDK, and Laravel MCP tools don’t implement exactly the same interface.

An MCP tool already has:

  • a name;

  • a description;

  • an input schema;

  • a handle method;

  • reusable business logic.

A Laravel AI SDK tool requires very similar elements:

  • a name;

  • a description;

  • a schema;

  • a handle method.

Conceptually, the two worlds look very similar. Yet without adaptation, you risk duplicating code: one version of the tool for MCP, then another for the AI SDK.

At Exolnet, we chose a simple approach: creating a proxy that wraps a Laravel MCP tool in a tool compatible with the Laravel AI SDK.

Our approach: a proxy between Laravel MCP and the AI SDK

Here’s a simplified version of our ProxyMcpTool class:

<?php

namespace App\Ai\Tools;

use Illuminate\Contracts\JsonSchema\JsonSchema;
use Illuminate\Support\Facades\App;
use Laravel\Ai\Contracts\Tool;
use Laravel\Ai\Tools\Request as AgentRequest;
use Laravel\Mcp\Request as McpRequest;
use Laravel\Mcp\ResponseFactory;
use Laravel\Mcp\Server\Tool as McpTool;
use Stringable;

class ProxyMcpTool implements Tool
{
    protected McpTool $tool;

    public function __construct(McpTool|string $tool)
    {
        $this->tool = $tool instanceof McpTool ? $tool : App::make($tool);
    }

    /**
     * Get the name of the tool.
     */
    public function name(): string
    {
        return $this->tool->name();
    }

    /**
     * Get the description of the tool's purpose.
     */
    public function description(): string
    {
        return $this->tool->description();
    }

    /**
     * Execute the tool.
     */
    public function handle(AgentRequest $request): Stringable|string
    {
        $mcpRequest = new McpRequest($request->all());

        /** @var \Laravel\Mcp\Response|\Laravel\Mcp\ResponseFactory $response */
        $response = App::call([$this->tool, 'handle'], [
            'request' => $mcpRequest,
        ]);

        $data = $response instanceof ResponseFactory
            ? json_encode($response->getStructuredContent())
            : (string)$response->content();

        return $data;
    }

    /**
     * Get the tool's schema definition.
     */
    public function schema(JsonSchema $schema): array
    {
        return $this->tool->schema($schema);
    }
}

The idea is intentionally simple: the proxy implements the Laravel\Ai\Contracts\Tool contract, but delegates all the work to the original MCP tool.

The name, description, and schema are pulled directly from the MCP tool. When a Laravel AI SDK agent calls the tool, the proxy converts the SDK request into an MCP request, then calls the MCP tool’s handle method.

This allows us to maintain a single source of truth for the business logic.

A concrete example: our bug tracking system

At Exolnet, we used this approach to create various specialized MCP tools around our internal bug tracking system.

These tools can, for example, help:

  • view the details of a request;

  • analyze a ticket’s context;

  • identify missing information;

  • suggest a priority;

  • help triage new requests.

At first, we connected these tools to GitHub Copilot, ChatGPT, and Claude to test different prompts and workflows. This allowed the team to quickly validate what works well, what needs adjustment, and what limits should be imposed on the agent.

Then, once we were satisfied with the behavior, we reused the same tools in specialized agents integrated directly into our bug tracker. For example, when a new request is created, a hook runs and a triage agent analyzes it, proposes a categorization, identifies duplicates, and helps the team get started faster.

This kind of automation doesn’t replace human judgment. It reduces friction, speeds up certain repetitive steps, and enables the team to focus on decisions that truly require experience.

Why this approach is useful

This approach provides several benefits:

  • less code duplication;

  • centralized business logic;

  • better alignment between experimentation and production;

  • a gradual adoption of AI in our applications;

  • an easier way to test tools before integrating them into the user experience.

It also reflects an important idea in software development: start small, validate quickly, then gradually integrate what delivers real value.

Conclusion

Laravel’s AI ecosystem is evolving quickly, and that’s excellent news for teams that want to integrate AI agents into their applications without straying from their usual Laravel practices.

Ideally, this kind of reuse between Laravel MCP and the Laravel AI SDK will eventually become a native feature of the Laravel ecosystem. It would be even more powerful if the Laravel AI SDK could also connect directly to local or external MCP servers, with the ability to specify which tools are allowed.

In the meantime, a proxy class like this lets us move forward today. It provides a simple, pragmatic solution aligned with how we build at Exolnet: explore with curiosity, collaborate efficiently, and deliver useful solutions that simplify day-to-day work.

Need a team to integrate AI features into your Laravel application? Contact our experts for a consultation.

Share this article:

These articles might interest you

Let’s talk technology!

We’d be more than happy to chat about your technology goals and always enjoy learning about new businesses along the way. Get in touch today!

Call us

(514) 447-5217

Drop us a line

or use contact@exolnet.com