Skip to main content
Glama
README.md
# AI Connect MCP Server

An MCP (Model Context Protocol) server that allows AI agents to query and manage jobs in the AI Connect platform.

## About AI Connect Jobs

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.

## Features

This MCP Server provides tools for AI agents to:

- ๐Ÿ“‹ **List Jobs**: Query all jobs with advanced filtering
- ๐Ÿ” **Get Specific Job**: Retrieve details of a specific job by ID
- โœ… **Create Jobs**: Create new jobs for immediate or scheduled execution
- โŒ **Cancel Jobs**: Cancel running or scheduled jobs
- ๐Ÿ“Š **Monitor Status**: Track job status (WAITING, RUNNING, COMPLETED, FAILED, CANCELED)

## Technologies

- **Node.js** with **TypeScript**
- **Model Context Protocol (MCP)** by Anthropic
- **Zod** for schema validation
- **AI Connect API** for integration with the Agent Jobs system

## Installation

### NPX (Recommended)

You can run the MCP server directly using npx without installation:

```bash
npx @aiconnect/agentjobs-mcp --help
```

### Local Installation

1. **Clone the repository:**
```bash
git clone <repository-url>
cd agentjobs-mcp
```

2. **Install dependencies:**
```bash
npm install
```

3. **Configure environment variables (Optional):**

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.

```bash
cp .env.example .env
```

Edit the `.env` file with your credentials:
```env
DEFAULT_ORG_ID=your-organization     # Default: aiconnect
AICONNECT_API_KEY=your-api-key       # Required: Must be provided
AICONNECT_API_URL=https://api.aiconnect.cloud/api/v0  # Default
DEFAULT_TIMEZONE=America/Sao_Paulo   # Default: UTC (informational only, surfaced via get_context)
```

**Important**: If no environment variables are provided, the server will use these defaults:
- `DEFAULT_ORG_ID`: `aiconnect`
- `AICONNECT_API_URL`: `https://api.aiconnect.cloud/api/v0`
- `AICONNECT_API_KEY`: empty (must be provided for API calls to work)
- `DEFAULT_TIMEZONE`: `UTC`

4. **Build the project:**
```bash
npm run build
```

## Usage

### CLI Usage

The MCP server now supports CLI commands for easy management:

```bash
# Show help and usage information
npx @aiconnect/agentjobs-mcp --help

# Show version information
npx @aiconnect/agentjobs-mcp --version

# Show current configuration status
npx @aiconnect/agentjobs-mcp --config

# Start MCP server (default behavior)
npx @aiconnect/agentjobs-mcp
```

**Setting Environment Variables:**
```bash
# Using environment variables with npx
AICONNECT_API_URL=https://api.aiconnect.cloud/api/v0 \
AICONNECT_API_KEY=your-api-key-here \
npx @aiconnect/agentjobs-mcp

# Or create a .env file (recommended for development)
cp .env.example .env
# Edit .env with your credentials
npx @aiconnect/agentjobs-mcp
```

**Required Environment Variables:**
- `AICONNECT_API_URL`: API endpoint URL (e.g., https://api.aiconnect.cloud/api/v0)
- `AICONNECT_API_KEY`: Your API authentication key

**Optional Environment Variables:**

- `DEFAULT_ORG_ID`: Fallback organization ID when a tool's `org_id` parameter is omitted (default: `aiconnect`)
- `DEFAULT_TIMEZONE`: Preferred timezone surfaced by the `get_context` tool so LLM clients can format timestamps. Informational only โ€” does not change behavior of other tools, which continue to emit timestamps in UTC (default: `UTC`)

**CLI Command Examples:**
```bash
# Quick help
npx @aiconnect/agentjobs-mcp -h

# Check version
npx @aiconnect/agentjobs-mcp -v

# Verify configuration before starting
npx @aiconnect/agentjobs-mcp -c

# Test with environment variables
env AICONNECT_API_URL=https://api.aiconnect.cloud/api/v0 \
    AICONNECT_API_KEY=test-key \
    npx @aiconnect/agentjobs-mcp --config
```

### Local Development

For local development, you can use npm scripts:

```bash
# Build and test CLI commands
npm run cli:help
npm run cli:version  
npm run cli:config

# Run test suite (if available)
npm run test:cli
```

### Configuration Options

This MCP server is designed to work out-of-the-box with minimal configuration. It uses a smart fallback system:

1. **With environment variables**: Full control over all settings
2. **Without environment variables**: Uses defaults from `.env.example`
3. **Partial configuration**: Mix of environment variables and defaults

**Default Values (when no env vars are set):**

- `DEFAULT_ORG_ID`: `"aiconnect"`
- `AICONNECT_API_URL`: `"https://api.aiconnect.cloud/api/v0"`
- `AICONNECT_API_KEY`: `""` (empty - you must provide this)
- `DEFAULT_TIMEZONE`: `"UTC"`

**Error Handling:**

- The server will always start, even if environment variables are missing.
- If `AICONNECT_API_KEY` or `AICONNECT_API_URL` are not provided, each tool will return a clear error message upon execution, guiding the user to configure the environment correctly.
- If `DEFAULT_ORG_ID` is not set, it defaults to "aiconnect".
- If `DEFAULT_TIMEZONE` is not set, it defaults to "UTC". This value is purely informational (returned by the `get_context` tool) and does not affect timestamp parsing or formatting in other tools.

### Running the MCP server

```bash
npm start
```

The server will start and wait for connections via stdio transport.

### Claude Desktop Configuration

To use this MCP server with Claude Desktop, add the following configuration to your `claude_desktop_config.json` file:

```json
{
  "mcpServers": {
    "agentjobs": {
      "command": "node",
      "args": ["/path/to/agentjobs-mcp/build/index.js"],
      "env": {
        "DEFAULT_ORG_ID": "your-organization",
        "AICONNECT_API_KEY": "your-api-key",
        "AICONNECT_API_URL": "https://api.aiconnect.cloud/api/v0",
        "DEFAULT_TIMEZONE": "America/Sao_Paulo"
      }
    }
  }
}
```

### Local Development with Claude Code

For development and testing, you can add this MCP server directly to your Claude Code project:

```bash
# Prerequisites: build the project first
npm install
npm run build

# Configure your .env file
cp .env.example .env
# Edit .env with your API credentials

# Add MCP server to Claude Code (project scope)
claude mcp add --scope project agentjobs -- ./mcp-agentjobs.sh
```

This allows you to test and use the AgentJobs tools directly within Claude Code during development, providing immediate feedback and easier debugging.

## Available Tools

### ๐Ÿ“Š `get_jobs_stats`
Get aggregated statistics for agent jobs without retrieving individual job data. Optimized for dashboards and monitoring with minimal network overhead.

**Parameters:**
- `scheduled_at_gte`: Start of period (ISO 8601)
- `scheduled_at_lte`: End of period (ISO 8601)
- `org_id`: Organization filter
- `job_type_id`: Job type filter
- `tags`: Tags filter (comma-separated)
- `status`: Status filter
- `channel_code`: Channel filter

### ๐Ÿ”ง `list_jobs`
Lists all jobs with filtering and pagination options.

**Parameters:**
- `status` (optional): Filter by status (WAITING, RUNNING, COMPLETED, FAILED, CANCELED)
- `job_type_id` (optional): Filter by job type
- `channel_code` (optional): Filter by channel code
- `limit` (optional): Result limit (default: 50)
- `offset` (optional): Pagination offset
- `sort` (optional): Field and direction for sorting
- `include_activities` (optional): Attach recent activities to each job (default: false)
- `activities_limit_per_job` (optional): Max activities per job (1โ€“100, default 15)
- `activities_total_limit` (optional): Global cap across the response (1โ€“3000, default 500)
- `activities_sort` (optional): `created_at` or `-created_at` (default `-created_at`)

### ๐Ÿ” `get_job`
Gets details of a specific job.

**Parameters:**
- `job_id` (required): ID of the job to query
- `include_activities` (optional): Attach recent activities as an inline overlay (default: false)
- `include_limit` (optional): Max activities to attach (1โ€“100, default 50)
- `include_sort` (optional): `created_at` or `-created_at` (default `-created_at`)

### ๐Ÿงพ `get_job_activities`
Retrieves the audit activity trail for a specific agent job via the dedicated `/services/activities` endpoint. Supports real pagination (no truncation) and server-side filtering. Use this for focused investigation of a job's activity log; for a quick overlay of recent activities, use `get_job` with `include_activities=true`.

**Parameters:**
- `job_id` (required): ID of the agent job
- `org_id` (optional): Organization scope
- `status` (optional): `submitted`, `completed`, or `canceled`
- `activity_type_code` (optional): Open-string code (e.g., `ai_completion`)
- `source_type` (optional): `dispatch`, `process_module`, or `direct`
- `limit` (optional): Page size (default 50)
- `offset` (optional): Pagination offset (default 0)
- `sort` (optional): Sort field/direction (default `-created_at`)

### โœ… `create_job`
Creates a new job for execution.

**Parameters:**
- `target_channel`: Target channel configuration
- `job_type_id`: Job type ID
- `config`: Job configuration (timeouts, retries, etc.)
- `params`: Job-specific parameters
- `scheduled_at` (optional): Date/time for scheduled execution
- `delay` (optional): Random delay in minutes

### โŒ `cancel_job`
Cancels a running or scheduled job.

**Parameters:**
- `job_id` (required): ID of the job to cancel
- `reason` (optional): Cancellation reason

## Job Status

Jobs can have the following status values:

- `WAITING`: Job waiting for execution
- `SCHEDULED`: Job scheduled for future execution
- `RUNNING`: Job currently running
- `COMPLETED`: Job completed successfully
- `FAILED`: Job failed
- `CANCELED`: Job was canceled

## Usage Examples

### List running jobs
```
Agent: "Show me all jobs that are currently running"
```

### Query specific job
```
Agent: "What's the status of job job-123?"
```

### Create scheduled job
```
Agent: "Create a daily report job for Slack channel C123456 to run tomorrow at 9 AM"
```

### Cancel job
```
Agent: "Cancel job job-456 because it's no longer needed"
```

## Project Structure

```
agentjobs-mcp/
โ”œโ”€โ”€ src/                    # TypeScript source code
โ”‚   โ”œโ”€โ”€ index.ts           # Main MCP server entry point
โ”‚   โ”œโ”€โ”€ config.ts          # Configuration loader
โ”‚   โ””โ”€โ”€ tools/             # Directory for all MCP tools
โ”‚       โ”œโ”€โ”€ get_jobs_stats.ts     # Tool for getting job statistics
โ”‚       โ”œโ”€โ”€ list_jobs.ts          # Tool for listing jobs
โ”‚       โ”œโ”€โ”€ get_job.ts            # Tool for getting a job
โ”‚       โ”œโ”€โ”€ get_job_activities.ts # Tool for getting a job's activity trail
โ”‚       โ”œโ”€โ”€ create_job.ts         # Tool for creating a job
โ”‚       โ””โ”€โ”€ cancel_job.ts         # Tool for canceling a job
โ”œโ”€โ”€ build/                 # Compiled JavaScript code
โ”œโ”€โ”€ docs/                  # Documentation
โ”‚   โ””โ”€โ”€ agent-jobs-api.md  # API documentation
โ”œโ”€โ”€ package.json           # Dependencies and scripts
โ”œโ”€โ”€ tsconfig.json          # TypeScript configuration
โ”œโ”€โ”€ .env.example           # Environment variables example
โ””โ”€โ”€ README.md              # This file
```

## Development

### Available scripts

- `npm run build`: Compiles TypeScript
- `npm start`: Runs the compiled server
- `npm run debug`: Runs server in debug mode with detailed logging
- `npm run test:tools`: Tests tool loading without starting server
- `npm run cli:config`: Shows current configuration
- `npm run cli:version`: Shows version information
- `npm run cli:help`: Shows help information

### Debugging

For detailed debugging information, see [Debug Guide](docs/debug-guide.md).

**Quick Debug Commands:**
```bash
# Test configuration
npm run cli:config

# Test tool loading
npm run test:tools

# Run in debug mode
MCP_DEBUG=true npm run debug

# Use debug helper script (Fish shell)
./debug.fish help
./debug.fish quick
```

**Debug Environment:**
```bash
# Copy debug environment template
cp .env.debug .env
# Edit .env with your API credentials
# Run with debug environment
./debug.fish debug-with-env
```

### Adding new tools

Adding a new tool is simple:

1. Create a new TypeScript file inside the `src/tools/` directory (e.g., `my_new_tool.ts`).
2. Implement your tool logic following the existing pattern. The server will automatically detect and register it on startup.
3. Recompile the project with `npm run build`.
4. Test with `npm run test:tools` to verify loading.

## Contributing

1. Fork the project
2. Create a feature branch (`git checkout -b feature/new-feature`)
3. Commit your changes (`git commit -am 'Add new feature'`)
4. Push to the branch (`git push origin feature/new-feature`)
5. Open a Pull Request

## License

This project is licensed under the [MIT License](LICENSE).

## Support

For technical support or questions about AI Connect Jobs:
- Check the [API documentation](docs/agent-jobs-api.md)
- Contact the AI Connect development team

---

**Note**: This project was developed using the Anthropic mcp-tools scaffold for integration with the AI Connect platform.

TDQS

A3.7/5.0

Scored across 6 tools

Disambiguation5/5

Every tool has a clearly distinct purpose with no ambiguity. Each targets a specific resource or action: cancel_job, create_job, get_job, get_jobs_stats, get_job_type, and list_jobs are all well-defined and non-overlapping. An agent can easily distinguish between them based on their names and descriptions.

Naming Consistency5/5

All tool names follow a consistent verb_noun pattern throughout, using snake_case uniformly. The verbs (cancel, create, get, list) are clear and predictable, making the set easy to navigate and understand without any deviations or mixed conventions.

Tool Count5/5

With 6 tools, the server is well-scoped for managing agent jobs. Each tool earns its place by covering essential operations like creation, retrieval, listing, cancellation, statistics, and job type handling, without being too sparse or bloated for the domain.

Completeness4/5

The tool surface provides strong coverage for the agent jobs domain, including CRUD-like operations (create, get, list, cancel) and additional utilities (stats, job type). A minor gap exists in update operations (e.g., update_job), but agents can likely work around this by recreating jobs or using other methods.

Maintenance

ActivityInactive
ResponsivenessNo issues