Skip to main content
Glama

fxapis — MetaTrader 5

Close a position

close_position
DestructiveIdempotent

Closes a position on the user's real broker account (or demo), whole or by volume. Sent twice it opens the opposite position, so reuse an idempotency_key only to retry the same close. Example: {"account_id": "", "position_id": "", "idempotency_key": ""}

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
volumeNoOptional: how much to close. Omit to close the whole position. In lots, preferably as a string: "0.01" is a micro lot, "1.00" a standard lot.
commentNoOptional note stored on the order. MT5 keeps the first 17 characters after our reference.
account_idYesThe fxapis account id (a UUID) from list_accounts — not the MT5 login number.
position_idYesThe position ticket: `brokerPositionId` from list_positions.
client_order_idNoOptional reference of your own, echoed back on the order.
idempotency_keyYesA unique string you generate for THIS action, e.g. a fresh UUID. If a call fails or times out and you retry the same action, send the SAME key: fxapis then returns the first result instead of acting twice. Use a new key only for a genuinely new action.
deviation_pointsNoMaximum slippage in points.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
orderYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A3.7/5.0
Behavior4/5

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

Annotations declare destructiveHint=true and idempotentHint=true, but the description goes beyond them by warning that a duplicate send "opens the opposite position" and explaining the retry-vs-new-action distinction. That is a non-obvious, high-consequence behavioral trait. It does not cover auth/preconditions (e.g. whether the account must be online), so not a 5.

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?

Three sentences, front-loaded with the action, then the idempotency caveat, then a concrete example. No filler, though the phrase "Sent twice it opens the opposite position" is slightly ambiguous on its own before the following clause clarifies it.

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

Completeness4/5

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

With rich annotations, an output schema, and 100% schema coverage, the description's main remaining burden is the dangerous double-submit behavior, which it covers. A precondition an agent might need (e.g. does the account need to be brought online first) is not addressed, keeping it from a 5.

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 every parameter in detail. The description only restates the whole-vs-partial volume choice and shows a minimal call example, adding no syntax or format meaning beyond the schema. Baseline 3 is appropriate.

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?

States a specific verb and resource ("Closes a position") plus scope ("whole or by volume") and the target ("user's real broker account (or demo)"). It is clear what the tool does, but it never distinguishes itself from the similar siblings modify_position or place_market_order, so it stops short of a 5.

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

Usage Guidelines3/5

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

It gives real conditional guidance about the idempotency key (reuse only to retry the same close, new key for a new action) and notes that omitting volume closes the whole position. However it never says when to pick this tool over modify_position or place_market_order, so usage context is only partial.

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

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.

Resources