Skip to content

Add optional Prism Relay MCP server integration#151

Closed
fosron wants to merge 2 commits intolaravel:0.xfrom
fosron:0.x
Closed

Add optional Prism Relay MCP server integration#151
fosron wants to merge 2 commits intolaravel:0.xfrom
fosron:0.x

Conversation

@fosron
Copy link
Copy Markdown
Contributor

@fosron fosron commented Feb 13, 2026

This PR adds first-party, optional MCP tool integration via Prism Relay without coupling Laravel AI to a required extra package.

What’s included

  • New McpServer tool (Laravel\Ai\Providers\Tools\McpServer) to represent an MCP server in an agent’s tools().
  • Prism gateway tool resolution now supports:
    • Laravel AI tools (Laravel\Ai\Contracts\Tool)
    • Provider tools (ProviderTool)
    • Native Prism tools (Prism\Prism\Tool) as pass-through
    • McpServer, resolved via Prism\Relay\RelayFactory::tools(...)
  • Clear runtime exception if prism-php/relay is not installed and McpServer is used.
  • composer.json now includes a suggest entry for prism-php/relay.

Why

Current provider-tool mapping is provider-specific. MCP should be provider-agnostic and composable.

Usage example

use Laravel\Ai\Providers\Tools\McpServer;

public function tools(): iterable
{
    return [
        new McpServer('github'), // uses config/relay.php
    ];
}

Inline custom server config (remote HTTP example):

use Laravel\Ai\Providers\Tools\McpServer;
use Prism\Relay\Enums\Transport;

new McpServer('github', [
    'url' => env('RELAY_GITHUB_SERVER_URL'),
    'api_key' => env('RELAY_GITHUB_SERVER_API_KEY'),
    'timeout' => 30,
    'transport' => Transport::Http,
]);

You can also pass native Prism tools directly (including Relay-generated tools), which enables fully custom MCP calling flows.

How to test

  1. Install optional dependency:
    • composer require prism-php/relay
  2. Publish Relay config:
    • php artisan vendor:publish --tag=relay-config
  3. Configure at least one MCP server in config/relay.php (HTTP or STDIO).
  4. Add new McpServer('<server-name>') to an agent’s tools().
  5. Prompt the agent and confirm MCP tools are callable.

Notes

We are still missing proper Streamable HTTP (PR) and OAuth support in the upstream package.

@pushpak1300
Copy link
Copy Markdown
Member

laravel/mcp#149

@fosron
Copy link
Copy Markdown
Contributor Author

fosron commented Feb 13, 2026

@pushpak1300 I think using existing Relay library which is made for the underlying Prism package makes more sense. But lets see what maintainers thinks.

@pushpak1300
Copy link
Copy Markdown
Member

pushpak1300 commented Feb 26, 2026

Added MR for ai sdk in relay itself instead here.

prism-php/relay#33

*/
public function __construct(
public string $name,
public ?array $config = null,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bnk

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 861603977gjansgxc [ yeu] 368- - 2[ stv] 1bnk12@5ydoo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants