mcp-data-agent

mcp-data-agent

A real MCP server exposing data-analyst tools (SQL querying, schema introspection, stats, charting) over a sales database, with a Gemini agent that discovers and calls those tools at runtime via the standard MCP protocol.

Category
访问服务器

README

MCP Data Agent

CI License

A real Model Context Protocol (MCP) server exposing data-analyst tools over a sales database, plus an LLM agent (Gemini) that discovers those tools at runtime and decides which to call to answer a question — the actual point of MCP being that the tool definitions live on the server, not hardcoded into the agent.

Why this is a real MCP implementation, not a mock

  • src/mcp_server.py is a genuine MCP server, built on the official mcp Python SDK, exposing 4 tools (list_tables, run_sql_query, get_column_stats, plot_bar_chart) over the standard stdio transport.
  • src/smoke_test_client.py is a protocol-level test with no LLM involved at all — it launches the server as a real subprocess, connects over stdio, calls list_tools(), and calls run_sql_query through the actual MCP wire protocol. This is what proves the server works, independent of whether the agent on top of it works.
  • src/mcp_client_agent.py is the agent: it lists the server's tools, converts their JSON schemas directly into Gemini function declarations (parameters_json_schema=tool.input_schema — no manual schema translation), and runs the standard tool-calling loop: ask the model → execute any requested tool call via the real MCP session → feed the result back → repeat until the model gives a final answer.

Requires Python 3.10+

The mcp package doesn't support Python 3.9. If your default python is older, use py -3.12 (or whichever 3.10+ interpreter you have) for every command below.

Pipeline

pip install -r requirements.txt
python src/generate_data.py          # -> data/sales.db (3,000 synthetic orders)
python src/smoke_test_client.py      # protocol-only sanity check, no LLM
python src/mcp_client_agent.py "Which category has the highest revenue?"

Without GEMINI_API_KEY set, mcp_client_agent.py runs a manual fallback: it lists the tools discovered from the live server and calls one directly, so the MCP plumbing is demonstrable with zero API keys. With a key (copy .env.example to .env), it runs the full agent loop.

Tests

tests/test_pipeline.py calls the server's tool functions directly (schema introspection, SQL rejection of non-SELECT statements, stats), and — the real proof this is a working MCP implementation — runs smoke_test_client.py, which launches the server as an actual subprocess and talks to it over the real stdio protocol. No API key needed, so this runs in CI on every push, on Python 3.12.

pip install -r requirements.txt pytest
pytest tests/ -v

Tools exposed by the server

Tool Purpose
list_tables Schema introspection
run_sql_query Read-only SQL — rejects anything that isn't a SELECT before it reaches the database
get_column_stats Summary stats for quantity, unit_price, or revenue
plot_bar_chart Aggregates by region/category and saves a PNG

Verified vs. not independently verified

  • Verified: the MCP server and protocol wiring (tool discovery, tool execution over stdio) — smoke_test_client.py runs it end to end with no LLM in the loop, and the manual fallback path in mcp_client_agent.py exercises the same real protocol.
  • Implemented against the current google-genai SDK, not run against a live key in this environment: the Gemini tool-calling loop itself. The function-declaration and function-response types were checked directly against the installed SDK, but the actual multi-turn call requires an API key this environment doesn't have. Run it with your own GEMINI_API_KEY to exercise that path.

Project structure

data/     generated sales.db
src/      mcp_server, smoke_test_client, mcp_client_agent, generate_data
reports/  charts saved by plot_bar_chart

Stack

Python 3.12 · mcp (official Model Context Protocol SDK) · google-genai · SQLite · matplotlib

License

MIT — see LICENSE.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选