Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions src/McpServer/McpConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ final class McpConfig extends InjectableConfig
'git_operations' => [
'enable' => true,
],
'project_operations' => [
'enable' => true,
],
];

public function getDocumentNameFormat(string $path, string $description, string $tags): string
Expand Down Expand Up @@ -97,4 +100,9 @@ public function isGitOperationsEnabled(): bool
{
return $this->config['git_operations']['enable'] ?? true;
}

public function isProjectOperationsEnabled(): bool
{
return $this->config['project_operations']['enable'] ?? true;
}
}
14 changes: 14 additions & 0 deletions src/McpServer/McpServerBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
use Butschster\ContextGenerator\McpServer\Action\Tools\Prompts\GetPromptToolAction;
use Butschster\ContextGenerator\McpServer\Action\Tools\Prompts\ListPromptsToolAction;
use Butschster\ContextGenerator\McpServer\Console\MCPServerCommand;
use Butschster\ContextGenerator\McpServer\Projects\Actions\ProjectsListToolAction;
use Butschster\ContextGenerator\McpServer\Projects\Actions\ProjectSwitchToolAction;
use Butschster\ContextGenerator\McpServer\Projects\McpProjectsBootloader;
use Butschster\ContextGenerator\McpServer\ProjectService\ProjectServiceInterface;
use Butschster\ContextGenerator\McpServer\Prompt\McpPromptBootloader;
Expand Down Expand Up @@ -98,6 +100,9 @@ public function init(EnvironmentInterface $env): void
'git_operations' => [
'enable' => (bool) $env->get('MCP_GIT_OPERATIONS', !$isCommonProject),
],
'project_operations' => [
'enable' => (bool) $env->get('MCP_PROJECT_OPERATIONS', true),
],
],
);
}
Expand Down Expand Up @@ -189,6 +194,7 @@ private function actions(McpConfig $config): array
FetchLibraryDocsAction::class,
];
}

if ($config->isFileOperationsEnabled()) {
$actions = [
...$actions,
Expand All @@ -209,6 +215,14 @@ private function actions(McpConfig $config): array
}
}

if ($config->isProjectOperationsEnabled()) {
$actions = [
...$actions,
ProjectsListToolAction::class,
ProjectSwitchToolAction::class,
];
}

if ($config->isGitOperationsEnabled()) {
$actions[] = GitStatusAction::class;
$actions[] = GitAddAction::class;
Expand Down
24 changes: 24 additions & 0 deletions src/McpServer/Projects/Actions/Dto/AliasResolutionResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Butschster\ContextGenerator\McpServer\Projects\Actions\Dto;

/**
* Response when alias resolution occurs
*/
final readonly class AliasResolutionResponse implements \JsonSerializable
{
public function __construct(
public string $originalAlias,
public string $resolvedPath,
) {}

public function jsonSerialize(): array
{
return [
'original_alias' => $this->originalAlias,
'resolved_path' => $this->resolvedPath,
];
}
}
31 changes: 31 additions & 0 deletions src/McpServer/Projects/Actions/Dto/CurrentProjectResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Butschster\ContextGenerator\McpServer\Projects\Actions\Dto;

/**
* Represents current project information in response
*/
final readonly class CurrentProjectResponse implements \JsonSerializable
{
/**
* @param string[] $aliases
*/
public function __construct(
public string $path,
public ?string $configFile,
public ?string $envFile,
public array $aliases,
) {}

public function jsonSerialize(): array
{
return [
'path' => $this->path,
'config_file' => $this->configFile,
'env_file' => $this->envFile,
'aliases' => $this->aliases,
];
}
}
35 changes: 35 additions & 0 deletions src/McpServer/Projects/Actions/Dto/ProjectInfoResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Butschster\ContextGenerator\McpServer\Projects\Actions\Dto;

/**
* Represents a single project in the response
*/
final readonly class ProjectInfoResponse implements \JsonSerializable
{
/**
* @param string[] $aliases
*/
public function __construct(
public string $path,
public ?string $configFile,
public ?string $envFile,
public string $addedAt,
public array $aliases,
public bool $isCurrent,
) {}

public function jsonSerialize(): array
{
return [
'path' => $this->path,
'config_file' => $this->configFile,
'env_file' => $this->envFile,
'added_at' => $this->addedAt,
'aliases' => $this->aliases,
'is_current' => $this->isCurrent,
];
}
}
12 changes: 12 additions & 0 deletions src/McpServer/Projects/Actions/Dto/ProjectListRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Butschster\ContextGenerator\McpServer\Projects\Actions\Dto;

final readonly class ProjectListRequest
{
public function __construct(
// No parameters needed for listing projects
) {}
}
17 changes: 17 additions & 0 deletions src/McpServer/Projects/Actions/Dto/ProjectSwitchRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Butschster\ContextGenerator\McpServer\Projects\Actions\Dto;

use Spiral\JsonSchemaGenerator\Attribute\Field;

final readonly class ProjectSwitchRequest
{
public function __construct(
#[Field(
description: 'Alias to the project to switch to. Should be project alias.',
)]
public string $alias,
) {}
}
28 changes: 28 additions & 0 deletions src/McpServer/Projects/Actions/Dto/ProjectSwitchResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Butschster\ContextGenerator\McpServer\Projects\Actions\Dto;

/**
* Response for project switch tool
*/
final readonly class ProjectSwitchResponse implements \JsonSerializable
{
public function __construct(
public bool $success,
public string $message,
public ?CurrentProjectResponse $currentProject = null,
public ?AliasResolutionResponse $resolvedFromAlias = null,
) {}

public function jsonSerialize(): array
{
return \array_filter([
'success' => $this->success,
'message' => $this->message,
'current_project' => $this->currentProject,
'resolved_from_alias' => $this->resolvedFromAlias,
], static fn($value) => $value !== null);
}
}
31 changes: 31 additions & 0 deletions src/McpServer/Projects/Actions/Dto/ProjectsListResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Butschster\ContextGenerator\McpServer\Projects\Actions\Dto;

/**
* Response for projects list tool
*/
final readonly class ProjectsListResponse implements \JsonSerializable
{
/**
* @param ProjectInfoResponse[] $projects
*/
public function __construct(
public array $projects,
public ?CurrentProjectResponse $currentProject,
public int $totalProjects,
public ?string $message = null,
) {}

public function jsonSerialize(): array
{
return [
'projects' => $this->projects,
'current_project' => $this->currentProject,
'total_projects' => $this->totalProjects,
'message' => $this->message,
];
}
}
Loading
Loading