Token导航 LogoToken导航TokenDH.com
MCP For Laravel logo
AI代理未说明官方级别未说明来源级核验

MCP For Laravel

MCP Server

MCP for Laravel是一个强大的AI框架,用于构建智能应用程序,支持多种LLM提供商和工具调用。

工具数

1

提示词数

0

GitHub Stars

6

资源数

0
PHPAI代理工作流自动化

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

SettledCo

提供方

SettledCo

最后核验

2026/5/17 20:19

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

详细介绍

Laravel的MCP

](https://packagist.org/packages/settled/mcp-laravel) ![License](//packagist.org/packages/settled/mcp-laravel)

Laravel的MCP(模型上下文协议)-用于构建智能应用程序的强大AI框架。基于 检测器apm/神经元ai

需求

  • PHP:^8.0
  • Laravel:^11.0

正式文件

转到官方文件

安装

安装最新版本的软件包:

composer require settled/mcp-laravel

创建代理

Laravel的MCP为您提供了Agent类,您可以扩展该类以继承框架的主要功能, 并创建功能齐全的代理。这个类会自动为你管理一些高级机制,比如内存, 工具和函数调用,直至RAG系统。让我们创建第一个代理,扩展 Settled\MCP\Agent 类别:

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.",
            ]
        );
    }
}

SystemPrompt 类旨在接受您的基本指令,并为底层模型构建一致的提示 减少了快速工程的工作量。

与代理人交谈

向代理发送提示,以获取底层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.

正如您在上面的示例中看到的,Agent会自动记住正在进行的对话。在中了解有关内存的更多信息 文档.

支持的LLM提供商

使用Neuron,您只需一行代码就可以在LLM提供者之间切换,而不会对您的代理实现产生任何影响。 支持的提供商:

  • Anthropic
  • Ollama(也可作为 嵌入提供者)
  • OpenAI
  • 米斯特拉尔
  • 深度求索

工具和函数调用

您可以使用以下数组为代理添加执行具体任务的能力 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
            })
        ];
    }
}

了解有关工具的更多信息,请访问 文档.

MCP服务器连接器

您可以将MCP服务器公开的工具与 McpConnector 组件:

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
            })
        ];
    }
}

了解有关MCP连接器的更多信息,请访问 文档.

实施RAG系统

对于RAG用例,您必须扩展 NeuronAI\RAG\RAG 类,而不是默认的Agent类。

要创建RAG,您需要附加除AI提供者之外的一些其他组件,例如 vector store, 和a embeddings provider.

以下是RAG实现的示例:

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'
        );
    }
}

了解更多关于RAG的信息 文档.

正式文件

转到官方文件

贡献

我们鼓励您为Neuron AI框架的发展做出贡献! 请查看 贡献指南 关于如何继续。加入我们!

许可证

此捆绑包根据 麻省理工学院 许可证。

目录标签

目录标签

PHPAI代理工作流自动化本地部署AI框架Laravel扩展LLM集成工具调用RAG系统

接入字段

传输方式(transport,传输协议)

未说明

鉴权方式(authType,认证方式)

none

工具数量(toolCount,工具数)

1

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

未说明none部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

仍需确认:installCommand

来源信息

继续浏览同类 MCP