Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion src/McpServer/Console/MCPServerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Butschster\ContextGenerator\McpServer\Tool\Command\CommandExecutor;
use Butschster\ContextGenerator\McpServer\Tool\Command\CommandExecutorInterface;
use Psr\Log\LoggerInterface;
use Spiral\Boot\EnvironmentInterface;
use Spiral\Console\Attribute\Option;
use Spiral\Core\Container;
use Spiral\Core\Scope;
Expand All @@ -36,6 +37,24 @@ final class MCPServerCommand extends BaseCommand
)]
protected ?string $configPath = null;

#[Option(
name: 'sse',
description: 'Enable SSE (Server-Sent Events) support',
)]
protected bool $isSse = false;

#[Option(
name: 'host',
description: 'Sse host to bind to',
)]
protected string $host = '127.0.0.1';

#[Option(
name: 'port',
description: 'Sse port to bind to',
)]
protected string $port = '8080';

#[Option(
name: 'env',
shortcut: 'e',
Expand Down Expand Up @@ -75,6 +94,19 @@ public function __invoke(

$this->logger->info('Starting MCP server...');

$envs = [];
if ($this->isSse) {
$envs['MCP_TRANSPORT'] = 'http';
}

if ($this->host) {
$envs['MCP_HOST'] = $this->host;
}

if ($this->port) {
$envs['MCP_PORT'] = $this->port;
}

return $container->runScope(
bindings: new Scope(
bindings: [
Expand All @@ -85,10 +117,15 @@ public function __invoke(
Container $container,
ConfigurationProvider $configProvider,
LoggerInterface $logger,
) use ($dirs, $app) {
EnvironmentInterface $env,
) use ($dirs, $app, $envs) {
$rootPathStr = (string) $dirs->getRootPath();
$logger->info(\sprintf('Using root path: %s', $rootPathStr));

foreach ($envs as $key => $value) {
$env->set($key, $value);
}

try {
// Get the appropriate loader based on options provided
if (!\is_dir($rootPathStr)) {
Expand Down Expand Up @@ -121,6 +158,7 @@ public function __invoke(
CommandExecutorInterface::class => $container->make(CommandExecutor::class, [
'projectRoot' => (string) $dirs->getRootPath(),
]),
EnvironmentInterface::class => $env,
],
),
scope: static function (ServerRunnerInterface $factory) use ($app): void {
Expand Down
Loading