agent-tools.ts•8.08 kB
/**
* ByteBot Agent API MCP Tools
*
* MCP tool definitions for ByteBot task management operations
*/
import { AgentClient } from '../clients/agent-client.js';
import { formatErrorForMCP } from '../utils/error-handler.js';
/**
* Tool definitions for Agent API
*/
export function getAgentTools() {
return [
{
name: 'bytebot_create_task',
description:
'Create a new task for ByteBot to execute. Returns task ID and initial status. Use this to start autonomous task execution.',
inputSchema: {
type: 'object' as const,
properties: {
description: {
type: 'string',
description:
'Natural language description of the task to execute. Be specific and clear about what you want ByteBot to do.',
},
priority: {
type: 'string',
enum: ['LOW', 'MEDIUM', 'HIGH', 'URGENT'],
description:
'Task priority level. Higher priority tasks are executed first. Default: MEDIUM',
default: 'MEDIUM',
},
files: {
type: 'array',
items: {
type: 'object',
properties: {
name: {
type: 'string',
description: 'File name',
},
content: {
type: 'string',
description: 'Base64-encoded file content',
},
mimeType: {
type: 'string',
description: 'MIME type of the file (optional)',
},
},
required: ['name', 'content'],
},
description:
'Optional: Array of file attachments to include with the task',
},
},
required: ['description'],
},
},
{
name: 'bytebot_list_tasks',
description:
'List all tasks with optional filters. Use this to see what tasks exist and their current status.',
inputSchema: {
type: 'object' as const,
properties: {
status: {
type: 'string',
enum: [
'PENDING',
'IN_PROGRESS',
'NEEDS_HELP',
'NEEDS_REVIEW',
'COMPLETED',
'CANCELLED',
'FAILED',
],
description: 'Filter tasks by status',
},
priority: {
type: 'string',
enum: ['LOW', 'MEDIUM', 'HIGH', 'URGENT'],
description: 'Filter tasks by priority',
},
limit: {
type: 'number',
description: 'Maximum number of tasks to return',
},
offset: {
type: 'number',
description: 'Number of tasks to skip (for pagination)',
},
},
},
},
{
name: 'bytebot_get_task',
description:
'Get detailed information about a specific task by ID, including full message history and current status.',
inputSchema: {
type: 'object' as const,
properties: {
taskId: {
type: 'string',
description: 'The unique identifier of the task',
},
useCache: {
type: 'boolean',
description:
'Whether to use cached task data if available. Default: true',
default: true,
},
},
required: ['taskId'],
},
},
{
name: 'bytebot_get_in_progress_task',
description:
'Get the currently running task, if any. Returns null if no task is currently in progress.',
inputSchema: {
type: 'object' as const,
properties: {},
},
},
{
name: 'bytebot_update_task',
description:
'Update a task\'s status or priority. Use this to cancel tasks, mark them for review, or change priority.',
inputSchema: {
type: 'object' as const,
properties: {
taskId: {
type: 'string',
description: 'The unique identifier of the task to update',
},
status: {
type: 'string',
enum: [
'PENDING',
'IN_PROGRESS',
'NEEDS_HELP',
'NEEDS_REVIEW',
'COMPLETED',
'CANCELLED',
'FAILED',
],
description: 'New status for the task',
},
priority: {
type: 'string',
enum: ['LOW', 'MEDIUM', 'HIGH', 'URGENT'],
description: 'New priority for the task',
},
message: {
type: 'string',
description:
'Optional message to add to the task (e.g., intervention instructions)',
},
},
required: ['taskId'],
},
},
{
name: 'bytebot_delete_task',
description:
'Delete a task by ID. This permanently removes the task and its history. Cannot be undone.',
inputSchema: {
type: 'object' as const,
properties: {
taskId: {
type: 'string',
description: 'The unique identifier of the task to delete',
},
},
required: ['taskId'],
},
},
];
}
/**
* Tool handlers for Agent API
*/
export async function handleAgentTool(
toolName: string,
args: Record<string, unknown>,
agentClient: AgentClient
) {
try {
switch (toolName) {
case 'bytebot_create_task': {
const result = await agentClient.createTask({
description: args.description as string,
priority: args.priority as any,
files: args.files as any,
});
return {
content: [
{
type: 'text',
text: JSON.stringify(result, null, 2),
},
],
};
}
case 'bytebot_list_tasks': {
const result = await agentClient.listTasks(args as any);
return {
content: [
{
type: 'text',
text: JSON.stringify(
{
count: result.length,
tasks: result,
},
null,
2
),
},
],
};
}
case 'bytebot_get_task': {
const result = await agentClient.getTask(
args.taskId as string,
args.useCache !== false
);
return {
content: [
{
type: 'text',
text: JSON.stringify(result, null, 2),
},
],
};
}
case 'bytebot_get_in_progress_task': {
const result = await agentClient.getInProgressTask();
return {
content: [
{
type: 'text',
text: result
? JSON.stringify(result, null, 2)
: 'No task currently in progress',
},
],
};
}
case 'bytebot_update_task': {
const { taskId, ...update } = args;
const result = await agentClient.updateTask(taskId as string, update);
return {
content: [
{
type: 'text',
text: JSON.stringify(result, null, 2),
},
],
};
}
case 'bytebot_delete_task': {
await agentClient.deleteTask(args.taskId as string);
return {
content: [
{
type: 'text',
text: `Task ${args.taskId} deleted successfully`,
},
],
};
}
default:
throw new Error(`Unknown tool: ${toolName}`);
}
} catch (error) {
const errorInfo = formatErrorForMCP(error);
return {
content: [
{
type: 'text',
text: `Error: ${errorInfo.error}${errorInfo.details ? '\n\nDetails:\n' + errorInfo.details : ''}`,
},
],
isError: true,
};
}
}