My Portfolio MCP Server
A Model Context Protocol (MCP) server for managing investment portfolios, enabling transaction tracking, position management, alerts, and daily snapshots with Google Drive sync.
README
My Portfolio MCP Server
A Model Context Protocol (MCP) server for managing investment portfolios. Built with Node.js, SQLite, and Google Drive integration.
Quick Start
👉 New? See QUICKSTART.md for setup in 5 minutes
Features
- Transaction Management: Track buys, sells, and dividends
- Position Tracking: Manage open and closed positions with cost basis
- Alerts: Create and store price/gain-loss alerts
- Daily Position Snapshots: Record end-of-day portfolio snapshots
- Comments with History: Full comment history on positions and alerts
- Google Drive Sync: Automatic sync and daily backups
- MCP Integration: Use with Claude for natural language portfolio queries
Setup
Prerequisites
- Node.js 18+
- Google account with Drive access
- Railway account (for deployment)
OAuth Setup
This project uses OAuth 2.0 for Google Drive access.
For detailed setup instructions including:
- Creating OAuth credentials in Google Cloud
- Generating authorization tokens
- Creating a Google Drive folder
- Configuring environment variables
👉 See OAUTH_SETUP.md
Local Development
- Clone and install:
npm install
- Create
.envfile from.env.example:
cp .env.example .env
-
Set up OAuth (see OAUTH_SETUP.md):
- Create OAuth credentials in Google Cloud Console
- Authorize locally to generate
tokens.json - Create a Google Drive folder
- Set
DRIVE_FOLDER_IDin.env
-
Build and run:
npm run build
npm start
The first run will prompt you to authorize with Google (opens browser). On subsequent runs, it uses the saved token.
Or for development with auto-reload:
npm run dev
Available Tools
Transactions
list_transactions- Get all transactions with optional filtersadd_transaction- Create a new transaction (BUY/SELL/DIVIDEND)update_transaction- Modify transaction detailsdelete_transaction- Remove a transaction
Positions
list_positions- Get all positions (OPEN/CLOSED)add_position- Create a new positionupdate_position- Update shares or average costclose_position- Mark position as closedadd_position_comment- Add comment to positionlist_position_comments- Get comment historyget_position_summary- Portfolio stats
Daily Positions
record_daily_position- Record single EOD snapshotrecord_daily_positions_batch- Bulk insert for historical datalist_daily_positions- Query snapshots with filters
Alerts
list_alerts- Get all alertsadd_alert- Create alert (PRICE_ABOVE/PRICE_BELOW/GAIN_LOSS_PERCENT)update_alert- Modify alertdelete_alert- Remove alertadd_alert_comment- Add comment to alertlist_alert_comments- Get comment history
Utilities
sync_portfolio_to_drive- Manual sync triggerget_portfolio_stats- Portfolio summary
Deployment to Railway
-
Complete OAuth setup locally first
-
Push code to git repository:
git add . git commit -m "Add portfolio MCP server" git push origin main -
Connect to Railway.app and link your GitHub repo
-
Set environment variables in Railway dashboard:
OAUTH_CREDENTIALS_JSON(base64-encoded, see OAUTH_SETUP.md)OAUTH_TOKEN_JSON(base64-encoded, see OAUTH_SETUP.md)DRIVE_FOLDER_IDDATABASE_SYNC_INTERVAL_MINUTES=1(optional, default: 1)BACKUP_TIME_UTC=23:00(optional, default: 23:00)
-
Railway will auto-build and deploy
Note: OAuth credentials and tokens are NOT stored in git (in .gitignore). They are provided via Railway environment variables. See OAUTH_SETUP.md for detailed instructions.
Data Storage
- Primary: SQLite database (
portfolio_data.db) - Backup: Synced to Google Drive every 1 minute
- Daily Backups: Timestamped backups retained for 7 days
- Files: Not encrypted by default (relies on Drive + file permissions)
Architecture
MCP Server (stdio transport)
↓
Tools (Transactions, Positions, Alerts, DailyPositions)
↓
SQLite Database (local)
↓
Google Drive (sync + backups)
Using with Claude
Connect this MCP server to Claude and query your portfolio:
- "What's my total cost basis?"
- "Add 100 shares of AAPL at $150"
- "Show me all OPEN positions"
- "Create an alert if TSLA goes above $250"
Configuration
Environment variables in .env:
| Variable | Description | Default |
|---|---|---|
NODE_ENV |
Environment | development |
OAUTH_CREDENTIALS_JSON |
OAuth credentials (JSON or base64) | (from file) |
OAUTH_TOKEN_JSON |
OAuth token (JSON or base64) | (from file) |
DRIVE_FOLDER_ID |
Google Drive folder ID | - |
DATABASE_PATH |
SQLite database path | ./portfolio_data.db |
DATABASE_SYNC_INTERVAL_MINUTES |
Sync interval | 1 |
BACKUP_TIME_UTC |
Daily backup time | 23:00 |
See OAUTH_SETUP.md for details on OAuth variables.
Security Notes
- OAuth tokens are refresh tokens (not passwords)
- Both credential files are in
.gitignore(never committed to GitHub) - Secrets stored as env vars in Railway, encrypted by Railway
- SQLite not encrypted by default (can add SQLCipher for sensitive data)
- Backups inherit Google Drive encryption
- Use parameterized SQL queries (no injection risk)
- You can revoke access anytime in Google Account
Development
Type checking:
npm run build
License
MIT
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。