AgentSkillsCN

streaming-output-mcp

将结构化内容流式传输至持久化SQLite存储,并自动实现会话断点恢复。核心原则:内容即状态。每次stream_write操作都会自动持久化。支持多种格式导出(Markdown、HTML、JSON、YAML、CSV、文本),并内置7种文档模板。常用命令:/stream-init、/stream-status、/stream-read、/stream-write、/stream-export。每次会话中断后,务必调用stream_status,以检查是否可以恢复会话并保留上下文。

SKILL.md
--- frontmatter
name: streaming-output-mcp
description: >
  Stream structured content to persistent SQLite storage with automatic session break recovery.
  Core principle: The content IS the state. Every stream_write is automatically persistent.
  Supports multi-format export (Markdown, HTML, JSON, YAML, CSV, Text) and 7 document templates.
  Commands: /stream-init, /stream-status, /stream-read, /stream-write, /stream-export.
  ALWAYS call stream_status after session breaks to check for resume_from and preserved_context.

Streaming Output MCP Skill

Agent instructions for using the streaming-output MCP to produce persistent, recoverable output.

Overview

This skill enables you to stream structured content to persistent SQLite storage with automatic session break recovery. Use it when producing reports, analysis results, task lists, or any structured output that needs to survive session interruptions.

Core Principle: The content IS the state. Every stream_write is automatically persistent.

Version 2.0 Features:

  • 7 pre-built document templates (security-audit, code-review, sprint-retrospective, etc.)
  • 6 export formats (Markdown, HTML, JSON, YAML, CSV, Plain Text)
  • Document finalization with completion verification
  • File export with path expansion

First Action Protocol

CRITICAL: Always follow this protocol at the start of any streaming task.

code
IF you have a document_id (from previous session or user):
    1. Call stream_status(document_id) FIRST
    2. Check for resume_from field
    3. If preserved_context exists, READ IT and CONTINUE from that point
    4. Do NOT restart blocks from scratch

IF you don't have a document_id:
    1. Call stream_start() to create new document
    2. Optionally use a template for structure
    3. Begin writing blocks in sequence

Why This Matters

Session breaks happen. When they do:

  • The MCP knows which blocks are incomplete
  • Partial content may be preserved in preserved_context
  • You should CONTINUE from the interruption point, not restart

Document Templates

Use templates for common document types with pre-defined structure:

TemplateUse CasePre-declared Blocks
security-auditSecurity assessmentsexecutive_summary, scope, findings, recommendations
code-reviewPR/code reviewssummary, critical_issues, suggestions, approval_status
sprint-retrospectiveSprint retroswhat_went_well, improvements, action_items
technical-specTechnical specsoverview, requirements, architecture, implementation_plan
adrArchitecture decisionscontext, decision, consequences, alternatives
research-reportResearch docsabstract, methodology, findings, conclusions
task-listTask trackingNo pre-declared blocks (dynamic)

To use a template:

json
{
  "title": "Q4 Security Audit",
  "template": "security-audit"
}

List available templates:

json
stream_templates({})

Tool Reference

stream_start

Initialize a new document.

json
// Minimal
{"title": "Code Review Report"}

// With template
{
  "title": "Security Assessment",
  "template": "security-audit"
}

// Custom structure
{
  "title": "Custom Report",
  "schema_type": "report",
  "blocks": [
    {"key": "summary", "type": "section"},
    {"key": "findings", "type": "finding"}
  ]
}

stream_write

Write content to a block. Each write is atomic and SHA-256 verified.

json
{
  "document_id": "doc_...",
  "block_key": "summary",
  "content": {
    "title": "Executive Summary",
    "body": "This audit identified 3 critical vulnerabilities..."
  },
  "block_type": "section"
}

Block Types:

TypeWhen to UseRequired Fields
sectionNarrative contenttitle, body
taskActionable itemsid, title, status
findingAnalysis resultsid, severity, description
decisionADR-style decisionsid, title, decision, rationale
rawArbitrary JSONcontent

Content Schemas:

json
// section
{"title": "...", "body": "..."}

// task
{"id": "T-001", "title": "...", "status": "pending|in_progress|complete", "assignee": "...", "notes": "..."}

// finding
{"id": "F-001", "severity": "critical|high|medium|low|info", "description": "...", "evidence": "...", "recommendation": "..."}

// decision
{"id": "ADR-001", "title": "...", "context": "...", "decision": "...", "rationale": "...", "alternatives": [...]}

stream_status

Check document state. Always call after session breaks.

json
// List recent documents
{}

// Check specific document with verification
{"document_id": "doc_...", "verify": true}

Response Fields:

json
{
  "resume_from": "findings",           // ← Start here
  "preserved_context": {
    "block_key": "findings",
    "partial_content": "Found 3 SQL injection..."
  },
  "summary": {
    "total": 5,
    "complete": 2,
    "pending": 3
  }
}

stream_read

Read document content in various formats.

json
// As JSON
{"document_id": "doc_...", "format": "json"}

// As Markdown
{"document_id": "doc_...", "format": "markdown"}

// Specific blocks
{"document_id": "doc_...", "format": "markdown", "blocks": ["summary", "recommendations"]}

stream_export (NEW)

Export document to a file.

json
{
  "document_id": "doc_...",
  "format": "html",
  "output_path": "~/Documents/report.html"
}

Supported Formats:

  • markdown - Clean Markdown with headers
  • html - Styled HTML with embedded CSS
  • json - Full structured data
  • text - Plain text without formatting
  • yaml - YAML representation
  • csv - Tabular format (best for tasks/findings)

stream_finalize (NEW)

Mark document as complete after all blocks are written.

json
{"document_id": "doc_..."}

Returns verification of completion status.

stream_delete (NEW)

Delete a document and all its blocks.

json
{"document_id": "doc_..."}

stream_templates (NEW)

List available document templates.

json
{}  // Returns all 7 templates with their structure

Recovery Workflow

Scenario 1: Session Break with Preserved Context

code
1. Call stream_status(document_id)
2. Response: resume_from: "analysis", preserved_context: "The security analysis..."
3. Action: Read preserved_context, CONTINUE from that point
4. Call stream_write("analysis", {complete_content}, repair=true)

Scenario 2: Session Break without Preserved Context

code
1. Call stream_status(document_id)
2. Response: resume_from: "analysis", no preserved_context
3. Action: Check complete blocks, re-analyze source, write fresh

Scenario 3: User Wants Previous Work

code
User: "Continue the security report from yesterday"
1. stream_status() - list recent documents
2. Identify by title/date
3. stream_status(document_id) - get details
4. Follow resume_from to continue

Anti-Patterns

DO NOT:

  1. Skip status check after session break
  2. Restart blocks from scratch when preserved_context exists
  3. Write multiple blocks without status checks
  4. Use wrong content structure for block type
  5. Forget repair=true when continuing interrupted blocks

Workflow Examples

Example 1: Using a Template

code
1. stream_start(title="Q4 Security Audit", template="security-audit")
   → Creates doc with: executive_summary, scope, findings, recommendations

2. stream_write(doc_xxx, "executive_summary", {title: "...", body: "..."})
3. stream_write(doc_xxx, "scope", {title: "...", body: "..."})
4. stream_write(doc_xxx, "findings", {severity: "critical", ...})
5. stream_write(doc_xxx, "recommendations", {title: "...", body: "..."})

6. stream_finalize(doc_xxx)
   → Document finalized

7. stream_export(doc_xxx, format="html", output_path="~/reports/q4-audit.html")
   → Exported to file

Example 2: Resume After Interruption

code
User: "Continue the security report"

1. stream_status()
   → Lists recent docs, find "Security Audit"

2. stream_status("doc_xxx")
   → resume_from: "findings", preserved_context: {partial: "Scanned 45/120..."}

3. Read preserved_context, note endpoint 45

4. Continue from endpoint 46

5. stream_write(doc_xxx, "findings", {complete}, repair=true)

Example 3: Multi-Format Export

code
1. Complete document with stream_write calls

2. stream_read(doc_xxx, format="markdown")
   → Preview in chat

3. stream_export(doc_xxx, format="html", output_path="~/report.html")
   → HTML file for sharing

4. stream_export(doc_xxx, format="json", output_path="~/backup.json")
   → JSON backup for archival

Slash Commands

CommandPurpose
/stream-initInitialize a new document
/stream-statusCheck document status and resume point
/stream-readRead document content
/stream-writeWrite content to a block
/stream-exportExport document to file

Database Location

Documents are stored in: ~/.claude/streaming-output/streams.db

This SQLite database persists across sessions.

Export Format Examples

Markdown Output

markdown
# Document Title
*Status: finalized | Created: 2026-01-14*

## Executive Summary
Content here...

## Findings
- **[CRITICAL]** Finding 1
- **[HIGH]** Finding 2

HTML Output

Styled HTML with:

  • Embedded CSS (no external dependencies)
  • Severity badges for findings
  • Status indicators
  • Print-friendly formatting

CSV Output

csv
block_key,type,title,severity,status
finding_1,finding,SQL Injection,critical,
task_1,task,Fix auth,in_progress,