Skip to main content
Glama
kea0811
by kea0811

ig_switch_account

Switch to a different trading account on IG Trading by specifying the account ID. Enables users to manage multiple accounts efficiently for forex, indices, and commodities trading.

Instructions

Switch to a different trading account

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
accountIdYesAccount ID to switch to

Implementation Reference

  • Core handler function that switches the IG trading account by sending a PUT request to '/session' endpoint with the accountId and updates the session tokens.
    async switchAccount(accountId) {
      try {
        const response = await this.apiClient.put('/session', { accountId }, 1);
        
        config.setSessionTokens({
          'x-security-token': response.headers['x-security-token'],
          cst: response.headers.cst,
          lightstreamerEndpoint: config.sessionTokens.lightstreamerEndpoint,
          currentAccountId: accountId
        });
    
        logger.info(`Switched to account: ${accountId}`);
        return response.data;
      } catch (error) {
        logger.error('Account switch failed:', error.message);
        throw error;
      }
  • Tool schema definition including input validation requiring 'accountId'.
    {
      name: 'ig_switch_account',
      description: 'Switch to a different trading account',
      inputSchema: {
        type: 'object',
        properties: {
          accountId: {
            type: 'string',
            description: 'Account ID to switch to',
          },
        },
        required: ['accountId'],
      },
    },
  • MCP server dispatch handler that calls the igService.switchAccount method and formats the response.
    case 'ig_switch_account':
      const switchResult = await igService.switchAccount(args.accountId);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(switchResult, null, 2),
          },
        ],
      };
  • Registers the list of tools including ig_switch_account by returning the TOOLS array in response to ListToolsRequest.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: 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