Skip to main content
Glama

redflag-mcp

MCP 服务器,将反洗钱 (AML) 红旗知识作为可查询工具公开。合规官提出自然语言问题;服务器从本地向量数据库返回相关的、有来源的红旗信息。

概述

三个不同的工作流程:

  1. 提取 — 使用 LLM 从 PDF 或网页中提取 AML 红旗信息,并将其保存为 YAML

  2. 摄入 — 对 YAML 文件进行向量化并加载到本地向量数据库中

  3. 查询 — MCP 服务器针对该数据库回答语义搜索查询


Related MCP server: Financial Intelligence MCP Server

提取流水线

scripts/extract.py 获取监管文档(PDF 文件或 URL),将其文本发送给 OpenAI 模型,并将结构化的 YAML 文件写入 data/source/。每个提取的条目都包含一个指向原始文档的 source_url。

先决条件

uv sync --extra dev
export OPENAI_API_KEY=sk-...

批量添加 PDF(推荐工作流程)

分步指南:

  1. 将源 URL 添加到 red_flag_sources/pdflinks.txt — 每行一个 URL,按顺序排列。第 1 行 → 键 001,第 2 行 → 002,依此类推。

  2. 下载 PDF 并将其保存到 red_flag_sources/pdf/,命名为 NNN_short_descriptive_name.pdf,其中 NNN 与其在 pdflinks.txt 中的行位置匹配。

  3. 重新生成注册表: uv run python scripts/build_sources_registry.py

  4. 运行提取: uv run python scripts/extract.py --parallel

关键约束: 文件名中的 NNN_ 前缀必须与 pdflinks.txt 中的行号匹配。第 1 行 = 001_*.pdf,第 2 行 = 002_*.pdf,依此类推。这是提取器将每个 PDF 链接到其公共源 URL 的方式。


PDF 存储在 red_flag_sources/pdf/ 中,必须使用零填充的序列前缀命名:

red_flag_sources/pdf/
  001_fincen_alert_russian_sanctions_evasion.pdf
  002_ffiec_bsa_aml_examination_manual.pdf
  003_fatf_guidance_virtual_assets.pdf

每个序列号映射到源文档的公共 URL。在 red_flag_sources/pdflinks.txt 中维护此映射 — 每行一个 URL,按序列顺序排列:

# FinCEN Russian Sanctions Evasion Alert
https://fincen.gov/sites/default/files/2022-06/Alert%20FIN-2022-Alert001_508C.pdf

# FFIEC BSA/AML Examination Manual
https://bsaaml.ffiec.gov/manual

# FATF Guidance on Virtual Assets
https://www.fatf-gafi.org/...

空行和以 # 开头的行将被忽略。编辑 pdflinks.txt 后,重新生成 sources.yaml:

uv run python scripts/build_sources_registry.py

然后运行批量提取:

uv run python scripts/extract.py --parallel

仅提取新的(未处理的)PDF — 之前处理过的源会自动跳过。

批量提取命令

# Sequential batch
uv run python scripts/extract.py

# Parallel batch (4 workers by default)
uv run python scripts/extract.py --parallel

# Parallel batch with custom worker count
uv run python scripts/extract.py --parallel 8

# Force re-extract everything
uv run python scripts/extract.py --force --parallel

# Process only PDFs in a serial range (e.g. 001 through 005)
uv run python scripts/extract.py --range 001-005

# Range + parallel
uv run python scripts/extract.py --range 001-005 --parallel

# Force re-extract a range
uv run python scripts/extract.py --force --range 001-005 --parallel

注意: --range 仅适用于编号的 PDF。当激活范围时,Weblinks.md 中的 Web URL 将被排除。

单个源(临时)

# Extract from a local PDF
uv run python scripts/extract.py red_flag_sources/pdf/001_fincen_alert.pdf

# Extract from a URL
uv run python scripts/extract.py https://example.com/regulatory-guidance

# Re-extract a source that was already processed
uv run python scripts/extract.py --force red_flag_sources/pdf/001_fincen_alert.pdf

对于单个源 PDF,请先将 URL 添加到 pdflinks.txt 并运行 build_sources_registry.py,以便提取器可以在输出中填充 source_url。

功能说明

  1. 获取文档 — 下载网页(去除导航/页脚/脚本)或通过 pdfplumber 读取 PDF 中的文本

  2. 发送至 OpenAI — 提示 gpt-4o-mini(可通过 OPENAI_EXTRACTION_MODEL 覆盖)将每个不同的 AML 红旗指标提取为结构化 JSON

  3. 验证 — 根据 RedFlagSource 模式检查每个返回的红旗;无效条目将被跳过并发出警告

  4. 写入 YAML — 保存到 data/source/<slug>.yaml,每个红旗一个条目

  5. 更新清单 — 在 data/source/.extracted_sources.yaml 中记录源,以防止重复处理

输出模式

YAML 文件中的每个条目都有以下字段:

字段

类型

必需

描述

id

string

是

唯一标识符,例如 001-fincen-alert-01

description

string

是

红旗指标的独立描述

source_url

string

否

源文档的公共 URL

product_types

list[string]

否

适用的金融产品(例如 depository, crypto, msb)

industry_types

list[string]

否

适用的客户行业或部门(例如 oil_and_gas, government_benefits)

customer_profiles

list[string]

否

适用的客户原型(例如 small_business, charity_or_nonprofit)

geographic_footprints

list[string]

否

相关的地理位置或走廊(例如 southwest_border, mexico)

regulatory_source

string

否

源文档名称或权威机构(例如 FinCEN Alert FIN-2022-Alert001)

risk_level

string

否

high, medium 或 low

category

string

否

AML 类型学(例如 structuring, sanctions_evasion, shell_company)

simulation_type

string

否

可选的模拟复杂性代码(例如 1A, 2B)

去重

data/source/.extracted_sources.yaml 通过其规范路径或 URL 跟踪每个已处理的源。清单中已有的源在批量和单源模式下都会被跳过。使用 --force 强制重新提取源。


摄入

提取后,对 YAML 文件进行向量化并加载到向量数据库中:

uv run python scripts/ingest.py

对于初始本地语料库,仅摄入三个目标文件:

uv run python scripts/ingest.py \
  data/source/001_federal_child_nutrition_fraud.yaml \
  data/source/002_oil_smuggling_cartels.yaml \
  data/source/003_bulk_cash_smuggling_repatriation.yaml

这将使用 nomic-embed-text-v1.5 生成嵌入,并将记录插入到 data/vectors/ 的 LanceDB 中。在将 MCP 服务器连接到桌面客户端之前运行摄入;嵌入模型在首次使用时下载,在摄入期间比在服务器启动期间缓存效果更好。

OPENAI_API_KEY 对于摄入是可选的。设置后,摄入可以自动将缺失的元数据标记到派生的 LanceDB 记录中。未设置时,摄入将保留现有的 YAML 元数据,并使缺失的丰富咨询字段保持为空。源 YAML 文件不会被摄入过程重写。


MCP 服务器

# Start server (stdio mode, for Claude Desktop / Claude Code)
uv run python -m redflag_mcp

# Start in MCP inspector
uv run mcp dev src/redflag_mcp/server.py

# Start as HTTP server (for OpenAI agents or other HTTP clients)
MCP_TRANSPORT=http MCP_HOST=0.0.0.0 MCP_PORT=8000 uv run python -m redflag_mcp

服务器公开了三个工具:search_red_flags、get_red_flag 和 list_filters。摄入后它完全离线 — 查询时不需要 API 密钥。

从 Codex 使用

对于本地 Codex 线程,首选 stdio,以便 Codex 自动启动 MCP 服务器:

codex mcp add redflag-mcp -- zsh -lc 'cd /Users/learningmachine/Documents/Python-dev/redflag-mcp && HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1 uv run python -m redflag_mcp'

验证注册:

codex mcp list
codex mcp get redflag-mcp

然后启动一个新的 Codex 线程并按名称请求服务器,例如:

Use the redflag-mcp MCP server. List the available AML red flag filters.

如果您已经运行了 HTTP 服务器,则可以改为注册该服务器:

codex mcp add redflag-mcp-http --url http://127.0.0.1:8000/mcp

本地冒烟测试

摄入三个目标文件后,使用以下命令验证工具:

list_filters
search_red_flags(query="federal child nutrition program sponsor receives reimbursements inconsistent with its profile", product_types=["depository"])
search_red_flags(query="southwest border oil company wires for waste oil or hazardous materials")
search_red_flags(query="bulk cash moved by armored car service to Mexico")
get_red_flag(red_flag_id="001_federal_child_nutrition_fraud-01")

对于诸如“我在商业账户中应该寻找什么?”之类的模糊查询,调用代理应首先提出一个简短的咨询问题,涵盖产品/渠道、行业、客户概况、地理位置以及交易渠道或金额。对于特定查询,它应直接搜索。


开发

uv sync --extra dev              # Install dependencies
uv run pytest tests/             # Run tests
uv run ruff check src/           # Lint
uv run mypy src/                 # Type check

Available Tools

7 tools
classify_red_flag_requestA

Classify an AML red flag request before searching when the user asks which red flags apply to a product, customer, geography, industry, scenario, transaction pattern, or institution profile. Returns one route: needs_more_context, metadata_filter, filtered_relevance_search, or direct_relevance_search, plus the recommended next tool and arguments. Use it for ambiguous 'what red flags apply' requests; skip it when the user already gives specific metadata filters or a concrete scenario.

Inputs: query (required), limit, category, subjects, +6 more. Returns: object

filter_red_flagsA

Return AML red flags for exact metadata criteria without ranked relevance search. Use this for exact metadata requests, broad investigative subjects, and broad industry groups, such as high-risk depository structuring red flags, FINTRAC human trafficking red flags with subjects, trade logistics red flags with industry_groups, or red flags from regulators in France. category is the primary record classification; subjects is a broader eligibility layer that catches cross-category flags; typology_family is a broader proceeds or typology grouping. For example, a human-trafficking-relevant darknet crypto flag can have category="virtual_currency" while matching subjects=["human_trafficking"]. Paginate with next_cursor whenever truncated is true; search_red_flags is ranked and limit-based, with no cursor. For country or jurisdiction requests, translate names to ISO-style regulator_jurisdiction codes before filtering: France -> FR, Singapore -> SG, Australia -> AU, United Kingdom/UK -> GB, United States/US -> US, and European Union/EU regulators -> EU. Prefer filter_red_flags(regulator_jurisdiction="FR") for requests like "red flags from regulators in France." regulator_jurisdiction describes issuer jurisdiction; geographic_footprints describes affected geography or typology geography. Use search_red_flags instead for open-ended relevance questions. Successful responses include table-ready display hints in display and a portable Markdown fallback in markdown_table; clients decide how to render them.

Inputs: limit, cursor, detail, category, +16 more. Returns: object

get_red_flagB

Return one AML red flag by id, including source and citation metadata.

Inputs: red_flag_id (required). Returns: object

get_sourceA

Return bounded detail for one source by source_id, including citations, aggregate metadata, related red flag IDs, and short snippets. Use get_red_flag when full text for one red flag is needed.

Inputs: source_id (required). Returns: object

list_filtersA

List available filter values for product_types, industry_types, industry_groups, customer_profiles, geographic_footprints, subjects, typology_family, transaction_patterns, category, risk_level, regulator, and regulator_jurisdiction. Agents should call this before or during consultation when they need valid local filter values. category is the primary record classification; subjects is the broad investigative eligibility layer; typology_family is a broader proceeds or typology grouping. regulator_jurisdiction describes issuer jurisdiction; geographic_footprints describes affected geography or typology geography.

Inputs: no named parameters. Returns: object

list_sourcesA

List ingested AML red flag source coverage with citation URLs, source counts, aggregate metadata, and red flag IDs. Use when users ask what sources or citations the corpus covers.

Inputs: no named parameters. Returns: object

search_red_flagsA

Search AML red flags using natural-language context and optional filters.

Successful responses include table-ready display hints in display and a portable Markdown fallback in markdown_table; clients decide how to render them.

Agent guidance: use classify_red_flag_request before searching for ambiguous "what red flags apply" requests; skip that extra call when the user already gives specific metadata filters or a concrete scenario. If the user's request is vague, briefly ask for product/channel, industry, customer profile, geography, and transaction channel or volume before searching. If the request already names those details or has a specific scenario, search directly. Call list_filters when you need valid filter values. Use filter_red_flags for exact metadata requests and exhaustive enumeration; use search_red_flags for ranked relevance questions and increase limit for more ranked results because search has no cursor. For broad investigative topics such as human trafficking red flags, use subjects as an eligibility filter. Category is the primary record classification; subjects is a broader eligibility layer that catches cross-category flags; typology_family is a broader proceeds or typology grouping. For example, a human-trafficking-relevant darknet crypto flag can have category="virtual_currency" while matching subjects=["human_trafficking"]. For broad sector requests such as trade logistics red flags, use industry_groups as an eligibility filter. regulator_jurisdiction describes issuer jurisdiction; geographic_footprints describes affected geography or typology geography. For country or jurisdiction requests about issuing regulators, translate names to regulator_jurisdiction codes before filtering, such as France -> FR, Singapore -> SG, Australia -> AU, United Kingdom/UK -> GB, United States/US -> US, and European Union/EU regulators -> EU.

Inputs: query (required), limit, category, subjects, +7 more. Returns: object

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.2/5.0

    Scored across 7 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose: classification, exact filtering, single retrieval, source retrieval, listing filters, listing sources, and semantic search. No overlap or ambiguity.

    Naming Consistency5/5

    All tool names follow a consistent verb_noun pattern in snake_case (classify_red_flag_request, filter_red_flags, etc.), with predictable verbs like get_, list_, search_.

    Tool Count5/5

    7 tools is well-scoped for the AML red flag domain, covering classification, filtering, retrieval, and metadata browsing without unnecessary bloat.

    Completeness5/5

    The tool set provides a complete read-only surface: routing ambiguous requests, exact filtering, single record lookup, source detail, filter values, source coverage, and full-text search. No obvious gaps.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      A production-grade MCP server that provides financial ML tools including RAG search, anomaly detection, contract summarization, vendor graph analysis, and model drift monitoring using entirely free, open-source components.
      1
      -
    • A
      license
      A
      quality
      C
      maintenance
      An MCP server for anti-money laundering (AML) compliance, including customer due diligence, transaction monitoring, and SAR filing, compliant with 6AMLD, UK MLR 2017, and FinCEN.
      4
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      A Retrieval Augmented Generation MCP server that ingests documents into a local vector database and enables semantic search queries.
      9
      -