Skip to main content
Glama
kea0811
by kea0811

ig_close_position

Close an open trading position by specifying the deal ID. Facilitates efficient position management within the IG Trading MCP server for forex, indices, and commodities.

Instructions

Close an open position

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dealIdYesDeal ID of the position to close

Implementation Reference

  • Core implementation of closing a position: fetches current positions, constructs opposite market close ticket, sends DELETE request to IG API /positions/otc, retrieves confirmation if available.
    async closePosition(dealId) {
      try {
        const positions = await this.getPositions();
        const position = positions.positions.find(p => p.position.dealId === dealId);
        
        if (!position) {
          throw new Error(`Position ${dealId} not found`);
        }
    
        const closeTicket = {
          dealId,
          direction: position.position.direction === 'BUY' ? 'SELL' : 'BUY',
          orderType: 'MARKET',
          size: position.position.size
        };
    
        const response = await this.apiClient.delete('/positions/otc', closeTicket, 1);
        
        if (response.data.dealReference) {
          const confirmation = await this.getConfirmation(response.data.dealReference);
          return {
            position: response.data,
            confirmation
          };
        }
        
        return response.data;
      } catch (error) {
        logger.error(`Failed to close position ${dealId}:`, error.message);
        throw error;
      }
    }
  • Tool schema definition including name, description, and input validation requiring dealId.
    {
      name: 'ig_close_position',
      description: 'Close an open position',
      inputSchema: {
        type: 'object',
        properties: {
          dealId: {
            type: 'string',
            description: 'Deal ID of the position to close',
          },
        },
        required: ['dealId'],
      },
    },
  • MCP tool dispatch/registration: handles CallToolRequest for ig_close_position by invoking igService.closePosition and formatting JSON response.
    case 'ig_close_position':
      const closeResult = await igService.closePosition(args.dealId);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(closeResult, null, 2),
          },
        ],
      };
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 action ('Close') which implies a destructive mutation, but doesn't mention consequences (e.g., financial settlement, irreversible action), permissions required, rate limits, or what happens after closing. This leaves significant behavioral gaps for a mutation tool.

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

Conciseness5/5

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

The description is a single, efficient sentence that states the core action without unnecessary words. It's appropriately sized for a simple tool with one parameter and gets straight to the point.

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?

For a mutation tool with no annotations and no output schema, the description is incomplete. It doesn't explain what 'closing' entails (e.g., selling assets, settling trades), potential side effects, error conditions, or return values. Given the complexity of financial position management, this leaves too many unanswered questions.

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 100%, so the schema already documents the single parameter 'dealId' adequately. The description doesn't add any additional meaning about the parameter beyond what's in the schema (e.g., format examples, where to find deal IDs). Baseline 3 is appropriate when the schema does the heavy lifting.

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 resource ('an open position'), making the purpose immediately understandable. However, it doesn't differentiate from the sibling tool 'ig_close_all_positions' or specify what type of position (e.g., trading position) is being closed, which prevents a perfect score.

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 like 'ig_close_all_positions' or 'ig_update_position'. It lacks context about prerequisites (e.g., needing an open position) or typical scenarios for closing a single position versus all positions.

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

Related 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/kea0811/ig-trading-mcp'

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