Claude Skill

cancellable-loop

Example skill — demonstrates cooperative cancellation inside a skill script loop using check_cancelled(). Use as a reference when writing long-running domain skills that must respond to notifications/cancelled. Not intended for production use.

LLM Mart · 0 points · 0 views 0 listing impressions 0 install-command copies
Download dcc-mcp-dcc-mcp-core-examples_skills_cancellable-loop-8d8c969.zip · 2 KB

Install

skills CLI npx skills add https://github.com/dcc-mcp/dcc-mcp-core/tree/main/examples/skills/cancellable-loop
Claude Code claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install dcc-mcp-dcc-mcp-core@llmmart
Git git clone https://github.com/dcc-mcp/dcc-mcp-core.git

The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole dcc-mcp/dcc-mcp-core collection as a plugin from our marketplace. Git is the plain clone.

Skill manifest

Cancellable Loop

A minimal example that shows how to write a skill script that honours notifications/cancelled from the MCP client.

The pattern is simple: call check_cancelled() at the top of every iteration of a long-running loop. When the dispatcher installs a CancelToken and the client cancels the request, check_cancelled() raises CancelledError and the script unwinds cleanly. Outside of a request context (REPL, unit tests) check_cancelled() is a no-op, so the same script remains easy to run in isolation.

Tools

  • cancellable_loop__count — Iterate iterations times, sleeping sleep_ms milliseconds per step, checking for cancellation each iteration.

Example

{"name": "cancellable_loop__count", "arguments": {"iterations": 100, "sleep_ms": 50}}
# → {"success": true, "message": "Completed 100 iterations", "context": {"iterations": 100}}

If the client sends notifications/cancelled while the loop is running, the next check_cancelled() call raises CancelledError and the @skill_entry wrapper converts it into a standard error dict.

Related

  • dcc_mcp_core.check_cancelled — the API this skill demonstrates.
  • Issue #329 — cooperative cancellation checkpoints.
  • Issue #318 — async dispatcher integration (wires the CancelToken).
Files (dcc-mcp-core)
  • scripts
    • count.py 2.4 KB
      Loading…
  • SKILL.md 2 KB
    ---
    name: cancellable-loop
    description: >-
      Example skill — demonstrates cooperative cancellation inside a skill script
      loop using check_cancelled(). Use as a reference when writing long-running
      domain skills that must respond to notifications/cancelled. Not intended for
      production use.
    license: MIT
    compatibility: Python 3.7+
    metadata:
      dcc-mcp:
        dcc: python
        recall-context:
          app_type: python
          domain: runtime
          workflow_stage: authoring
          task_category: query
        version: "1.0.0"
        layer: example
        search-hint: "cancellation, cancel, long-running, cooperative, check_cancelled, abort, authoring reference"
        tags: "example, cancellation, long-running"
    ---
    
    # Cancellable Loop
    
    A minimal example that shows how to write a skill script that honours
    `notifications/cancelled` from the MCP client.
    
    The pattern is simple: call `check_cancelled()` at the top of every
    iteration of a long-running loop.  When the dispatcher installs a
    `CancelToken` and the client cancels the request, `check_cancelled()`
    raises `CancelledError` and the script unwinds cleanly.  Outside of a
    request context (REPL, unit tests) `check_cancelled()` is a no-op, so
    the same script remains easy to run in isolation.
    
    ## Tools
    
    - `cancellable_loop__count` — Iterate `iterations` times, sleeping
      `sleep_ms` milliseconds per step, checking for cancellation each
      iteration.
    
    ## Example
    
    ```python
    {"name": "cancellable_loop__count", "arguments": {"iterations": 100, "sleep_ms": 50}}
    # → {"success": true, "message": "Completed 100 iterations", "context": {"iterations": 100}}
    ```
    
    If the client sends `notifications/cancelled` while the loop is
    running, the next `check_cancelled()` call raises `CancelledError` and
    the `@skill_entry` wrapper converts it into a standard error dict.
    
    ## Related
    
    - `dcc_mcp_core.check_cancelled` — the API this skill demonstrates.
    - Issue #329 — cooperative cancellation checkpoints.
    - Issue #318 — async dispatcher integration (wires the CancelToken).
    

Comments (0)

Sign in to join the conversation.

No comments yet.

Reviews (0)

No reviews yet.