Skip to main content
Glama
VaishnaviK23

Trading MCP Server

by VaishnaviK23

portfolio

Calculate current stock holdings by analyzing trade history to show net shares for each symbol with positive balances.

Instructions

Show current portfolio holdings.

This tool calculates the net number of shares held for each stock symbol by summing all buy and sell trades in the trade history CSV.

Returns: A dictionary mapping stock symbols to their current number of held shares. Only symbols with a positive balance are included.

Example: portfolio() -> {"AAPL": 120, "GOOG": 60}

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The 'portfolio' tool implementation. It uses the @mcp.tool() decorator for registration and calculates holdings from a global DataFrame 'df'.
    @mcp.tool()
    def portfolio() -> dict[str, int]:
        """Show current portfolio holdings.
    
        This tool calculates the net number of shares held for each stock symbol by
        summing all buy and sell trades in the trade history CSV.
    
        Returns:
            A dictionary mapping stock symbols to their current number of held shares.
            Only symbols with a positive balance are included.
    
        Example:
            portfolio() -> {"AAPL": 120, "GOOG": 60}
        """
        holdings = defaultdict(int)
        for _, row in df.iterrows():
            if row['type'] == 'Buy':
                holdings[row['symbol']] += row['shares']
            else:
                holdings[row['symbol']] -= row['shares']
        return {k: v for k, v in holdings.items() if v > 0}

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/VaishnaviK23/Trading-MCP-Server'

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