Boyce

io.github.boyce-io由 GitHub 账号 boyce-io 发布v0.1.1更新于 Oct 24, 2026

Deterministic SQL compiler for AI agents. Your agent stops guessing SQL.

概览

AI 生成的概览

本地 MCP 服务器,为 AI 助手提供结构化数据库上下文和确定性 SQL 编译器,让助手生成并校验 SQL 而非猜测

可以做什么
从 dbt、LookML、DDL、SQLite、Django、SQLAlchemy、Prisma、CSV 或 Parquet 来源导入模式与语义上下文,并保存查询时自动注入的认证业务定义。返回完整模式上下文和 StructuredFilter 格式,供宿主模型自行构造查询。将自然语言请求转换为确定性 SQL,并附带 NULL 风险检查与 EXPLAIN 预检。在不执行的情况下校验手写 SQL,包括 Redshift 语法检查。执行只读 SELECT 查询,并分析列的空值率、去重计数与最小/最大值。检查数据库连通性、快照新鲜度和环境健康状况。
适用场景
适合助手需要针对 Postgres、Redshift、DuckDB 或 BigQuery 编写 SQL,并希望基于真实模式和连接关系而非猜测的场景。也适合需要可重复、逐字节一致的 SQL 输出,以及在查询到达生产库前做预检的团队。
运行要求
需要 Python 3.10+ 并在本地安装 boyce 包(pip 或 uv);postgres 附加组件启用实时适配器。BOYCE_DB_URL 连接字符串可选,启用后可实时查询、数据剖析和 EXPLAIN 预检。使用自身模型的 MCP 宿主无需 LLM 密钥;CLI 或 HTTP 方式需要 BOYCE_PROVIDER 以及 ANTHROPIC_API_KEY 或 OPENAI_API_KEY 等提供商密钥。仅支持桌面 MCP 宿主。
安装前请注意
BOYCE_DB_URL 含数据库凭据,安装向导会将其写入宿主配置文件。实时查询工具会访问真实数据库,虽然写操作会被拒绝并设有语句超时。若配置内置规划器,ANTHROPIC_API_KEY 或 OPENAI_API_KEY 等提供商密钥会存放在环境变量中,请求将发送给该提供商。模式与业务定义按会话保存在内存中。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Boyce,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

Boyce: Semantic Protocol & Safety Layer for Agentic Database Workflows

The semantic safety layer for agentic database workflows. Boyce connects LLMs to live database context with built-in safety rails.

Named for Raymond F. Boyce, co-inventor of SQL (1974) and co-author of Boyce-Codd Normal Form (BCNF).

AI agents querying databases without proper context generate unreliable SQL — working from incomplete schemas, inferring column names, guessing join paths. Boyce gives agents the structured database intelligence they need to generate correct, safe SQL every time — through three interconnected systems:

LayerWhat it does
SQL Compilerask_boyce — NL → StructuredFilter → deterministic SQL. Zero LLM in the SQL builder. Same inputs, same SQL, byte-for-byte, every time.
Database Inspectorquery_database / profile_data — Live Postgres/Redshift adapters let your agent see real schema and real data distributions before writing a single filter.
Query VerificationPre-flight EXPLAIN loops on every generated query. Bad SQL is caught at planning time, not at 2am in your on-call rotation.

Why does this matter? → The Null Trap: Your AI Agent's SQL Is Correct. The Answer Is Still Wrong.


Install

Requires Python 3.10+

bash
pip install boyce
# With live Postgres/Redshift adapter (enables EXPLAIN pre-flight + column profiling)pip install "boyce[postgres]"
bash
# uv (recommended)uv pip install boyceuv pip install "boyce[postgres]"

From source:

bash
git clone https://github.com/boyce-io/boyceuv pip install -e "boyce/"

Quickstart

After installing, run boyce init to configure your MCP host automatically:

bash
boyce init

The wizard detects Claude Desktop, Cursor, Claude Code, and JetBrains (DataGrip, IntelliJ, etc.), and writes the correct config block for each.

Developing from source? The repo includes a setup script:

bash
./quickstart.sh   # detects uv or python, installs package, writes .env template

Configure Your MCP Host

The fastest path is boyce init — it detects your MCP host and writes the config automatically:

bash
boyce init

Or configure manually. There are two setup paths depending on your host:


Path 1 — MCP Hosts (No LLM key required)

If you're using Claude Desktop, Cursor, Claude Code, Codex, Cline, Windsurf, JetBrains (DataGrip, IntelliJ), or any MCP-compatible host, you do not need to configure an LLM provider for Boyce. The host's own model handles reasoning — Boyce supplies the schema context and deterministic SQL compiler via get_schema and ask_boyce. Only BOYCE_DB_URL is needed (and even that is optional).

Claude Desktop (~/Library/Application Support/Claude/claude_desktop_config.json):

json
{  "mcpServers": {    "boyce": {      "command": "boyce",      "env": {        "BOYCE_DB_URL": "postgresql://user:pass@host:5432/db"      }    }  }}

Cursor (.cursor/mcp.json in project root):

json
{  "mcpServers": {    "boyce": {      "command": "boyce",      "env": {        "BOYCE_DB_URL": "postgresql://user:pass@host:5432/db"      }    }  }}

Path 2 — With Boyce's Built-in NL→SQL

If you're using the CLI (boyce ask), HTTP API, or a non-MCP client (e.g., the VS Code extension), configure Boyce's internal query planner with your LLM provider:

json
{  "mcpServers": {    "boyce": {      "command": "boyce",      "env": {        "BOYCE_PROVIDER": "anthropic",        "BOYCE_MODEL": "claude-sonnet-4-6",        "ANTHROPIC_API_KEY": "sk-ant-...",        "BOYCE_DB_URL": "postgresql://user:pass@host:5432/db"      }    }  }}

Boyce supports any LLM provider available through LiteLLM: Anthropic, OpenAI, Ollama (local), vLLM (local), Azure, Bedrock, Vertex, Mistral, and more.


BOYCE_DB_URL is optional on both paths. Without it, Boyce runs in schema-only mode — SQL generation still works; EXPLAIN pre-flight and live query tools return "status": "unchecked".


Environment Variables

VariableWhen neededExamplePurpose
BOYCE_PROVIDERPath 2 only (CLI/HTTP/non-MCP)anthropicLiteLLM provider name
BOYCE_MODELPath 2 only (CLI/HTTP/non-MCP)claude-sonnet-4-6Model ID passed to LiteLLM
ANTHROPIC_API_KEYWhen using Anthropicsk-ant-...Anthropic credentials
OPENAI_API_KEYWhen using OpenAIsk-...OpenAI credentials
BOYCE_DB_URLOptional (either path)postgresql://user:pass@host:5432/dbasyncpg DSN — enables EXPLAIN pre-flight + live query tools
BOYCE_HTTP_TOKENPath 2 HTTP API onlymy-secret-tokenBearer token for boyce serve --http
BOYCE_STATEMENT_TIMEOUT_MSOptional30000Per-statement timeout in ms (default: 30s)

MCP Tools

ToolDescription
ingest_sourceParse a SemanticSnapshot from dbt manifest, dbt project, LookML, DDL, SQLite, Django, SQLAlchemy, Prisma, CSV, or Parquet.
ingest_definitionStore a certified business definition — injected automatically at query time.
get_schemaReturn full schema context + StructuredFilter format docs. Used by MCP hosts so the host LLM can construct queries without a Boyce API key.
ask_boyceFull NL → SQL pipeline: query planner (LiteLLM) → deterministic kernel → NULL trap check → EXPLAIN pre-flight.
validate_sqlValidate hand-written SQL — EXPLAIN pre-flight, Redshift lint, NULL risk — without executing.
query_databaseExecute a read-only SELECT against the live database. Write operations rejected at two independent layers.
profile_dataNull %, distinct count, min/max for any column — surface data quality issues before they affect query results.
check_healthOperational health check — DB connectivity, snapshot freshness, actionable fix commands. Call when queries fail unexpectedly.

Architecture

SemanticSnapshot (JSON)        │        ▼  ingest_source ┌─────────────────────────────────────────────┐ │          SemanticGraph (NetworkX)            │  ← in-memory, loaded per session │  nodes = entities (tables/views/dbt models) │ │  edges = joins  (weighted by confidence)    │ └─────────────────────────────────────────────┘        │                         │        ▼  ask_boyce              ▼  (internal)  QueryPlanner                 Dijkstra  (LiteLLM)                    join resolver  NL → StructuredFilter             │        │                           │        └──────────┬────────────────┘                   ▼           kernel.process_request()          ← ZERO LLM HERE           SQLBuilder (dialect-aware)                   │                   ▼           EXPLAIN pre-flight                ← Query Verification           (PostgresAdapter)                   │                   ▼            SQL + validation result

Dialect support: redshift, postgres, duckdb, bigquery

Redshift safety rails (safety.py): Automatic linting for LATERAL, JSONB, REGEXP_COUNT, lookahead regex patterns, and numeric cast rewrites for Redshift 1.0 (PG 8.0.2).


Scan CLI

bash
# Scan a single fileboyce scan demo/magic_moment/manifest.json
# Scan a directory (auto-detects all parseable sources)boyce scan ./my-project/ -v
# Save snapshots for MCP server useboyce scan ./my-project/ --save

10 parsers: dbt manifest, dbt project, LookML, SQLite, DDL, CSV, Parquet, Django, SQLAlchemy, Prisma.


Verify the Install

bash
# Unit tests — no DB required, runs in ~4 secondspython boyce/tests/verify_eyes.py
# Expected output:# Ran 15 tests in 3.5s# OK# ✅  All checks passed.

SemanticSnapshot Format

The ingest_source tool accepts a SemanticSnapshot JSON dict. Minimal example:

json
{  "snapshot_id": "<sha256>",  "source_system": "dbt",  "entities": {    "entity:orders": {      "id": "entity:orders",      "name": "orders",      "schema": "public",      "fields": ["field:orders:order_id", "field:orders:revenue"]    }  },  "fields": {    "field:orders:order_id": {      "id": "field:orders:order_id",      "entity_id": "entity:orders",      "name": "order_id",      "field_type": "ID",      "data_type": "INTEGER"    }  },  "joins": []}

See boyce/tests/live_fire/mock_snapshot.json for a complete field/entity example.


Project Layout

boyce/                          ← PRIMARY — headless FastMCP server + pip package├── boyce/│   ├── server.py               ← MCP entry point (8 tools)│   ├── kernel.py               ← Deterministic SQL kernel│   ├── graph.py                ← SemanticGraph (NetworkX)│   ├── safety.py               ← Redshift compatibility rails│   ├── types.py                ← Protocol contract (Pydantic)│   ├── scan.py                 ← Scan CLI (boyce scan)│   ├── connections.py          ← DSN persistence (ConnectionStore)│   ├── doctor.py               ← Environment diagnostics (boyce doctor)│   ├── sql/                    ← SQLBuilder, dialect layer, join resolver│   ├── parsers/                ← 10 parsers (dbt, lookml, ddl, sqlite, csv, etc.)│   ├── planner/                ← QueryPlanner (LiteLLM → StructuredFilter)│   └── adapters/               ← PostgresAdapter (Eyes)└── tests/    ├── verify_eyes.py          ← 15-test suite, no DB required    ├── test_parsers.py         ← Parser tests (all 10 parsers)    ├── test_scan.py            ← Scan CLI tests    └── live_fire/              ← Docker Compose integration tests

Status

CapabilityStatus
NL → SQL (deterministic kernel)Operational
SemanticGraph (join resolution)Operational
10 source parsersOperational
Scan CLI (boyce scan)Operational
PostgresAdapter (read-only)Operational
EXPLAIN pre-flight validationOperational
NULL Trap detectionOperational
Redshift 1.0 safety lintingOperational
Snapshot persistence across restartsOperational
Audit logging (append-only JSONL)Operational
Business definitions (ingest_definition)Operational
DSN persistence (ConnectionStore)Operational
Environment diagnostics (boyce doctor / check_health)Operational
Multi-snapshot mergePlanned

Support


Copyright 2026 Convergent Methods, LLC. MIT License.

来源:README.md,提交 9aad343

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v0.1.1最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分