PHP Classes

File: examples/http_client.php

Recommend this page to a friend!
  Classes of Mohamed Ahmed   Laravel MCP SDK   examples/http_client.php   Download  
File: examples/http_client.php
Role: Example script
Content typex: text/plain
Description: Example script
Class: Laravel MCP SDK
Create tools to process user requests with prompts
Author: By
Last change:
Date: 2 days ago
Size: 1,345 bytes
 

Contents

Class file image Download
<?php

require __DIR__ . '/../vendor/autoload.php';

use
LaravelMCP\MCP\MCPClient;

// Create client instance
$client = new MCPClient(baseUrl: 'http://127.0.0.1:8080',apiKey: 'test-key');

// Example 1: Tool Call
try {
   
$result = $client->createContext([
       
'type' => 'tool_call',
       
'name' => 'example_tool',
       
'arguments' => ['arg1' => 'value1', 'arg2' => 'value2']
    ]);
    echo
"Tool Call Result:\n";
    echo
json_encode($result, JSON_PRETTY_PRINT) . "\n\n";
} catch (
Exception $e) {
    echo
"Error making tool call: " . $e->getMessage() . "\n";
}

// Example 2: Resource Request
try {
   
$result = $client->createContext([
       
'type' => 'resource_request',
       
'uri' => 'example://resource/123'
   
]);
    echo
"Resource Request Result:\n";
    echo
json_encode($result, JSON_PRETTY_PRINT) . "\n\n";
} catch (
Exception $e) {
    echo
"Error making resource request: " . $e->getMessage() . "\n";
}

// Example 3: Prompt Request
try {
   
$result = $client->createContext([
       
'type' => 'prompt_request',
       
'name' => 'example_prompt',
       
'arguments' => ['context' => 'This is a test prompt']
    ]);
    echo
"Prompt Request Result:\n";
    echo
json_encode($result, JSON_PRETTY_PRINT) . "\n\n";
} catch (
Exception $e) {
    echo
"Error making prompt request: " . $e->getMessage() . "\n";
}