Skip to main content
Glama
laukikk

Alpaca Trading MCP Server

by laukikk

get_portfolio_summary

Retrieve a comprehensive summary of your trading portfolio, including account details and current open positions, to monitor your investment status.

Instructions

Get a comprehensive summary of the portfolio including account details and open positions.

Returns: Portfolio summary with account and positions information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The primary handler function for the 'get_portfolio_summary' tool. Decorated with @mcp.tool() which handles registration in FastMCP. Fetches account and positions data via helpers from calls.py and generates a formatted portfolio summary string.
    @mcp.tool()
    def get_portfolio_summary() -> str:
        """
        Get a comprehensive summary of the portfolio including account details and open positions.
        
        Returns:
            Portfolio summary with account and positions information
        """
        try:
            # Get account info
            account = calls.get_account(trading_client)
            
            # Get all positions
            positions = calls.get_positions(trading_client)
            
            # Generate summary
            summary = (
                f"Portfolio Summary\n"
                f"=================\n\n"
                f"Account Information:\n"
                f"-------------------\n"
                f"Status: {account.status}\n"
                f"Cash: ${account.cash:.2f}\n"
                f"Portfolio Value: ${account.portfolio_value:.2f}\n"
                f"Buying Power: ${account.buying_power:.2f}\n"
                f"Equity: ${account.equity:.2f}\n"
                f"Daytrade Count: {account.daytrade_count}\n"
                f"Pattern Day Trader: {account.pattern_day_trader}\n\n"
            )
            
            if positions:
                summary += f"Open Positions ({len(positions)}):\n-------------------\n"
                
                # Calculate total P/L and allocation
                total_pl = sum(pos.unrealized_pl for pos in positions)
                total_value = account.portfolio_value - account.cash
                
                for pos in positions:
                    pl_percent = pos.unrealized_plpc * 100
                    pl_sign = "+" if pos.unrealized_pl >= 0 else ""
                    allocation = (pos.market_value / account.portfolio_value) * 100 if account.portfolio_value > 0 else 0
                    
                    summary += (
                        f"{pos.symbol} ({pos.side.value.upper()}):\n"
                        f"  Quantity: {pos.qty}\n"
                        f"  Avg Entry: ${pos.avg_entry_price:.2f}\n"
                        f"  Current: ${pos.current_price:.2f}\n"
                        f"  Value: ${pos.market_value:.2f} ({allocation:.2f}% of portfolio)\n"
                        f"  P/L: {pl_sign}${pos.unrealized_pl:.2f} ({pl_sign}{pl_percent:.2f}%)\n\n"
                    )
                
                # Add overall P/L summary
                overall_pl_percent = (total_pl / total_value) * 100 if total_value > 0 else 0
                pl_sign = "+" if total_pl >= 0 else ""
                
                summary += (
                    f"Overall Position Summary:\n"
                    f"------------------------\n"
                    f"Total Position Value: ${total_value:.2f}\n"
                    f"Total Unrealized P/L: {pl_sign}${total_pl:.2f} ({pl_sign}{overall_pl_percent:.2f}%)\n"
                    f"Cash Allocation: ${account.cash:.2f} ({(account.cash / account.portfolio_value) * 100:.2f}% of portfolio)\n"
                )
            else:
                summary += "No open positions."
            
            return summary
        except Exception as e:
            return f"Error generating portfolio summary: {str(e)}"
  • src/server.py:547-547 (registration)
    The @mcp.tool() decorator registers this function as an MCP tool named 'get_portfolio_summary'.
    @mcp.tool()
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool returns a summary but doesn't describe what 'comprehensive' entails, whether it's real-time or cached data, if there are rate limits, authentication requirements, or error conditions. For a financial tool with zero annotation coverage, this leaves significant gaps in understanding its behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately concise with two sentences: one stating the purpose and one describing the return. Both sentences earn their place by providing essential information. It could be slightly more structured by front-loading the most critical information, but it's efficiently written without unnecessary words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (financial portfolio summary), lack of annotations, and no output schema, the description is minimally adequate. It explains what the tool does and what it returns at a high level, but doesn't provide details about the return structure, data freshness, or error handling. For a tool in a financial context with siblings that perform transactions, more completeness would be expected.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has 0 parameters with 100% schema description coverage, so the schema fully documents the absence of parameters. The description appropriately doesn't discuss parameters since none exist. It earns a 4 because it doesn't waste space on parameter discussion when none are needed, though it doesn't add value beyond the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Get a comprehensive summary of the portfolio including account details and open positions.' It specifies the verb ('Get') and resource ('portfolio summary'), and distinguishes it from siblings like get_account_info_tool by mentioning both account details AND positions. However, it doesn't explicitly contrast with get_account_info_tool, so it's not a perfect 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when to choose get_portfolio_summary over get_account_info_tool (which might provide only account info) or when it's appropriate to use this summary tool versus individual position/order tools. There's no context about prerequisites or timing.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/laukikk/alpaca-mcp'

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