How to Correctly Use the 'accountId' Parameter to Target Specific Accounts in MCP Tool Integration?

This topic was automatically generated from Slack. You can find the original thread here.

Hi Guys,

I’m currently integrating one of your MCP tools (for example, google_calendar) and have multiple accounts connected for the same app.
I’m passing all the required headers in my request, including:
x-pd-project-id
x-pd-environment
x-pd-external-user-id
x-pd-app-slug
x-pd-tool-mode
x-pd-account-id
Authorization
Additionally, I tried passing the accountId as a query parameter in the request URL as follows:

https://remote.mcp.pipedream.net/{external_user_id}/google_calendar?accountId={account_id}

However, the response always seems to come from the latest connected account instead of the specific account ID I’m trying to target.

Could you please confirm:

  1. Whether the accountId parameter is supported when calling the MCP tool endpoint directly?
  2. If so, should it be passed in the query string, headers, or request body?
  3. Is there any specific format or configuration needed to select a particular connected account?
    I’ve already verified that both accounts are linked and accessible under the same external user.
    Please someone help me to figure out this issue !

Can you show the full code snippet for how you’re calling the MCP server?

Btw in the future, it only slows down our team’s ability to help out when you post the same question in 3 different channels — we’ll see it, regardless of which channel you post a question in :pray::skin-tone-2:

I am sorry
i was so tired as i have tried a lot to solve this issue

Here is the full code snippet i am trying :

async def call_google_calendar_tool(tool_name: str, arguments: dict = None, account_id: str = None):
    """Call a specific Google Calendar MCP tool

    Args:
        tool_name: Name of the MCP tool to call
        arguments: Dictionary of arguments to pass to the tool
        account_id: Optional account ID (authProvisionId) to use for this call.
                   If not provided, Pipedream will use the most recently created account.
                   Example: "apn_x7hXoMr" or "apn_KAhXr0w"
    """
    try:
        # Get access token from Pipedream SDK
        access_token = pd.raw_access_token

        # Construct server URL for Google Calendar
        server_url = f"{MCP_SERVER_URL}/{EXTERNAL_USER_ID}/{APP_SLUG}"

        # Configure MCP client with authentication headers
        headers = {
            "Authorization": f"Bearer {access_token}",
            "x-pd-project-id": PIPEDREAM_PROJECT_ID,
            "x-pd-environment": PIPEDREAM_ENVIRONMENT,
            "x-pd-external-user-id": EXTERNAL_USER_ID,
            "x-pd-app-slug": APP_SLUG,
            "x-pd-tool-mode": "tools-only"
        }

        # Add account ID header if specified
        if account_id:
            headers["x-pd-account-id"] = account_id
            print(f"Using specific account: {account_id}")

        # Create MCP client connection
        async with streamablehttp_client(server_url, headers=headers) as (read, write, _):
            async with ClientSession(read, write) as session:
                await session.initialize()

                # Call the specific tool
                print(f"Calling tool: {tool_name}")
                print(f"Arguments: {json.dumps(arguments, indent=2)}")

                result = await session.call_tool(tool_name, arguments or {})

                print(f"--------{result}")
                print(f"Tool call successful!")
                print(f"Result: {json.dumps(result.content, indent=2)}")

                return result

    except Exception as e:
        print(f"Error calling tool {tool_name}: {e}")
        return None 

what happening is
i have connected 2 accounts with google_calendar
and i tried to pass the account_id in headers also in query parameters as well
but its taking latest connected account_id while calling the tool

i am expecting this to use the provided account_id to interact with respective app

I think I’m able to reproduce, it might be a bug on our side, I’m still looking into it

yes i am sure about the implementation at our end
other things are working fine and integrated in our platform as well
please keep me posted on the same if the bugs get resolved

Okay I think I’ve identified the bug and have a potential fix, hoping we can ship it tomorrow

We’ll update this issue when the fix goes out: [BUG] accountId arg is not always respected in the MCP server · Issue #18772 · PipedreamHQ/pipedream · GitHub

FYI I just shipped a fix for this and confirmed it’s now working as expected for me — can you try again?

Hey ,
Just tested it — everything’s working perfectly now
The accountId is being respected as expected.
Thanks a ton for the quick fix and support! :raised_hands:

Great! Thanks for flagging and thanks for your patience