Skip to main content
Glama
dok4everak47

Laravel MCP Server

by dok4everak47

Cortex Agent Runtime — 基于 MCP 的原生 AI Agent 框架

之前:AI 不理解你的项目。之后:AI 可以分析、生成和调试应用程序。

一个 Model Context Protocol (MCP) 服务器,可将任何编码代理(Claude、Cursor、Codex、OpenCode 等)转变为你所处理项目的自主工程大脑。该运行时与项目类型无关:它会根据你的项目类型加载一组领域,因此同一运行时适用于 Laravel 应用、Node 项目以及任何其他项目。

运行时

  • 项目类型检测core/detector.ts 检查项目并激活匹配的领域。通用工具始终加载;当存在 composer.json + artisan 时,Laravel 领域被激活。

  • 领域注册core/registry.ts 暴露 registerDomain(manifest)listTools() / callTool() 保持稳定,因此 MCP 表面在不同项目之间不会变化。

  • 默认安全 — 仅本地、离线、无遥测。命令白名单、危险命令阻止和敏感数据脱敏分层实现。

Related MCP server: Project Planner MCP

内置领域

领域

加载时机

工具

通用

始终

gitStatusfileSearchprojectTree

Laravel

存在 composer.json + artisan

artisan、schema、model、routes、migrations、CRUD/feature/API 生成器、调试工作流、intentPlanner、workflowStatus、context 等

通用领域

工具

描述

gitStatus

Git 状态摘要(分支、暂存/未暂存更改)

fileSearch

按 glob 搜索文件,排除 .git / node_modules / vendor

projectTree

项目的两级目录树

listRoles

列出此项目中可用的角色以及每个角色拥有的工具

Laravel 领域

工具

描述

artisan

运行白名单内的 php artisan 命令

migrateStatus

迁移状态

envInfo / envInfoSafe

环境信息(安全变体对机密信息进行脱敏)

cache

清除/缓存配置、路由、视图

configGet

检查配置值

schema

列出表 / 列

model

扫描 Eloquent 模型

log

最近的日志条目

routeList

带名称/URI/方法过滤器的路由

runTest

运行 PHPUnit 测试

frontendScanner

扫描视图/js/css 结构

makeModel / makeController / makeMigration

搭建类

migrationAnalyzer

将迁移解析为 schema

composerAnalyzer

项目依赖

projectContext

完整项目上下文(按文件 mtime 缓存)

crudGenerator

完整 CRUD 生成器

createFeature

CRUD + Blade 视图

apiGenerator

REST API 生成器(可选 Sanctum 认证)

debugWorkflow

错误定位、诊断、修复建议

intentPlanner

自然语言请求 → 可执行计划

workflowStatus

列出/检查/恢复/回滚运行

contextSource

显示每部分项目上下文来自缓存还是实时重建

listRoles

列出此项目中可用的角色以及每个角色拥有的工具

为什么代理信任它们的答案

两个借鉴自真实系统提示架构的设计原则:

  • 角色,而非工具列表。 listRoles 告诉代理它在此项目中可以是谁——探索者(只读调查)、工程师(构建和修复)或维护者(运维和验证)——以及每个角色拥有哪些工具。代理面对的不是一堵平坦的工具墙,而是选择一个角色并停留在其边界内。更少的失误,更清晰的意图。

  • 知道你的事实来自哪里。 contextSource 显示项目上下文的每个模块是从缓存提供还是实时重建,并且上下文本身通过优先级链(cache → live → safe default)组装,而不是“由代理自行解决”。当代理回答时,它知道事实有多新鲜——你也一样。

之前: 代理盯着 29 个工具和无法检查日期的过期上下文。 之后: 它知道自己的角色、工具集以及所读一切的新鲜度。

快速开始

npm install
npm start

设置要处理的项目路径:

# Any project (Node, Laravel, ...)
CORTEX_PROJECT_PATH=/path/to/project npm start

# Laravel-specific path resolution (backward compatible)
LARAVEL_PROJECT_PATH=/path/to/laravel-app npm start

# Nothing set → process.cwd()

通过单个 MCP 请求运行服务器,查看项目暴露了哪些工具:

echo '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' | \
  CORTEX_PROJECT_PATH=/path/to/node-project npx tsx src/index.ts
# → only generic tools

echo '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' | \
  CORTEX_PROJECT_PATH=/path/to/laravel-app npx tsx src/index.ts
# → generic + laravel tools

使用 OpenCode

添加到 ~/.config/opencode/opencode.jsonc

{
  "mcp": {
    "cortex": {
      "type": "local",
      "command": ["node", "/path/to/cortex-agent-runtime/dist/index.js"],
      "environment": { "CORTEX_PROJECT_PATH": "/path/to/project" }
    }
  }
}

使用 Claude Desktop

添加到 ~/Library/Application Support/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "cortex": {
      "command": "node",
      "args": ["/path/to/cortex-agent-runtime/dist/index.js"]
    }
  }
}

环境变量

变量

默认值

描述

CORTEX_PROJECT_PATH

项目路径(优先)

LARAVEL_PROJECT_PATH

process.cwd()

向后兼容的 Laravel 项目路径

PHP_PATH

php

PHP 可执行文件路径(Laravel 领域)

LLM_API_KEY

(空)

intentPlanner 启用 LLM 语义层

LLM_BASE_URL

https://api.deepseek.com/v1

兼容 OpenAI 的 API 基础 URL

LLM_MODEL

deepseek-chat

用于意图分析的 LLM 模型

架构

src/
├── index.ts                 # entry: detect → load domains → register → start MCP
├── core/                    # framework layer — project-type agnostic
│   ├── registry.ts          # ToolRegistry: registerDomain / listTools / callTool / roles
│   ├── source-chain.ts      # resolveChain: priority fallback chain (cache → live → default)
│   ├── mcp.ts               # getConfig / getLogger / runCommand
│   ├── logger.ts            # leveled logger
│   ├── detector.ts          # detectDomains(projectPath) → DomainManifest[]
│   ├── glob.ts              # minimal `*` / `**` glob
│   ├── context/             # generic context interface
│   └── tools/               # shared tools (listRoles)
└── domains/
    ├── generic/             # always loaded: gitStatus / fileSearch / projectTree / listRoles
    └── laravel/             # tools / workflows / context / security / planner / manifest

每个领域导出一个 DomainManifestidnamedetectgetToolsgetHandlersgetProjectPath?roles?)。角色声明代理在此项目中可以是谁(explorer / engineer / maintainer)以及每个角色拥有哪些工具——代理可以调用 listRoles 而不是猜测。Laravel 领域保留自己的运行时(domains/laravel/mcp.ts)、工具、工作流、上下文、安全和规划器——现有的 24 工具表面不变。

要求

  • Node.js 18+

  • PHP 8.1+(用于 Laravel 领域)

Pi 扩展(MCP 工具的移植)

相同的工具集,作为 pi coding agent 扩展:35 个工具中的 34 个从 MCP 服务器迁移到原生 pi 自定义工具,减去 intentPlanner(pi 本身是 LLM;自然语言 → 计划在那里是多余的)。来源:pi-extension/cortex-laravel/

安装

# either copy …
cp -R pi-extension/cortex-laravel ~/.pi/agent/extensions/
# … or symlink (always in sync with this repo)
ln -s "$(pwd)/pi-extension/cortex-laravel" ~/.pi/agent/extensions/cortex-laravel

然后重启 pi(或 /reload)。该扩展注册 34 个工具:

领域

工具

通用(5)

gitStatusfileSearchprojectTreelistRolestoolStats

Laravel 核心(5)

artisanmigrateStatusschemamodelrouteList

Laravel 运维(12)

envInfoenvInfoSafecacheconfigGetlogrunTestmakeModelmakeControllermakeMigrationmigrationAnalyzercomposerAnalyzerfrontendScanner

Laravel 工作流(7)

crudGeneratorcreateFeatureapiGeneratordebugWorkflowworkflowStatusprojectContextcontextSource

编排(5)

taskStatustaskMetricspolicyGettaskAccepttaskAdvance

项目路径解析:CORTEX_PROJECT_PATH / LARAVEL_PROJECT_PATH 环境变量,回退到 pi 的会话 cwd。Laravel 工具在非 Laravel 项目上通过清晰的错误进行自我保护;编排工具读写与 MCP 服务器(以及独立的 htask CLI)相同的 .htask/ 布局。

与 MCP 服务器的差异

  • 安全性 — 相同的命令白名单 + 危险模式验证器(两层),外加 taskAdvance / taskAccept / workflowStatus(恢复·回滚)上的确认门:设置 CORTEX_CONFIRM_OFF=1 以允许在脚本中使用。

  • Laravel 11+ 兼容性 — 上游移除的 config:get 回退到 tinker;当 routes/api.php 不存在时,API 路由通过 artisan install:api 自动创建。

  • nix flake 项目resolvePhpPath 探测已知的 nix 安装路径(不仅仅是 PATH 中的 nix)。

  • 错误 — 抛出的错误作为工具错误呈现;工具结果是纯文本(无 MCP JSON-RPC 包装)。

开发

npm install
npm run typecheck   # tsc --noEmit (type-check only)
npm test            # run all tests
npm run build       # compile to dist/
npm start           # node dist/index.js
npm run dev         # npx tsx src/index.ts (hot reload)

许可证

MIT

Install Server
A
license - permissive license
B
quality
B
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    Not graded
    quality
    C
    maintenance
    Integrates with the Laravel Forge API to provide comprehensive management of servers and sites. It enables users to perform health checks, monitor logs, create resources, and execute deployment tasks through MCP-compliant tools.
    20
    2
    MIT
  • F
    license
    Not graded
    quality
    D
    maintenance
    Provides various developer utilities such as UUID generation, timestamp conversion, Base64 encoding, color conversion, password generation, hash generation, and JSON formatting via MCP.
    77
    1
  • A
    license
    Not graded
    quality
    B
    maintenance
    Enables AI assistants to introspect a Laravel application's routes, models, controllers, migrations, and more through the Model Context Protocol, running locally via php artisan commands and filesystem scanning.
    16
    MIT

View all related MCP servers

Related MCP Connectors

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/dok4everak47/cortex-agent-runtime'

If you have feedback or need assistance with the MCP directory API, please join our Discord server