Skip to main content
Glama
iaptic

Iaptic MCP Server

Official
by iaptic

iaptic_switch_app

Switch to a different Iaptic app by specifying the app name and optional API key. Subsequent API calls use the new app's credentials.

Instructions

Switch to a different Iaptic app.

  • Allows temporarily using a different app's credentials

  • All subsequent API calls will use the new app name and API key

  • Useful for managing multiple apps in the same session

  • Required: appName parameter (apiKey required only if not using master key)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
appNameYesName of the app to switch to
apiKeyNoAPI key for the app (not required if using master key)

Implementation Reference

  • Handler for the 'iaptic_switch_app' tool. Routes to the switchApp method on the IapticAPI class, handling both master-key and app-specific API key scenarios. Returns success message or error if apiKey is missing when not using a master key.
    async handleTool(name: string, args: any) {
      switch (name) {
        case 'iaptic_switch_app': {
          const appInfo = this.api.getCurrentAppInfo();
          
          // If using master key, apiKey is not required
          if (appInfo.usingMasterKey && !args.apiKey) {
            this.api.switchApp('dummy-api-key', args.appName);
            return {
              content: [{
                type: "text",
                text: `Successfully switched to app: ${args.appName}`
              }]
            };
          }
          
          // Otherwise, apiKey is required
          if (!args.apiKey) {
            return {
              isError: true,
              content: [{
                type: "text",
                text: "Error: apiKey parameter is required when not using a master key"
              }]
            };
          }
          
          this.api.switchApp(args.apiKey, args.appName);
          return {
            content: [{
              type: "text",
              text: `Successfully switched to app: ${args.appName}`
            }]
          };
        }
  • Input schema definition for 'iaptic_switch_app' tool. Requires appName (string) and optionally apiKey (string). Includes description explaining the tool allows switching to a different Iaptic app's credentials.
          {
            name: "iaptic_switch_app",
            description: `Switch to a different Iaptic app.
    - Allows temporarily using a different app's credentials
    - All subsequent API calls will use the new app name and API key
    - Useful for managing multiple apps in the same session
    - Required: appName parameter (apiKey required only if not using master key)`,
            inputSchema: {
              type: "object",
              properties: {
                appName: { 
                  type: "string", 
                  description: "Name of the app to switch to" 
                },
                apiKey: { 
                  type: "string", 
                  description: "API key for the app (not required if using master key)" 
                }
              },
              required: ["appName"]
            }
          },
  • Core implementation of switchApp() on IapticAPI. If master key is set, only updates appName; otherwise updates both apiKey and appName. Then re-initializes the HTTP client with new credentials.
    // Method to switch to a different app
    switchApp(apiKey: string, appName: string): void {
      // If we have a master key, we only need to update the appName
      if (this.masterKey) {
        this.appName = appName;
        console.error(`Switched to app: ${appName} (using master key)`);
      } else {
        this.apiKey = apiKey;
        this.appName = appName;
        console.error(`Switched to app: ${appName}`);
      }
      this.initializeClient();
    }
  • src/server.ts:68-110 (registration)
    Registration of all tools, including iaptic_switch_app, via ListToolsRequestSchema. Tool calls starting with 'iaptic_' are routed to AppTools.handleTool() in the CallToolRequestSchema handler.
    private setupHandlers() {
      // List available tools
      this.server.setRequestHandler(ListToolsRequestSchema, async () => {
        return {
          tools: [
            ...this.tools.customers.getTools(),
            ...this.tools.purchases.getTools(),
            ...this.tools.transactions.getTools(),
            ...this.tools.statistics.getTools(),
            ...this.tools.stripe.getTools(),
            ...this.tools.events.getTools(),
            ...this.tools.app.getTools()
          ]
        };
      });
    
      // Handle tool calls
      this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
        const { name, arguments: args } = request.params;
        
        try {
          // Route tool calls to appropriate handler
          if (name.startsWith('customer_')) {
            return await this.tools.customers.handleTool(name, args);
          }
          if (name.startsWith('purchase_')) {
            return await this.tools.purchases.handleTool(name, args);
          }
          if (name.startsWith('transaction_')) {
            return await this.tools.transactions.handleTool(name, args);
          }
          if (name.startsWith('stats_')) {
            return await this.tools.statistics.handleTool(name, args);
          }
          if (name.startsWith('stripe_')) {
            return await this.tools.stripe.handleTool(name, args);
          }
          if (name.startsWith('event_')) {
            return await this.tools.events.handleTool(name, args);
          }
          if (name.startsWith('iaptic_')) {
            return await this.tools.app.handleTool(name, args);
          }
  • initializeClient() recreates the HTTP client with updated auth token (appName + apiKey or masterKey), used by switchApp() after changing credentials.
    private initializeClient() {
      const authToken = this.masterKey 
        ? Buffer.from(`${this.appName}:${this.masterKey}`).toString('base64')
        : Buffer.from(`${this.appName}:${this.apiKey}`).toString('base64');
    
      this.client = axios.create({
        baseURL: 'https://validator.iaptic.com/v3',
        headers: {
          'Authorization': `Bearer ${authToken}`,
          'Content-Type': 'application/json'
        }
      });
    
      // Add request interceptor to log curl command
      this.client.interceptors.request.use(request => {
        const method = (request.method || 'GET').toUpperCase();
        const url = (request.baseURL || '') + (request.url || '');
        const headers = Object.entries(request.headers)
          .map(([key, value]) => `-H '${key}: ${value}'`)
          .join(' ');
        const data = request.data ? `-d '${JSON.stringify(request.data)}'` : '';
        const params = request.params ? 
          '?' + new URLSearchParams(request.params).toString() : '';
        
        console.error(`curl -X ${method} '${url}${params}' ${headers} ${data}`);
        return request;
      });
    
      // Add response interceptor for error handling
      this.client.interceptors.response.use(
        response => response,
        (error: AxiosError<IapticErrorResponse>) => {
          if (error.response?.data) {
            const { message, code, status } = error.response.data;
            throw new Error(`Iaptic API Error (${status || code}): ${message || 'Unknown error'}`);
          }
          throw error;
        }
      );
    }
Behavior4/5

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

Without annotations, the description discloses key behavioral traits: temporary state change affecting all subsequent calls, and apiKey conditional on master key. This provides sufficient transparency for a state-switching 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 uses bullet points to convey essential information efficiently. Every sentence adds value: purpose, effect, use case, and parameter requirements. No redundant or filler content.

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?

The description adequately covers the tool's effect on session state, parameter requirements, and typical use case. It lacks return value details, but for a utility action without output schema, this is acceptable. Sibling tools provide additional context.

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?

Schema coverage is 100%, so the description adds value by clarifying the conditional nature of apiKey (not needed with master key) and the effect of appName on credentials. This goes beyond the schema's basic descriptions.

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

Purpose5/5

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

The description clearly states the tool switches to a different Iaptic app, with a specific verb and resource. It distinguishes from siblings like iaptic_current_app and iaptic_reset_app by focusing on switching credentials for subsequent API calls.

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

Usage Guidelines4/5

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

The description provides context for when to use: temporarily using different app credentials for multi-app management. It mentions prerequisites (appName required, apiKey conditional) but does not explicitly exclude scenarios or compare with alternatives like iaptic_reset_app.

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/iaptic/mcp-server-iaptic'

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