@aiconnect/agentjobs-mcp 1.0.8 → 1.1.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.
@@ -1,71 +0,0 @@
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
- };
@@ -1,151 +0,0 @@
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 DELETED
@@ -1,62 +0,0 @@
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
- };
@@ -1,88 +0,0 @@
1
- import { z } from "zod";
2
- import axios from 'axios';
3
- import { config } from './config.js';
4
- // Define the schema for job status based on docs/agent-jobs-api.md:246-251
5
- const jobStatusSchema = z.enum([
6
- "waiting",
7
- "scheduled",
8
- "running",
9
- "completed",
10
- "failed",
11
- "canceled"
12
- ]);
13
- export default (server) => {
14
- server.tool("list_jobs", "Retrieves a list of agent jobs, with optional filters and pagination.", {
15
- org_id: z.string().optional().describe("Filter by organization ID. If not provided, uses the default organization."),
16
- status: jobStatusSchema.optional().describe("Filter by job status."),
17
- scheduled_at: z.string().datetime().optional().describe("Filter by exact scheduled time (ISO 8601)."),
18
- scheduled_at_gte: z.string().datetime().optional().describe("Filter by scheduled time greater than or equal to (ISO 8601)."),
19
- scheduled_at_lte: z.string().datetime().optional().describe("Filter by scheduled time less than or equal to (ISO 8601)."),
20
- created_at_gte: z.string().datetime().optional().describe("Filter by creation time greater than or equal to (ISO 8601)."),
21
- created_at_lte: z.string().datetime().optional().describe("Filter by creation time less than or equal to (ISO 8601)."),
22
- job_type_id: z.string().optional().describe("Filter by job type ID."),
23
- channel_code: z.string().optional().describe("Filter by channel code."),
24
- limit: z.number().int().positive().optional().describe("Maximum number of jobs to return."),
25
- offset: z.number().int().nonnegative().optional().describe("Number of jobs to skip (for pagination)."),
26
- sort: z.string().optional().describe("Sorting field and direction (e.g., created_at:desc)."),
27
- }, async (params) => {
28
- const apiUrl = config.AICONNECT_API_URL;
29
- const apiKey = config.AICONNECT_API_KEY;
30
- if (!apiUrl) {
31
- return {
32
- content: [{
33
- type: "text",
34
- text: "Error: API URL is not configured. Please set AICONNECT_API_URL environment variable."
35
- }]
36
- };
37
- }
38
- if (!apiKey) {
39
- return {
40
- content: [{
41
- type: "text",
42
- text: "Error: API Key is not configured. Please set AICONNECT_API_KEY environment variable."
43
- }]
44
- };
45
- }
46
- const endpoint = `${apiUrl}/services/agent-jobs`;
47
- const headers = {
48
- "Authorization": `Bearer ${apiKey}`,
49
- };
50
- // Build query parameters object from provided params
51
- const queryParams = {};
52
- for (const [key, value] of Object.entries(params)) {
53
- if (value !== undefined) {
54
- queryParams[key] = value;
55
- }
56
- }
57
- try {
58
- const response = await axios.get(endpoint, {
59
- headers,
60
- params: queryParams, // Axios uses 'params' for query parameters in GET requests
61
- });
62
- // Return the data part of the response, stringified as JSON text
63
- // API docs show jobs under 'data' key, and meta for pagination
64
- return {
65
- content: [{
66
- type: "text",
67
- text: JSON.stringify(response.data, null, 2),
68
- }]
69
- };
70
- }
71
- catch (error) {
72
- let errorMessage = `Failed to list jobs.`;
73
- if (axios.isAxiosError(error) && error.response) {
74
- const apiError = error.response.data?.message || error.response.data?.error || JSON.stringify(error.response.data);
75
- errorMessage = `API Error (${error.response.status}): ${apiError || error.message}`;
76
- }
77
- else if (error instanceof Error) {
78
- errorMessage = `Error: ${error.message}`;
79
- }
80
- return {
81
- content: [{
82
- type: "text",
83
- text: errorMessage,
84
- }]
85
- };
86
- }
87
- });
88
- };