-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstdio.php
More file actions
37 lines (30 loc) · 816 Bytes
/
Copy pathstdio.php
File metadata and controls
37 lines (30 loc) · 816 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
36
37
<?php
declare(strict_types=1);
/**
* SimpleMCP stdio JSON-RPC entry point.
*
* Runs the MCP server over standard input/output (line-delimited JSON-RPC 2.0).
* Every request runs under the trusted local user context with full tool access.
*
* Usage:
* php stdio.php
*/
require_once __DIR__ . '/vendor/autoload.php';
use McpServer\McpServer;
$server = new McpServer();
$server->registerToolsFromDirectory(__DIR__ . '/src/Tools', 'McpServer\\Tools\\');
$in = fopen('php://stdin', 'r');
if ($in === false) {
fwrite(STDERR, "Failed to open php://stdin\n");
exit(1);
}
while (($line = fgets($in)) !== false) {
$trimmed = trim($line);
if ($trimmed === '') {
continue;
}
if ($response = $server->handleRequest($trimmed)) {
echo $response . "\n";
}
}
fclose($in);