Token导航 LogoToken导航TokenDH.com
Laravel MCP logo
开发工具stdio官方级别未说明来源级核验

Laravel MCP

MCP Server

@modelcontextprotocol/inspector

一个实现模型上下文协议(MCP)的Laravel扩展包,提供标准化API实现Laravel应用与AI助手间的通信,支持资源暴露和工具调用功能。

工具数

0

提示词数

0

GitHub Stars

17

资源数

0
协议实现JavaScriptClaudePHPClaude DesktopClaude

安装说明

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

作者 / 组织

InnoGE

提供方

InnoGE

最后核验

2026/5/17 21:06

运行时

Node.js

快速接入

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

命令预览

npx @modelcontextprotocol/inspector php /path/to/your/app/artisan mcp:serve

详细介绍

Laravel MCP(模型上下文协议)

](https://packagist.org/packages/innoge/laravel-mcp) ](https://github.com/innoge/laravel-mcp/actions?query=workflow%3Arun-tests+branch%3Amain) ](https://github.com/innoge/laravel-mcp/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain) ](https://packagist.org/packages/innoge/laravel-mcp)

一个Laravel包,实现了 模型上下文协议(MCP),通过标准化的API实现Laravel应用程序与人工智能助手或其他系统之间的无缝通信。 请注意,此软件包仍在开发中,尚未准备好投入生产使用。

安装

您可以通过composer安装该软件包:

composer require innoge/laravel-mcp

基本用法

设置MCP服务器

此软件包目前仅支持通过STDIO传输创建MCP服务器。 目前还不支持HTTP传输,但将来会添加。

创建一个命令来为您的MCP服务器提供服务:

serveMcp('your-app-name', '1.0.0');
    }

    private function getTools(): array
    {
        return [
            // List your tool classes here
        ];
    }

    private function getResources(): array
    {
        return [
            // List your resource providers here
        ];
    }
}

资源

资源允许您通过MCP协议公开应用程序的数据模型。该包提供了两种类型的资源提供者:

  1. Eloquent资源提供者:展示Eloquent模型
use InnoGE\LaravelMcp\Resources\EloquentResourceProvider;
use App\Models\User;

// In your getResources() method:
return [
    new EloquentResourceProvider(User::query(), 'users', 'A User of the Application')
];
  1. 内存资源提供程序:公开自定义数据结构或非Eloquent数据
use InnoGE\LaravelMcp\Resources\InMemoryResourceProvider;
use InnoGE\LaravelMcp\Types\Resources\ResourceContent;
use InnoGE\LaravelMcp\Types\Resources\ResourceItem;

// Create a resource provider
$resourceProvider = new InMemoryResourceProvider();

// Add example documents as resources
$resourceProvider->addResource(
    new ResourceItem('doc://example/document1', 'Example Document 1', 'This is an example document', 'text/plain', 1024),
    new ResourceContent('doc://example/document1', 'text/plain', 'This is the content of the document')
);

$resourceProvider->addResource(
    new ResourceItem('doc://example/document2', 'Example Document 2', 'This is an example document 2', 'text/plain', 1024),
    new ResourceContent('doc://example/document2', 'text/plain', 'This is the content of the document 2')
);

// In your getResources() method:
return [
    $resourceProvider
];

工具

工具定义了可以通过MCP协议执行的操作:

  • 内置示例工具:

- HelloTool:一个简单的hello world示例 - ClockTool:返回当前时间

  • 自定义工具:通过实施 ToolInterface
use InnoGE\LaravelMcp\Tools\Examples\HelloTool;
use InnoGE\LaravelMcp\Tools\Examples\ClockTool;
use App\MCP\Tools\YourCustomTool;

// In your getTools() method:
return [
    HelloTool::class,
    ClockTool::class,
    YourCustomTool::class,
];

创建工具

工具是MCP的核心功能,允许AI助手与Laravel应用程序进行交互。它们提供了一种通过定义良好的接口在应用程序中执行特定操作的方法。

MCP工具的真实示例包括:

  • 数据库操作:创建、读取、更新或删除记录
  • 外部API集成:对第三方服务进行API调用
  • 文件管理:上传、下载或处理文件
  • 认证:验证用户凭据或生成令牌
  • 报告:生成报告或导出数据
  • 电子邮件/通知:向用户发送消息

示例工具:

 'object',
            'properties' => [
                'command' => [
                    'type' => 'string',
                    'description' => 'The Artisan command to call (e.g. "migrate")',
                ],
            ],
            'required' => ['command'],
        ];
    }

    /**
     * Execute the tool with the provided arguments
     */
    public function execute(array $arguments): string
    {
        $command = $arguments['command'];

        $outputBuffer = new BufferedOutput;

        Artisan::call($command, [], $outputBuffer);

        return $outputBuffer->fetch();
    }
}

测试您的MCP服务器

使用Modelcontext协议检查器测试MCP服务器:

npx @modelcontextprotocol/inspector php /path/to/your/app/artisan mcp:serve

将MCP服务器添加到Claude桌面

编辑您的Claude Desktop配置文件:

~/库/应用支持/Claude/Claude_desktop_config json

将您的MCP服务器添加到配置文件中:

{
  "mcpServers": {
    "laravel-mcp": {
      "command": "php",
      "args": [
        "/path/to/your/app/artisan",
        "mcp:serve"
      ]
    }
  }
}

现在,您可以在Claude Desktop中使用MCP服务器。请注意,Claude目前不使用MCP资源。如果你想访问应用程序的数据,你可以使用工具调用。

测试

composer test

更新日志

请看 更新日志 有关最近发生的变化的更多信息。

贡献

请看 贡献 了解详情。

安全漏洞

请审阅 我们的安全政策 关于如何报告安全漏洞。

鸣谢

许可证

MIT许可证(MIT)。请看 许可证文件 了解更多信息。

目录标签

目录标签

协议实现JavaScriptClaudePHP本地部署Laravel扩展AI集成API通信开发工具

支持客户端

Claude DesktopClaude

接入字段

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

stdio

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

none

运行时(runtime,运行环境)

Node.js

来源包(packageName,安装包名)

@modelcontextprotocol/inspector

工具数量(toolCount,工具数)

0

资源数量(resourceCount,资源数)

0

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

0

权限和风险

stdionone部署方式未说明

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

安装前确认

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

来源信息

继续浏览同类 MCP