currency-bot-db
Currency MCP Bot(教学项目)
一个简单的 Telegram Bot + 公共 API + Docker/PostgreSQL + MCP + Cursor 集成示例。
架构图
Telegram
↓
Python Bot
↓
API курса валют
Python Bot
↓
PostgreSQL
↑
MCP
↑
CursorRelated MCP server: postgres-mcp
Telegram Bot 在这里做什么
接收 /start、/усд、/еur、/цну 命令,并返回这些货币兑卢布的汇率。
API 在这里做什么
机器人向免费公共 API(open.er-api.com)请求实时汇率——无需密钥,也无需注册。
Docker 在这里做什么
docker compose 在容器中启动 PostgreSQL。机器人本身在本地用 Python 运行。
MCP 在这里做什么
MCP 服务器为 Cursor 提供两个访问同一数据库的工具:
get_recent_requests— 用户最近的请求get_currency_stats— USD / EUR / CNY 被询问的次数
文件
文件 | 用途 |
| Telegram 机器人(aiogram) |
| 不带 ORM 的 PostgreSQL |
| 用于 Cursor 的 MCP 服务器 |
| Docker 中的 PostgreSQL |
| 本项目中的 MCP 连接 |
| 密钥和配置(不纳入 Git) |
快速开始
1. Python 依赖
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txt2. 环境变量
复制示例并粘贴机器人令牌:
copy .env.example .env在 .env 中填写:
TELEGRAM_BOT_TOKEN=ваш_токен_от_BotFather3. 通过 Docker 使用 PostgreSQL
docker compose up -d验证:
docker compose ps4. 启动机器人
python bot.py在 Telegram 中向机器人发送 /start,然后发送 /usd、/eur、/cyn。
5. Cursor 中的 MCP
项目中有 .cursor/mcp.json。在 Windows 上,服务器也已添加到用户级 ~/.cursor/mcp.json,确保它一定出现在 Connected 列表中。
先创建 venv 并安装依赖(见上面的第 1 步)
Ctrl+Shift+P→ Developer: Reload Window打开 Settings → MCP
找到
currency-bot-db— 状态应为绿色,tools:get_recent_requests、get_currency_stats
如果服务器不存在或状态为红色:请检查 PostgreSQL(docker compose ps)以及 .venv 是否已安装。
如何获取 Telegram Bot Token
打开 Telegram,找到 @BotFather
发送
/newbot为机器人想一个名称和 username
BotFather 会发送一个形如
123456:ABC...的令牌将其作为
TELEGRAM_BOT_TOKEN=...粘贴到.env中
不要将令牌提交到 Git — .env 文件已在 .gitignore 中。
在 Cursor 中向 MCP 发送测试请求
向机器人发送几条命令后,在 Cursor 聊天中写下:
“显示用户的最近请求”
“用户最常查询哪些货币?”
“用 limit=5 调用 get_recent_requests”
“调用 get_currency_stats”
Cursor 应使用 MCP 工具 get_recent_requests 和 get_currency_stats。
This server cannot be deployed
Maintenance
Related MCP Connectors
Read-only analytics for Convex apps, queryable via MCP from Claude, Cursor, and other clients.
Hosted PostgreSQL MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
Query your real net worth, spending, transactions, budgets and portfolio from any MCP client.
Analytics for MCP servers. Query your tool calls, first-call success, retries and schema cost.
Related MCP Servers
- AlicenseCqualityDmaintenanceEnables querying PostgreSQL database metadata including table lists and schema information through the MCP protocol. Supports stdio transport for Cursor/IDE integration as well as HTTP transport with health check endpoints.2MIT
- AlicenseNot gradedqualityDmaintenanceMCP server for PostgreSQL that enables Cursor and other MCP clients to execute SQL queries, list tables, and explore database schemas via HTTP.1,139 npmMIT
- FlicenseNot gradedqualityFmaintenanceProvides read-only SQL query access to Postgres and DuckDB databases via MCP tools, with extensive security hardening for public endpoints.1-
- AlicenseAqualityDmaintenanceEnables querying and interacting with PostgreSQL databases using natural language through MCP. Supports configuration via environment variables and Cursor IDE integration.3MIT