-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
35 lines (27 loc) · 933 Bytes
/
Copy pathindex.php
File metadata and controls
35 lines (27 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
declare(strict_types=1);
require_once __DIR__ . '/vendor/autoload.php';
use McpServer\McpServer;
$server = new McpServer();
// Auto-register tools from the Tools directory automatically!
$server->registerToolsFromDirectory(__DIR__ . '/src/Tools', 'McpServer\\Tools\\');
if (php_sapi_name() === 'cli') {
$in = fopen('php://stdin', 'r');
while (($line = fgets($in)) !== false) {
// Assignment inside condition simplifies control flow
if ($response = $server->handleRequest(trim($line))) {
echo $response . "\n";
}
}
fclose($in);
} else {
header('Content-Type: application/json');
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
http_response_code(405);
echo json_encode(['error' => 'Method Not Allowed. Use POST.']);
exit;
}
if ($response = $server->handleRequest(file_get_contents('php://input'))) {
echo $response;
}
}