Add redMCP Streamable HTTP server
This commit is contained in:
Executable
+43
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use RedMCP\McpEnvironment;
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
$options = getopt('', ['host:', 'port:', 'path:', 'help']);
|
||||
if (isset($options['help'])) {
|
||||
fwrite(STDOUT, "Usage: redmcp-http-server.php [--host 0.0.0.0] [--port 8765] [--path /mcp]\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
$host = (string) ($options['host'] ?? '0.0.0.0');
|
||||
$port = (int) ($options['port'] ?? 8765);
|
||||
$path = (string) ($options['path'] ?? '/mcp');
|
||||
|
||||
try {
|
||||
$env = McpEnvironment::load(__DIR__ . '/../.env');
|
||||
if ($env['mcp_server_token'] === null) {
|
||||
throw new RuntimeException('MCP_SERVER_TOKEN is required for the network MCP server.');
|
||||
}
|
||||
} catch (Throwable $exception) {
|
||||
fwrite(STDERR, $exception->getMessage() . PHP_EOL);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
putenv('MCP_HTTP_PATH=' . $path);
|
||||
$router = __DIR__ . '/../app/mcp-http-router.php';
|
||||
$command = [
|
||||
PHP_BINARY,
|
||||
'-S',
|
||||
$host . ':' . $port,
|
||||
$router,
|
||||
];
|
||||
|
||||
fwrite(STDERR, "redMCP HTTP server listening on http://{$host}:{$port}{$path}\n");
|
||||
fwrite(STDERR, "Authorization: Bearer <MCP_SERVER_TOKEN> is required.\n");
|
||||
|
||||
passthru(implode(' ', array_map('escapeshellarg', $command)), $exitCode);
|
||||
exit((int) $exitCode);
|
||||
Reference in New Issue
Block a user