G2 Product Analytics MCP
Provides a governed analytics layer over synthetic product data, exposing MCP tools for investigating product metrics, slicing by dimensions, and comparing periods while preventing unrestricted SQL access.
README
G2 Product Analytics MCP
A portfolio project exploring a practical question:
How do you let an AI agent answer product-analytics questions autonomously without giving it unrestricted SQL access or letting it invent business definitions?
This project builds a small governed analytics layer, exposes it through Model Context Protocol (MCP), and lets an MCP-capable LLM investigate product questions in natural language.
The synthetic dataset intentionally contains a hidden July 2026 deterioration in mobile review completion. The agent is not told the answer. It has to discover the metric, compare periods, segment the change, and stop where the evidence stops.
What the demo proved
In a cold-start test, the agent was asked:
“One of our product metrics changed materially in July 2026. Using only the G2 Product Analytics MCP tools, investigate what happened.”
The agent independently found:
review_completion_ratewas the material outlier.- Overall completion fell from 66.7% in June to 60.5% in July.
- The decline was concentrated in mobile: 62.7% → 47.9% (-14.8pp).
- Desktop was nearly flat, which made device type a much cleaner signal than country or product category.
- Daily volume was too thin to claim an exact “cliff day.”
- The evidence established association, not causation.
That distinction is the core design goal: LLM reasoning on top of governed evidence, not free-form guessing against raw tables.
Architecture
flowchart TD
U["User<br/>Natural-language business question"]
A["LLM / Agent<br/>Reasoning + tool selection"]
MCP["MCP Server<br/>Tools + Resource + Prompt"]
SEM["Governed metric layer<br/>definitions + dimensions + ownership + freshness"]
EXE["Analytics execution<br/>Python + DuckDB"]
DATA["Synthetic product data<br/>CSV tables"]
U --> A
A --> MCP
MCP --> SEM
MCP --> EXE
EXE --> DATA
SEM --> EXE
EXE --> MCP
MCP --> A
A --> U
Mental model
LLM decides. MCP connects. Tools execute. Semantic definitions govern. Data provides evidence.
MCP is not the model, semantic layer, or database. It is the standardized interface through which the agent discovers and invokes capabilities.
Why I built it this way
A naive analytics agent might expose:
run_sql(sql: str)
That is convenient, but it also lets the model:
- silently redefine metrics,
- choose the wrong denominator,
- double-count joins,
- query deprecated or sensitive fields,
- create inconsistent answers across users,
- and sound confident even when the underlying question is ambiguous.
This project takes the opposite approach.
The agent receives a deliberately small set of governed analytical primitives:
| Tool | Purpose |
|---|---|
list_metrics |
Discover approved business metrics. |
get_metric_definition |
Retrieve the governed definition before interpretation. |
get_metric |
Calculate one approved metric for an inclusive date range. |
compare_review_completion_by_dimension |
Slice review completion by an approved dimension. |
compare_periods |
Quantify absolute and relative change across two periods. |
diagnose_review_completion_change |
Compare device segments across two periods and explicitly warn that association is not causation. |
The server also exposes:
- an MCP resource:
metrics://catalog - an MCP prompt:
product_analytics_investigation
Repository map
g2-product-analytics-mcp/
├── README.md
├── LICENSE
├── pyproject.toml
├── .gitignore
│
├── data/
│ ├── users.csv
│ ├── software_products.csv
│ ├── buyer_sessions.csv
│ ├── search_events.csv
│ ├── comparison_events.csv
│ ├── reviews.csv
│ ├── review_events.csv
│ └── metric_catalog.csv
│
├── scripts/
│ └── generate_dummy_data.py
│
├── src/
│ └── g2_product_analytics_mcp/
│ ├── __init__.py
│ └── server.py
│
├── tests/
│ └── test_server.py
│
├── docs/
│ ├── ARCHITECTURE.md
│ ├── DATA_MODEL.md
│ ├── CODE_WALKTHROUGH.md
│ ├── AGENT_EVALUATION.md
│ └── INTERVIEW_WALKTHROUGH.md
│
└── .github/
└── workflows/
└── test.yml
See docs/CODE_WALKTHROUGH.md for a detailed explanation of the Python code and docs/DATA_MODEL.md for every synthetic table.
Quick start
1. Install prerequisites
- Python 3.10+
uv- Node/npm only if you want MCP Inspector
- An MCP-capable client such as Claude Code if you want the agent demo
2. Clone and install
git clone <YOUR-REPO-URL>
cd g2-product-analytics-mcp
uv sync --extra dev
3. Run tests
uv run pytest -q
4. Inspect the MCP server manually
uv run mcp dev src/g2_product_analytics_mcp/server.py
MCP Inspector should discover the tools, prompt, and metric-catalog resource.
5. Connect Claude Code
From this repository:
claude mcp add g2-product-analytics -- \
uv run --with mcp==2.0.0 mcp run src/g2_product_analytics_mcp/server.py
Check health:
claude mcp list
Then launch Claude:
claude
A useful cold-start evaluation prompt is:
One of our product metrics changed materially in July 2026.
Using only the G2 Product Analytics MCP tools, investigate what happened.
Identify the metric, quantify the change, determine when the change emerged,
find where it is most concentrated, and explain what the evidence does and
does not support. Do not inspect source code or CSV files.
Reproduce the synthetic data
The committed CSVs make the demo immediately runnable.
They can also be regenerated deterministically:
uv run python scripts/generate_dummy_data.py
The generator uses a fixed random seed and intentionally plants one anomaly: mobile review completion deteriorates in July 2026.
This is synthetic portfolio data. It contains no G2 proprietary information.
Tests and guardrails
The current unit tests validate two foundational properties:
review_completion_rateis a valid ratio with a non-zero denominator.- mobile completion in July is lower than mobile completion in June.
The more important evaluation layer is behavioral. See docs/AGENT_EVALUATION.md for prompts covering:
- definition governance,
- unsupported metrics,
- unsupported dimensions,
- ambiguous questions,
- causality traps,
- leading questions,
- cold-start anomaly investigation.
What I would productionize next
The portfolio version is intentionally compact:
CSV → DuckDB → governed Python metrics → MCP → LLM agent
A production version would likely add:
- warehouse/dbt models instead of CSVs,
- a formal semantic/metrics layer,
- identity propagation and SSO/OAuth,
- row- and column-level authorization,
- audit logs and tool-call observability,
- metric lineage/versioning,
- freshness/schema monitoring,
- query budgets and timeouts,
- PII policies,
- golden-question eval suites,
- and a self-service UI/Slack surface.
Design tradeoff I learned
The project intentionally contains both atomic tools (get_metric) and a more opinionated workflow tool (diagnose_review_completion_change).
During testing, the agent showed it could compose atomic tools into new workflows, including weekly trend analysis, without a dedicated weekly_trend() function.
That suggests the scalable direction is not to hard-code every analyst question as a new MCP tool. It is to expose a small number of trusted primitives with strong semantics and let the agent compose them.
Documentation
License
MIT. Synthetic data only.
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。