semaphore-mcp 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- semaphore_mcp-0.1.0/PKG-INFO +601 -0
- semaphore_mcp-0.1.0/README.md +563 -0
- semaphore_mcp-0.1.0/pyproject.toml +73 -0
- semaphore_mcp-0.1.0/setup.cfg +4 -0
- semaphore_mcp-0.1.0/src/semaphore_mcp/__init__.py +7 -0
- semaphore_mcp-0.1.0/src/semaphore_mcp/api.py +308 -0
- semaphore_mcp-0.1.0/src/semaphore_mcp/config.py +61 -0
- semaphore_mcp-0.1.0/src/semaphore_mcp/server.py +127 -0
- semaphore_mcp-0.1.0/src/semaphore_mcp/tools/__init__.py +12 -0
- semaphore_mcp-0.1.0/src/semaphore_mcp/tools/base.py +37 -0
- semaphore_mcp-0.1.0/src/semaphore_mcp/tools/environments.py +207 -0
- semaphore_mcp-0.1.0/src/semaphore_mcp/tools/projects.py +41 -0
- semaphore_mcp-0.1.0/src/semaphore_mcp/tools/tasks.py +978 -0
- semaphore_mcp-0.1.0/src/semaphore_mcp/tools/templates.py +45 -0
- semaphore_mcp-0.1.0/src/semaphore_mcp.egg-info/PKG-INFO +601 -0
- semaphore_mcp-0.1.0/src/semaphore_mcp.egg-info/SOURCES.txt +25 -0
- semaphore_mcp-0.1.0/src/semaphore_mcp.egg-info/dependency_links.txt +1 -0
- semaphore_mcp-0.1.0/src/semaphore_mcp.egg-info/entry_points.txt +2 -0
- semaphore_mcp-0.1.0/src/semaphore_mcp.egg-info/requires.txt +15 -0
- semaphore_mcp-0.1.0/src/semaphore_mcp.egg-info/top_level.txt +1 -0
- semaphore_mcp-0.1.0/tests/test_api_client.py +181 -0
- semaphore_mcp-0.1.0/tests/test_api_comprehensive.py +433 -0
- semaphore_mcp-0.1.0/tests/test_config.py +129 -0
- semaphore_mcp-0.1.0/tests/test_environment_tools_coverage.py +244 -0
- semaphore_mcp-0.1.0/tests/test_mcp_server.py +347 -0
- semaphore_mcp-0.1.0/tests/test_server_coverage.py +189 -0
- semaphore_mcp-0.1.0/tests/test_task_tools_coverage.py +503 -0
|
@@ -0,0 +1,601 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: semaphore-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Model Context Protocol (MCP) server for SemaphoreUI automation
|
|
5
|
+
Author: Colin McNaughton
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/cloin/semaphore-mcp
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/cloin/semaphore-mcp/issues
|
|
9
|
+
Project-URL: Documentation, https://github.com/cloin/semaphore-mcp#readme
|
|
10
|
+
Project-URL: Source Code, https://github.com/cloin/semaphore-mcp
|
|
11
|
+
Keywords: mcp,model-context-protocol,semaphore,ansible,automation,devops
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: System Administrators
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Classifier: Topic :: System :: Systems Administration
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
Requires-Dist: requests>=2.31.0
|
|
26
|
+
Requires-Dist: pydantic>=2.5.0
|
|
27
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
28
|
+
Requires-Dist: mcp>=1.9.3
|
|
29
|
+
Requires-Dist: aiohttp>=3.8.5
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: pytest>=7.4.0; extra == "dev"
|
|
32
|
+
Requires-Dist: pytest-asyncio>=0.21.1; extra == "dev"
|
|
33
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
34
|
+
Requires-Dist: isort>=5.12.0; extra == "dev"
|
|
35
|
+
Provides-Extra: server
|
|
36
|
+
Requires-Dist: fastapi>=0.104.0; extra == "server"
|
|
37
|
+
Requires-Dist: uvicorn>=0.23.2; extra == "server"
|
|
38
|
+
|
|
39
|
+
# SemaphoreUI MCP Server
|
|
40
|
+
|
|
41
|
+
A Model Context Protocol (MCP) server that provides AI assistants with powerful automation capabilities for SemaphoreUI - a modern, web-based Ansible management platform.
|
|
42
|
+
|
|
43
|
+
## 🎯 What is this?
|
|
44
|
+
|
|
45
|
+
This MCP server bridges AI assistants (like Claude) with SemaphoreUI, enabling you to:
|
|
46
|
+
|
|
47
|
+
- **Automate Ansible playbook execution** through natural language
|
|
48
|
+
- **Monitor and analyze task failures** with AI-powered insights
|
|
49
|
+
- **Manage infrastructure projects** with conversational commands
|
|
50
|
+
- **Streamline DevOps workflows** by combining AI reasoning with automation
|
|
51
|
+
|
|
52
|
+
Perfect for DevOps teams who want to leverage AI for infrastructure management while maintaining the power and flexibility of Ansible.
|
|
53
|
+
|
|
54
|
+
## 🎯 Use Cases
|
|
55
|
+
|
|
56
|
+
### For DevOps Engineers
|
|
57
|
+
- **Incident Response**: "Find all failed deployments in the last 6 hours and analyze the errors"
|
|
58
|
+
- **Routine Operations**: "Deploy the latest version to staging and run the smoke tests"
|
|
59
|
+
- **Infrastructure Scaling**: "Add the new servers to our production inventory and update the load balancer config"
|
|
60
|
+
|
|
61
|
+
### For Platform Teams
|
|
62
|
+
- **Self-Service**: Enable developers to deploy to staging environments through conversational AI
|
|
63
|
+
- **Monitoring**: Get intelligent summaries of deployment status and failure patterns
|
|
64
|
+
- **Compliance**: Ensure deployment procedures are followed consistently
|
|
65
|
+
|
|
66
|
+
### For Site Reliability Engineers
|
|
67
|
+
- **Automation**: Convert manual runbooks into conversational workflows
|
|
68
|
+
- **Troubleshooting**: AI-powered analysis of failure logs and suggested remediation
|
|
69
|
+
- **Capacity Planning**: Monitor deployment patterns and resource usage trends
|
|
70
|
+
|
|
71
|
+
## ⚡ Quick Start
|
|
72
|
+
|
|
73
|
+
1. **Spin up SemaphoreUI locally:**
|
|
74
|
+
```bash
|
|
75
|
+
docker run -d \
|
|
76
|
+
--name semaphore-dev \
|
|
77
|
+
-p 3000:3000 \
|
|
78
|
+
-e SEMAPHORE_DB_DIALECT=bolt \
|
|
79
|
+
-e SEMAPHORE_ADMIN_PASSWORD=admin123 \
|
|
80
|
+
-e SEMAPHORE_ADMIN_NAME=admin \
|
|
81
|
+
-e SEMAPHORE_ADMIN_EMAIL=admin@localhost \
|
|
82
|
+
-e SEMAPHORE_ADMIN=admin \
|
|
83
|
+
-v semaphore-data:/etc/semaphore \
|
|
84
|
+
semaphoreui/semaphore:latest
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
2. **Install and configure:** (Requires Python 3.10+)
|
|
88
|
+
```bash
|
|
89
|
+
# Install the package
|
|
90
|
+
pip install semaphore-mcp
|
|
91
|
+
|
|
92
|
+
# Generate API token automatically
|
|
93
|
+
curl -O https://raw.githubusercontent.com/cloin/semaphore-mcp/main/scripts/generate-token.sh
|
|
94
|
+
chmod +x generate-token.sh
|
|
95
|
+
./generate-token.sh admin admin123
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
3. **Test the server:**
|
|
99
|
+
```bash
|
|
100
|
+
semaphore-mcp --help
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
4. **Connect to Claude Desktop** (see [Claude Integration](#claude-desktop-integration) below)
|
|
104
|
+
|
|
105
|
+
## 🚀 What You Can Do
|
|
106
|
+
|
|
107
|
+
Once connected to an AI assistant, you can perform complex automation tasks through natural conversation:
|
|
108
|
+
|
|
109
|
+
### Ansible Automation
|
|
110
|
+
- "Run the database backup playbook on production servers"
|
|
111
|
+
- "Execute the server update template and monitor progress"
|
|
112
|
+
- "Show me all failed deployments from the last week"
|
|
113
|
+
|
|
114
|
+
### Infrastructure Management
|
|
115
|
+
- "Create a new environment for staging with these variables"
|
|
116
|
+
- "List all running tasks and stop any that are failing"
|
|
117
|
+
- "Analyze the last deployment failure and suggest fixes"
|
|
118
|
+
|
|
119
|
+
### Project Operations
|
|
120
|
+
- "Set up a new project for the web application deployment"
|
|
121
|
+
- "Show me all templates in the infrastructure project"
|
|
122
|
+
- "Update the production inventory with new server IPs"
|
|
123
|
+
|
|
124
|
+
The AI can reason about your infrastructure, suggest solutions, and execute actions all in one conversation.
|
|
125
|
+
|
|
126
|
+
## 🛠️ Features
|
|
127
|
+
|
|
128
|
+
The server uses FastMCP for efficient protocol handling and simple tool registration.
|
|
129
|
+
|
|
130
|
+
## Project Status
|
|
131
|
+
|
|
132
|
+
### Completed
|
|
133
|
+
- [x] Basic project structure setup
|
|
134
|
+
- [x] SemaphoreUI API client implementation
|
|
135
|
+
- [x] MCP server implementation with FastMCP and stdio transport
|
|
136
|
+
- [x] Initial tool definitions for projects, templates, and tasks
|
|
137
|
+
- [x] Basic tests for API client and MCP server
|
|
138
|
+
- [x] GitHub Actions workflow for testing with Docker
|
|
139
|
+
- [x] Secure token handling for tests and CI
|
|
140
|
+
- [x] Environment variables configuration
|
|
141
|
+
- [x] Improved error handling in server response formatting
|
|
142
|
+
- [x] Project operations (list, get, create, update, delete)
|
|
143
|
+
- [x] Template operations (list, get)
|
|
144
|
+
- [x] Task operations (list, get, filter by status, execute with monitoring)
|
|
145
|
+
- [x] Task control operations (stop, bulk stop with confirmation, restart)
|
|
146
|
+
- [x] Task status polling and streaming updates
|
|
147
|
+
- [x] Environment management (list, get, create, update, delete)
|
|
148
|
+
- [x] Inventory management (list, get, create, update, delete)
|
|
149
|
+
- [x] LLM-based task failure analysis tools
|
|
150
|
+
- [x] MCP server tools for project management
|
|
151
|
+
- [x] JSON response formatting with content blocks
|
|
152
|
+
|
|
153
|
+
### To Do
|
|
154
|
+
- [ ] Server-Sent Events (SSE) transport implementation (not sure if there's client support)
|
|
155
|
+
- [ ] Authentication handling improvements
|
|
156
|
+
- [ ] Integration examples with Claude and other AI models
|
|
157
|
+
- [ ] Key operations and run task operations
|
|
158
|
+
- [ ] Performance optimization for large Semaphore installations
|
|
159
|
+
- [ ] Implement better error handling and recovery mechanisms
|
|
160
|
+
|
|
161
|
+
## Testing
|
|
162
|
+
|
|
163
|
+
### Setting up a Test Environment
|
|
164
|
+
|
|
165
|
+
Spin up a local SemaphoreUI instance using Docker:
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
docker run -d \
|
|
169
|
+
--name semaphore-dev \
|
|
170
|
+
-p 3000:3000 \
|
|
171
|
+
-e SEMAPHORE_DB_DIALECT=bolt \
|
|
172
|
+
-e SEMAPHORE_ADMIN_PASSWORD=admin123 \
|
|
173
|
+
-e SEMAPHORE_ADMIN_NAME=admin \
|
|
174
|
+
-e SEMAPHORE_ADMIN_EMAIL=admin@localhost \
|
|
175
|
+
-e SEMAPHORE_ADMIN=admin \
|
|
176
|
+
-v semaphore-data:/etc/semaphore \
|
|
177
|
+
semaphoreui/semaphore:latest
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
After starting SemaphoreUI:
|
|
181
|
+
|
|
182
|
+
1. Access the web UI at http://localhost:3000
|
|
183
|
+
2. Login with username `admin` and password `admin123`
|
|
184
|
+
3. Navigate to User Settings and create an API token
|
|
185
|
+
4. Set up the API token in your `.env` file or generate one using the provided script (semaphore url hardcoded as http://localhost:3000):
|
|
186
|
+
```bash
|
|
187
|
+
# Generate a token with default admin credentials
|
|
188
|
+
./scripts/generate-token.sh admin admin123
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Running Tests
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
# Run all tests
|
|
195
|
+
pytest
|
|
196
|
+
|
|
197
|
+
# Run with verbose output
|
|
198
|
+
pytest -v
|
|
199
|
+
|
|
200
|
+
# Run specific test files
|
|
201
|
+
pytest tests/test_api_client.py
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Test Coverage
|
|
205
|
+
|
|
206
|
+
The project includes comprehensive tests for all major functionality:
|
|
207
|
+
- Project operations (CRUD)
|
|
208
|
+
- Template operations (list, get)
|
|
209
|
+
- Task operations (CRUD, monitoring, bulk operations, failure analysis)
|
|
210
|
+
- Environment operations (CRUD)
|
|
211
|
+
- Inventory operations (CRUD)
|
|
212
|
+
- Error handling scenarios
|
|
213
|
+
|
|
214
|
+
## 📦 Installation
|
|
215
|
+
|
|
216
|
+
### Prerequisites
|
|
217
|
+
- Python 3.10+
|
|
218
|
+
- SemaphoreUI instance (local or remote)
|
|
219
|
+
- SemaphoreUI API token
|
|
220
|
+
|
|
221
|
+
## 🚀 For Users
|
|
222
|
+
|
|
223
|
+
### Install from PyPI (Recommended)
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
# Install the package
|
|
227
|
+
pip install semaphore-mcp
|
|
228
|
+
|
|
229
|
+
# Or with uv (faster)
|
|
230
|
+
uv pip install semaphore-mcp
|
|
231
|
+
|
|
232
|
+
# Verify installation
|
|
233
|
+
semaphore-mcp --help
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Install from GitHub
|
|
237
|
+
|
|
238
|
+
```bash
|
|
239
|
+
# Install latest development version
|
|
240
|
+
pip install git+https://github.com/cloin/semaphore-mcp.git
|
|
241
|
+
|
|
242
|
+
# Or specific version
|
|
243
|
+
pip install git+https://github.com/cloin/semaphore-mcp.git@v0.1.0
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## 🛠️ For Developers
|
|
247
|
+
|
|
248
|
+
### Development Setup
|
|
249
|
+
|
|
250
|
+
```bash
|
|
251
|
+
# Clone the repository
|
|
252
|
+
git clone https://github.com/cloin/semaphore-mcp.git
|
|
253
|
+
cd semaphore-mcp
|
|
254
|
+
|
|
255
|
+
# Option 1: Using uv (recommended)
|
|
256
|
+
uv venv && source .venv/bin/activate
|
|
257
|
+
uv pip install -e ".[dev]"
|
|
258
|
+
|
|
259
|
+
# Option 2: Using pip
|
|
260
|
+
python -m venv .venv
|
|
261
|
+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
|
|
262
|
+
pip install -e ".[dev]"
|
|
263
|
+
|
|
264
|
+
# Option 3: Using poetry
|
|
265
|
+
poetry install && poetry shell
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### Run Tests
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
# Run all tests
|
|
272
|
+
pytest
|
|
273
|
+
|
|
274
|
+
# Run with coverage
|
|
275
|
+
pytest --cov=src/semaphore_mcp --cov-report=term-missing
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
## ⚙️ Configuration
|
|
279
|
+
|
|
280
|
+
### Environment Variables
|
|
281
|
+
|
|
282
|
+
Set these in your environment or create a `.env` file:
|
|
283
|
+
|
|
284
|
+
```bash
|
|
285
|
+
SEMAPHORE_URL=http://localhost:3000
|
|
286
|
+
SEMAPHORE_API_TOKEN=your-token-here
|
|
287
|
+
MCP_LOG_LEVEL=INFO # Optional, defaults to INFO
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
To generate a token automatically:
|
|
291
|
+
|
|
292
|
+
```bash
|
|
293
|
+
./scripts/generate-token.sh admin admin123
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
### Running the Server
|
|
297
|
+
|
|
298
|
+
```bash
|
|
299
|
+
# Run the MCP server
|
|
300
|
+
python scripts/start_server.py
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
## Claude Desktop Integration
|
|
304
|
+
|
|
305
|
+
### Step 1: Install and Configure
|
|
306
|
+
|
|
307
|
+
First, install semaphore-mcp:
|
|
308
|
+
|
|
309
|
+
```bash
|
|
310
|
+
# Install from PyPI
|
|
311
|
+
pip install semaphore-mcp
|
|
312
|
+
|
|
313
|
+
# Create a directory for configuration
|
|
314
|
+
mkdir ~/.semaphore-mcp
|
|
315
|
+
cd ~/.semaphore-mcp
|
|
316
|
+
|
|
317
|
+
# Create .env file with your configuration
|
|
318
|
+
echo "SEMAPHORE_URL=http://localhost:3000" > .env
|
|
319
|
+
echo "SEMAPHORE_API_TOKEN=your-token-here" >> .env
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
If you need to generate a token and have SemaphoreUI running locally:
|
|
323
|
+
|
|
324
|
+
```bash
|
|
325
|
+
# Download the token generation script
|
|
326
|
+
curl -O https://raw.githubusercontent.com/cloin/semaphore-mcp/main/scripts/generate-token.sh
|
|
327
|
+
chmod +x generate-token.sh
|
|
328
|
+
|
|
329
|
+
# Generate token automatically
|
|
330
|
+
./generate-token.sh admin admin123 >> .env
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### Step 2: Update Claude Desktop Configuration
|
|
334
|
+
|
|
335
|
+
Edit your Claude Desktop config file:
|
|
336
|
+
- **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
337
|
+
- **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
|
|
338
|
+
- **Linux**: `~/.config/claude-desktop/claude_desktop_config.json`
|
|
339
|
+
|
|
340
|
+
Add this configuration:
|
|
341
|
+
|
|
342
|
+
```json
|
|
343
|
+
{
|
|
344
|
+
"mcpServers": {
|
|
345
|
+
"semaphore": {
|
|
346
|
+
"command": "semaphore-mcp",
|
|
347
|
+
"args": [],
|
|
348
|
+
"env": {
|
|
349
|
+
"SEMAPHORE_URL": "http://localhost:3000",
|
|
350
|
+
"SEMAPHORE_API_TOKEN": "your-token-here"
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
**Alternative**: If you prefer using a config directory:
|
|
358
|
+
|
|
359
|
+
```json
|
|
360
|
+
{
|
|
361
|
+
"mcpServers": {
|
|
362
|
+
"semaphore": {
|
|
363
|
+
"command": "bash",
|
|
364
|
+
"args": [
|
|
365
|
+
"-c",
|
|
366
|
+
"cd ~/.semaphore-mcp && semaphore-mcp"
|
|
367
|
+
]
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
### Step 3: Test the Configuration
|
|
374
|
+
|
|
375
|
+
Verify your setup works before connecting to Claude:
|
|
376
|
+
|
|
377
|
+
```bash
|
|
378
|
+
# Test the command directly
|
|
379
|
+
SEMAPHORE_URL=http://localhost:3000 SEMAPHORE_API_TOKEN=your-token semaphore-mcp --verbose
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
You should see output like:
|
|
383
|
+
```
|
|
384
|
+
INFO:semaphore_mcp:Starting SemaphoreMCP server...
|
|
385
|
+
INFO:semaphore_mcp:Connected to SemaphoreUI at http://localhost:3000
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
Press `Ctrl+C` to stop the test.
|
|
389
|
+
|
|
390
|
+
### Step 4: Restart Claude Desktop
|
|
391
|
+
|
|
392
|
+
After updating the configuration file, restart Claude Desktop to apply the changes.
|
|
393
|
+
|
|
394
|
+
### Step 5: Verify Connection
|
|
395
|
+
|
|
396
|
+
In Claude Desktop, start a new conversation and try:
|
|
397
|
+
```
|
|
398
|
+
List all projects in SemaphoreUI
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
If successful, Claude will use the MCP server to fetch and display your projects.
|
|
402
|
+
|
|
403
|
+
### Available MCP Tools
|
|
404
|
+
|
|
405
|
+
The FastMCP server registers the following tools for interacting with SemaphoreUI:
|
|
406
|
+
|
|
407
|
+
**Project Management:**
|
|
408
|
+
- `list_projects` - List all projects
|
|
409
|
+
- `get_project` - Get a specific project by ID
|
|
410
|
+
- `create_project` - Create a new project
|
|
411
|
+
- `update_project` - Update an existing project
|
|
412
|
+
- `delete_project` - Delete a project
|
|
413
|
+
|
|
414
|
+
**Template Operations:**
|
|
415
|
+
- `list_templates` - List templates for a project
|
|
416
|
+
- `get_template` - Get a specific template
|
|
417
|
+
|
|
418
|
+
**Task Management:**
|
|
419
|
+
- `list_tasks` - List tasks for a project
|
|
420
|
+
- `get_task` - Get a specific task
|
|
421
|
+
- `run_task` - Execute a task from a template
|
|
422
|
+
- `get_task_output` - Get structured task output
|
|
423
|
+
- `get_task_raw_output` - Get raw task output for analysis
|
|
424
|
+
- `stop_task` - Stop a running task
|
|
425
|
+
- `bulk_stop_tasks` - Stop multiple tasks with confirmation
|
|
426
|
+
- `filter_tasks` - Filter tasks by status and other criteria
|
|
427
|
+
- `run_task_with_monitoring` - Execute task with real-time monitoring
|
|
428
|
+
|
|
429
|
+
**LLM-Based Failure Analysis:**
|
|
430
|
+
- `analyze_task_failure` - Comprehensive analysis of failed tasks
|
|
431
|
+
- `bulk_analyze_failures` - Pattern detection across multiple failures
|
|
432
|
+
- `get_latest_failed_task` - Get most recent failed task
|
|
433
|
+
|
|
434
|
+
**Environment Management:**
|
|
435
|
+
- `list_environments` - List environments for a project
|
|
436
|
+
- `get_environment` - Get a specific environment
|
|
437
|
+
- `create_environment` - Create a new environment with variables
|
|
438
|
+
- `update_environment` - Update environment name and variables
|
|
439
|
+
- `delete_environment` - Delete an environment
|
|
440
|
+
|
|
441
|
+
**Inventory Management:**
|
|
442
|
+
- `list_inventory` - List inventory items for a project
|
|
443
|
+
- `get_inventory` - Get a specific inventory item
|
|
444
|
+
- `create_inventory` - Create a new inventory with content
|
|
445
|
+
- `update_inventory` - Update inventory name and content
|
|
446
|
+
- `delete_inventory` - Delete an inventory item
|
|
447
|
+
|
|
448
|
+
### Development with FastMCP
|
|
449
|
+
|
|
450
|
+
Tools are registered using the FastMCP decorator pattern for simplicity and maintainability:
|
|
451
|
+
|
|
452
|
+
```python
|
|
453
|
+
@mcp.tool()
|
|
454
|
+
def list_projects():
|
|
455
|
+
# Implementation
|
|
456
|
+
pass
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
This approach allows for easy extension with new tools as needed. Check the `server.py` file for implementation details.
|
|
460
|
+
|
|
461
|
+
## 📖 Practical Usage Examples
|
|
462
|
+
|
|
463
|
+
### Example 1: Setting Up a New Project
|
|
464
|
+
|
|
465
|
+
**You say to Claude:**
|
|
466
|
+
> "I need to set up a new project for deploying our web application. Create a project called 'webapp-deploy' and add a staging environment with these variables: APP_ENV=staging, DB_HOST=staging-db.example.com"
|
|
467
|
+
|
|
468
|
+
**Claude will:**
|
|
469
|
+
1. Create the project using `create_project`
|
|
470
|
+
2. Create a staging environment using `create_environment`
|
|
471
|
+
3. Confirm the setup and provide you with project details
|
|
472
|
+
|
|
473
|
+
### Example 2: Monitoring and Troubleshooting
|
|
474
|
+
|
|
475
|
+
**You say to Claude:**
|
|
476
|
+
> "Check if there are any failed tasks in the last hour and analyze what went wrong"
|
|
477
|
+
|
|
478
|
+
**Claude will:**
|
|
479
|
+
1. Use `filter_tasks` to find recent failed tasks
|
|
480
|
+
2. Use `analyze_task_failure` to examine error logs
|
|
481
|
+
3. Provide detailed analysis and suggested fixes
|
|
482
|
+
4. Optionally restart tasks if appropriate
|
|
483
|
+
|
|
484
|
+
### Example 3: Automated Deployment Workflow
|
|
485
|
+
|
|
486
|
+
**You say to Claude:**
|
|
487
|
+
> "Run the 'deploy-app' template on production, monitor the progress, and let me know when it's done"
|
|
488
|
+
|
|
489
|
+
**Claude will:**
|
|
490
|
+
1. Execute the template using `run_task_with_monitoring`
|
|
491
|
+
2. Stream real-time progress updates
|
|
492
|
+
3. Notify you of completion status
|
|
493
|
+
4. If it fails, automatically analyze the failure
|
|
494
|
+
|
|
495
|
+
### Example 4: Infrastructure Inventory Management
|
|
496
|
+
|
|
497
|
+
**You say to Claude:**
|
|
498
|
+
> "Update our production inventory to add these new servers: web-03.prod.example.com, web-04.prod.example.com"
|
|
499
|
+
|
|
500
|
+
**Claude will:**
|
|
501
|
+
1. Retrieve current inventory using `get_inventory`
|
|
502
|
+
2. Parse and update the inventory content
|
|
503
|
+
3. Use `update_inventory` to save changes
|
|
504
|
+
4. Confirm the servers were added successfully
|
|
505
|
+
|
|
506
|
+
### Example 5: Bulk Operations
|
|
507
|
+
|
|
508
|
+
**You say to Claude:**
|
|
509
|
+
> "I see there are several stuck tasks running for more than 2 hours. Please stop them all safely"
|
|
510
|
+
|
|
511
|
+
**Claude will:**
|
|
512
|
+
1. Use `filter_tasks` to find long-running tasks
|
|
513
|
+
2. Use `bulk_stop_tasks` with confirmation prompts
|
|
514
|
+
3. Provide summary of stopped tasks
|
|
515
|
+
4. Suggest investigating why tasks got stuck
|
|
516
|
+
|
|
517
|
+
## 🔧 Troubleshooting
|
|
518
|
+
|
|
519
|
+
### Common Issues
|
|
520
|
+
|
|
521
|
+
**Connection refused to SemaphoreUI**
|
|
522
|
+
- Ensure SemaphoreUI is running on the configured URL
|
|
523
|
+
- Check firewall settings if using remote SemaphoreUI
|
|
524
|
+
- Verify the URL format (include http:// or https://)
|
|
525
|
+
|
|
526
|
+
**Authentication errors**
|
|
527
|
+
- Regenerate your API token using `./scripts/generate-token.sh`
|
|
528
|
+
- Ensure the token is correctly set in your `.env` file
|
|
529
|
+
- Check that the user account has appropriate permissions
|
|
530
|
+
|
|
531
|
+
**Claude Desktop not connecting**
|
|
532
|
+
- Verify the absolute path in your config is correct
|
|
533
|
+
- Test the command manually in terminal first
|
|
534
|
+
- Check Claude Desktop logs for specific error messages
|
|
535
|
+
- Ensure virtual environment has all required dependencies
|
|
536
|
+
|
|
537
|
+
**Tasks failing to execute**
|
|
538
|
+
- Verify your templates are properly configured in SemaphoreUI
|
|
539
|
+
- Check that inventory and environment variables are set correctly
|
|
540
|
+
- Ensure your Ansible playbooks are accessible to SemaphoreUI
|
|
541
|
+
|
|
542
|
+
### Debug Mode
|
|
543
|
+
|
|
544
|
+
Enable detailed logging by setting:
|
|
545
|
+
```bash
|
|
546
|
+
export MCP_LOG_LEVEL=DEBUG
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
This will provide verbose output about MCP communications and API calls.
|
|
550
|
+
|
|
551
|
+
## 🤝 Contributing
|
|
552
|
+
|
|
553
|
+
We welcome contributions! Here's how to get started:
|
|
554
|
+
|
|
555
|
+
1. Fork the repository
|
|
556
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
557
|
+
3. Make your changes and add tests
|
|
558
|
+
4. Run the test suite (`pytest`)
|
|
559
|
+
5. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
560
|
+
6. Push to the branch (`git push origin feature/amazing-feature`)
|
|
561
|
+
7. Open a Pull Request
|
|
562
|
+
|
|
563
|
+
### Development Setup
|
|
564
|
+
|
|
565
|
+
```bash
|
|
566
|
+
# Clone your fork
|
|
567
|
+
git clone https://github.com/cloin/semaphore-mcp.git
|
|
568
|
+
cd semaphore-mcp
|
|
569
|
+
|
|
570
|
+
# Install in development mode
|
|
571
|
+
uv venv && source .venv/bin/activate
|
|
572
|
+
uv pip install -e ".[dev]"
|
|
573
|
+
|
|
574
|
+
# Run tests
|
|
575
|
+
pytest
|
|
576
|
+
|
|
577
|
+
# Run linting
|
|
578
|
+
black src/ tests/
|
|
579
|
+
isort src/ tests/
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
## 📜 License
|
|
583
|
+
|
|
584
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
585
|
+
|
|
586
|
+
## 🔗 Related Resources
|
|
587
|
+
|
|
588
|
+
- **SemaphoreUI Documentation**: https://docs.semaphoreui.com/
|
|
589
|
+
- **SemaphoreUI API Reference**: https://semaphoreui.com/api-docs/
|
|
590
|
+
- **Model Context Protocol**: https://modelcontextprotocol.io/introduction
|
|
591
|
+
- **FastMCP Documentation**: https://github.com/jlowin/fastmcp
|
|
592
|
+
|
|
593
|
+
## 📞 Support
|
|
594
|
+
|
|
595
|
+
- **Issues**: Report bugs and request features on [GitHub Issues](https://github.com/cloin/semaphore-mcp/issues)
|
|
596
|
+
- **Discussions**: Join conversations on [GitHub Discussions](https://github.com/cloin/semaphore-mcp/discussions)
|
|
597
|
+
- **SemaphoreUI Community**: Get help with SemaphoreUI at their [community forums](https://github.com/ansible-semaphore/semaphore)
|
|
598
|
+
|
|
599
|
+
---
|
|
600
|
+
|
|
601
|
+
**⭐ If this project helps you, please give it a star on GitHub!**
|