Skip to content

Sample Jobs

samples/HangfireJobs defines job interfaces that cover the full range of supported parameter shapes — primitives, complex objects, enums, collections, defaults, and nullable optionals.

Recurring jobs

Registered in samples/Web/Program.cs via IRecurringJobManager.AddOrUpdate:

Recurring IDInterfaceMethodParameters
time.executeITimeJobExecuteAsync()none
send-message.textISendMessageJobExecuteAsync(string text)one required string
send-message.envelopeISendMessageJobExecuteAsync(Message message)one required complex object
report.generateIReportJobGenerateAsync(int year, string format = "pdf", DateTimeOffset? since = null)one required + two optional
data.exportIDataExportJobExportAsync(ExportFormat format, IReadOnlyList<string> tables)enum + string array
notify.dispatchINotificationJobNotifyAsync(string channel, string? message, int? priority)required + nullable optionals
maint.rebuild-indexesMaintenanceJobRebuildIndexesAsync(string schema = "public")one optional with default

Manifest-only jobs

Discovered from one-shot Enqueue calls by the source generator. They become tools when Sources includes StaticManifest or All:

  • Run_INotificationJob_BroadcastAsync
  • Run_IReportJob_PreviewAsync
  • Run_MaintenanceJob_VacuumAsync

Description metadata

Sample jobs annotate parameters with [Description] so MCP clients see human-readable schema docs:

csharp
public interface IReportJob
{
    [Description("Generate the annual financial report and persist it to the report store.")]
    [Authorize(Policy = "jobs:run")]
    Task GenerateAsync(
        [Description("Calendar year of the report (e.g. 2026).")] int year,
        [Description("Output file format. Supported: pdf, html, csv.")] string format = "pdf",
        [Description("Optional cutoff: only include data on or after this timestamp.")]
            DateTimeOffset? since = null
    );
}

Authorization

IReportJob.GenerateAsync carries [Authorize(Policy = "jobs:run")]. The sample defines this policy as RequireRole("admin") — calling the tool without the role returns Forbidden. Assign the role in Keycloak to flip it open. See Authentication for the full setup.

Parameter schema rules

C# signatureJSON Schema
string namerequired string
string format = "pdf"optional string (default applied server-side)
string? tagoptional string (nullable reference)
int? priorityoptional integer (nullable value type)
ExportFormat formatrequired string enum ("Csv", "Json", "Parquet")
IReadOnlyList<string> tablesrequired array of strings
Message messagerequired object with inferred JSON Schema
DateTimeOffset? sinceoptional string (ISO 8601)