Skip to main content
Glama
smiryagin

Investment MCP Server

by smiryagin

# Investment MCP Server

Private, authenticated MCP server for your SQL Server investment database.

It exposes read-only tools over:

  • dbo.Series

  • dbo.SeriesData

  • dbo.TradeGetDaysChangeReturn

The server does not expose a raw SQL tool. All database access is parameterized. Private portfolio tools derive the caller from the bearer token and scope every account query to that authenticated user.

Install

cd "C:\Users\asmir\source\repos\investment_mcp"
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txt
copy .env.example .env

Edit .env with your SQL Server name and database name.

Related MCP server: yahoo-finance-mcp

SQL Permissions

Use a read-only SQL login/user if possible:

CREATE LOGIN mcp_investments_login WITH PASSWORD = 'replace-with-strong-password';
CREATE USER mcp_investments_user FOR LOGIN mcp_investments_login;

GRANT SELECT ON dbo.Series TO mcp_investments_user;
GRANT SELECT ON dbo.SeriesData TO mcp_investments_user;
GRANT EXECUTE ON dbo.TradeGetDaysChangeReturn TO mcp_investments_user;

If you use Windows authentication instead, grant the same permissions to your Windows user.

Run Locally

.\.venv\Scripts\Activate.ps1
python server.py

With MCP_TRANSPORT=stdio, the command starts silently and waits for an MCP client. A blank terminal is expected. Press Ctrl+C to stop it.

For MCP Inspector:

mcp dev server.py

Codex MCP Config Example

Add something like this to your Codex MCP config, adjusting paths and connection string:

[mcp_servers.investments]
command = "C:\\Users\\asmir\\source\\repos\\investment_mcp\\.venv\\Scripts\\python.exe"
args = ["C:\\Users\\asmir\\source\\repos\\investment_mcp\\server.py"]
env = { SQLSERVER_CONN = "DRIVER={ODBC Driver 17 for SQL Server};SERVER=localhost;DATABASE=Investments;Trusted_Connection=yes;Encrypt=yes;TrustServerCertificate=yes;" }

Tools

  • search_symbols

  • get_symbol_profile

  • get_latest_prices

  • get_price_history

  • get_research_snapshot

  • compare_symbols

  • screen_instruments

  • get_watched_symbols

  • get_traded_symbols

  • get_data_freshness

  • get_market_indicators

Caller-scoped portfolio tools:

  • get_my_accounts

  • get_my_portfolio

  • get_my_open_orders

  • record_trade_execution

  • create_limit_order_record

  • update_limit_order_record

  • cancel_limit_order_record

  • update_cash_balance

  • get_my_strategy

  • update_my_strategy

Explicit sharing tools:

  • share_portfolio

  • revoke_portfolio_access

  • list_portfolio_access

  • get_shared_portfolios

Write tools require UUID idempotency keys. Concurrent updates use SQL Server rowversion values returned as hexadecimal strings.

Limit-order create and update tools accept optional duration and expires_on fields. duration accepts DAY, GTC, GTD, IOC, or FOK (including common long-form aliases), and expires_on uses YYYY-MM-DD. For example, an order good through October 2, 2026 uses duration="GTD" and expires_on="2026-10-02".

Private schema migrations

Run these in order against the investment database:

  1. sql/001_create_invest_schema.sql

  2. sql/002_add_private_tool_safety.sql

  3. sql/003_grant_mcp_connector_runtime.sql

  4. sql/004_add_database_api_tokens.sql

  5. sql/005_add_order_duration_expiration.sql

The second migration adds idempotency records, order status history, the (UserId, AccountId, ClientOrderId) uniqueness rule, and soft-deletion fields.

Database-backed bearer identity

Each user can have multiple independently revocable tokens. SQL Server stores only a SHA-256 digest of each cryptographically random 256-bit token. The MCP runtime cannot read token hashes or issue tokens; it can only execute invest.AuthenticateApiToken.

Issue a token from an administrator connection in SSMS:

EXEC invest.IssueApiToken
    @AuthenticationSubject = N'local:andreySr',
    @TokenName = N'Andrey Codex desktop',
    @ExpiresAt = '2027-08-10T00:00:00-04:00';

Copy PlaintextToken from the result immediately. It is returned only once and must be delivered to the user through a secure channel. Configure the hosted service with:

MCP_TOKEN_AUTH_MODE=database

The user's Codex configuration continues to reference an environment variable:

[mcp_servers.investments]
url = "https://investments-mcp.torusystems.com/mcp"
bearer_token_env_var = "INVESTMENTS_MCP_TOKEN"
startup_timeout_sec = 30
tool_timeout_sec = 120

Set INVESTMENTS_MCP_TOKEN to the issued plaintext token on that user's computer. Never store plaintext tokens in SQL Server, GitHub, logs, or support messages.

List or revoke tokens from an administrator connection:

EXEC invest.ListApiTokens
    @AuthenticationSubject = N'local:andreySr';

EXEC invest.RevokeApiToken
    @AuthenticationSubject = N'local:andreySr',
    @ApiTokenId = '00000000-0000-0000-0000-000000000000';

Safe migration from environment tokens

  1. Run migration 004 and issue a new database token.

  2. Set MCP_TOKEN_AUTH_MODE=hybrid, retaining the old token variables.

  3. Deploy and restart the service. Both old and database tokens work.

  4. Move every client to its new database token and verify caller isolation.

  5. Set MCP_TOKEN_AUTH_MODE=database, delete MCP_BEARER_TOKEN, MCP_DEFAULT_AUTH_SUBJECT, and MCP_TOKEN_SUBJECTS_JSON, then restart.

A future website should authenticate the human user, enforce subscription or entitlement rules separately from the token table, and call the issue/list/revoke procedures through a separate least-privilege database principal. The MCP runtime database principal must never receive token-administration permissions. For a public self-service integration, plan to add MCP-standard OAuth 2.1 rather than making permanent API keys the only login method.

The research tools call dbo.TradeGetDaysChangeReturn by default. If that procedure returns a large result set, create the optional filtered wrapper in sql/create_mcp_research_sp.sql and set:

MCP_RESEARCH_PROCEDURE=dbo.McpGetResearch
MCP_RESEARCH_PROCEDURE_HAS_FILTERS=true

Important

The order tools record portfolio state only. They do not submit orders to a brokerage. Codex approval prompts are supplemental protection; authorization is always enforced by this server.

F
license - not found
-
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    -
    quality
    D
    maintenance
    Provides database interaction and business intelligence capabilities, enabling users to run SQL queries, analyze business data, and automatically generate business insight memos for Microsoft SQL Server databases.
    39
    MIT
  • A
    license
    A
    quality
    C
    maintenance
    Provides access to Yahoo Finance data including real-time stock quotes, historical prices, financial statements, company info, symbol search, and news.
    6
    59
    1
    MIT
  • F
    license
    -
    quality
    D
    maintenance
    Provides secure, read-only access to Microsoft SQL Server with multi-layer protection, enabling safe query execution, schema discovery, and SQL script analysis through natural language.
    1
  • F
    license
    -
    quality
    D
    maintenance
    Enables secure interaction with Microsoft SQL Server databases, allowing schema exploration, metadata retrieval, and read-only query execution through natural language.
    1

View all related MCP servers

Related MCP Connectors

  • The stock market, in SQL — scan, replay, or subscribe across ~12k US tickers and top 100 cryptos.

  • Access SEC filings, insider transactions, and financial data via the ShareSEER API.

  • Search SEC filings, read 10-K/8-K, query XBRL facts, track Form 4 insider trades.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/smiryagin/investment_mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server