← 全部项目

在 GitHub 查看 ↗Python · 2026-11-18

fd-scraw-harness

Part of the Wire line (寻数·柏讯) of FindData — Crawl harness — shared scaffolding for source adapters: retries, pacing, evidence capture.

Automated datasource discovery pipeline: web search via LLM, page analysis via ego-browser, manifest generation via LiteLLM, dual-database persistence.

Install

cd fd-scraw-harness
uv sync
uv pip install -e ../fd-open-data-protocol

Usage

1. Discover candidate data sources

# From a keyword (uses LLM web search)
fd-scraw-harness discover "Chinese GDP data"

# From a direct URL
fd-scraw-harness discover --url https://data.stats.gov.cn

2. Analyze a candidate via ego-browser

fd-scraw-harness analyze --discovery-id 1 --candidate-index 0
# or
fd-scraw-harness analyze --discovery-id 1 --url https://data.stats.gov.cn

3. Generate a DatasourceManifest

fd-scraw-harness generate --discovery-id 1

4. Review and approve

fd-scraw-harness list                    # list all manifests
fd-scraw-harness list --status draft     # filter by status
fd-scraw-harness approve 1               # approve manifest
fd-scraw-harness export 1                # print YAML to stdout
fd-scraw-harness export 1 -o manifest.yaml  # export to file

5. Analyze coverage (NEW!)

Automatically analyze which candidate data sources are already covered by existing sources in fd-open-data-mcp or fd-industry-data:

# Run coverage analysis
uv run scripts/analyze_coverage.py

# With verbose logging
uv run scripts/analyze_coverage.py --verbose

This will:

Output example:

================================================================================
📊 覆盖分析报告
================================================================================

总计候选数据源: 320
  ✅ 已覆盖 (covered): 4
  ⚠️  部分覆盖 (partial): 0
  🆕 新数据源 (new): 316
  ❓ 未知 (unknown): 0

💡 建议:
  • 优先处理 'new' 状态的数据源(新增价值)
  • 谨慎处理 'covered' 状态的数据源(可能重复)
  • 评估 'partial' 状态的数据源(可能有独特数据)
================================================================================

Integration with discovery workflow:

The coverage analysis automatically runs after discovery and updates the adjusted_score field in the database. Use adjusted_score instead of score to prioritize truly new data sources.

Configuration

Copy .env.example to .env and configure:

# Database (default: SQLite at data/harness.db)
HARNESS_DATABASE_URL=postgresql+psycopg2://user:pass@host:5432/db

# LiteLLM model
HARNESS_LITELLM_MODEL=deepseek-chat
HARNESS_MODEL_DISCOVERY=doubao-pro-32k
HARNESS_MODEL_GENERATION=deepseek-chat

# API keys (set the ones you need)
DEEPSEEK_API_KEY=sk-...
ARK_API_KEY=...        # for Doubao via Volcengine Ark

Architecture

keyword/URL → discover (LLM search) → analyze (ego-browser) → generate (LLM → YAML) → approve → export

Using as MCP Server

The harness can be used as an MCP server integrated with agents like OpenCode and Claude Code.

Quick Setup

Add this to your ~/.config/opencode/opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "fd-scraw-harness": {
      "enabled": true,
      "command": "uv",
      "args": ["run", "--directory", "/Users/chengsishi/finddata/fd-scraw-harness", "python", "-m", "fd_scraw_harness.server"],
      "env": {
        "LINJIE_API_KEY": "sk-...",
        "HARNESS_LITELLM_MODEL": "linjie/gm51model"
      }
    }
  }
}

Or set LINJIE_API_KEY in your shell environment before starting the agent.

Available MCP Tools

Once connected, agents can call:

Tool Description
harness_status() Report server capabilities (mode, models, ego-browser availability)
discover_sources(keyword) Discover candidates from keyword via LLM web search
discover_sources(url="...") Analyze direct URL (skips LLM search)
analyze_page(url, discovery_id) Page structure analysis via ego-browser
generate_manifest(discovery_id) Generate DatasourceManifest YAML
list_candidates(discovery_id) List discovered sources with coverage status
list_manifests(status?) List manifests filtered by status
approve_manifest(manifest_id) Mark draft manifest as approved
reject_manifest(manifest_id) Reject a draft manifest
export_manifest(manifest_id) Export approved manifest as YAML text
coverage_report() Full coverage analysis report
test_spider(manifest_id_or_path, test_type?, verbose?) Test spider implementation (integer = manifest id, string = spider file path)
test_all_spiders(limit?, parallel?) Batch test all spiders

Example Workflow

Agent can now:

1. harness_status() → verify server is ready
2. discover_sources(keyword="半导体行业数据源") → get discovery_id
3. list_candidates(discovery_id=N) → see discovered sources
4. analyze_page(url="...", discovery_id=N) → analyze top candidate
5. generate_manifest(discovery_id=N) → create manifest
6. approve_manifest(M) → mark as ready
7. export_manifest(M) → get full YAML
8. test_spider(M) → validate generated spider
9. coverage_report() → check for duplicates

All without leaving the agent’s workflow!

Environment Variables

Required for LLM calls:

Optional model selection:

Database:

Async Architecture (v0.2.0+)

Starting from v0.2.0, the MCP server uses async tool handlers for improved concurrency and throughput:

Deployment

The async MCP server runs on FastMCP’s async runtime. No special deployment changes needed — app.run() handles the event loop. For production, ensure your environment supports async Python (Python 3.10+).

Concurrency Tuning

Environment variables for concurrency limits:

Timeout Configuration

Per-tool timeouts (seconds):

Central state (platform integration)

Pipeline state lives in the central fd_open_data PG since the harness-platform-integration change. Point the harness at it before use:

export HARNESS_DATABASE_URL='postgresql://fd:<password>@<db-host>:30432/fd_open_data'

Without the env var the harness falls back to a local sqlite (kept for tests only). One-time backfill: scripts/migrate_sqlite_to_pg.py (idempotent, backs up the sqlite file first). Any machine pointing at the same DSN shares one funnel.

Landing generated sources into fd-industry-data

Approved exports are landing-ready for the content repo. The contract:

Landing (runs in the fd-industry-data checkout; local admission checks must pass before anything is committed):

cd ../fd-industry-data
python3 scripts/land_source.py /tmp/x/manifest.yaml /tmp/x/spider.py
# then: trigger a test run via MCP platform_trigger, and light up later
# by adding `schedule:` to spiders/<src>/manifest.yaml in its own commit