Trading Journal MCP
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
Trading Journal MCP
Trading Journal MCP is a Python/FastAPI portfolio and trade-journaling application built as a practical Model Context Protocol (MCP) use case. The current codebase is the accepted prototype for a graduate project and is now being evolved into the full application.
The app helps track accounts, holdings, manual trades, open positions, closed positions, realized profit/loss, unrealized profit/loss, and the reason behind every trade. It also exposes portfolio and market-data capabilities through MCP servers so external clients can discover and call application features in a standard way.
Project Goals
Build a day-to-day trading journal for portfolio review and trade reasoning.
Demonstrate MCP concepts using a real financial application instead of a toy example.
Support multiple asset classes such as stocks, ETFs, mutual funds, bonds, options, and cash.
Track realized and unrealized P&L across accounts and asset classes.
Add watchlists so the user can track symbols before taking a trade.
Show how an application can act as both an MCP server and an MCP client.
Prepare for future IBKR broker sync, stock news, order staging, paper trading, and safe live-trading workflows.
Related MCP server: openportfolio
Prototype Features Included
FastAPI backend with server-rendered HTML pages.
SQLite-backed local database.
Default accounts for
IBKR LiveandManual Entry.Manual import flow for existing holdings.
Manual buy/sell trade entry.
Required trade reason field for every manual trade.
Position updates using average-cost accounting.
Partial close and full close behavior.
Closed positions page with realized P&L.
Manual mark-price updates for unrealized P&L.
Dashboard P&L tables for overall, account-level, and account plus asset-class reporting.
Grouped top navigation for Dashboard, Portfolio, Trading, and Configuration workflows.
Market-data page for portfolio symbols.
Alpaca market-data snapshots by default using saved API keys; Yahoo quotes remain optional.
Trading Journal MCP server.
Market Data MCP server.
Yahoo Finance-backed News MCP server for demo stock-news lookup.
Safe Broker MCP and Trading MCP scaffolding for future phases.
Internal MCP client calls from the web app to the Market Data MCP server.
External command-line MCP demo client.
Persistent audit logging foundation with correlation IDs, redaction, and an audit viewer.
Planning documents for requirements, implementation, deployment, and prototype baseline.
Current Architecture
flowchart LR
U["User"] --> UI["FastAPI Web UI"]
UI --> SVC["Application Services"]
SVC --> DB["SQLite Database"]
UI --> HOST["Internal MCP Client"]
UI --> AUDIT["Audit Logs"]
HOST --> PMCP["Trading Journal MCP Server"]
HOST --> MMCP["Market Data MCP Server"]
HOST --> NMCP["News MCP Server"]
HOST --> BMCP["Broker MCP Server"]
HOST --> TMCP["Trading MCP Server"]
PMCP --> DB
MMCP --> MARKET["Provider adapter: Alpaca by default"]
MARKET --> ALPACA["Alpaca Market Data API"]
MARKET -. optional .-> YCHART["Yahoo Finance Public Chart API"]
NMCP --> YAHOO["Yahoo Finance Demo News Provider"]
BMCP --> IBKR["IBKR Placeholder"]
TMCP --> SAFE["Preview-Only Safety Gate"]
HOST --> AUDIT
MARKET --> AUDIT
CLI["External MCP Demo Client"] --> PMCP
CLI --> MMCP
CLI --> NMCP
CLI --> BMCP
CLI --> TMCPRepository Structure
.
├── app/
│ ├── main.py # FastAPI app factory, routers, mounted MCP servers
│ ├── config.py # Environment-based settings
│ ├── db.py # SQLAlchemy database setup
│ ├── mcp_server.py # Trading Journal MCP server
│ ├── market_data_mcp.py # Market Data MCP server
│ ├── audit/ # Audit logging, middleware, redaction, correlation IDs
│ ├── models/ # SQLAlchemy entities and enums
│ ├── mcp_servers/ # Domain-specific MCP server factories
│ ├── providers/ # External provider adapter interfaces
│ ├── routes/ # Web and JSON API route modules
│ ├── services/ # Portfolio, market data, and MCP host logic
│ ├── static/ # CSS
│ └── templates/ # Jinja2 HTML templates
├── docs/
│ ├── application_requirements.md
│ ├── architecture_plan.md
│ ├── deployment_plan.md
│ ├── implementation_plan.md
│ ├── prototype_baseline.md
│ └── proposal/
│ ├── Trading_Journal_MCP_Proposal_Revised.docx
│ └── Trading_Journal_MCP_Proposal_Revised.pdf
├── scripts/
│ └── mcp_demo_client.py # External MCP client demo
├── tests/
│ ├── test_trade_flow.py
│ └── test_mcp_flow.py
├── tools/
│ └── build_revised_proposal.py
├── PROPOSAL.md
├── pyproject.toml
└── README.mdPrerequisites
Python 3.12 or newer.
Git.
Internet access and Alpaca API keys for market snapshots; Yahoo Finance supplies demo stock news.
Alpaca is the default market-data source as of November 1, 2026. Existing saved credentials are reused. Yahoo Finance remains the news source, with its quote adapter available only when explicitly selected.
Download The Project
Clone the repository:
git clone https://github.com/thejavascriptways/IFSC-78603-Graduate-Project-trading_journal-mcp.git
cd IFSC-78603-Graduate-Project-trading_journal-mcpLocal Setup
Create and activate a virtual environment:
python3 -m venv .venv
source .venv/bin/activateInstall the application with development dependencies:
python3 -m pip install --upgrade pip
python3 -m pip install -e ".[dev]"Market Data Setup
Use the default Alpaca provider with saved credentials:
Start the app and configure keys under
Configuration > Market Data Settings > Manage Alpaca Keysif they are not already saved.Click
Refresh Quotesto fetch snapshots for open and closed portfolio symbols.Check
As Of,Feed, andData Statusfor each result. IEX stocks have exchange-limited coverage; indicative option rows are labeledINDICATIVE.To apply prices to open positions, open
Portfolio > Open Positionsand clickRefresh Quotes via MCP.Inspect the current provider under
Configuration > Market Data Settings.
The flow is Web/CLI -> Market Data MCP -> provider interface -> Alpaca Market Data API.
Stocks/ETFs use /v2/stocks/snapshots; options use /v1beta1/options/snapshots with the saved feed selection.
These are requested snapshots, not continuous streaming. Missing symbols and provider failures remain visible; bid/ask is shown when supplied.
Prices are applied to open positions only when the returned currency matches the position currency (when supplied); no FX conversion is performed.
Mutual-fund NAV lookup and individual bond quotes remain unimplemented.
The integration uses the existing httpx dependency, with no new library required.
See the market-data workflow for implementation details, CLI examples, and references.
Alpaca Credentials And Provider Selection
Alpaca is the default. If a shell previously selected Yahoo, set this before starting the server (restart a running server):
export TRADING_JOURNAL_MARKET_DATA_PROVIDER=alpacaTo explicitly use the optional Yahoo demo quote provider, set TRADING_JOURNAL_MARKET_DATA_PROVIDER=yahoo and restart. It requires no keys, may be delayed, and does not supply bid/ask. Stock News continues using Yahoo independently of this choice.
Use the browser settings screen to manage Alpaca credentials:
Start the app.
Open
Configuration > Market Data Settings > Manage Alpaca Keys.Paste the Alpaca API Key ID and Secret Key.
Keep
iexandindicativefor the free/paper-friendly setup, unless your account has paid feed entitlements.Click
Save Alpaca Settings.Open
Portfolio > Market Datato test live quote retrieval.
The saved settings are written to a local Git-ignored instance/alpaca_market_data.json file. The secret is not displayed back in the browser, and audit metadata uses masked/redacted values.
You can still use environment variables instead of the settings screen if you prefer command-line setup:
export ALPACA_API_KEY_ID="your-key-id"
export ALPACA_API_SECRET_KEY="your-secret-key"
export ALPACA_STOCK_FEED="iex"
export ALPACA_OPTION_FEED="indicative"If you have paid real-time data entitlements, you can change the feeds:
export ALPACA_STOCK_FEED="sip"
export ALPACA_OPTION_FEED="opra"Alpaca asset-class notes:
Stocks and ETFs can use Alpaca stock feeds.
Options require appropriate options-data entitlement for true OPRA quotes.
Mutual funds usually publish NAV once per business day rather than live intraday quotes.
Bonds are not covered by Alpaca stock/options quote feeds.
Run The Web App
Start the local server:
uvicorn app.main:app --reloadOpen the app:
http://127.0.0.1:8000/If --reload causes a permission issue on macOS or in a restricted environment, run without reload:
uvicorn app.main:appShort-Term Professor Demo With A Tunnel
For a quick live demo, run the app locally and expose it temporarily through a public tunnel. This lets the professor open the web UI and MCP endpoints without a cloud deployment.
Use the step-by-step runbook here:
Fastest no-install tunnel option:
export TRADING_JOURNAL_DEMO_PASSWORD="choose-a-temporary-demo-password"
ssh -R 80:localhost:8000 nokey@localhost.runOnly share the tunnel URL and temporary demo password during the demo, and stop the tunnel with Control-C when finished.
How To Use The Current App
Open the dashboard at
http://127.0.0.1:8000/.Use Import Holdings to add existing Fidelity or other manual holdings one at a time, or bulk import them from CSV.
Use Add Trade to manually record buy or sell trades.
Enter a clear trade reason. The app requires this field.
Use Positions to review open holdings, update mark prices, refresh market data, or close positions.
Use Closed Positions to review realized P&L after a position is fully closed.
Use Market Data to view quote data and provider status for portfolio symbols.
Use Stock News to view global news for portfolio symbols or search any symbol.
Use MCP Console to discover MCP servers, call tools, read resources, and render prompts from the browser.
Use Audit to inspect recent web/API actions, MCP requests, external API calls, and application events.
Use the MCP demo client to show how external clients discover and call MCP capabilities.
Bulk Holding CSV Format
The Import Holdings page displays this same template. Use these exact headers:
account_name,symbol,description,asset_class,opening_date,quantity,average_cost,currency,notes
Manual Entry,VOO,Vanguard S&P 500 ETF,ETF,2026-01-02,10,500.25,USD,Initial Fidelity import
Manual Entry,AAPL,Apple Inc.,STOCK,2026-02-15,5,180.10,USD,Long-term core positionSupported asset_class values are STOCK, ETF, MUTUAL_FUND, BOND, OPTION, and CASH. The account_name must match an active manual account, such as Manual Entry.
MCP Endpoints
The app currently mounts five MCP servers:
Trading Journal MCP: http://127.0.0.1:8000/mcp/
Market Data MCP: http://127.0.0.1:8000/market-data-mcp/
News MCP: http://127.0.0.1:8000/news-mcp/
Broker MCP: http://127.0.0.1:8000/broker-mcp/
Trading MCP: http://127.0.0.1:8000/trading-mcp/Audit And Observability
The app now creates a correlation ID for each non-static HTTP request and stores initial audit records.
Current audit views:
Browser page:
http://127.0.0.1:8000/auditJSON API:
http://127.0.0.1:8000/api/audit/logs
Current audit tables:
user_action_logsmcp_request_logsexternal_api_call_logsapplication_event_logs
Sensitive fields such as API keys, secrets, tokens, cookies, and authorization values are redacted before being stored.
Trading Journal MCP Server
Current tools:
get_portfolio_summarylist_accountslist_positionslist_tradesadd_opening_holdingadd_manual_trade
Current resources:
portfolio://summaryportfolio://positions
Current prompts:
daily_portfolio_reviewjournal_follow_up
Market Data MCP Server
Current tools:
get_market_data_capabilitiesget_equity_snapshotsget_option_snapshots
Current resources:
market-data://capabilities
Current prompts:
market_data_health_check
News MCP Server
Current tools:
get_news_capabilitiesget_symbol_newsget_portfolio_news
Current resources:
news://capabilities
Current prompts:
portfolio_news_review
This server uses Yahoo Finance public search results by default for Phase 1 demo stock-news lookup. Set TRADING_JOURNAL_NEWS_PROVIDER=demo if you want deterministic synthetic news for offline demos, or TRADING_JOURNAL_NEWS_PROVIDER=gdelt to try the GDELT provider.
Broker MCP Server
Current tools:
get_broker_statuslist_broker_accounts
Current resources:
broker://status
Current prompts:
broker_sync_readiness
This server is safe scaffolding for future IBKR sync. It does not connect to IBKR or place trades yet.
Trading MCP Server
Current tools:
get_trading_capabilitiespreview_order
Current resources:
trading://capabilities
Current prompts:
order_safety_review
This server only supports preview scaffolding. Live trading is disabled.
Demonstrate MCP From The Command Line
Run these commands after the web app is running.
Explain what the demo client shows:
python3 scripts/mcp_demo_client.py explainList MCP servers exposed by the app:
python3 scripts/mcp_demo_client.py serversDiscover the Trading Journal MCP server:
python3 scripts/mcp_demo_client.py discover
python3 scripts/mcp_demo_client.py tools
python3 scripts/mcp_demo_client.py resources
python3 scripts/mcp_demo_client.py promptsCall portfolio tools and resources:
python3 scripts/mcp_demo_client.py summary
python3 scripts/mcp_demo_client.py call list_positions --arguments '{"symbol":"VOO"}'
python3 scripts/mcp_demo_client.py read-resource portfolio://summary
python3 scripts/mcp_demo_client.py get-prompt daily_portfolio_review --arguments '{"focus":"risk"}'Run a guided portfolio review:
python3 scripts/mcp_demo_client.py portfolio-review --focus riskDiscover the Market Data MCP server:
python3 scripts/mcp_demo_client.py --server market discover
python3 scripts/mcp_demo_client.py --server market tools
python3 scripts/mcp_demo_client.py --server market resources
python3 scripts/mcp_demo_client.py --server market promptsDiscover the future domain MCP scaffolds:
python3 scripts/mcp_demo_client.py --server news discover
python3 scripts/mcp_demo_client.py --server broker discover
python3 scripts/mcp_demo_client.py --server trading discover
python3 scripts/mcp_demo_client.py --server trading call get_trading_capabilitiesCall stock-news tools:
python3 scripts/mcp_demo_client.py stock-news --symbol AAPL
python3 scripts/mcp_demo_client.py portfolio-news --symbols AAPL,MSFT
python3 scripts/mcp_demo_client.py --server news call get_symbol_news --arguments '{"symbol":"AAPL","limit":5}'Call market-data tools:
python3 scripts/mcp_demo_client.py --server market call get_market_data_capabilities
python3 scripts/mcp_demo_client.py --server market call get_equity_snapshots --arguments '{"symbols":["AAPL","MSFT"]}'
python3 scripts/mcp_demo_client.py --server market read-resource market-data://capabilities
python3 scripts/mcp_demo_client.py --server market get-prompt market_data_health_check --arguments '{"symbols":"AAPL,MSFT"}'Run a guided market-data check:
python3 scripts/mcp_demo_client.py market-check --symbols AAPL,MSFTRun the complete multi-server demo:
python3 scripts/mcp_demo_client.py client-demoThe CLI also supports a remote base URL, which will be useful after deployment:
python3 scripts/mcp_demo_client.py --base-url https://your-demo-url.example discoverRun Tests
Run the automated test suite:
python3 -m pytestCurrent baseline result at prototype freeze:
13 passedThe tests cover:
Manual trade position updates.
Required trade reason validation.
Opening holding imports.
Duplicate import rejection.
Partial sell and full close behavior.
Realized and unrealized P&L.
Dashboard P&L summaries.
Trading Journal MCP discovery and tool calls.
Market Data MCP discovery and capability calls.
News MCP discovery and mocked stock-news calls.
Broker and Trading MCP scaffold discovery.
Trading MCP live-trading-disabled safety signal.
Browser MCP Console route and catalog API.
Audit correlation IDs, persistent MCP logs, and secret redaction.
Important Safety Notes
This is a prototype/graduate-project application, not a production trading system.
Do not commit
.envfiles or API keys.Do not commit local SQLite databases.
Do not use real broker credentials in a public demo environment.
Live trading is not implemented in the current prototype.
Future live trading must require explicit user confirmation, audit logging, and safety gates.
Public professor demos should use sample data and simulated/paper trading only.
Planning Documents
The documentation index identifies current guides, demo material, and historical submissions. Current operation restores Alpaca market data on November 1, 2026, while keeping Yahoo Finance for news and optional demo quotes. The October 20 Yahoo-default revision remains documented as history.
The project roadmap and supporting material are documented in:
PROPOSAL.md is the earlier short proposal draft. The revised final proposal accepted by the professor is stored under docs/proposal/ and is preserved as submitted. Its earlier provider assumptions are explained by the implementation addendum. In the app, open Configuration > Documentation for the current slides, white paper, and market-data guide, or Configuration > Workflow Map for graphical request paths.
Recommended Next Build Step
The next implementation step is to continue Phase 2 by expanding audit coverage:
Add filters on the Audit page by event type, client type, status, and correlation ID.
Add export support for audit logs.
Add deeper domain-level logs for manual trades, position closes, and market-data refreshes.
Add audit links from MCP Console actions to matching audit records.
Add migration tooling before the schema grows much further.
This foundation should be completed before IBKR broker sync, paper trading, or any future live trading workflow.
Architecture tab
Open /architecture (top navigation: Architecture) for an interactive block diagram of the browser, FastAPI app, five MCP servers and data providers. Hover over or tab to any box to see what it does, the MCP tools/resources/prompts it exposes, and where it lives in the code. Diagram content lives in app/architecture.py.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
Related MCP Connectors
AI trading partner and trading journal: trades, reports, journaling, market data.
Trading journal, options risk checks, position sizing and Monte Carlo analytics for AI assistants.
Trading journal with pattern detection: log trades by voice, query your own history.
Chart-first trading journal: log trades from notes or chart screenshots, review setups and stats.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceProvides AI-powered trading analytics and coaching by analyzing historical trades to identify strategies, emotional patterns, and behavioral mistakes via MCP tools.1MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to read and write a self-hosted portfolio tracker through 25 MCP tools, covering net worth, flows, forecasts, decisions, and audit.4Apache 2.0
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to connect to a trading journal, analyze performance metrics, identify psychological biases, and receive continuous trading coaching.MIT
- AlicenseAqualityCmaintenanceEnables AI assistants to read and write trading journal data, including trade logs, analytics, psychology audits, risk limits, playbooks, and daily reviews. Provides 38 tools across 7 domains plus workflow prompts for pre-market prep and post-session analysis.38MIT