Skip to main content
Glama
laukikk

Alpaca Trading MCP Server

by laukikk

close_position

Close an open trading position for a specified stock symbol to manage portfolio risk and lock in profits or losses.

Instructions

Close an open position for a specific symbol.

Args: symbol: Stock symbol to close position for

Returns: Confirmation of position closure

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYes

Implementation Reference

  • The handler function decorated with @mcp.tool() that implements the close_position tool. It validates the existence of a position for the given symbol and closes it using the Alpaca trading client, returning appropriate success or error messages.
    @mcp.tool()
    def close_position(symbol: str) -> str:
        """
        Close an open position for a specific symbol.
        
        Args:
            symbol: Stock symbol to close position for
        
        Returns:
            Confirmation of position closure
        """
        try:
            # First check if position exists
            position = calls.get_position(trading_client, symbol)
            if not position:
                return f"No open position found for {symbol}."
            
            # Close the position
            trading_client.close_position(symbol)
            return f"Position for {symbol} has been successfully closed."
        except Exception as e:
            return f"Error closing position for {symbol}: {str(e)}"
Behavior2/5

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

No annotations are provided, so the description carries full burden. It states the action is to 'close' a position, implying a destructive/mutative operation, but doesn't disclose critical behavioral traits: whether this requires specific permissions, if it's irreversible, what happens on failure (e.g., symbol not found), rate limits, or confirmation details. For a mutation tool with zero annotation coverage, this is a significant gap.

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 sized and front-loaded: the first sentence states the core purpose clearly. The Args and Returns sections are structured but could be more integrated. No wasted sentences, though it could be slightly more polished (e.g., merging sections).

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

Completeness2/5

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

Given complexity (a destructive financial operation), no annotations, no output schema, and low schema coverage, the description is incomplete. It lacks details on behavioral risks, error handling, return format (beyond vague 'Confirmation'), and context like account or position type. For such a tool, more comprehensive guidance is needed.

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

Parameters3/5

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

Schema description coverage is 0%, so the description must compensate. It adds meaning by specifying 'symbol' as a 'Stock symbol to close position for', which clarifies the parameter's purpose beyond the schema's generic 'Symbol' title. However, it doesn't provide format details (e.g., ticker format like 'AAPL'), validation rules, or examples, leaving some ambiguity.

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 action ('Close') and target resource ('an open position for a specific symbol'), which is specific and unambiguous. It distinguishes from siblings like cancel_order (which cancels unfilled orders) and place_*_order tools (which open positions). However, it doesn't explicitly mention what type of position (long/short) or account context, leaving slight room for improvement.

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 prerequisites (e.g., must have an open position for the symbol), exclusions (e.g., cannot close if no position exists), or comparisons to sibling tools like cancel_order (for orders) or place_*_order (for opening). Usage is implied but not explicitly stated.

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