sheetspec

sheetspec

Validates Excel (.xlsx) workbooks against reviewed, lockable acceptance contracts, catching errors and outputting structured issues that agents can repair.

Category
访问服务器

README

SheetSpec

<!-- mcp-name: io.github.helloo1568/sheetspec -->

English | 简体中文

CI PyPI Python License: MIT

Catch spreadsheet delivery errors before an AI agent says "done."

SheetSpec validates .xlsx workbooks against reviewed, lockable acceptance contracts. It catches missing formulas, duplicate identifiers, wrong totals, invalid data types, and unauthorized template edits, then returns structured issues at worksheet, cell, or range level that an agent can repair.

It provides deterministic Excel/XLSX validation, contract testing, and quality gates for workbooks created or modified by AI agents. It is not another Excel chatbot or a silent auto-fixer.

user requirements -> reviewed contract -> locked acceptance target
-> agent creates or edits Excel -> SheetSpec validates independently
-> structured repair issues -> agent repairs and revalidates -> deliver after passing

SheetSpec Agent Gate demo

Why agents need an independent gate

An agent can create a workbook that opens successfully and looks plausible while still shipping hidden errors. Asking the same agent to "check its work" is useful, but it is not an independent acceptance test: the agent can overlook the same mistake, reinterpret the requirement, or change the target while repairing the file.

SheetSpec separates creation from acceptance:

Capability Risk addressed
Reviewed contracts Business requirements being guessed from workbook structure
Contract locks Acceptance-target changes going undetected after work begins
Independent validation "The file saved" being treated as "the task is correct"
Structured repair issues Vague retries without a rule, worksheet, cell, expected value, or actual value
Protected baseline ranges Unauthorized template value or formula changes going undetected

SheetSpec validates only the rules you declare. A passing result means the declared contract passed; it does not claim that every unstated business assumption is correct.

Try SheetSpec

SheetSpec requires Python >=3.11,<3.15. With uv, you can run it without installing it permanently.

1. Verify the CLI

uvx sheetspec --version

Or install it with pip:

pip install sheetspec

2. Run the included broken/fixed demo

git clone --depth 1 https://github.com/helloo1568/SheetSpec.git
cd SheetSpec
uv sync
uv run python examples/create_demo.py

uv run sheetspec lock examples/sales-report.spec.yaml \
  --baseline examples/sales-report-template.xlsx \
  --output examples/sales-report.spec.lock.demo.json

uv run sheetspec check examples/sales-report-broken.xlsx \
  --spec examples/sales-report.spec.yaml \
  --lock examples/sales-report.spec.lock.demo.json \
  --format text

uv run sheetspec check examples/sales-report-fixed.xlsx \
  --spec examples/sales-report.spec.yaml \
  --lock examples/sales-report.spec.lock.demo.json \
  --format json

The broken workbook demonstrates missing month headers, duplicate orders, text stored as an amount, missing and inconsistent formulas, a wrong total, and protected-template changes. The fixed workbook passes the same locked contract. Its JSON summary includes:

{
  "status": "passed",
  "summary": {
    "checks": 12,
    "passed": 12,
    "warnings": 0,
    "errors": 0,
    "skipped": 0,
    "total_issues": 0
  }
}

3. Validate your own workbook

uvx sheetspec inspect report.xlsx --format json
uvx sheetspec init report.xlsx --output report.spec.yaml
# Review report.spec.yaml before treating it as the acceptance target.
uvx sheetspec lock report.spec.yaml --output report.spec.lock.json
uvx sheetspec check report.xlsx \
  --spec report.spec.yaml \
  --lock report.spec.lock.json \
  --format json

init drafts checks from workbook structure; it does not infer your complete business intent. Review the contract before locking it.

Use it with your agent

Run SheetSpec as a local STDIO MCP server:

uvx sheetspec mcp

Copy-paste setup instructions are available for Codex, Claude Code, Cursor, and OpenCode.

The recommended delivery loop is:

inspect -> draft/review -> lock -> create/edit -> validate
-> repair ERROR -> validate again -> deliver

MCP makes SheetSpec callable. The included Agent Skill defines when it should be called, and CI can enforce the same acceptance contract after the agent finishes.

Validation output agents can repair

Every issue uses a stable machine-readable shape:

{
  "issue_code": "duplicate-value",
  "rule_id": "order-id-unique",
  "severity": "error",
  "sheet": "Raw Data",
  "cell": "A4",
  "range": null,
  "message": "发现重复值:SO-002",
  "expected": "unique",
  "actual": "SO-002",
  "suggestion": null,
  "related_cells": ["A3", "A4"]
}

Results are deterministically ordered and capped at 500 visible issues while preserving the total issue count.

SheetSpec validation report preview

How the Agent Gate works

flowchart LR
  A["Describe requirements"] --> B["Draft acceptance contract"]
  B --> C["Human reviews contract"]
  C --> D["Lock contract"]
  D --> E["Agent creates or edits Excel"]
  E --> F["Validate independently"]
  F -->|failed| G["Read structured issues and repair"]
  G --> F
  F -->|passed| H["Deliver workbook and report"]

The contract lock stores SHA-256 hashes for the normalized contract and optional baseline workbook. It detects changes; Git history, review, and CI remain the security boundary.

SheetSpec architecture

Contract example

version: "0.1"
name: Annual sales report acceptance
baseline: sales-report-template.xlsx

checks:
  - id: required-sheets
    type: required_sheets
    sheets: [Raw Data, Monthly Summary]

  - id: order-id-unique
    type: unique_values
    sheet: Raw Data
    range: A2:A500

  - id: amount-formulas
    type: formulas_required
    sheet: Raw Data
    range: F2:F500

  - id: annual-total
    type: total_equals_sum
    sheet: Monthly Summary
    total_cell: N2
    source_range: B2:M2
    tolerance: 0.01

  - id: protect-summary-header
    type: unchanged_ranges
    sheet: Monthly Summary
    ranges: [A1:N1]
    compare: both

Included rules

Rule Purpose
required_sheets Require worksheets
required_columns Require exact column names
required_cells Require non-empty cells or exact values
no_blank_values Reject blank cells in a range
unique_values Require unique values
allowed_values Restrict values to an allowlist
data_type Validate numbers, text, dates, booleans, or formulas
formulas_required Require formulas
formula_consistency Detect structural formula outliers
total_equals_sum Compare a total with the numeric source range
unchanged_ranges Protect baseline values and formulas

CLI reference

sheetspec --version
sheetspec inspect report.xlsx --format json
sheetspec init report.xlsx --output report.spec.yaml
sheetspec lock report.spec.yaml --output report.spec.lock.json
sheetspec check report.xlsx --spec report.spec.yaml --lock report.spec.lock.json --format json
sheetspec diff before.xlsx after.xlsx --format json
sheetspec report report.xlsx --spec report.spec.yaml --output report.html
sheetspec mcp

Exit codes:

0  validation passed
1  one or more error-level rules failed
2  invalid file, contract, baseline, or lock
3  internal error

MCP reference

Generic configuration:

{
  "mcpServers": {
    "sheetspec": {
      "command": "uvx",
      "args": ["sheetspec", "mcp"]
    }
  }
}

Tools:

  • inspect_workbook
  • draft_workbook_spec
  • validate_workbook
  • compare_workbooks
  • generate_validation_report

The test suite launches a real STDIO subprocess, initializes an MCP client session, lists all tools, and calls workbook inspection and validation end to end.

Agent Skill

Install skills/sheetspec/ in the agent's skill directory. The skill instructs the agent not to change the contract merely to pass validation, edit the workbook during validation, claim formula results were verified when cached values are missing, or claim delivery success while error-level issues remain. Contract locks and CI provide the enforceable checks around that workflow.

Technical boundaries

  • .xlsx workbooks are read-only; SheetSpec does not modify the source workbook.
  • openpyxl does not recalculate arbitrary Excel formulas.
  • Complex external formulas, VBA, Power Query, and pivot-table semantics are outside the v0.1 scope.
  • passed means all declared checks passed, not that the entire business model is universally correct.
  • Workbooks above 50 MB and rules covering more than 100,000 cells are rejected.
  • Results expose at most 500 visible issues while preserving the total issue count.

Roadmap

  • 0.2: optional LibreOffice recalculation, JUnit/SARIF output, and rule plugins;
  • 0.3: more templates, interactive MCP reports, and constrained repair helpers;
  • long term: a standard quality gate for spreadsheet-producing agents.

Open source

SheetSpec uses an original validation engine and depends on openpyxl, Pydantic, PyYAML, Typer, Jinja2, and the MCP Python SDK. See THIRD_PARTY_NOTICES.md.

License: MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选