seconds-mcp
Summarizes tabular data (ambulance dispatch response times) and lets AI agents query it in natural language via MCP tools for aggregates, grouping, and trends.
README
SECONDS — Data Summary API + AI Agent Interface
A small, focused service that summarizes tabular data and lets an AI agent query it in natural language — e.g. "what was the average A1 response time in September?"
The sample dataset models the domain of the SECONDS ambulance-dispatch
software: each row is an emergency call with a region, an urgency class
(A1/A2/B) and a response time in seconds — the key performance metric
for ambulance services.
Three ways to reach the same summarization engine:
- A REST API (FastAPI) with auto-generated OpenAPI docs at
/docs. - An MCP server that exposes the summaries as tools, so Claude (Claude Code / Claude Desktop) can answer questions by calling them directly.
- A web dashboard (Reflex + buridan/ui) with docs, database-grounded statistics + a reset button, and a live trace of every MCP / REST call.
Quick start
One script bootstraps everything (virtualenv, dependencies, sample data) and launches a service — Linux & macOS:
./start.sh # REST API → http://localhost:8000 (docs at /docs)
./start.sh web # dashboard → http://localhost:3000
./start.sh mcp # MCP server (stdio) for Claude
./start.sh test # run the test suite
./start.sh setup # just set up the venv + deps + data, don't launch
Prefer to do it by hand? See Setup below.
Architecture
All query logic lives in a single core layer (seconds/queries.py); the REST
routes and the MCP tools are thin wrappers over it — one implementation, two
front doors. The Python core lives at the root; the whole web UI is isolated
under web/.
seconds/ # CORE — the summarization engine (API + MCP share it)
schema.py # column metadata + validation whitelists (the safety net)
db.py # read-only SQLite connection helper
queries.py # list_schema, distinct_values, summarize, group_by, trend
models.py # Pydantic request/response models + enums
api.py # FastAPI app (thin routes)
mcp_server.py # FastMCP server (thin tools)
stats.py # grounded headline statistics for the dashboard
call_log.py # trace log (separate DB) for MCP + REST calls
seed/generate_data.py # sample-data generator (fresh random data each run)
tests/ # unit tests (core) + API tests (TestClient)
data/ # generated SQLite databases (git-ignored)
web/ # Reflex + buridan/ui web UI — self-contained
rxconfig.py # Reflex config (run `reflex run` from here)
dashboard/ # the app: pages (docs / database / logs) + state
components/ # buridan/ui component kit
blocks/ # buridan/ui example blocks
assets/ # static assets + globals.css
start.sh # one-command launcher (see Quick start)
Safety: column and aggregation names are validated against a whitelist in
schema.py before any SQL is built; filter values are always bound
parameters; and query connections are opened read-only. So a request can never
inject SQL or mutate data.
Setup
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
# Generate the sample database (data/seconds.db)
python -m seed.generate_data
Run the REST API
uvicorn seconds.api:app --reload
Open http://localhost:8000/docs for interactive docs. Examples:
# Discover the schema
curl localhost:8000/schema
# Average A1 response time in September
curl -X POST localhost:8000/summarize -H 'Content-Type: application/json' -d '{
"metric": "avg",
"column": "response_time_seconds",
"filters": {"urgency": "A1", "date_from": "2025-09-01", "date_to": "2025-09-30"}
}'
# Average response time per region
curl -X POST localhost:8000/group-by -H 'Content-Type: application/json' -d '{
"metric": "avg", "group_by": "region", "column": "response_time_seconds"
}'
# Monthly response-time trend with a 3-month moving average
curl -X POST localhost:8000/trend -H 'Content-Type: application/json' -d '{
"metric": "avg", "column": "response_time_seconds",
"bucket": "month", "moving_average_window": 3
}'
Endpoints
| Method & path | Purpose |
|---|---|
GET /health |
Liveness check |
GET /schema |
Columns, roles, example values, available ops |
GET /columns/{col}/values |
Distinct values of a categorical column |
POST /summarize |
Single aggregate (avg/sum/min/max/count) + filters |
POST /group-by |
Aggregate grouped by a dimension or time bucket |
POST /trend |
Time-series with optional moving average |
Hook up the AI agent (MCP)
The MCP server exposes five tools — list_schema, list_column_values,
summarize, group_by, trend — over stdio.
Try it standalone with the MCP Inspector:
mcp dev seconds/mcp_server.py
Register it with Claude Code. Use the absolute path to this project's venv
Python so the mcp/fastapi/seconds packages are importable (bare python
may resolve to a different interpreter without the dependencies):
claude mcp add seconds -- "$(pwd)/.venv/bin/python" -m seconds.mcp_server
If you move the project or recreate the venv, re-run this command so the path stays correct.
…or add it to a Claude Desktop config (claude_desktop_config.json). Use the
absolute path to this project's Python (the venv) so seconds is importable:
{
"mcpServers": {
"seconds": {
"command": "/absolute/path/to/folder/.venv/bin/python",
"args": ["-m", "seconds.mcp_server"]
}
}
}
Then ask, in natural language:
"What was the average A1 response time in September, and how does it compare per region?"
The agent discovers the schema via list_schema, then calls summarize /
group_by with the right column and filters and explains the result.
Web dashboard
A Reflex + buridan/ui app with three pages:
- Docs — installation, features, how-to, and a schema table rendered live
from
seconds/schema.py. - Database — headline statistics computed live from the database, plus a Reset / reinitialize button. Each reset regenerates a fresh random dataset; the live statistics recompute from it, so they stay the ground truth you can validate the agent's answers against.
- Logs — a newest-first trace of every MCP tool call and REST request (source, arguments, status, duration).
./start.sh web # easiest: bootstraps + launches the dashboard
# …or by hand:
pip install -e ".[ui]" # Reflex + buridan/ui (one-time)
python -m seed.generate_data # ensure data/seconds.db exists
cd web && reflex run # dashboard at http://localhost:3000
The whole web UI is self-contained under web/, so reflex run is invoked
from there. The dashboard imports the seconds core directly (no HTTP hop).
Call logging is written to a separate database (data/seconds_logs.db), so
it survives a database reset and never touches the read-only incidents data.
Backend server: this project pins
REFLEX_USE_GRANIAN=false(seeweb/.env) so Reflex serves its backend with uvicorn. Granian's Rust/pyo3 layer panics on state events in this version; uvicorn avoids it. The buridan components were added withburidan init && buridan apply --preset b0 && buridan add ...and live inweb/components/andweb/blocks/.
Tests
pytest -q
Tests build a small database with known values and assert exact aggregates
(including that date_to is inclusive and that invalid columns/metrics are
rejected).
Out of scope (next steps)
Auth, pagination, write endpoints, multi-table joins and deployment were left out to keep this focused; the layered structure leaves room to add them.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。