Skip to content

Commit 7ae9f9e

Browse files
committed
Added information about custom tools
1 parent ac9deba commit 7ae9f9e

File tree

3 files changed

+128
-56
lines changed

3 files changed

+128
-56
lines changed

docs/index.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# CTX: Context as Code (CaC) tool with MCP server inside.
1+
# CTX: Context as Code (CaC) tool with MCP server inside.
2+
23
### The missing link between your codebase and your LLM.
34

45
![Good morning, LLM](https://github.com/user-attachments/assets/8129f227-dc3f-4671-bc0e-0ecd2f3a1888)
@@ -47,6 +48,9 @@ When working with AI-powered development tools context is everything.
4748
- **Seamless AI Integration**: With MCP support, [connect](/mcp-server) Claude AI directly to your codebase, allowing
4849
for real-time, context-aware assistance without manual context sharing.
4950

51+
- **Automated Tool Execution**: Define [custom tools](/mcp/tools) that can be triggered through the MCP server, enabling
52+
automated code checks, builds, and other development workflows directly from your AI assistant.
53+
5054
## How it works
5155

5256
1. Gathers code from files, directories, GitHub repositories, web pages, or custom text.

docs/mcp-server.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
# MCP Server Integration
22

3-
The Model Control Protocol (MCP) server is a bridge that enables AI assistants like Claude to directly access and
4-
understand your project's context. It acts as an intermediary that provides real-time, structured information about your
5-
codebase to AI models, enabling more accurate and contextually relevant assistance.
6-
7-
**CTX** now supports the MCP protocol, allowing Claude to seamlessly access your project's contexts, and
8-
documentation without requiring manual context uploads.
3+
The MCP Server can also be integrated with AI assistants like Claude to provide direct access to your project's context.
4+
This allows AI models to request specific information about your codebase without requiring manual context uploads.
95

106
## How integration works
117

12-
When you connect Claude to **CTX** via MCP:
8+
When you connect an AI assistant to your application via **MCP**:
9+
10+
1. The assistant can request specific context about your project directly through the MCP protocol
11+
2. Your application processes these requests by accessing your codebase based on your configuration
12+
3. Relevant code, documentation, and structural information is formatted and returned to the assistant
13+
4. The assistant uses this rich context to provide more accurate, project-aware responses
14+
15+
This integration enhances both Tools and Prompts components by:
1316

14-
1. Claude can request specific context about your project directly through the MCP protocol
15-
2. **CTX** processes these requests by accessing your codebase based on your `context.yaml`
16-
3. Relevant code, documentation, and structural information is formatted and returned to Claude
17-
4. Claude uses this rich context to provide more accurate, project-aware responses
17+
- Allowing AI assistants to trigger tool execution directly
18+
- Enabling assistants to access and utilize your prompt library
19+
- Providing real-time context awareness for more accurate assistance
1820

1921
```mermaid
2022
sequenceDiagram
@@ -23,21 +25,19 @@ sequenceDiagram
2325
participant MCP Server as "CTX<br/>MCP Server"
2426
participant Files as "Project Files"
2527
participant Config as "context.yaml/<br/>context.json"
26-
27-
User->>Claude: Ask question about project
28-
Claude->>MCP Server: Request context (MCP protocol)
29-
MCP Server->>Config: Read configuration
30-
MCP Server->>Files: Access relevant files
28+
User ->> Claude: Ask question about project
29+
Claude ->> MCP Server: Request context (MCP protocol)
30+
MCP Server ->> Config: Read configuration
31+
MCP Server ->> Files: Access relevant files
3132
Note over MCP Server: Filter & process content<br/>based on configuration
32-
MCP Server-->>Claude: Return formatted context
33-
Claude->>User: Provide contextually aware response
34-
35-
Note over User,Claude: Subsequent questions
36-
User->>Claude: Follow-up question
37-
Claude->>MCP Server: Request additional context
38-
MCP Server->>Files: Access specific files
39-
MCP Server-->>Claude: Return targeted information
40-
Claude->>User: Provide detailed response
33+
MCP Server -->> Claude: Return formatted context
34+
Claude ->> User: Provide contextually aware response
35+
Note over User, Claude: Subsequent questions
36+
User ->> Claude: Follow-up question
37+
Claude ->> MCP Server: Request additional context
38+
MCP Server ->> Files: Access specific files
39+
MCP Server -->> Claude: Return targeted information
40+
Claude ->> User: Provide detailed response
4141
```
4242

4343
The diagram shows how Claude communicates with the MCP Server, which accesses your project files

docs/mcp/tools.md

Lines changed: 98 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@ description of each tool.
55

66
## Environment Variables Configuration
77

8+
The tools system can be configured using environment variables to enable or disable specific features:
9+
810
### General Configuration
911

10-
- `MCP_DOCUMENT_NAME_FORMAT`: Controls how documents are named in the system.
11-
- Default: `[{path}] {description}`
12-
- Example: A document might appear as `[src/file.php] Main controller file`
12+
| Variable | Description | Default |
13+
|-----------------------------|--------------------------------------------|---------|
14+
| `MCP_CUSTOM_TOOLS_ENABLE` | Enable/disable custom tools | `true` |
15+
| `MCP_TOOL_MAX_RUNTIME` | Maximum runtime for a command in seconds | `30` |
16+
| `MCP_FILE_OPERATIONS` | Master switch for all file operation tools | `true` |
17+
| `MCP_FILE_WRITE` | Enable/disable file write operations | `true` |
18+
| `MCP_FILE_APPLY_PATCH` | Enable/disable applying patches to files | `false` |
19+
| `MCP_FILE_DIRECTORIES_LIST` | Enable/disable directory listing | `true` |
1320

1421
## Available Tool Categories
1522

@@ -60,40 +67,101 @@ These tools are always available regardless of environment configuration:
6067
| `document-content` | Get document content by ID |
6168
| `list-tools` | List all available tools (what you're using now) |
6269

63-
## Configuration Examples
70+
## Custom Tools
71+
72+
The Custom Tools feature allows you to define project-specific commands that can be executed directly from the
73+
configuration files. This enables easy integration of common development tasks, build processes, code analysis, and
74+
more.
75+
76+
## Configuration Format
77+
78+
Custom tools are defined in the `tools` section of the configuration file.
79+
80+
**Here's the basic structure:**
81+
82+
```yaml
83+
tools:
84+
- id: tool-id # Unique identifier for the tool
85+
description: 'Tool description' # Human-readable description
86+
env: # Optional environment variables for all commands
87+
KEY1: value1
88+
KEY2: value2
89+
commands: # List of commands to execute
90+
- cmd: executable # Command to run
91+
args: # Command arguments (array)
92+
- arg1
93+
- arg2
94+
workingDir: path/to/dir # Optional working directory (relative to project root)
95+
env: # Optional environment variables for this command
96+
KEY1: value1
97+
KEY2: value2
98+
```
6499
65-
### Developer Mode (All Features)
100+
## Example Use Cases
66101
67-
```
68-
MCP_FILE_OPERATIONS=true
69-
MCP_FILE_WRITE=true
70-
MCP_FILE_APPLY_PATCH=true
71-
MCP_FILE_DIRECTORIES_LIST=true
72-
MCP_CONTEXT_OPERATIONS=true
73-
MCP_PROMPT_OPERATIONS=true
102+
### 1. Code Style Fixing
103+
104+
```yaml
105+
tools:
106+
- id: cs-fixer
107+
description: 'Fix code style issues'
108+
commands:
109+
- cmd: composer
110+
args: [
111+
- cs:fix
74112
```
75113
76-
### Read-Only Mode (Safe for Production)
114+
### 2. Static Analysis
77115
116+
```yaml
117+
tools:
118+
- id: phpstan
119+
description: 'Run static analysis'
120+
commands:
121+
- cmd: vendor/bin/phpstan
122+
args: [ 'analyse', 'src', '--level', '8' ]
78123
```
79-
MCP_FILE_OPERATIONS=true
80-
MCP_FILE_WRITE=false
81-
MCP_FILE_APPLY_PATCH=false
82-
MCP_FILE_DIRECTORIES_LIST=true
83-
MCP_CONTEXT_OPERATIONS=true
84-
MCP_PROMPT_OPERATIONS=false
85-
```
86-
87-
### Minimal Mode
88124
125+
### 3. Multi-Step Processes
126+
127+
```yaml
128+
tools:
129+
- id: test-suite
130+
description: 'Run full test suite with coverage'
131+
commands:
132+
- cmd: composer
133+
args: [ 'install', '--no-dev' ]
134+
- cmd: vendor/bin/phpunit
135+
args: [ '--coverage-html', 'coverage' ]
136+
- cmd: vendor/bin/infection
137+
args: [ '--min-msi=80' ]
89138
```
90-
MCP_FILE_OPERATIONS=true
91-
MCP_FILE_WRITE=false
92-
MCP_FILE_APPLY_PATCH=false
93-
MCP_FILE_DIRECTORIES_LIST=true
94-
MCP_CONTEXT_OPERATIONS=false
95-
MCP_PROMPT_OPERATIONS=false
139+
140+
### 4. Deployment
141+
142+
```yaml
143+
tools:
144+
- id: deploy-staging
145+
description: 'Deploy to staging environment'
146+
commands:
147+
- cmd: bash
148+
args: [ 'deploy.sh', 'staging' ]
149+
env:
150+
DEPLOY_TOKEN: "${STAGING_TOKEN}"
96151
```
97152
98-
This documentation provides users with a clear understanding of available tools, their purpose, and how to enable or
99-
disable them without requiring knowledge of the underlying class implementation.
153+
## Security Considerations
154+
155+
The custom tools feature includes several security measures:
156+
157+
1. **Environment Variable Controls**:
158+
- `MCP_CUSTOM_TOOLS_ENABLE`: Enable/disable the custom tools feature (default: `true`)
159+
- `MCP_TOOL_MAX_RUNTIME`: Maximum runtime for a command in seconds (default: `30`)
160+
161+
## Best Practices
162+
163+
1. **Keep Commands Simple**: Break complex operations into multiple commands
164+
2. **Use Environment Variables**: Avoid hardcoding secrets in tool configurations
165+
3. **Set Appropriate Timeouts**: Adjust the `max_runtime` for long-running commands
166+
4. **Test Thoroughly**: Test custom tools before implementing them in production
167+
5. **Consider Security**: Be cautious about what commands are allowed and who can execute them

0 commit comments

Comments
 (0)