Skip to main content

Overview

import { JobRegistry } from '@frontmcp/sdk';

// Access via scope
const jobs = scope.jobs;

// List all jobs
const allJobs = jobs.getJobs();

// Find a specific job
const job = jobs.findByName('analyze-text');

Methods

getJobs()

Get all jobs (local + dynamic).
getJobs(includeHidden?: boolean): JobEntry[]
ParameterTypeDefaultDescription
includeHiddenbooleanfalseInclude hidden jobs in results
Example:
// Get all visible jobs
const jobs = registry.getJobs();

// Include hidden jobs
const allJobs = registry.getJobs(true);

findByName()

Find a job by its base name.
findByName(name: string): JobEntry | undefined
Example:
const job = registry.findByName('analyze-text');
if (job) {
  console.log(`Found: ${job.name}`);
}

findById()

Find a job by its ID.
findById(id: string): JobEntry | undefined
Example:
const job = registry.findById('custom-job-id');
Search jobs by query, tags, or labels.
search(
  query?: string,
  opts?: { tags?: string[]; labels?: Record<string, string> }
): JobEntry[]
Example:
// Search by name/description
const results = registry.search('email');

// Filter by tags
const tagged = registry.search(undefined, { tags: ['notification'] });

// Filter by labels
const labeled = registry.search(undefined, {
  labels: { priority: 'high' },
});

registerDynamic()

Register a dynamic job at runtime.
registerDynamic(record: JobDynamicRecord): void
Example:
registry.registerDynamic({
  kind: JobKind.DYNAMIC,
  provide: 'my-dynamic-job',
  metadata: {
    id: 'my-dynamic-job',
    name: 'my-dynamic-job',
    description: 'A dynamically registered job',
    inputSchema: {},
    outputSchema: {},
  },
  script: 'module.exports = (input) => ({ result: input.value })',
  registeredBy: 'admin',
  registeredAt: Date.now(),
});

removeDynamic()

Remove a dynamic job.
removeDynamic(jobId: string): boolean
Returns: true if the job was found and removed, false otherwise.

subscribe()

Subscribe to job change events.
subscribe(
  opts: { immediate?: boolean },
  cb: (event: JobChangeEvent) => void
): () => void
Returns: Unsubscribe function. Example:
const unsubscribe = registry.subscribe(
  { immediate: true },
  (event) => {
    console.log(`Job ${event.kind}:`, event.version);
  }
);

// Later: stop listening
unsubscribe();

hasAny()

Check if any jobs exist in the registry.
hasAny(): boolean

MCP Tools Registered

When the jobs system is enabled, the registry’s capabilities are exposed through these MCP tools:
ToolDescription
list-jobsList all registered jobs with optional filtering
execute-jobExecute a job by name (inline or background)
get-job-statusGet execution status by runId
register-jobRegister a dynamic job with JavaScript source
remove-jobRemove a dynamic job

Change Events

The registry emits events when jobs are added, updated, or removed:
interface JobChangeEvent {
  kind: 'added' | 'updated' | 'removed' | 'reset';
  changeScope: 'global' | 'session';
  version: number;
  snapshot: readonly JobEntry[];
  sessionId?: string;
}

Lifecycle

buildMap()     → Extract tokens, definitions from metadata
buildGraph()   → Validate dependencies, populate graph
initialize()   → Create instances, register dynamic jobs