Skip to main content

What is MCP?

The Model Context Protocol (MCP) is an open standard that allows AI assistants (such as Claude Desktop, Cursor, and Claude Code) to securely discover and invoke tools in external applications. Geni turns your Laravel application into a fully autonomous, AI-ready toolkit:
  • Zero-Effort Tool Discovery (tools/list): Every documented route becomes an AI tool with strictly typed parameter schemas derived directly from your Form Requests, Data DTOs, and migrations.
  • Autonomous Action Execution (tools/call): AI agents can execute real actions against your app. You can ask an agent: “Find user alex@example.com and update their role to admin”, and the agent will discover GET /api/users and dispatch PATCH /api/users/{id} on its own. Available through the stdio server; over HTTP it is opt-in.
  • Isolated Authentication: Bearer tokens and API keys are injected at the HTTP layer and never exposed in the OpenAPI document or prompt context.

Live Stdio Server

Run php artisan geni:mcp:serve for local AI clients like Claude Desktop or Claude Code.

HTTP Remote Endpoint

Access GET / POST on /docs/api/mcp for tool discovery from remote AI agents. Execution over HTTP is opt-in.

Running the Live MCP Server

Geni includes a built-in stdio MCP server command:
This starts a JSON-RPC server listening on standard input and output, responding to MCP protocol messages:
  • tools/list: Returns all available endpoints formatted as tool definitions.
  • tools/call: Dispatches HTTP requests to your application and returns structured responses.

Connecting to Claude Desktop

Add Geni to your claude_desktop_config.json:
claude_desktop_config.json
Restart Claude Desktop, and your AI assistant can now search, inspect, and call your Laravel API endpoints directly!

Generating Static Manifests

You can also export an MCP tool manifest or client configuration to a file:

HTTP MCP Endpoint

Geni also serves an HTTP MCP endpoint at /docs/api/mcp (and /docs/api/{name}/mcp for each named API):
  • GET /docs/api/mcp: Returns tool definitions as JSON.
  • POST /docs/api/mcp: Handles JSON-RPC 2.0 requests: initialize, ping, tools/list and, when enabled, tools/call.
This route inherits the access rules of your documentation portal (restrict_to_local, the viewApiDocs gate and docs_auth). See Documentation Authentication.

Enabling HTTP Execution

tools/call over HTTP is disabled by default. When enabled, anyone who can open the docs can run any documented endpoint, including DELETE routes, with the bearer token or API key configured in mcp.execution.auth. Only enable it when the docs are restricted to trusted users.
.env
config/geni.php
While disabled, a tools/call request receives a JSON-RPC error (-32601) explaining how to enable it. The stdio server (php artisan geni:mcp:serve) is not affected by this flag.

Protocol Details

  • JSON only: POST requests must be sent with Content-Type: application/json; anything else returns 415 Unsupported Media Type. This keeps cross-site forms and text/plain requests out.
  • No CSRF: the MCP routes skip CSRF verification in every auth mode, so adding web to geni.middleware (or using form auth) does not break JSON-RPC clients.
  • Notifications: JSON-RPC notifications (requests without an id, such as notifications/initialized) never receive a JSON-RPC response; the HTTP endpoint answers them with 204 No Content.
  • Version negotiation: initialize answers with the protocol version the client requested when it is supported (2025-06-18, 2025-03-26 or 2024-11-05), and with 2025-06-18 otherwise.
  • Errors: internal exceptions are reported to your application’s exception handler; clients only receive a generic Internal error.

Tool Naming

geni.mcp.tool_naming controls tool names:
  • snake (default): tools are named from the method and path (for example get_api_posts). An explicit operationId (@operationId or #[Endpoint(operationId: ...)]) is converted to snake case and used instead. The operationIds that Geni generates automatically since 3.0 do not rename tools in this mode, so existing tool names stay stable.
  • operation_id: tools use the operation’s operationId, including generated ones. See Operation IDs.

Security & Authentication

Configure token injection in config/geni.php:
config/geni.php
Authentication credentials configured in execution.auth are injected into HTTP requests during tool execution and are never leaked in tool schemas or manifest exports.