-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Claude/add mcp transport 011 cu nfd m4i6 wc lq z xh b1n ad #1827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Daytona39264
wants to merge
5
commits into
dingo:master
Choose a base branch
from
Daytona39264:claude/add-mcp-transport-011CUNfdM4i6WCLqZXhB1nAd
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a19eef1
Initial plan
Copilot 05273ec
Merge pull request #1 from Daytona39264/copilot/git-fetch-clone-commit
Daytona39264 cb068ad
Add Model Context Protocol (MCP) transport support
claude a028841
Update HttpTransport.php
Daytona39264 d4103a9
Update Mcp.php
Daytona39264 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <?php | ||
|
|
||
| namespace Dingo\Api\Contract\Mcp; | ||
|
|
||
| interface Transport | ||
| { | ||
| /** | ||
| * Connect to the MCP server and establish a session. | ||
| * | ||
| * @return mixed | ||
| */ | ||
| public function connect(); | ||
|
|
||
| /** | ||
| * Send a request to the MCP server. | ||
| * | ||
| * @param string $method | ||
| * @param array $params | ||
| * | ||
| * @return mixed | ||
| */ | ||
| public function send($method, array $params = []); | ||
|
|
||
| /** | ||
| * Close the connection to the MCP server. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function disconnect(); | ||
|
|
||
| /** | ||
| * Check if the transport is connected. | ||
| * | ||
| * @return bool | ||
| */ | ||
| public function isConnected(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <?php | ||
|
|
||
| namespace Dingo\Api\Facade; | ||
|
|
||
| use Illuminate\Support\Facades\Facade; | ||
|
|
||
| class MCP extends Facade | ||
| { | ||
| /** | ||
| * Get the registered name of the component. | ||
| * | ||
| * @return string | ||
| */ | ||
| protected static function getFacadeAccessor() | ||
| { | ||
| return 'api.mcp'; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| <?php | ||
|
|
||
| namespace Dingo\Api\Mcp; | ||
|
|
||
| use Illuminate\Container\Container; | ||
|
|
||
| class Mcp | ||
| { | ||
| /** | ||
| * Illuminate container instance. | ||
| * | ||
| * @var \Illuminate\Container\Container | ||
| */ | ||
| protected $container; | ||
|
|
||
| /** | ||
| * Array of available MCP transports. | ||
| * | ||
| * @var array | ||
| */ | ||
| protected $transports = []; | ||
|
|
||
| /** | ||
| * Create a new MCP instance. | ||
| * | ||
| * @param \Illuminate\Container\Container $container | ||
| * @param array $transports | ||
| * | ||
| * @return void | ||
| */ | ||
| public function __construct(Container $container, array $transports = []) | ||
| { | ||
| $this->container = $container; | ||
| $this->transports = $transports; | ||
| } | ||
|
|
||
| /** | ||
| * Get a transport by name. | ||
| * | ||
| * @param string $name | ||
| * | ||
| * @throws \InvalidArgumentException | ||
| * | ||
| * @return \Dingo\Api\Contract\Mcp\Transport | ||
| */ | ||
| public function transport($name) | ||
| { | ||
| if (!isset($this->transports[$name])) { | ||
| throw new \InvalidArgumentException("MCP transport [{$name}] is not registered."); | ||
| } | ||
|
|
||
| return $this->transports[$name]; | ||
| } | ||
|
|
||
| /** | ||
| * Get all registered transports. | ||
| * | ||
| * @return array | ||
| */ | ||
| public function getTransports() | ||
| { | ||
| return $this->transports; | ||
| } | ||
|
|
||
| /** | ||
| * Register a new transport. | ||
| * | ||
| * @param string $name | ||
| * @param \Dingo\Api\Contract\Mcp\Transport|callable $transport | ||
| * Either a transport instance or a callable that returns a transport. | ||
| * If a callable is provided, it will be invoked with the container. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function registerTransport($name, $transport) | ||
| { | ||
| if (is_callable($transport)) { | ||
| $transport = call_user_func($transport, $this->container); | ||
| } | ||
| $this->transports[$name] = $transport; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| <?php | ||
|
|
||
| namespace Dingo\Api\Mcp\Transport; | ||
|
|
||
| use Dingo\Api\Contract\Mcp\Transport; | ||
| use GuzzleHttp\Client; | ||
| use GuzzleHttp\Exception\GuzzleException; | ||
|
|
||
| class HttpTransport implements Transport | ||
| { | ||
| /** | ||
| * The HTTP client instance. | ||
| * | ||
| * @var \GuzzleHttp\Client | ||
| */ | ||
| protected $client; | ||
|
|
||
| /** | ||
| * The MCP server URL. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $url; | ||
|
|
||
| /** | ||
| * The transport name/identifier. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $name; | ||
|
|
||
| /** | ||
| * Connection state. | ||
| * | ||
| * @var bool | ||
| */ | ||
| protected $connected = false; | ||
|
|
||
| /** | ||
| * Additional headers for requests. | ||
| * | ||
| * @var array | ||
| */ | ||
| protected $headers = []; | ||
|
|
||
| /** | ||
| * Create a new HTTP transport instance. | ||
| * | ||
| * @param string $name | ||
| * @param string $url | ||
| * @param array $options | ||
| */ | ||
| public function __construct($name, $url, array $options = []) | ||
| { | ||
| $this->name = $name; | ||
| $this->url = $url; | ||
| $this->headers = $options['headers'] ?? []; | ||
|
|
||
| $this->client = new Client([ | ||
| 'base_uri' => $url, | ||
| 'timeout' => $options['timeout'] ?? 30, | ||
| 'verify' => $options['verify'] ?? true, | ||
| ]); | ||
| } | ||
|
|
||
| /** | ||
| * Connect to the MCP server and establish a session. | ||
| * | ||
| * @return mixed | ||
| */ | ||
| public function connect() | ||
| { | ||
| try { | ||
| // Test connection with a ping or initialization request | ||
| $response = $this->client->get('', [ | ||
| 'headers' => array_merge([ | ||
| 'Accept' => 'application/json', | ||
| 'Content-Type' => 'application/json', | ||
| ], $this->headers), | ||
| ]); | ||
|
|
||
| $this->connected = $response->getStatusCode() === 200; | ||
|
|
||
| return $this->connected; | ||
| } catch (GuzzleException $e) { | ||
| $this->connected = false; | ||
| throw new \RuntimeException( | ||
| "Failed to connect to MCP server [{$this->name}] at {$this->url}: {$e->getMessage()}" | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Send a request to the MCP server. | ||
| * | ||
| * @param string $method | ||
| * @param array $params | ||
| * | ||
| * @return mixed | ||
| */ | ||
| public function send($method, array $params = []) | ||
| { | ||
| if (!$this->connected) { | ||
| $this->connect(); | ||
| } | ||
Daytona39264 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| try { | ||
| $response = $this->client->post('', [ | ||
| 'headers' => array_merge([ | ||
| 'Accept' => 'application/json', | ||
| 'Content-Type' => 'application/json', | ||
| ], $this->headers), | ||
| 'json' => [ | ||
| 'jsonrpc' => '2.0', | ||
| 'method' => $method, | ||
| 'params' => $params, | ||
| 'id' => uniqid('mcp_', true), | ||
Daytona39264 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ], | ||
| ]); | ||
|
|
||
| $body = json_decode($response->getBody()->getContents(), true); | ||
Daytona39264 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (json_last_error() !== JSON_ERROR_NONE) { | ||
| throw new \RuntimeException('Invalid JSON response from MCP server'); | ||
| } | ||
|
|
||
| if (isset($body['error'])) { | ||
| throw new \RuntimeException( | ||
| "MCP server error: {$body['error']['message']} (code: {$body['error']['code']})" | ||
| ); | ||
| } | ||
|
|
||
| return $body['result'] ?? null; | ||
| } catch (GuzzleException $e) { | ||
| throw new \RuntimeException( | ||
| "Failed to send request to MCP server [{$this->name}]: {$e->getMessage()}" | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Close the connection to the MCP server. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function disconnect() | ||
| { | ||
| $this->connected = false; | ||
| } | ||
|
|
||
| /** | ||
| * Check if the transport is connected. | ||
| * | ||
| * @return bool | ||
| */ | ||
| public function isConnected() | ||
| { | ||
| return $this->connected; | ||
| } | ||
|
|
||
| /** | ||
| * Get the transport name. | ||
| * | ||
| * @return string | ||
| */ | ||
| public function getName() | ||
| { | ||
| return $this->name; | ||
| } | ||
|
|
||
| /** | ||
| * Get the transport URL. | ||
| * | ||
| * @return string | ||
| */ | ||
| public function getUrl() | ||
| { | ||
| return $this->url; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.