Skip to main content

MCP server for managing Hangfire background jobs

Project description

Hangfire MCP Server

License: MIT Python 3.11+ CI

A Model Context Protocol (MCP) server for managing Hangfire background jobs directly from VS Code Copilot and other MCP-compatible clients. Monitor job queues, retry failed jobs, manage recurring tasks, and view real-time statistics — all without leaving your editor.

Features

  • Job Management: List, view, retry, delete, and requeue jobs
  • Recurring Jobs: List, view, trigger, pause, and resume recurring jobs
  • Statistics: View server stats, queues, and active servers
  • Auto-Discovery: Automatically finds connection strings from appsettings.json
  • Web Dashboard: Built-in web UI with real-time stats and job management

Quick Start (One-Click Setup)

# Clone the repo
git clone https://github.com/pyyupsk/hangfire-mcp.git
cd hangfire-mcp

# Run cross-platform setup (Windows, macOS, Linux)
python setup.py

The setup script will:

  1. Create a virtual environment
  2. Install all dependencies (including dashboard)
  3. Prompt for your SQL Server connection string (or read from .vscode/mcp.json)
  4. Create VS Code MCP configuration
  5. Test the connection
  6. Optionally start the dashboard

Installation

pip install hangfire-mcp

Or with uvx:

uvx hangfire-mcp

Configuration

VS Code (Global Settings)

Add to your VS Code settings (settings.json):

{
  "mcp": {
    "servers": {
      "hangfire-mcp": {
        "command": "uvx",
        "args": ["hangfire-mcp", "--workspace", "${workspaceFolder}"]
      }
    }
  }
}

VS Code (Per-Project)

Create .vscode/mcp.json in your project:

{
  "servers": {
    "hangfire-mcp": {
      "command": "uvx",
      "args": ["hangfire-mcp", "--workspace", "${workspaceFolder}"]
    }
  }
}

With Explicit Connection String

Use ODBC-style connection strings:

{
  "servers": {
    "hangfire-mcp": {
      "command": "python",
      "args": ["-m", "hangfire_mcp", "--workspace", "${workspaceFolder}"],
      "env": {
        "HANGFIRE_CONNECTION_STRING": "Driver={ODBC Driver 17 for SQL Server};Server=localhost;Database=Hangfire;UID=sa;PWD=yourpassword;Encrypt=no;"
      }
    }
  }
}

Note: This project uses pyodbc and requires ODBC-format connection strings, not ADO.NET format.

Connection String Discovery

The server finds connection strings in this priority order:

  1. --connection-string CLI argument
  2. HANGFIRE_CONNECTION_STRING environment variable
  3. Auto-discover from ${workspaceFolder}/**/appsettings*.json
  4. User config at ~/.config/hangfire-mcp/connections.json (Linux/macOS) or %APPDATA%\hangfire-mcp\connections.json (Windows)
  5. Use the configure tool to set it manually

Available Tools

Job Tools

Tool Description
list_jobs List jobs by state (Enqueued, Processing, Succeeded, Failed, etc.)
get_job Get detailed job info including arguments and exception details
get_job_history Get the state history of a job
retry_job Retry a failed job
delete_job Delete a job
requeue_job Move a job back to queue

Recurring Job Tools

Tool Description
list_recurring_jobs List all recurring jobs with cron schedules
get_recurring_job Get recurring job details
trigger_recurring_job Run a recurring job immediately
pause_recurring_job Pause scheduled executions
resume_recurring_job Resume a paused job

Statistics Tools

Tool Description
get_stats Server statistics (succeeded, failed, processing counts)
list_queues List queues with pending job counts
list_servers List active Hangfire servers

Configuration Tool

Tool Description
configure Set connection string for current workspace

Usage Examples

In VS Code Copilot Chat:

User: Show me failed jobs
Agent: [calls list_jobs(state="Failed")]
      Found 3 failed jobs:
      | ID | State | Job Type | Created | Reason |
      |----|-------|----------|---------|--------|
      | 123 | Failed | OrderSyncJob.Execute | 2026-03-17 10:30 | Connection timeout |
      | 124 | Failed | EmailJob.Send | 2026-03-17 10:45 | SMTP error |

User: Retry job 123
Agent: [calls retry_job(job_id=123)]
      Job 123 has been requeued to 'default' queue.

User: When did CacheRefreshJob last run?
Agent: [calls get_recurring_job(job_id="CacheRefreshJob")]
      Recurring Job: CacheRefreshJob
      - Cron: 0 */5 * * * (every 5 minutes)
      - Last Run: 2026-03-17 12:55:00
      - Queue: default

User: Trigger CacheRefreshJob now
Agent: [calls trigger_recurring_job(job_id="CacheRefreshJob")]
      CacheRefreshJob has been triggered. New job ID: 456

Web Dashboard

The package includes a built-in web dashboard for visual job management.

Installation

pip install hangfire-mcp[dashboard]

Running the Dashboard

# Windows
.\scripts\run-dashboard.ps1

# macOS / Linux
chmod +x scripts/run-dashboard.sh
./scripts/run-dashboard.sh

# Or manually (any platform)
export HANGFIRE_CONNECTION_STRING="Driver={ODBC Driver 17 for SQL Server};Server=localhost;Database=Hangfire;..."
python -m uvicorn hangfire_mcp.dashboard:app --host 127.0.0.1 --port 8080

Open http://127.0.0.1:8080 in your browser.

Dashboard Features

  • Real-time Stats: Succeeded, Failed, Processing, Enqueued, Scheduled counts
  • Job List: View all jobs with filtering by state
  • Job Actions: Retry, Delete, View details with one click
  • Recurring Jobs: Pause, Resume, Trigger recurring jobs
  • Server Status: Online/Idle/Offline status based on heartbeat
  • Auto-refresh: Updates every 10 seconds

Requirements

  • Python 3.11+
  • SQL Server with Hangfire database
  • ODBC Driver 17 for SQL Server (or compatible)

Development

# Clone the repository
git clone https://github.com/pyyupsk/hangfire-mcp.git
cd hangfire-mcp

# Install all dependencies
pip install -e ".[dev]"

# Run tests
pytest

Contributing

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

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hangfire_mcp-0.1.0.tar.gz (27.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hangfire_mcp-0.1.0-py3-none-any.whl (27.9 kB view details)

Uploaded Python 3

File details

Details for the file hangfire_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: hangfire_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 27.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for hangfire_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1fac51966b4683ade6c90ed82b455cd5da8502fee8eab6b84a07154120de6952
MD5 f55f471b1c84a9b8952518497bc78606
BLAKE2b-256 0f811bcb36c4a282fd3e237da5bc8b8074b6f18cd726a37bebd74f553f3c97e3

See more details on using hashes here.

File details

Details for the file hangfire_mcp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: hangfire_mcp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 27.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for hangfire_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0ce6c6640ac19b5b4f012ca6fc15aa4ae9649df226fccc485731e5e8d7c4d995
MD5 718b915b00416f32694deba103b587b6
BLAKE2b-256 a893984065ffb7e69b5d529acdeb876c53ef047ab24ce178adaa0417ca594461

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page