API发现工具

LMAD是一个Laravel MCP API发现包,为AI代理提供全面的API发现和分析能力,帮助理解Laravel应用程序的API结构、验证规则和响应模式。

  • by 0xmergen
  • PHP
  • 本地部署
  • 3 星标
  • 更新于
在 GitHub 查看 0xmergen/lmad

使用说明

LMAD-Laravel MCP API发现

Laravel 12 MCP(模型上下文协议)包,为人工智能代理提供全面的API发现和分析功能。LMAD使AI编码助手能够理解Laravel应用程序的API结构、验证规则和响应模式。

特性

  • 路由发现:按路径、HTTP方法、域和供应商排除列出并筛选API路由
  • 控制器检查:获取详细的控制器方法信息,包括文件路径和行号
  • 请求验证分析:解析FormRequest验证规则、自定义错误消息和授权逻辑
  • 响应模式分析:分析控制器返回类型、JsonResource结构和Model属性
  • 完成端点分析:在一次呼叫中获取有关任何端点的全面信息
  • 动态资源:通过MCP URI模板访问控制器和路由信息

需求

  • PHP:8.2或更高
  • 拉瑞维尔:12.x
  • 拉瓦尔/mcp:0.5.x或更高

安装

composer require 0xmergen/lmad

该包将自动注册其服务提供商。

配置

发布路线文件(可选)

如果要自定义MCP服务器注册:

php artisan vendor:publish --tag=lmad-routes

这将MCP路由发布到 routes/lmad.php.

MCP服务器注册

LMAD MCP服务器通过软件包自动注册到您的应用程序中 routes/ai.php 文件:

use Laravel\Mcp\Facades\Mcp;
use Lmad\Mcp\LmadServer;

Mcp::local('lmad', LmadServer::class);

可用的MCP工具

工具 说明
list_api_routes 列出所有API路由以及路径、方法、域和供应商路由的可选筛选器
get_route_details 获取有关特定路由的详细信息,包括控制器、中间件和文件位置
get_request_rules 解析FormRequest验证规则、自定义错误消息和授权逻辑
get_response_schema 分析端点返回的内容(JsonResource、Model、array、JsonResponse)
analyze_endpoint 结合路由、控制器、请求和响应信息完成端点分析

可用MCP资源

资源 URI模板 描述
api_routes route://{uri} 动态访问API路由
controller controller://{class}/{method?} 控制器和方法信息

Claude代码设置指南

步骤1:验证MCP服务器

启动Laravel开发服务器:

composer run dev

步骤2:配置Claude代码

创建或编辑您的Claude Code MCP配置文件以连接到LMAD服务器。

对于通过stdio连接的本地MCP服务器:

添加到您的Claude桌面配置(~/.claude_desktop_config.json 在macOS/Linux上):

{
  "mcpServers": {
    "lmad": {
      "command": "php",
      "args": [
        "/path/to/your/lmad/project/artisan",
        "mcp:serve",
        "--server=lmad"
      ],
      "env": {
        "APP_ENV": "local"
      }
    }
  }
}

对于基于HTTP的MCP服务器:

{
  "mcpServers": {
    "lmad": {
      "url": "http://localhost:8000/mcp/lmad"
    }
  }
}

步骤3:重新启动Claude代码

重新启动Claude Desktop或重新加载IDE扩展以激活MCP服务器。

步骤4:验证连接

询问克劳德代码:

List all available MCP tools and resources.

你应该看到LMAD工具,比如 list_api_routes, get_route_details等等。

Claude代码中的示例用法

Get all CRM API routes:
Use list_api_routes with path filter "api/crm"

Analyze the companies endpoint:
Use analyze_endpoint for URI "api/crm/companies" with method "GET"

Get validation rules for company creation:
Use get_request_rules for "App\Http\Requests\Crm\Company\StoreRequest"

Cline(VS Code)安装指南

步骤1:安装Cline扩展

安装 临床扩展 来自VS代码市场。

步骤2:在Cline中配置MCP服务器

  1. 打开VS代码设置
  2. 搜索“临床:MCP服务器”
  3. 添加LMAD服务器配置:

对于stdio连接:

{
  "lmad": {
    "command": "php",
    "args": [
      "/absolute/path/to/your/lmad/project/artisan",
      "mcp:serve",
      "--server=lmad"
    ],
    "env": {
      "APP_ENV": "local",
      "LARAVEL_ROOT": "/absolute/path/to/your/lmad/project"
    }
  }
}

对于HTTP连接:

{
  "lmad": {
    "url": "http://localhost:8000/mcp/lmad",
    "headers": {
      "Accept": "application/json"
    }
  }
}

步骤3:启动Laravel服务器

cd /path/to/your/lmad/project
composer run dev

步骤4:重新加载VS代码

重新加载VS Code窗口以激活MCP服务器连接。

步骤5:测试连接

在Cline聊天中,问:

What MCP tools are available?

您应该看到列出的LMAD工具。

临床使用示例

I need to understand the CRM API. Can you:
1. List all routes under "api/crm"
2. Get details for the companies store endpoint
3. Show me the validation rules for creating a company

Cline将使用LMAD MCP工具收集这些信息。


发展

运行测试

composer test

代码格式化

composer pint

MCP检查员

Laravel MCP提供了一个用于测试MCP服务器的检查器工具:

php artisan mcp:inspector lmad

许可证

MIT许可证(MIT)。请参阅 许可证 了解更多信息。

作者

0xmergen

支持

有关问题、疑问或贡献,请访问 GitHub存储库.