MCP ExplorerExplorer

Mcp For Laravel

@SettledCoon 9 months ago
4 MIT
FreeCommunity
AI Systems
MCP for Laravel is an AI framework for building intelligent applications.

Overview

What is Mcp For Laravel

MCP-for-Laravel is an AI framework designed for building intelligent applications using the Laravel PHP framework. It leverages the Model Context Protocol (MCP) to facilitate advanced AI functionalities.

Use cases

Use cases for MCP-for-Laravel include creating AI agents for summarizing YouTube videos, automating customer service responses, generating content for blogs, and developing applications that require natural language processing.

How to use

To use MCP-for-Laravel, you need to install it via Composer with the command ‘composer require settled/mcp-laravel’. After installation, you can create an agent by extending the Agent class provided by the framework, allowing you to implement specific AI functionalities.

Key features

Key features of MCP-for-Laravel include the ability to create custom agents, manage memory and function calls automatically, and integrate with various AI providers such as Anthropic. It also supports advanced mechanisms for building intelligent applications.

Where to use

MCP-for-Laravel can be used in various fields including content creation, customer support automation, data analysis, and any application that requires intelligent processing of information.

Content

MCP for Laravel

Latest Stable Version
License

MCP (Model Context Protocol) for Laravel - A powerful AI framework for building intelligent applications. Based on inspector-apm/neuron-ai

Requirements

  • PHP: ^8.0
  • Laravel: ^11.0

Official documentation

Go to the official documentation

Install

Install the latest version of the package:

composer require settled/mcp-laravel

Create an Agent

MCP for Laravel provides you with the Agent class you can extend to inherit the main features of the framework,
and create fully functional agents. This class automatically manages some advanced mechanisms for you such as memory,
tools and function calls, up to the RAG systems. Let’s create the first agent, extending the Settled\MCP\Agent class:

use Settled\MCP\Agent;
use Settled\MCP\SystemPrompt;
use Settled\MCP\Providers\AIProviderInterface;
use Settled\MCP\Providers\Anthropic\Anthropic;

class YouTubeAgent extends Agent
{
    public function provider(): AIProviderInterface
    {
        return new Anthropic(
            key: 'ANTHROPIC_API_KEY',
            model: 'ANTHROPIC_MODEL',
        );
    }

    public function instructions(): string
    {
        return new SystemPrompt(
            background: ["You are an AI Agent specialized in writing YouTube video summaries."],
            steps: [
                "Get the url of a YouTube video, or ask the user to provide one.",
                "Use the tools you have available to retrieve the transcription of the video.",
                "Write the summary.",
            ],
            output: [
                "Write a summary in a paragraph without using lists. Use just fluent text.",
                "After the summary add a list of three sentences as the three most important take away from the video.",
            ]
        );
    }
}

The SystemPrompt class is designed to take your base instructions and build a consistent prompt for the underlying model
reducing the effort for prompt engineering.

Talk to the Agent

Send a prompt to the agent to get a response from the underlying LLM:

$agent = YouTubeAgent::make();

$response = $agent->run(new UserMessage("Hi, I'm Valerio. Who are you?"));
echo $response->getContent();
// I'm a friendly YouTube assistant to help you summarize videos.


$response = $agent->run(
    new UserMessage("Do you know my name?")
);
echo $response->getContent();
// Your name is Valerio, as you said in your introduction.

As you can see in the example above, the Agent automatically has memory of the ongoing conversation. Learn more about memory in the documentation.

Supported LLM Providers

With Neuron you can switch between LLM providers with just one line of code, without any impact on your agent implementation.
Supported providers:

Tools & Function Calls

You can add the ability to perform concrete tasks to your Agent with an array of Tool:

use NeuronAI\Agent;
use NeuronAI\SystemPrompt;
use NeuronAI\Providers\AIProviderInterface;
use NeuronAI\Providers\Anthropic\Anthropic;
use NeuronAI\Tools\Tool;
use NeuronAI\Tools\ToolProperty;

class YouTubeAgent extends Agent
{
    public function provider(): AIProviderInterface
    {
        return new Anthropic(
            key: 'ANTHROPIC_API_KEY',
            model: 'ANTHROPIC_MODEL',
        );
    }

    public function instructions(): string
    {
        return new SystemPrompt(
            background: ["You are an AI Agent specialized in writing YouTube video summaries."],
            steps: [
                "Get the url of a YouTube video, or ask the user to provide one.",
                "Use the tools you have available to retrieve the transcription of the video.",
                "Write the summary.",
            ],
            output: [
                "Write a summary in a paragraph without using lists. Use just fluent text.",
                "After the summary add a list of three sentences as the three most important take away from the video.",
            ]
        );
    }

    public function tools(): array
    {
        return [
            Tool::make(
                'get_transcription',
                'Retrieve the transcription of a youtube video.',
            )->addProperty(
                new ToolProperty(
                    name: 'video_url',
                    type: 'string',
                    description: 'The URL of the YouTube video.',
                    required: true
                )
            )->setCallable(function (string $video_url) {
                // ... retrieve the video transcription
            })
        ];
    }
}

Learn more about Tools on the documentation.

MCP server connector

Instead of implementing tools manually, you can connect tools exposed by an MCP server with the McpConnector component:

use NeuronAI\Agent;
use NeuronAI\MCP\McpConnector;
use NeuronAI\Providers\AIProviderInterface;
use NeuronAI\Providers\Anthropic\Anthropic;
use NeuronAI\Tools\Tool;
use NeuronAI\Tools\ToolProperty;

class SEOAgent extends Agent
{
    public function provider(): AIProviderInterface
    {
        return new Anthropic(
            key: 'ANTHROPIC_API_KEY',
            model: 'ANTHROPIC_MODEL',
        );
    }

    public function instructions(): string
    {
        return new SystemPrompt(
            background: ["Act as an expert of SEO (Search Engine Optimization)."]
            steps: [
                "Analyze a text of an article.",
                "Provide suggestions on how the content can be improved to get a better rank on Google search."
            ],
            output: ["Structure your analysis in sections. One for each suggestion."]
        );
    }

    public function tools(): array
    {
        return [
            // Connect an MCP server
            ...McpConnector::make([
                'command' => 'npx',
                'args' => ['-y', '@modelcontextprotocol/server-everything'],
            ])->tools(),

            // Implement your custom tools
            Tool::make(
                'get_transcription',
                'Retrieve the transcription of a youtube video.',
            )->addProperty(
                new ToolProperty(
                    name: 'video_url',
                    type: 'string',
                    description: 'The URL of the YouTube video.',
                    required: true
                )
            )->setCallable(function (string $video_url) {
                // ... retrieve the video transcription
            })
        ];
    }
}

Learn more about MCP connector on the documentation.

Implement RAG systems

For RAG use case, you must extend the NeuronAI\RAG\RAG class instead of the default Agent class.

To create a RAG you need to attach some additional components other than the AI provider, such as a vector store,
and an embeddings provider.

Here is an example of a RAG implementation:

use NeuronAI\Providers\AIProviderInterface;
use NeuronAI\Providers\Anthropic\Anthropic;
use NeuronAI\RAG\Embeddings\EmbeddingsProviderInterface;
use NeuronAI\RAG\Embeddings\VoyageEmbeddingProvider;
use NeuronAI\RAG\RAG;
use NeuronAI\RAG\VectorStore\PineconeVectoreStore;
use NeuronAI\RAG\VectorStore\VectorStoreInterface;

class MyChatBot extends RAG
{
    public function provider(): AIProviderInterface
    {
        return new Anthropic(
            key: 'ANTHROPIC_API_KEY',
            model: 'ANTHROPIC_MODEL',
        );
    }

    public function embeddings(): EmbeddingsProviderInterface
    {
        return new VoyageEmbeddingProvider(
            key: 'VOYAGE_API_KEY',
            model: 'VOYAGE_MODEL'
        );
    }

    public function vectorStore(): VectorStoreInterface
    {
        return new PineconeVectoreStore(
            key: 'PINECONE_API_KEY',
            indexUrl: 'PINECONE_INDEX_URL'
        );
    }
}

Learn more about RAG on the documentation.

Official documentation

Go to the official documentation

Contributing

We encourage you to contribute to the development of Neuron AI Framework!
Please check out the Contribution Guidelines about how to proceed. Join us!

LICENSE

This bundle is licensed under the MIT license.

Tools

No tools

Comments

Recommend MCP Servers

View All MCP Servers