@172ai/containers-mcp-server 1.0.0
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.
- package/.env.example +43 -0
- package/README.md +366 -0
- package/dist/auth.d.ts +57 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +192 -0
- package/dist/auth.js.map +1 -0
- package/dist/config.d.ts +84 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +246 -0
- package/dist/config.js.map +1 -0
- package/dist/server.d.ts +63 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +886 -0
- package/dist/server.js.map +1 -0
- package/dist/services/buildService.d.ts +51 -0
- package/dist/services/buildService.d.ts.map +1 -0
- package/dist/services/buildService.js +268 -0
- package/dist/services/buildService.js.map +1 -0
- package/dist/services/capabilityService.d.ts +62 -0
- package/dist/services/capabilityService.d.ts.map +1 -0
- package/dist/services/capabilityService.js +240 -0
- package/dist/services/capabilityService.js.map +1 -0
- package/dist/services/containerService.d.ts +52 -0
- package/dist/services/containerService.d.ts.map +1 -0
- package/dist/services/containerService.js +251 -0
- package/dist/services/containerService.js.map +1 -0
- package/dist/services/fileService.d.ts +65 -0
- package/dist/services/fileService.d.ts.map +1 -0
- package/dist/services/fileService.js +330 -0
- package/dist/services/fileService.js.map +1 -0
- package/dist/setup.d.ts +30 -0
- package/dist/setup.d.ts.map +1 -0
- package/dist/setup.js +328 -0
- package/dist/setup.js.map +1 -0
- package/dist/types.d.ts +229 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/errorHandler.d.ts +78 -0
- package/dist/utils/errorHandler.d.ts.map +1 -0
- package/dist/utils/errorHandler.js +269 -0
- package/dist/utils/errorHandler.js.map +1 -0
- package/package.json +81 -0
package/.env.example
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# 172.ai MCP Server Configuration Example
|
|
2
|
+
# Copy this file to .env and fill in your actual values
|
|
3
|
+
|
|
4
|
+
# API Configuration
|
|
5
|
+
CONTAINER_API_URL=https://api.172.ai
|
|
6
|
+
NODE_ENV=development
|
|
7
|
+
|
|
8
|
+
# Authentication (choose one method)
|
|
9
|
+
|
|
10
|
+
# Method 1: API Key (Recommended for production)
|
|
11
|
+
# API_KEY=your_api_key_here
|
|
12
|
+
|
|
13
|
+
# Method 2: OAuth Token (for temporary access)
|
|
14
|
+
# OAUTH_TOKEN=your_oauth_token_here
|
|
15
|
+
|
|
16
|
+
# Method 3: OAuth Client Credentials (for automated systems)
|
|
17
|
+
# OAUTH_CLIENT_ID=your_client_id_here
|
|
18
|
+
# OAUTH_CLIENT_SECRET=your_client_secret_here
|
|
19
|
+
|
|
20
|
+
# Logging
|
|
21
|
+
LOG_LEVEL=info
|
|
22
|
+
|
|
23
|
+
# Timeouts (in milliseconds)
|
|
24
|
+
REQUEST_TIMEOUT=30000
|
|
25
|
+
CONNECT_TIMEOUT=10000
|
|
26
|
+
|
|
27
|
+
# Rate Limiting
|
|
28
|
+
RATE_LIMIT_PER_MINUTE=60
|
|
29
|
+
RATE_LIMIT_PER_HOUR=1000
|
|
30
|
+
|
|
31
|
+
# Retry Configuration
|
|
32
|
+
MAX_RETRIES=3
|
|
33
|
+
BACKOFF_MULTIPLIER=2
|
|
34
|
+
MAX_BACKOFF_MS=30000
|
|
35
|
+
|
|
36
|
+
# Security
|
|
37
|
+
VALIDATE_CERTIFICATES=true
|
|
38
|
+
ALLOWED_SCOPES=containers:read,containers:write,builds:read,builds:write,files:read,files:write
|
|
39
|
+
|
|
40
|
+
# Development Settings (for development environment only)
|
|
41
|
+
# Set these only for development/testing purposes
|
|
42
|
+
# BYPASS_AUTH=false # Never set to true in production
|
|
43
|
+
EOF < /dev/null
|
package/README.md
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
# 172.ai Container Management MCP Server
|
|
2
|
+
|
|
3
|
+
A **Model Context Protocol (MCP) server** that provides AI assistants with access to the 172.ai container management platform. This server exposes powerful tools for managing containers, builds, files, and capabilities through a standardized MCP interface, enabling natural language interactions with your containerized applications.
|
|
4
|
+
|
|
5
|
+
🌐 **Live Documentation**: [https://172.ai/#/mcp](https://172.ai/#/mcp)
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@172ai/containers-mcp-server)
|
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
|
|
10
|
+
## 🚀 Quick Start
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
# Install globally
|
|
14
|
+
npm install -g @172ai/containers-mcp-server
|
|
15
|
+
|
|
16
|
+
# Run interactive setup
|
|
17
|
+
containers-mcp-server --setup
|
|
18
|
+
|
|
19
|
+
# Start the server
|
|
20
|
+
containers-mcp-server
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## ✨ Features
|
|
24
|
+
|
|
25
|
+
### Container Management
|
|
26
|
+
- **List Containers**: Browse available containers with filtering options
|
|
27
|
+
- **Get Container Details**: Retrieve detailed information about specific containers
|
|
28
|
+
- **Create Container**: Create new container templates
|
|
29
|
+
- **Update Container**: Modify existing container configurations
|
|
30
|
+
- **Delete Container**: Remove containers from the system
|
|
31
|
+
- **Copy Container**: Create copies of existing containers
|
|
32
|
+
|
|
33
|
+
### Build Management
|
|
34
|
+
- **Build Container**: Initiate container build processes
|
|
35
|
+
- **Get Build Status**: Monitor build progress and status
|
|
36
|
+
- **List Builds**: View build history for containers
|
|
37
|
+
- **Get Build Logs**: Access detailed build logs and output
|
|
38
|
+
|
|
39
|
+
### File Management
|
|
40
|
+
- **List Container Files**: Browse files within containers
|
|
41
|
+
- **Get File Content**: Read file contents
|
|
42
|
+
- **Upload Files**: Add new files to containers
|
|
43
|
+
- **Update Files**: Modify existing file contents
|
|
44
|
+
- **Delete Files**: Remove files from containers
|
|
45
|
+
|
|
46
|
+
### Capability Management
|
|
47
|
+
- **List Capabilities**: View available system capabilities
|
|
48
|
+
- **Get Capability Details**: Access detailed capability information
|
|
49
|
+
- **Search Capabilities**: Find capabilities by name or description
|
|
50
|
+
|
|
51
|
+
## Installation
|
|
52
|
+
|
|
53
|
+
1. **Clone or create the MCP server directory**:
|
|
54
|
+
```bash
|
|
55
|
+
mkdir containers-mcp-server
|
|
56
|
+
cd containers-mcp-server
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
2. **Install dependencies**:
|
|
60
|
+
```bash
|
|
61
|
+
npm install
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
3. **Configure environment variables**:
|
|
65
|
+
```bash
|
|
66
|
+
cp .env.example .env
|
|
67
|
+
# Edit .env with your configuration
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
4. **Build the project**:
|
|
71
|
+
```bash
|
|
72
|
+
npm run build
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Configuration
|
|
76
|
+
|
|
77
|
+
### Environment Variables
|
|
78
|
+
|
|
79
|
+
The server requires configuration through environment variables. Copy `.env.example` to `.env` and configure:
|
|
80
|
+
|
|
81
|
+
#### Required Settings
|
|
82
|
+
- `CONTAINER_API_URL`: Base URL for the container management API
|
|
83
|
+
- Authentication (choose one):
|
|
84
|
+
- `API_KEY`: Your API key for authentication
|
|
85
|
+
- `OAUTH_TOKEN`: OAuth token for temporary access
|
|
86
|
+
- `OAUTH_CLIENT_ID` + `OAUTH_CLIENT_SECRET`: For automated token refresh
|
|
87
|
+
|
|
88
|
+
#### Optional Settings
|
|
89
|
+
- `NODE_ENV`: Environment (development, production, test)
|
|
90
|
+
- `LOG_LEVEL`: Logging verbosity (error, warn, info, debug)
|
|
91
|
+
- `RATE_LIMIT_PER_MINUTE`: API rate limiting
|
|
92
|
+
- `REQUEST_TIMEOUT`: Request timeout in milliseconds
|
|
93
|
+
- `MAX_RETRIES`: Number of retry attempts for failed requests
|
|
94
|
+
|
|
95
|
+
### Authentication Methods
|
|
96
|
+
|
|
97
|
+
The server supports three authentication methods:
|
|
98
|
+
|
|
99
|
+
1. **API Key** (Recommended for production):
|
|
100
|
+
```bash
|
|
101
|
+
API_KEY=your_api_key_here
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
2. **OAuth Token** (For temporary access):
|
|
105
|
+
```bash
|
|
106
|
+
OAUTH_TOKEN=your_oauth_token_here
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
3. **OAuth Client Credentials** (For automated systems):
|
|
110
|
+
```bash
|
|
111
|
+
OAUTH_CLIENT_ID=your_client_id_here
|
|
112
|
+
OAUTH_CLIENT_SECRET=your_client_secret_here
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Usage
|
|
116
|
+
|
|
117
|
+
### Running the Server
|
|
118
|
+
|
|
119
|
+
#### Development Mode
|
|
120
|
+
```bash
|
|
121
|
+
npm run dev
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
#### Production Mode
|
|
125
|
+
```bash
|
|
126
|
+
npm start
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Connecting to Claude Code
|
|
130
|
+
|
|
131
|
+
1. **Add to your Claude Code configuration**:
|
|
132
|
+
```json
|
|
133
|
+
{
|
|
134
|
+
"mcpServers": {
|
|
135
|
+
"containers": {
|
|
136
|
+
"command": "node",
|
|
137
|
+
"args": ["/path/to/containers-mcp-server/dist/server.js"],
|
|
138
|
+
"env": {
|
|
139
|
+
"CONTAINER_API_URL": "http://localhost:3000",
|
|
140
|
+
"API_KEY": "your_api_key_here"
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
2. **Restart Claude Code** to load the new server
|
|
148
|
+
|
|
149
|
+
### Available Tools
|
|
150
|
+
|
|
151
|
+
Once connected, you can use these tools in your AI conversations:
|
|
152
|
+
|
|
153
|
+
#### Container Operations
|
|
154
|
+
- `list_containers` - List available containers
|
|
155
|
+
- `get_container` - Get detailed container information
|
|
156
|
+
- `create_container` - Create new container templates
|
|
157
|
+
- `update_container` - Update container configurations
|
|
158
|
+
- `delete_container` - Remove containers
|
|
159
|
+
- `copy_container` - Create container copies
|
|
160
|
+
|
|
161
|
+
#### Build Operations
|
|
162
|
+
- `build_container` - Start container builds
|
|
163
|
+
- `get_build_status` - Check build progress
|
|
164
|
+
- `list_builds` - View build history
|
|
165
|
+
|
|
166
|
+
#### File Operations
|
|
167
|
+
- `list_container_files` - Browse container files
|
|
168
|
+
- `get_file_content` - Read file contents
|
|
169
|
+
- `upload_file` - Add files to containers
|
|
170
|
+
|
|
171
|
+
#### Capability Operations
|
|
172
|
+
- `list_capabilities` - View available capabilities
|
|
173
|
+
|
|
174
|
+
### Example Usage
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
// List public containers
|
|
178
|
+
await listContainers({ scope: 'public', limit: 10 });
|
|
179
|
+
|
|
180
|
+
// Get container details
|
|
181
|
+
await getContainer({ containerId: 'container-123' });
|
|
182
|
+
|
|
183
|
+
// Build a container
|
|
184
|
+
await buildContainer({ containerId: 'container-123' });
|
|
185
|
+
|
|
186
|
+
// Upload a file
|
|
187
|
+
await uploadFile({
|
|
188
|
+
containerId: 'container-123',
|
|
189
|
+
filePath: 'src/app.js',
|
|
190
|
+
content: 'console.log("Hello, world!");',
|
|
191
|
+
mimeType: 'application/javascript'
|
|
192
|
+
});
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## API Reference
|
|
196
|
+
|
|
197
|
+
### Tool Parameters
|
|
198
|
+
|
|
199
|
+
#### `list_containers`
|
|
200
|
+
- `scope`: Filter by scope ('public', 'myCollection', 'all')
|
|
201
|
+
- `limit`: Maximum number of results (1-100)
|
|
202
|
+
- `offset`: Number of results to skip
|
|
203
|
+
- `query`: Search query for filtering
|
|
204
|
+
|
|
205
|
+
#### `get_container`
|
|
206
|
+
- `containerId`: Container ID to retrieve
|
|
207
|
+
|
|
208
|
+
#### `create_container`
|
|
209
|
+
- `name`: Container name
|
|
210
|
+
- `description`: Container description
|
|
211
|
+
- `dockerfile`: Dockerfile content
|
|
212
|
+
- `tags`: Array of tags (optional)
|
|
213
|
+
- `isPrivate`: Privacy setting (optional)
|
|
214
|
+
- `envVars`: Environment variables (optional)
|
|
215
|
+
|
|
216
|
+
#### `build_container`
|
|
217
|
+
- `containerId`: Container ID to build
|
|
218
|
+
|
|
219
|
+
#### `upload_file`
|
|
220
|
+
- `containerId`: Target container ID
|
|
221
|
+
- `filePath`: File path within container
|
|
222
|
+
- `content`: File content (base64 for binary files)
|
|
223
|
+
- `mimeType`: MIME type (optional)
|
|
224
|
+
|
|
225
|
+
## Error Handling
|
|
226
|
+
|
|
227
|
+
The server provides comprehensive error handling with:
|
|
228
|
+
|
|
229
|
+
- **Validation errors**: Invalid input parameters
|
|
230
|
+
- **Authentication errors**: Invalid or missing credentials
|
|
231
|
+
- **Authorization errors**: Insufficient permissions
|
|
232
|
+
- **Network errors**: Connection issues
|
|
233
|
+
- **Rate limiting**: API quota exceeded
|
|
234
|
+
- **Timeouts**: Request timeouts
|
|
235
|
+
|
|
236
|
+
All errors include:
|
|
237
|
+
- Human-readable error messages
|
|
238
|
+
- Error codes for programmatic handling
|
|
239
|
+
- Request IDs for debugging
|
|
240
|
+
- Troubleshooting hints
|
|
241
|
+
|
|
242
|
+
## Development
|
|
243
|
+
|
|
244
|
+
### Project Structure
|
|
245
|
+
```
|
|
246
|
+
containers-mcp-server/
|
|
247
|
+
├── server.ts # Main server entry point
|
|
248
|
+
├── auth.ts # Authentication management
|
|
249
|
+
├── config.ts # Configuration management
|
|
250
|
+
├── services/
|
|
251
|
+
│ ├── containerService.ts # Container management
|
|
252
|
+
│ ├── buildService.ts # Build management
|
|
253
|
+
│ ├── fileService.ts # File management
|
|
254
|
+
│ └── capabilityService.ts # Capability management
|
|
255
|
+
├── utils/
|
|
256
|
+
│ ├── errorHandler.ts # Error handling utilities
|
|
257
|
+
│ └── apiError.ts # API error classes
|
|
258
|
+
├── package.json
|
|
259
|
+
├── tsconfig.json
|
|
260
|
+
├── .env.example
|
|
261
|
+
└── README.md
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### Available Scripts
|
|
265
|
+
- `npm run dev` - Development mode with hot reload
|
|
266
|
+
- `npm run build` - Build for production
|
|
267
|
+
- `npm run start` - Start production server
|
|
268
|
+
- `npm run test` - Run tests
|
|
269
|
+
- `npm run lint` - Code linting
|
|
270
|
+
- `npm run clean` - Clean build artifacts
|
|
271
|
+
|
|
272
|
+
### Adding New Tools
|
|
273
|
+
|
|
274
|
+
1. **Define the tool in `server.ts`**:
|
|
275
|
+
```typescript
|
|
276
|
+
this.server.registerTool("my_new_tool", {
|
|
277
|
+
title: "My New Tool",
|
|
278
|
+
description: "Description of what it does",
|
|
279
|
+
inputSchema: z.object({
|
|
280
|
+
param1: z.string(),
|
|
281
|
+
param2: z.number().optional()
|
|
282
|
+
})
|
|
283
|
+
}, async ({ param1, param2 }) => {
|
|
284
|
+
// Implementation
|
|
285
|
+
});
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
2. **Add service methods** in appropriate service files
|
|
289
|
+
|
|
290
|
+
3. **Update documentation** and examples
|
|
291
|
+
|
|
292
|
+
## Troubleshooting
|
|
293
|
+
|
|
294
|
+
### Common Issues
|
|
295
|
+
|
|
296
|
+
1. **Authentication Failed**
|
|
297
|
+
- Check API key or OAuth credentials
|
|
298
|
+
- Verify the container API URL is correct
|
|
299
|
+
- Ensure the API key has required scopes
|
|
300
|
+
|
|
301
|
+
2. **Connection Timeout**
|
|
302
|
+
- Check network connectivity
|
|
303
|
+
- Verify container service is running
|
|
304
|
+
- Increase `REQUEST_TIMEOUT` if needed
|
|
305
|
+
|
|
306
|
+
3. **Rate Limiting**
|
|
307
|
+
- Reduce request frequency
|
|
308
|
+
- Check `RATE_LIMIT_PER_MINUTE` setting
|
|
309
|
+
- Consider using API key instead of OAuth
|
|
310
|
+
|
|
311
|
+
4. **Build Failures**
|
|
312
|
+
- Check container configuration
|
|
313
|
+
- Verify Dockerfile syntax
|
|
314
|
+
- Review build logs for errors
|
|
315
|
+
|
|
316
|
+
### Debug Mode
|
|
317
|
+
|
|
318
|
+
Enable debug logging:
|
|
319
|
+
```bash
|
|
320
|
+
LOG_LEVEL=debug npm run dev
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
This provides detailed information about:
|
|
324
|
+
- API requests and responses
|
|
325
|
+
- Authentication flow
|
|
326
|
+
- Error details and stack traces
|
|
327
|
+
- Performance metrics
|
|
328
|
+
|
|
329
|
+
## Security
|
|
330
|
+
|
|
331
|
+
### Best Practices
|
|
332
|
+
|
|
333
|
+
1. **Use API Keys**: Prefer API keys over OAuth tokens for production
|
|
334
|
+
2. **Secure Storage**: Store credentials securely (environment variables, secrets manager)
|
|
335
|
+
3. **Network Security**: Use HTTPS endpoints when possible
|
|
336
|
+
4. **Access Control**: Use minimum required scopes
|
|
337
|
+
5. **Monitoring**: Monitor API usage and errors
|
|
338
|
+
|
|
339
|
+
### Security Features
|
|
340
|
+
|
|
341
|
+
- **Request timeout protection**
|
|
342
|
+
- **Rate limiting**
|
|
343
|
+
- **Input validation**
|
|
344
|
+
- **Error message sanitization**
|
|
345
|
+
- **SSL/TLS certificate validation**
|
|
346
|
+
|
|
347
|
+
## License
|
|
348
|
+
|
|
349
|
+
MIT License - see LICENSE file for details
|
|
350
|
+
|
|
351
|
+
## Support
|
|
352
|
+
|
|
353
|
+
For issues and support:
|
|
354
|
+
1. Check the troubleshooting section
|
|
355
|
+
2. Review error messages and request IDs
|
|
356
|
+
3. Enable debug logging for detailed information
|
|
357
|
+
4. Create an issue with reproduction steps
|
|
358
|
+
|
|
359
|
+
## Contributing
|
|
360
|
+
|
|
361
|
+
1. Fork the repository
|
|
362
|
+
2. Create a feature branch
|
|
363
|
+
3. Make changes with tests
|
|
364
|
+
4. Submit a pull request
|
|
365
|
+
|
|
366
|
+
Please follow the existing code style and include tests for new functionality.
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { ApiKeyInfo } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Authentication manager for the MCP server
|
|
5
|
+
*/
|
|
6
|
+
export declare class AuthManager {
|
|
7
|
+
private httpClient;
|
|
8
|
+
private currentToken?;
|
|
9
|
+
private tokenExpiry?;
|
|
10
|
+
constructor();
|
|
11
|
+
/**
|
|
12
|
+
* Get a valid authentication token
|
|
13
|
+
*/
|
|
14
|
+
private getValidToken;
|
|
15
|
+
/**
|
|
16
|
+
* Get OAuth token using client credentials flow
|
|
17
|
+
*/
|
|
18
|
+
private getOAuthToken;
|
|
19
|
+
/**
|
|
20
|
+
* Check if current token is valid and not expired
|
|
21
|
+
*/
|
|
22
|
+
private isTokenValid;
|
|
23
|
+
/**
|
|
24
|
+
* Get authenticated HTTP client
|
|
25
|
+
*/
|
|
26
|
+
getHttpClient(): AxiosInstance;
|
|
27
|
+
/**
|
|
28
|
+
* Test authentication by making a simple API call
|
|
29
|
+
*/
|
|
30
|
+
testAuthentication(): Promise<boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* Get current user's API keys (if using OAuth)
|
|
33
|
+
*/
|
|
34
|
+
getApiKeys(): Promise<ApiKeyInfo[]>;
|
|
35
|
+
/**
|
|
36
|
+
* Validate API key
|
|
37
|
+
*/
|
|
38
|
+
validateApiKey(apiKey: string): Promise<ApiKeyInfo>;
|
|
39
|
+
/**
|
|
40
|
+
* Refresh OAuth token if needed
|
|
41
|
+
*/
|
|
42
|
+
refreshTokenIfNeeded(): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Clear authentication state
|
|
45
|
+
*/
|
|
46
|
+
clearAuth(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Get authentication status
|
|
49
|
+
*/
|
|
50
|
+
getAuthStatus(): {
|
|
51
|
+
method: 'api_key' | 'oauth_token' | 'client_credentials' | 'none';
|
|
52
|
+
isValid: boolean;
|
|
53
|
+
expiresAt?: Date;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export declare const authManager: AuthManager;
|
|
57
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAqB,UAAU,EAAE,MAAM,SAAS,CAAC;AAIxD;;GAEG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,UAAU,CAAgB;IAClC,OAAO,CAAC,YAAY,CAAC,CAAS;IAC9B,OAAO,CAAC,WAAW,CAAC,CAAO;;IAwC3B;;OAEG;YACW,aAAa;IA0B3B;;OAEG;YACW,aAAa;IA2B3B;;OAEG;IACH,OAAO,CAAC,YAAY;IAUpB;;OAEG;IACH,aAAa,IAAI,aAAa;IAI9B;;OAEG;IACG,kBAAkB,IAAI,OAAO,CAAC,OAAO,CAAC;IAY5C;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;IASzC;;OAEG;IACG,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAgBzD;;OAEG;IACG,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;IAY3C;;OAEG;IACH,SAAS,IAAI,IAAI;IAKjB;;OAEG;IACH,aAAa,IAAI;QACf,MAAM,EAAE,SAAS,GAAG,aAAa,GAAG,oBAAoB,GAAG,MAAM,CAAC;QAClE,OAAO,EAAE,OAAO,CAAC;QACjB,SAAS,CAAC,EAAE,IAAI,CAAC;KAClB;CAiBF;AAGD,eAAO,MAAM,WAAW,aAAoB,CAAC"}
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.authManager = exports.AuthManager = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const config_1 = require("./config");
|
|
9
|
+
const errorHandler_1 = require("./utils/errorHandler");
|
|
10
|
+
/**
|
|
11
|
+
* Authentication manager for the MCP server
|
|
12
|
+
*/
|
|
13
|
+
class AuthManager {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.httpClient = axios_1.default.create({
|
|
16
|
+
baseURL: config_1.config.get('baseUrl'),
|
|
17
|
+
timeout: config_1.config.getTimeoutConfig().request,
|
|
18
|
+
headers: {
|
|
19
|
+
'Content-Type': 'application/json',
|
|
20
|
+
'User-Agent': '@172ai/containers-mcp-server/1.0.0'
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
// Add request interceptor for auth
|
|
24
|
+
this.httpClient.interceptors.request.use(async (config) => {
|
|
25
|
+
const token = await this.getValidToken();
|
|
26
|
+
if (token) {
|
|
27
|
+
config.headers.Authorization = `Bearer ${token}`;
|
|
28
|
+
}
|
|
29
|
+
return config;
|
|
30
|
+
}, (error) => Promise.reject(error));
|
|
31
|
+
// Add response interceptor for error handling
|
|
32
|
+
this.httpClient.interceptors.response.use((response) => response, (error) => {
|
|
33
|
+
const processedError = errorHandler_1.ErrorHandler.processError(error, 'AuthManager');
|
|
34
|
+
errorHandler_1.ErrorHandler.logError(processedError);
|
|
35
|
+
return Promise.reject(new errorHandler_1.ApiError(processedError.message, processedError.status, processedError.code, processedError.details));
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get a valid authentication token
|
|
40
|
+
*/
|
|
41
|
+
async getValidToken() {
|
|
42
|
+
const authConfig = config_1.config.getAuthConfig();
|
|
43
|
+
// Use API key if available (preferred method)
|
|
44
|
+
if (authConfig.apiKey) {
|
|
45
|
+
return authConfig.apiKey;
|
|
46
|
+
}
|
|
47
|
+
// Use existing OAuth token if valid
|
|
48
|
+
if (authConfig.oauthToken && this.isTokenValid()) {
|
|
49
|
+
return this.currentToken || authConfig.oauthToken;
|
|
50
|
+
}
|
|
51
|
+
// Get new OAuth token using client credentials
|
|
52
|
+
if (authConfig.clientId && authConfig.clientSecret) {
|
|
53
|
+
try {
|
|
54
|
+
const token = await this.getOAuthToken(authConfig.clientId, authConfig.clientSecret);
|
|
55
|
+
return token;
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
throw errorHandler_1.ErrorHandler.createAuthError('Failed to obtain OAuth token', { error: error.message });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
throw errorHandler_1.ErrorHandler.createAuthError('No valid authentication method configured');
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get OAuth token using client credentials flow
|
|
65
|
+
*/
|
|
66
|
+
async getOAuthToken(clientId, clientSecret) {
|
|
67
|
+
try {
|
|
68
|
+
const response = await axios_1.default.post(`${config_1.config.get('baseUrl')}/oauth/token`, {
|
|
69
|
+
grant_type: 'client_credentials',
|
|
70
|
+
client_id: clientId,
|
|
71
|
+
client_secret: clientSecret,
|
|
72
|
+
scope: 'containers:read containers:write builds:read builds:write files:read files:write'
|
|
73
|
+
}, {
|
|
74
|
+
headers: {
|
|
75
|
+
'Content-Type': 'application/json'
|
|
76
|
+
},
|
|
77
|
+
timeout: config_1.config.getTimeoutConfig().request
|
|
78
|
+
});
|
|
79
|
+
const tokenData = response.data;
|
|
80
|
+
this.currentToken = tokenData.access_token;
|
|
81
|
+
this.tokenExpiry = new Date(Date.now() + (tokenData.expires_in * 1000));
|
|
82
|
+
return tokenData.access_token;
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
throw errorHandler_1.ErrorHandler.createAuthError('OAuth token request failed', {
|
|
86
|
+
clientId,
|
|
87
|
+
error: error.response?.data || error.message
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Check if current token is valid and not expired
|
|
93
|
+
*/
|
|
94
|
+
isTokenValid() {
|
|
95
|
+
if (!this.currentToken || !this.tokenExpiry) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
// Check if token expires within next 5 minutes
|
|
99
|
+
const fiveMinutesFromNow = new Date(Date.now() + 5 * 60 * 1000);
|
|
100
|
+
return this.tokenExpiry > fiveMinutesFromNow;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Get authenticated HTTP client
|
|
104
|
+
*/
|
|
105
|
+
getHttpClient() {
|
|
106
|
+
return this.httpClient;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Test authentication by making a simple API call
|
|
110
|
+
*/
|
|
111
|
+
async testAuthentication() {
|
|
112
|
+
try {
|
|
113
|
+
const response = await this.httpClient.get('/health');
|
|
114
|
+
return response.status === 200;
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
if (error instanceof errorHandler_1.ApiError && (error.status === 401 || error.status === 403)) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Get current user's API keys (if using OAuth)
|
|
125
|
+
*/
|
|
126
|
+
async getApiKeys() {
|
|
127
|
+
try {
|
|
128
|
+
const response = await this.httpClient.get('/v1/users/me/api-keys');
|
|
129
|
+
return response.data;
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
throw errorHandler_1.ErrorHandler.createAuthError('Failed to retrieve API keys', { error: error.message });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Validate API key
|
|
137
|
+
*/
|
|
138
|
+
async validateApiKey(apiKey) {
|
|
139
|
+
try {
|
|
140
|
+
const response = await axios_1.default.get(`${config_1.config.get('baseUrl')}/v1/auth/validate`, {
|
|
141
|
+
headers: {
|
|
142
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
143
|
+
'Content-Type': 'application/json'
|
|
144
|
+
},
|
|
145
|
+
timeout: config_1.config.getTimeoutConfig().request
|
|
146
|
+
});
|
|
147
|
+
return response.data;
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
throw errorHandler_1.ErrorHandler.createAuthError('API key validation failed', { error: error.message });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Refresh OAuth token if needed
|
|
155
|
+
*/
|
|
156
|
+
async refreshTokenIfNeeded() {
|
|
157
|
+
const authConfig = config_1.config.getAuthConfig();
|
|
158
|
+
if (!authConfig.clientId || !authConfig.clientSecret) {
|
|
159
|
+
return; // Cannot refresh without client credentials
|
|
160
|
+
}
|
|
161
|
+
if (!this.isTokenValid()) {
|
|
162
|
+
await this.getOAuthToken(authConfig.clientId, authConfig.clientSecret);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Clear authentication state
|
|
167
|
+
*/
|
|
168
|
+
clearAuth() {
|
|
169
|
+
this.currentToken = undefined;
|
|
170
|
+
this.tokenExpiry = undefined;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Get authentication status
|
|
174
|
+
*/
|
|
175
|
+
getAuthStatus() {
|
|
176
|
+
const authConfig = config_1.config.getAuthConfig();
|
|
177
|
+
if (authConfig.apiKey) {
|
|
178
|
+
return { method: 'api_key', isValid: true };
|
|
179
|
+
}
|
|
180
|
+
if (authConfig.oauthToken) {
|
|
181
|
+
return { method: 'oauth_token', isValid: this.isTokenValid(), expiresAt: this.tokenExpiry };
|
|
182
|
+
}
|
|
183
|
+
if (authConfig.clientId && authConfig.clientSecret) {
|
|
184
|
+
return { method: 'client_credentials', isValid: this.isTokenValid(), expiresAt: this.tokenExpiry };
|
|
185
|
+
}
|
|
186
|
+
return { method: 'none', isValid: false };
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
exports.AuthManager = AuthManager;
|
|
190
|
+
// Export singleton instance
|
|
191
|
+
exports.authManager = new AuthManager();
|
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