horizon-mcp-demo-extended-v2
A demo MCP server with two governed systems (pipeline semantic layer and predictive model) for querying and scoring professional services opportunities with cross-system governance.
README
Horizon MCP Demo -- Extended v2
Companion reference implementation for the Horizon Data Partners white paper The Governed Data Layer: Why AI Agents Fail Without One, and How to Build It.
Two governed systems, one agent:
+---------------------------+
| Claude agent |
| scripts/run_two_server_ |
| agent.py |
+------+-------------+------+
| MCP (SSE) |
+--------------+ +---------------+
v v
+-----------------------------+ +--------------------------------+
| Pipeline Semantic Layer | | Predictive Model Service |
| port 8001 | | port 8002 |
| dbt Core + DuckDB | | DuckDB segment store |
| list_models | | describe_inputs |
| get_model_details | | describe_outputs |
| get_metric_definitions | | validate_payload |
| query_data | | score_opportunity |
| owns: win_rate, fees, | | owns: segments, matching, |
| margin, velocity | | the 6 outcome estimates |
+-----------------------------+ +--------------------------------+
Why v2 exists
The first extension (horizon-mcp-demo-extended) wired a P&C insurance semantic layer into this same predictive model. Every tool call succeeded and the agent produced numerically precise, analytically meaningless answers -- insurance policies are not professional services opportunities. The failure was not technical; it was the absence of cross-system governance.
v2 fixes both failures of v1:
- Governance first.
docs/CROSS_SYSTEM_GOVERNANCE.mdwas written and approved before any code: a domain compatibility check, an approved exact field mapping (no assumptions -- and the document explains why that is the correct baseline), and a governed interface definition that the model server returns fromdescribe_inputsand enforces before scoring. The server refuses out-of-contract input; it does not adapt it. - SSE transport, not stdio. Both MCP servers run as independent local
HTTP processes (ports 8001/8002) and the agent connects with
mcp.client.sse.sse_client. With no stdio subprocesses nested inside the agent's event loop, the Windows anyioBrokenResourceErrorfrom v1 cannot occur, and the fix generalizes to any number of servers.
Repository layout
docs/CROSS_SYSTEM_GOVERNANCE.md governance doc (read this first)
seeds/ opportunities.csv, jobs.csv, pipeline_summary.csv
models/staging, models/marts dbt models (the semantic layer)
models/schema.yml descriptions + tests served through MCP
model_data/analytical_segments.csv the model's trained segment artifact
model_store/ built by scripts/build_model_store.py (gitignored)
mcp_server/pipeline_mcp_server.py System A, port 8001 (SSE)
mcp_server/predictive_model_mcp_server.py System B, port 8002 (SSE)
scripts/build_model_store.py loads the segment CSV into DuckDB
scripts/smoke_test_servers.py exercises all 8 tools, no API key needed
scripts/run_two_server_agent.py the 5-question agent demo
Quickstart (Windows PowerShell)
From the repository root:
# 1. environment
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txt
# 2. build the semantic layer (profiles.yml is at the repo root; run from here)
dbt seed
dbt run
dbt test
# 3. build the model's segment store
python scripts\build_model_store.py
# 4. start the servers -- one PowerShell terminal each
python mcp_server\pipeline_mcp_server.py # terminal 1, port 8001
python mcp_server\predictive_model_mcp_server.py # terminal 2, port 8002
# 5. pre-flight (terminal 3) -- 17 checks, no API key required
python scripts\smoke_test_servers.py
# 6. run the agent demo (terminal 3)
$env:ANTHROPIC_API_KEY = "sk-ant-..."
python scripts\run_two_server_agent.py
The five demo questions
- What does the pipeline semantic layer contain and what metrics are governed?
- What are the win rates and average fees by service line and client type in the pipeline data?
- Score a new Advisory/Business/Healthcare/New/Referral opportunity -- what are the six outcome estimates and how reliable is the segment match? (Deliberately chosen: its finest segment has only 27 observations, under the 30 minimum, so outcomes match at levels 1-2 and the response says so.)
- For open opportunities in the pipeline that have been open longer than the model's estimated DaysSellToStart, identify which ones are delayed and by how much. (Cross-system: mart_open_pipeline from System A, estimates per distinct segment from System B, joined by the agent.)
- Which service line has the highest fee-to-margin ratio in the historical data, and what does the model predict for win probability in that segment going forward? (Historical metric and forward estimate side by side, from independent definitions.)
Token logging
Each run writes logs/agent_run_<timestamp>.json in the same format as the
original horizon-mcp-demo, extended per server:
- every
tool_callsentry carries aserverfield; question_totalsandrun_totalscarryby_server, holdingtool_call_countand attributed API tokens. Attribution rule: an API call whose response invokes tools has its tokens split evenly across the distinct servers invoked in that response; synthesis calls (no tools) are attributed to"synthesis".
Data notes
- The pipeline seeds are a static snapshot:
days_openfor open opportunities is as of 2026-07-15, so demo output is reproducible. model_data/analytical_segments.csvis the model's trained artifact (the DuckDB analogue ofdbo.analytical_segmentsfrom HorizonDataPredictiveModel), built from a synthetic 1,400-record training corpus. Every coarser level is the exact observation-weighted aggregate of its children, so the numbers survive scrutiny.- Dimension drop order when coarsening: LeadSource, NewVsExisting, Industry,
ClientType, ServiceLine (level 0 finest to level 5 overall) -- the same
order as
usp_BuildSegments.
Troubleshooting
- Port already in use -- something else holds 8001/8002. Find it with
netstat -ano | findstr :8001, stop it, or change the PORT constant at the top of the affected server file (and the URL in both scripts). - Windows Firewall prompt on first server start -- uvicorn binding 127.0.0.1 can trigger a Defender prompt. Allow access; the servers bind loopback only.
- DuckDB lock errors from dbt -- stop the pipeline server before
re-running
dbt seed/dbt run; the server holds a read-only connection but dbt needs the writer. manifest.json not found/Model store not found-- run steps 2 and 3 of the quickstart before starting the servers.- Agent cannot connect -- both servers must be running first; the agent does not spawn them (that is the point of the SSE architecture).
Relationship to the other repositories
horizon-mcp-demo-- the original single-server insurance demo. Untouched by this project.HorizonDataPredictiveModel-- the SQL Server implementation this model service ports. The DuckDB segment-matching SQL mirrorsusp_ApplyModel's CROSS APPLY pattern: per-outcome, OR-IS-NULL per dimension, finest qualifying level, minimum 30 observations.
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。