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.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.