@aiconnect/agentjobs-mcp 1.0.8
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 +11 -0
- package/README.md +311 -0
- package/build/cancel_job.js +71 -0
- package/build/config.js +6 -0
- package/build/create_job.js +151 -0
- package/build/get_job.js +62 -0
- package/build/index.js +83 -0
- package/build/list_jobs.js +88 -0
- package/docs/agent-jobs-api.md +336 -0
- package/docs/guidelines.md +267 -0
- package/package.json +68 -0
package/.env.example
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# AI Connect MCP Server Configuration
|
|
2
|
+
# Copy this file to .env and fill in your values
|
|
3
|
+
|
|
4
|
+
# Required: API endpoint URL for AI Connect
|
|
5
|
+
AICONNECT_API_URL=https://api.aiconnect.cloud/api/v0
|
|
6
|
+
|
|
7
|
+
# Required: Your API authentication key
|
|
8
|
+
AICONNECT_API_KEY=your-api-key-here
|
|
9
|
+
|
|
10
|
+
# Optional: Default organization ID (defaults to 'aiconnect' if not set)
|
|
11
|
+
# DEFAULT_ORG_ID=your-organization-id
|
package/README.md
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
# AI Connect MCP Server
|
|
2
|
+
|
|
3
|
+
An MCP (Model Context Protocol) server that allows AI agents to query and manage jobs in the AI Connect platform.
|
|
4
|
+
|
|
5
|
+
## About AI Connect Jobs
|
|
6
|
+
|
|
7
|
+
AI Connect Jobs is a robust asynchronous task management system on the AI Connect platform, enabling the creation, monitoring, and execution of jobs across different platforms like Slack and WhatsApp, with support for scheduled execution, automatic retries, and timeout handling. The API provides endpoints to create, list, query, and cancel jobs, allowing developers and external systems to easily integrate asynchronous processing functionalities into their applications, automating complex workflows without the need to implement the entire task management infrastructure.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
This MCP Server provides tools for AI agents to:
|
|
12
|
+
|
|
13
|
+
- 📋 **List Jobs**: Query all jobs with advanced filtering
|
|
14
|
+
- 🔍 **Get Specific Job**: Retrieve details of a specific job by ID
|
|
15
|
+
- ✅ **Create Jobs**: Create new jobs for immediate or scheduled execution
|
|
16
|
+
- ❌ **Cancel Jobs**: Cancel running or scheduled jobs
|
|
17
|
+
- 📊 **Monitor Status**: Track job status (WAITING, RUNNING, COMPLETED, FAILED, CANCELED)
|
|
18
|
+
|
|
19
|
+
## Technologies
|
|
20
|
+
|
|
21
|
+
- **Node.js** with **TypeScript**
|
|
22
|
+
- **Model Context Protocol (MCP)** by Anthropic
|
|
23
|
+
- **Zod** for schema validation
|
|
24
|
+
- **AI Connect API** for integration with the Agent Jobs system
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
### NPX (Recommended)
|
|
29
|
+
|
|
30
|
+
You can run the MCP server directly using npx without installation:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npx @aiconnect/agentjobs-mcp --help
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Local Installation
|
|
37
|
+
|
|
38
|
+
1. **Clone the repository:**
|
|
39
|
+
```bash
|
|
40
|
+
git clone <repository-url>
|
|
41
|
+
cd agentjobs-mcp
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
2. **Install dependencies:**
|
|
45
|
+
```bash
|
|
46
|
+
npm install
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
3. **Configure environment variables (Optional):**
|
|
50
|
+
|
|
51
|
+
The MCP server comes with default values from `.env.example`, so you can run it without setting any environment variables. However, you **must** provide an API key for authentication.
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
cp .env.example .env
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Edit the `.env` file with your credentials:
|
|
58
|
+
```env
|
|
59
|
+
DEFAULT_ORG_ID=your-organization # Default: aiconnect
|
|
60
|
+
AICONNECT_API_KEY=your-api-key # Required: Must be provided
|
|
61
|
+
AICONNECT_API_URL=https://api.aiconnect.cloud/api/v0 # Default
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**Important**: If no environment variables are provided, the server will use these defaults:
|
|
65
|
+
- `DEFAULT_ORG_ID`: `aiconnect`
|
|
66
|
+
- `AICONNECT_API_URL`: `https://api.aiconnect.cloud/api/v0`
|
|
67
|
+
- `AICONNECT_API_KEY`: empty (must be provided for API calls to work)
|
|
68
|
+
|
|
69
|
+
4. **Build the project:**
|
|
70
|
+
```bash
|
|
71
|
+
npm run build
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Usage
|
|
75
|
+
|
|
76
|
+
### CLI Usage
|
|
77
|
+
|
|
78
|
+
The MCP server now supports CLI commands for easy management:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# Show help and usage information
|
|
82
|
+
npx @aiconnect/agentjobs-mcp --help
|
|
83
|
+
|
|
84
|
+
# Show version information
|
|
85
|
+
npx @aiconnect/agentjobs-mcp --version
|
|
86
|
+
|
|
87
|
+
# Show current configuration status
|
|
88
|
+
npx @aiconnect/agentjobs-mcp --config
|
|
89
|
+
|
|
90
|
+
# Start MCP server (default behavior)
|
|
91
|
+
npx @aiconnect/agentjobs-mcp
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**Setting Environment Variables:**
|
|
95
|
+
```bash
|
|
96
|
+
# Using environment variables with npx
|
|
97
|
+
AICONNECT_API_URL=https://api.aiconnect.cloud/api/v0 \
|
|
98
|
+
AICONNECT_API_KEY=your-api-key-here \
|
|
99
|
+
npx @aiconnect/agentjobs-mcp
|
|
100
|
+
|
|
101
|
+
# Or create a .env file (recommended for development)
|
|
102
|
+
cp .env.example .env
|
|
103
|
+
# Edit .env with your credentials
|
|
104
|
+
npx @aiconnect/agentjobs-mcp
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**Required Environment Variables:**
|
|
108
|
+
- `AICONNECT_API_URL`: API endpoint URL (e.g., https://api.aiconnect.cloud/api/v0)
|
|
109
|
+
- `AICONNECT_API_KEY`: Your API authentication key
|
|
110
|
+
|
|
111
|
+
**CLI Command Examples:**
|
|
112
|
+
```bash
|
|
113
|
+
# Quick help
|
|
114
|
+
npx @aiconnect/agentjobs-mcp -h
|
|
115
|
+
|
|
116
|
+
# Check version
|
|
117
|
+
npx @aiconnect/agentjobs-mcp -v
|
|
118
|
+
|
|
119
|
+
# Verify configuration before starting
|
|
120
|
+
npx @aiconnect/agentjobs-mcp -c
|
|
121
|
+
|
|
122
|
+
# Test with environment variables
|
|
123
|
+
env AICONNECT_API_URL=https://api.aiconnect.cloud/api/v0 \
|
|
124
|
+
AICONNECT_API_KEY=test-key \
|
|
125
|
+
npx @aiconnect/agentjobs-mcp --config
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Local Development
|
|
129
|
+
|
|
130
|
+
For local development, you can use npm scripts:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
# Build and test CLI commands
|
|
134
|
+
npm run cli:help
|
|
135
|
+
npm run cli:version
|
|
136
|
+
npm run cli:config
|
|
137
|
+
|
|
138
|
+
# Run test suite (if available)
|
|
139
|
+
npm run test:cli
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Configuration Options
|
|
143
|
+
|
|
144
|
+
This MCP server is designed to work out-of-the-box with minimal configuration. It uses a smart fallback system:
|
|
145
|
+
|
|
146
|
+
1. **With environment variables**: Full control over all settings
|
|
147
|
+
2. **Without environment variables**: Uses defaults from `.env.example`
|
|
148
|
+
3. **Partial configuration**: Mix of environment variables and defaults
|
|
149
|
+
|
|
150
|
+
**Default Values (when no env vars are set):**
|
|
151
|
+
- `DEFAULT_ORG_ID`: `"aiconnect"`
|
|
152
|
+
- `AICONNECT_API_URL`: `"https://api.aiconnect.cloud/api/v0"`
|
|
153
|
+
- `AICONNECT_API_KEY`: `""` (empty - you must provide this)
|
|
154
|
+
|
|
155
|
+
**Error Handling:**
|
|
156
|
+
- If `AICONNECT_API_KEY` is not provided, tools will return helpful error messages
|
|
157
|
+
- If `AICONNECT_API_URL` is not set, it defaults to the production API
|
|
158
|
+
- If `DEFAULT_ORG_ID` is not set, it defaults to "aiconnect"
|
|
159
|
+
|
|
160
|
+
### Running the MCP server
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
npm start
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
The server will start and wait for connections via stdio transport.
|
|
167
|
+
|
|
168
|
+
### Claude Desktop Configuration
|
|
169
|
+
|
|
170
|
+
To use this MCP server with Claude Desktop, add the following configuration to your `claude_desktop_config.json` file:
|
|
171
|
+
|
|
172
|
+
```json
|
|
173
|
+
{
|
|
174
|
+
"mcpServers": {
|
|
175
|
+
"agentjobs": {
|
|
176
|
+
"command": "node",
|
|
177
|
+
"args": ["/path/to/agentjobs-mcp/build/index.js"],
|
|
178
|
+
"env": {
|
|
179
|
+
"DEFAULT_ORG_ID": "your-organization",
|
|
180
|
+
"AICONNECT_API_KEY": "your-api-key",
|
|
181
|
+
"AICONNECT_API_URL": "https://api.aiconnect.cloud/api/v0"
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Available Tools
|
|
189
|
+
|
|
190
|
+
### 🔧 `list_jobs`
|
|
191
|
+
Lists all jobs with filtering and pagination options.
|
|
192
|
+
|
|
193
|
+
**Parameters:**
|
|
194
|
+
- `status` (optional): Filter by status (WAITING, RUNNING, COMPLETED, FAILED, CANCELED)
|
|
195
|
+
- `job_type_id` (optional): Filter by job type
|
|
196
|
+
- `channel_code` (optional): Filter by channel code
|
|
197
|
+
- `limit` (optional): Result limit (default: 50)
|
|
198
|
+
- `offset` (optional): Pagination offset
|
|
199
|
+
- `sort` (optional): Field and direction for sorting
|
|
200
|
+
|
|
201
|
+
### 🔍 `get_job`
|
|
202
|
+
Gets details of a specific job.
|
|
203
|
+
|
|
204
|
+
**Parameters:**
|
|
205
|
+
- `job_id` (required): ID of the job to query
|
|
206
|
+
|
|
207
|
+
### ✅ `create_job`
|
|
208
|
+
Creates a new job for execution.
|
|
209
|
+
|
|
210
|
+
**Parameters:**
|
|
211
|
+
- `target_channel`: Target channel configuration
|
|
212
|
+
- `job_type_id`: Job type ID
|
|
213
|
+
- `config`: Job configuration (timeouts, retries, etc.)
|
|
214
|
+
- `params`: Job-specific parameters
|
|
215
|
+
- `scheduled_at` (optional): Date/time for scheduled execution
|
|
216
|
+
- `delay` (optional): Random delay in minutes
|
|
217
|
+
|
|
218
|
+
### ❌ `cancel_job`
|
|
219
|
+
Cancels a running or scheduled job.
|
|
220
|
+
|
|
221
|
+
**Parameters:**
|
|
222
|
+
- `job_id` (required): ID of the job to cancel
|
|
223
|
+
- `reason` (optional): Cancellation reason
|
|
224
|
+
|
|
225
|
+
## Job Status
|
|
226
|
+
|
|
227
|
+
Jobs can have the following status values:
|
|
228
|
+
|
|
229
|
+
- `WAITING`: Job waiting for execution
|
|
230
|
+
- `SCHEDULED`: Job scheduled for future execution
|
|
231
|
+
- `RUNNING`: Job currently running
|
|
232
|
+
- `COMPLETED`: Job completed successfully
|
|
233
|
+
- `FAILED`: Job failed
|
|
234
|
+
- `CANCELED`: Job was canceled
|
|
235
|
+
|
|
236
|
+
## Usage Examples
|
|
237
|
+
|
|
238
|
+
### List running jobs
|
|
239
|
+
```
|
|
240
|
+
Agent: "Show me all jobs that are currently running"
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### Query specific job
|
|
244
|
+
```
|
|
245
|
+
Agent: "What's the status of job job-123?"
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### Create scheduled job
|
|
249
|
+
```
|
|
250
|
+
Agent: "Create a daily report job for Slack channel C123456 to run tomorrow at 9 AM"
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### Cancel job
|
|
254
|
+
```
|
|
255
|
+
Agent: "Cancel job job-456 because it's no longer needed"
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Project Structure
|
|
259
|
+
|
|
260
|
+
```
|
|
261
|
+
agentjobs-mcp/
|
|
262
|
+
├── src/ # TypeScript source code
|
|
263
|
+
│ ├── index.ts # Main MCP server
|
|
264
|
+
│ ├── cancel_job.ts # Tool for canceling jobs
|
|
265
|
+
│ ├── create_job.ts # Tool for creating jobs
|
|
266
|
+
│ ├── get_job.ts # Tool for querying job
|
|
267
|
+
│ └── list_jobs.ts # Tool for listing jobs
|
|
268
|
+
├── build/ # Compiled JavaScript code
|
|
269
|
+
├── docs/ # Documentation
|
|
270
|
+
│ └── agent-jobs-api.md # API documentation
|
|
271
|
+
├── package.json # Dependencies and scripts
|
|
272
|
+
├── tsconfig.json # TypeScript configuration
|
|
273
|
+
├── .env.example # Environment variables example
|
|
274
|
+
└── README.md # This file
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## Development
|
|
278
|
+
|
|
279
|
+
### Available scripts
|
|
280
|
+
|
|
281
|
+
- `npm run build`: Compiles TypeScript
|
|
282
|
+
- `npm start`: Runs the compiled server
|
|
283
|
+
|
|
284
|
+
### Adding new tools
|
|
285
|
+
|
|
286
|
+
1. Create a new file in the `src/` folder (e.g., `new_tool.ts`)
|
|
287
|
+
2. Implement the tool following the pattern of existing files
|
|
288
|
+
3. Register the tool in `src/index.ts`
|
|
289
|
+
4. Recompile with `npm run build`
|
|
290
|
+
|
|
291
|
+
## Contributing
|
|
292
|
+
|
|
293
|
+
1. Fork the project
|
|
294
|
+
2. Create a feature branch (`git checkout -b feature/new-feature`)
|
|
295
|
+
3. Commit your changes (`git commit -am 'Add new feature'`)
|
|
296
|
+
4. Push to the branch (`git push origin feature/new-feature`)
|
|
297
|
+
5. Open a Pull Request
|
|
298
|
+
|
|
299
|
+
## License
|
|
300
|
+
|
|
301
|
+
This project is licensed under the [MIT License](LICENSE).
|
|
302
|
+
|
|
303
|
+
## Support
|
|
304
|
+
|
|
305
|
+
For technical support or questions about AI Connect Jobs:
|
|
306
|
+
- Check the [API documentation](docs/agent-jobs-api.md)
|
|
307
|
+
- Contact the AI Connect development team
|
|
308
|
+
|
|
309
|
+
---
|
|
310
|
+
|
|
311
|
+
**Note**: This project was developed using the Anthropic mcp-tools scaffold for integration with the AI Connect platform.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import { config } from './config.js';
|
|
4
|
+
export default (server) => {
|
|
5
|
+
server.tool("cancel_job", "Cancels an agent job by its ID.", {
|
|
6
|
+
job_id: z.string({
|
|
7
|
+
description: "The ID of the job to cancel.",
|
|
8
|
+
}),
|
|
9
|
+
reason: z.string().optional().describe("Optional reason for cancellation."),
|
|
10
|
+
}, async (params) => {
|
|
11
|
+
const { job_id, reason } = params;
|
|
12
|
+
const apiUrl = config.AICONNECT_API_URL;
|
|
13
|
+
const apiKey = config.AICONNECT_API_KEY;
|
|
14
|
+
if (!apiUrl) {
|
|
15
|
+
return {
|
|
16
|
+
content: [{
|
|
17
|
+
type: "text",
|
|
18
|
+
text: "Error: API URL is not configured. Please set AICONNECT_API_URL environment variable."
|
|
19
|
+
}]
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
if (!apiKey) {
|
|
23
|
+
return {
|
|
24
|
+
content: [{
|
|
25
|
+
type: "text",
|
|
26
|
+
text: "Error: API Key is not configured. Please set AICONNECT_API_KEY environment variable."
|
|
27
|
+
}]
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const endpoint = `${apiUrl}/services/agent-jobs/${job_id}`;
|
|
31
|
+
const headers = {
|
|
32
|
+
"Authorization": `Bearer ${apiKey}`,
|
|
33
|
+
};
|
|
34
|
+
let requestBody;
|
|
35
|
+
if (reason) {
|
|
36
|
+
headers["Content-Type"] = "application/json";
|
|
37
|
+
requestBody = { reason };
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
const response = await axios.delete(endpoint, {
|
|
41
|
+
headers,
|
|
42
|
+
data: requestBody, // axios uses 'data' for DELETE request body
|
|
43
|
+
});
|
|
44
|
+
// Assuming the API returns a message field on success as per docs/agent-jobs-api.md:229
|
|
45
|
+
const responseMessage = response.data?.message || `Job with ID '${job_id}' successfully canceled.`;
|
|
46
|
+
return {
|
|
47
|
+
content: [{
|
|
48
|
+
type: "text",
|
|
49
|
+
text: responseMessage,
|
|
50
|
+
}]
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
let errorMessage = `Failed to cancel job ${job_id}.`;
|
|
55
|
+
if (axios.isAxiosError(error) && error.response) {
|
|
56
|
+
// Try to get a more specific error message from the API response
|
|
57
|
+
const apiError = error.response.data?.message || error.response.data?.error || JSON.stringify(error.response.data);
|
|
58
|
+
errorMessage = `API Error (${error.response.status}): ${apiError || error.message}`;
|
|
59
|
+
}
|
|
60
|
+
else if (error instanceof Error) {
|
|
61
|
+
errorMessage = `Error: ${error.message}`;
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
content: [{
|
|
65
|
+
type: "text",
|
|
66
|
+
text: errorMessage,
|
|
67
|
+
}]
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
};
|
package/build/config.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Configuration with fallback to .env.example defaults
|
|
2
|
+
export const config = {
|
|
3
|
+
DEFAULT_ORG_ID: process.env.DEFAULT_ORG_ID || 'aiconnect',
|
|
4
|
+
AICONNECT_API_KEY: process.env.AICONNECT_API_KEY || '',
|
|
5
|
+
AICONNECT_API_URL: process.env.AICONNECT_API_URL || 'https://api.aiconnect.cloud/api/v0'
|
|
6
|
+
};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import { config } from './config.js';
|
|
4
|
+
// Schema for the target_channel object
|
|
5
|
+
const targetChannelSchema = z
|
|
6
|
+
.object({
|
|
7
|
+
org_id: z.string().optional().describe('Organization ID for the target channel. If not provided, uses the default organization.'),
|
|
8
|
+
platform: z
|
|
9
|
+
.enum(['whatsapp', 'slack', 'web'])
|
|
10
|
+
.describe('Platform of the target channel.'),
|
|
11
|
+
type: z.string().describe('Type of the target channel (e.g., channel).'),
|
|
12
|
+
code: z.string().describe('Code/identifier for the target channel.'),
|
|
13
|
+
data: z
|
|
14
|
+
.record(z.any())
|
|
15
|
+
.optional()
|
|
16
|
+
.describe('Additional platform-specific data for the channel.')
|
|
17
|
+
})
|
|
18
|
+
.describe('Defines the target channel for the job.');
|
|
19
|
+
// Schema for the config object
|
|
20
|
+
const configSchema = z
|
|
21
|
+
.object({
|
|
22
|
+
max_follow_ups: z
|
|
23
|
+
.number()
|
|
24
|
+
.int()
|
|
25
|
+
.optional()
|
|
26
|
+
.describe('Maximum number of follow-ups allowed.'),
|
|
27
|
+
max_task_retries: z
|
|
28
|
+
.number()
|
|
29
|
+
.int()
|
|
30
|
+
.optional()
|
|
31
|
+
.describe('Maximum number of retries for a task.'),
|
|
32
|
+
task_retry_interval: z
|
|
33
|
+
.number()
|
|
34
|
+
.int()
|
|
35
|
+
.optional()
|
|
36
|
+
.describe('Interval in minutes between task retries.'),
|
|
37
|
+
start_prompt: z.string().describe('The initial prompt to start the job.'),
|
|
38
|
+
max_time_to_complete: z
|
|
39
|
+
.number()
|
|
40
|
+
.int()
|
|
41
|
+
.optional()
|
|
42
|
+
.describe('Maximum time in minutes for the job to complete.'),
|
|
43
|
+
profile_id: z.string().describe('Profile ID to be used for the job.')
|
|
44
|
+
})
|
|
45
|
+
.describe('Configuration settings for the job.');
|
|
46
|
+
export default (server) => {
|
|
47
|
+
server.tool('create_job', 'Creates a new agent job.', {
|
|
48
|
+
target_channel: targetChannelSchema,
|
|
49
|
+
job_type_id: z.string().describe('The ID of the job type.'),
|
|
50
|
+
config: configSchema.optional(),
|
|
51
|
+
params: z
|
|
52
|
+
.record(z.any())
|
|
53
|
+
.optional()
|
|
54
|
+
.describe('Arbitrary parameters for the job.'),
|
|
55
|
+
scheduled_at: z
|
|
56
|
+
.string()
|
|
57
|
+
.datetime({ message: 'Invalid datetime string. Must be ISO 8601' })
|
|
58
|
+
.optional()
|
|
59
|
+
.describe('Optional ISO 8601 date string for scheduling the job.'),
|
|
60
|
+
delay: z
|
|
61
|
+
.number()
|
|
62
|
+
.int()
|
|
63
|
+
.nonnegative()
|
|
64
|
+
.optional()
|
|
65
|
+
.describe('Optional maximum random delay in minutes to add to the scheduled time (query parameter).')
|
|
66
|
+
}, async (toolParams) => {
|
|
67
|
+
const apiUrl = config.AICONNECT_API_URL;
|
|
68
|
+
const apiKey = config.AICONNECT_API_KEY;
|
|
69
|
+
const defaultOrgId = config.DEFAULT_ORG_ID;
|
|
70
|
+
if (!apiUrl) {
|
|
71
|
+
return {
|
|
72
|
+
content: [
|
|
73
|
+
{
|
|
74
|
+
type: 'text',
|
|
75
|
+
text: 'Error: API URL is not configured. Please set AICONNECT_API_URL environment variable.'
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
if (!apiKey) {
|
|
81
|
+
return {
|
|
82
|
+
content: [
|
|
83
|
+
{
|
|
84
|
+
type: 'text',
|
|
85
|
+
text: 'Error: API Key is not configured. Please set AICONNECT_API_KEY environment variable.'
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
// Use default org_id if not provided
|
|
91
|
+
if (!toolParams.target_channel.org_id && defaultOrgId) {
|
|
92
|
+
toolParams.target_channel.org_id = defaultOrgId;
|
|
93
|
+
}
|
|
94
|
+
else if (!toolParams.target_channel.org_id && !defaultOrgId) {
|
|
95
|
+
return {
|
|
96
|
+
content: [
|
|
97
|
+
{
|
|
98
|
+
type: 'text',
|
|
99
|
+
text: 'Error: Organization ID is required. Please provide org_id or set DEFAULT_ORG_ID environment variable.'
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
const endpoint = `${apiUrl}/services/agent-jobs`;
|
|
105
|
+
const headers = {
|
|
106
|
+
Authorization: `Bearer ${apiKey}`,
|
|
107
|
+
'Content-Type': 'application/json'
|
|
108
|
+
};
|
|
109
|
+
// Separate delay as it's a query parameter
|
|
110
|
+
const { delay, ...bodyPayload } = toolParams;
|
|
111
|
+
const queryParams = {};
|
|
112
|
+
if (delay !== undefined) {
|
|
113
|
+
queryParams.delay = delay;
|
|
114
|
+
}
|
|
115
|
+
try {
|
|
116
|
+
const response = await axios.post(endpoint, bodyPayload, {
|
|
117
|
+
headers,
|
|
118
|
+
params: queryParams
|
|
119
|
+
});
|
|
120
|
+
// API returns job details under 'data' key
|
|
121
|
+
return {
|
|
122
|
+
content: [
|
|
123
|
+
{
|
|
124
|
+
type: 'text',
|
|
125
|
+
text: JSON.stringify(response.data, null, 2)
|
|
126
|
+
}
|
|
127
|
+
]
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
let errorMessage = `Failed to create job.`;
|
|
132
|
+
if (axios.isAxiosError(error) && error.response) {
|
|
133
|
+
const apiError = error.response.data?.message ||
|
|
134
|
+
error.response.data?.error ||
|
|
135
|
+
JSON.stringify(error.response.data);
|
|
136
|
+
errorMessage = `API Error (${error.response.status}): ${apiError || error.message}`;
|
|
137
|
+
}
|
|
138
|
+
else if (error instanceof Error) {
|
|
139
|
+
errorMessage = `Error: ${error.message}`;
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
content: [
|
|
143
|
+
{
|
|
144
|
+
type: 'text',
|
|
145
|
+
text: errorMessage
|
|
146
|
+
}
|
|
147
|
+
]
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
};
|
package/build/get_job.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import { config } from './config.js';
|
|
4
|
+
export default (server) => {
|
|
5
|
+
server.tool("get_job", "Retrieves an agent job by its ID.", {
|
|
6
|
+
job_id: z.string({
|
|
7
|
+
description: "The ID of the job to retrieve.",
|
|
8
|
+
}),
|
|
9
|
+
}, async (params) => {
|
|
10
|
+
const { job_id } = params;
|
|
11
|
+
const apiUrl = config.AICONNECT_API_URL;
|
|
12
|
+
const apiKey = config.AICONNECT_API_KEY;
|
|
13
|
+
if (!apiUrl) {
|
|
14
|
+
return {
|
|
15
|
+
content: [{
|
|
16
|
+
type: "text",
|
|
17
|
+
text: "Error: API URL is not configured. Please set AICONNECT_API_URL environment variable."
|
|
18
|
+
}]
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
if (!apiKey) {
|
|
22
|
+
return {
|
|
23
|
+
content: [{
|
|
24
|
+
type: "text",
|
|
25
|
+
text: "Error: API Key is not configured. Please set AICONNECT_API_KEY environment variable."
|
|
26
|
+
}]
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const endpoint = `${apiUrl}/services/agent-jobs/${job_id}`;
|
|
30
|
+
const headers = {
|
|
31
|
+
"Authorization": `Bearer ${apiKey}`,
|
|
32
|
+
};
|
|
33
|
+
try {
|
|
34
|
+
const response = await axios.get(endpoint, {
|
|
35
|
+
headers,
|
|
36
|
+
});
|
|
37
|
+
// Return the data part of the response, stringified as JSON text
|
|
38
|
+
return {
|
|
39
|
+
content: [{
|
|
40
|
+
type: "text",
|
|
41
|
+
text: JSON.stringify(response.data?.data || response.data, null, 2),
|
|
42
|
+
}]
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
let errorMessage = `Failed to retrieve job ${job_id}.`;
|
|
47
|
+
if (axios.isAxiosError(error) && error.response) {
|
|
48
|
+
const apiError = error.response.data?.message || error.response.data?.error || JSON.stringify(error.response.data);
|
|
49
|
+
errorMessage = `API Error (${error.response.status}): ${apiError || error.message}`;
|
|
50
|
+
}
|
|
51
|
+
else if (error instanceof Error) {
|
|
52
|
+
errorMessage = `Error: ${error.message}`;
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
content: [{
|
|
56
|
+
type: "text",
|
|
57
|
+
text: errorMessage,
|
|
58
|
+
}]
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
};
|
package/build/index.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import * as dotenv from 'dotenv';
|
|
3
|
+
dotenv.config();
|
|
4
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
5
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
6
|
+
import cancel_job from "./cancel_job.js";
|
|
7
|
+
import get_job from "./get_job.js";
|
|
8
|
+
import list_jobs from "./list_jobs.js";
|
|
9
|
+
import create_job from "./create_job.js";
|
|
10
|
+
// Get package version
|
|
11
|
+
const packageJson = JSON.parse(await import('fs').then(fs => fs.readFileSync(new URL('../package.json', import.meta.url), 'utf-8')));
|
|
12
|
+
// CLI argument parsing
|
|
13
|
+
const args = process.argv.slice(2);
|
|
14
|
+
// Help text
|
|
15
|
+
const helpText = `
|
|
16
|
+
AI Connect Agent Jobs MCP Server v${packageJson.version}
|
|
17
|
+
${packageJson.description}
|
|
18
|
+
|
|
19
|
+
USAGE:
|
|
20
|
+
npx @aiconnect/agentjobs-mcp [OPTIONS]
|
|
21
|
+
|
|
22
|
+
OPTIONS:
|
|
23
|
+
--help, -h Show this help message
|
|
24
|
+
--version, -v Show version information
|
|
25
|
+
--config, -c Show current configuration
|
|
26
|
+
--stdio Start MCP server with stdio transport (default)
|
|
27
|
+
|
|
28
|
+
EXAMPLES:
|
|
29
|
+
npx @aiconnect/agentjobs-mcp # Start MCP server
|
|
30
|
+
npx @aiconnect/agentjobs-mcp --help # Show help
|
|
31
|
+
npx @aiconnect/agentjobs-mcp --version # Show version
|
|
32
|
+
npx @aiconnect/agentjobs-mcp --config # Show configuration
|
|
33
|
+
|
|
34
|
+
ENVIRONMENT VARIABLES:
|
|
35
|
+
AICONNECT_API_URL API endpoint URL (required)
|
|
36
|
+
AICONNECT_API_KEY API authentication key (required)
|
|
37
|
+
|
|
38
|
+
For more information, visit: ${packageJson.homepage}
|
|
39
|
+
Author: ${packageJson.author}
|
|
40
|
+
`;
|
|
41
|
+
// Handle CLI arguments
|
|
42
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
43
|
+
console.log(helpText);
|
|
44
|
+
process.exit(0);
|
|
45
|
+
}
|
|
46
|
+
if (args.includes('--version') || args.includes('-v')) {
|
|
47
|
+
console.log(`v${packageJson.version}`);
|
|
48
|
+
process.exit(0);
|
|
49
|
+
}
|
|
50
|
+
if (args.includes('--config') || args.includes('-c')) {
|
|
51
|
+
console.log('Current Configuration:');
|
|
52
|
+
console.log(` API URL: ${process.env.AICONNECT_API_URL || 'Not set'}`);
|
|
53
|
+
console.log(` API Key: ${process.env.AICONNECT_API_KEY ? '[SET]' : 'Not set'}`);
|
|
54
|
+
console.log(` Node Version: ${process.version}`);
|
|
55
|
+
console.log(` MCP Server Version: ${packageJson.version}`);
|
|
56
|
+
process.exit(0);
|
|
57
|
+
}
|
|
58
|
+
// Validate required environment variables
|
|
59
|
+
if (!process.env.AICONNECT_API_URL) {
|
|
60
|
+
console.error('Error: AICONNECT_API_URL environment variable is required');
|
|
61
|
+
console.error('Use --help for more information');
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
if (!process.env.AICONNECT_API_KEY) {
|
|
65
|
+
console.error('Error: AICONNECT_API_KEY environment variable is required');
|
|
66
|
+
console.error('Use --help for more information');
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
// Initialize server
|
|
70
|
+
const server = new McpServer({
|
|
71
|
+
name: "agentjobs-mcp",
|
|
72
|
+
version: packageJson.version
|
|
73
|
+
});
|
|
74
|
+
// Initialize components
|
|
75
|
+
cancel_job(server);
|
|
76
|
+
get_job(server);
|
|
77
|
+
list_jobs(server);
|
|
78
|
+
create_job(server);
|
|
79
|
+
// Start server with stdio transport
|
|
80
|
+
const transport = new StdioServerTransport();
|
|
81
|
+
console.error(`Starting AI Connect Agent Jobs MCP Server v${packageJson.version}...`);
|
|
82
|
+
console.error('Server ready and listening for MCP connections');
|
|
83
|
+
await server.connect(transport);
|