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
46 changes: 0 additions & 46 deletions context.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,6 @@ tools:
type: "txt"
query: "{{query}}"

# CTX CLI Testing Tools
- id: ctx-run
description: 'Run any CTX command with arguments'
schema:
type: object
properties:
command:
type: string
description: "The CTX command to run (e.g., 'project:list', 'project', 'project:add')"
args:
type: string
description: "Additional arguments for the command (optional)"
default: ""
required:
- command
commands:
- cmd: ./ctx
args: ['{{command}}', '{{args}}']
workingDir: .

projects:
- name: ctx-mcp-server
description: MCP server library
Expand All @@ -59,32 +39,6 @@ exclude:
- ".claude"
- ".context"

rag:
enabled: true
store:
driver: qdrant
qdrant:
endpoint_url: ${RAG_QDRANT_URL:-http://localhost:6333}
api_key: ${RAG_QDRANT_API_KEY}
collection: ${RAG_COLLECTION:-ctx_knowledge}
embeddings_dimension: 1536
embeddings_distance: Cosine
vectorizer:
platform: openai
model: text-embedding-3-small
api_key: ${OPENAI_API_KEY}
transformer:
chunk_size: 1000
overlap: 200

projects:
- name: ctx-mcp-server
description: MCP server for CTX
- name: ctx-docs
description: CTX application docs
- name: module-config-templates
description: Initial config templates and CLI command

documents:
- description: 'Project structure overview'
outputPath: project-structure.md
Expand Down
77 changes: 77 additions & 0 deletions docs/fr-filesystem-excludes/01-feature-overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Feature Overview

## Description

Extend exclude pattern support to all MCP filesystem tools to provide consistent security and access control across all
file operations.

Currently, exclude patterns (defined in project configuration) only work for:

- `directory-list` tool
- `file-search` tool

This feature will extend exclude support to:

- `file-read` - prevent reading excluded files
- `file-write` - prevent writing to excluded paths
- `file-replace-content` - prevent modifying excluded files
- `file-insert-content` - prevent inserting into excluded files
- `file-delete-content` - prevent deleting from excluded files

## Business Value

1. **Security**: Prevent accidental exposure or modification of sensitive files (`.env`, credentials, secrets)
2. **Consistency**: All filesystem tools behave the same way regarding excludes
3. **Developer Experience**: Clear, predictable behavior across all operations
4. **Configuration Reuse**: Single exclude configuration applies everywhere

## User Benefit

- Configure excludes once, enforced everywhere
- No risk of AI assistant accidentally reading/modifying sensitive files
- Consistent error messages when accessing excluded paths

## Target Audience

- Developers using CTX MCP server for AI-assisted development
- Teams with sensitive files that should never be accessed by AI tools
- Projects with strict file access policies

## Implementation Status

All filesystem tools now respect exclude patterns:

```yaml
# context.yaml
exclude:
- .env
- .env.*
- secrets/
- vendor/
```

| Tool | Respects Excludes | Status |
|------------------------|-------------------|--------|
| `directory-list` | ✅ Yes | ✅ Done |
| `file-search` | ✅ Yes | ✅ Done |
| `file-read` | ✅ Yes | ✅ Done |
| `file-write` | ✅ Yes | ✅ Done |
| `file-replace-content` | ✅ Yes | ✅ Done |
| `file-insert-content` | ✅ Yes | ✅ Done |
| `file-delete-content` | ✅ Yes | ✅ Done |

## Current Behavior

All tools return clear error when attempting to access excluded paths:

```
Error: Path '.env' is excluded by project configuration
```

## FileWrite Architecture (Completed)

The `FileWriteAction` class has been refactored to follow the established Action/Handler separation pattern:

1. ✅ `FileWrite/FileWriteHandler.php` - Core logic with exclude support
2. ✅ `FileWrite/FileWriteResult.php` - Result DTO
3. ✅ `FileWriteAction.php` - Thin action delegating to handler
196 changes: 196 additions & 0 deletions docs/fr-filesystem-excludes/02-technical-architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
# Technical Architecture

## High-Level Architecture

The exclude system is built around the `ExcludeRegistryInterface` which provides a centralized registry of exclusion
patterns. Each filesystem handler will receive this registry via dependency injection and check paths before performing
operations.

## Integration Points

### Existing Exclude Infrastructure

```
src/Config/Exclude/
├── AbstractExclusion.php # Base class for exclusions
├── ExcludeBootloader.php # DI registration
├── ExcludeParserPlugin.php # YAML config parser
├── ExcludeRegistry.php # Main registry implementation
├── ExcludeRegistryInterface.php # Contract for injection
├── ExclusionPatternInterface.php # Pattern contract
├── PathExclusion.php # Path-based exclusion
└── PatternExclusion.php # Glob pattern exclusion
```

### Filesystem Tools Structure (Current)

```
src/McpServer/Action/Tools/Filesystem/
├── DirectoryListAction.php ✅ Has excludes
├── FileWriteAction.php ✅ Refactored - delegates to handler
├── Dto/
│ ├── DirectoryListRequest.php
│ ├── FileWriteRequest.php (kept in original location)
│ └── TreeViewConfig.php
├── FileDeleteContent/
│ ├── Dto/
│ ├── FileDeleteContentAction.php
│ ├── FileDeleteContentHandler.php ✅ Has excludes
│ └── FileDeleteResult.php
├── FileInsertContent/
│ ├── Dto/
│ ├── FileInsertContentAction.php
│ ├── FileInsertContentHandler.php ✅ Has excludes
│ └── FileInsertResult.php
├── FileRead/
│ ├── Dto/
│ ├── FileReadAction.php
│ ├── FileReadHandler.php ✅ Has excludes
│ ├── FileReadResult.php
│ └── MultiFileReadHandler.php
├── FileReplaceContent/
│ ├── Dto/
│ ├── FileReplaceContentAction.php
│ ├── FileReplaceContentHandler.php ✅ Has excludes
│ ├── FileReplaceResult.php
│ ├── LineEnding.php
│ └── LineEndingNormalizer.php
├── FileSearch/
│ ├── Dto/
│ ├── FileSearchAction.php
│ ├── FileSearchHandler.php ✅ Has excludes
│ ├── FileSearchResult.php
│ └── SearchMatch.php
└── FileWrite/
├── FileWriteHandler.php ✅ NEW - core logic with excludes
└── FileWriteResult.php ✅ NEW - result DTO
```

## Class Diagram

```mermaid
classDiagram
class ExcludeRegistryInterface {
<<interface>>
+addPattern(ExclusionPatternInterface pattern) self
+shouldExclude(string path) bool
+getPatterns() array
}

class ExcludeRegistry {
-array patterns
-LoggerInterface logger
+addPattern(ExclusionPatternInterface pattern) self
+shouldExclude(string path) bool
+getPatterns() array
}

class FileReadHandler {
-FilesInterface files
-DirectoriesInterface dirs
-ExcludeRegistryInterface excludeRegistry
-LoggerInterface logger
+read(string path, string encoding, int startLine, int endLine) FileReadResult
}

class FileWriteHandler {
-FilesInterface files
-DirectoriesInterface dirs
-ExcludeRegistryInterface excludeRegistry
-LoggerInterface logger
+handle(FileWriteRequest request) FileWriteResult
}

class FileReplaceContentHandler {
-FilesInterface files
-DirectoriesInterface dirs
-ExcludeRegistryInterface excludeRegistry
-LineEndingNormalizer normalizer
-LoggerInterface logger
+handle(FileReplaceContentRequest request) FileReplaceResult
}

class FileInsertContentHandler {
-FilesInterface files
-DirectoriesInterface dirs
-ExcludeRegistryInterface excludeRegistry
-LineEndingNormalizer normalizer
-LoggerInterface logger
+handle(FileInsertContentRequest request) FileInsertResult
}

class FileDeleteContentHandler {
-FilesInterface files
-DirectoriesInterface dirs
-ExcludeRegistryInterface excludeRegistry
-LineEndingNormalizer normalizer
-LoggerInterface logger
+handle(FileDeleteContentRequest request) FileDeleteResult
}

ExcludeRegistryInterface <|.. ExcludeRegistry
FileReadHandler --> ExcludeRegistryInterface
FileWriteHandler --> ExcludeRegistryInterface
FileReplaceContentHandler --> ExcludeRegistryInterface
FileInsertContentHandler --> ExcludeRegistryInterface
FileDeleteContentHandler --> ExcludeRegistryInterface
```

## Sequence Diagram: File Operation with Exclude Check

```mermaid
sequenceDiagram
participant Client
participant Action
participant Handler
participant ExcludeRegistry
participant Files
Client ->> Action: invoke(Request)
Action ->> Handler: handle(request)
Handler ->> Handler: Build relative path
Handler ->> ExcludeRegistry: shouldExclude(relativePath)

alt Path is excluded
ExcludeRegistry -->> Handler: true
Handler -->> Action: Result::error("Path excluded")
Action -->> Client: CallToolResult::error
else Path is allowed
ExcludeRegistry -->> Handler: false
Handler ->> Files: exists(fullPath)
Files -->> Handler: true
Handler ->> Files: read/write(fullPath)
Files -->> Handler: content/success
Handler -->> Action: Result::success
Action -->> Client: CallToolResult::text
end
```

## FileWrite Directory Structure (Implemented)

The FileWrite handler was added while keeping the action and request in their original locations:

```
src/McpServer/Action/Tools/Filesystem/
├── FileWriteAction.php # Thin action, delegates to handler
├── Dto/
│ └── FileWriteRequest.php # Kept in original location
└── FileWrite/
├── FileWriteHandler.php # Core logic + excludes
└── FileWriteResult.php # Result DTO
```

## Technology Stack

- **PHP 8.3+**: Constructor property promotion, readonly classes
- **Spiral Framework**: Dependency injection, `#[Proxy]` attribute
- **Symfony Finder**: File system operations (used by some tools)
- **PSR-3 Logging**: `LoggerInterface` for debugging

## Dependencies

No new dependencies required. All necessary components exist:

- `ExcludeRegistryInterface` - already defined
- `ExcludeRegistry` - already implemented
- `FilesInterface` - Spiral's file abstraction
- `DirectoriesInterface` - project path resolver
Loading
Loading