Skip to main content
Tool calls can be grouped together using custom headers. This can be used to group tool calls that are part of the same chat session, same product, or any other custom grouping.

Adding custom headers

Merge Agent Handler will register any header with a prefix of X- as a custom header, and will store that information. We’ll associate the header with the given tool call. These headers will be visible in the logs dashboard, and filterable using the Request Headers filter. Example code snippet:
async def connect_to_mcp():
    """Connect to an MCP server and use its tools"""
    from mcp.client.streamable_http import streamablehttp_client
    from mcp import ClientSession

    # Custom headers for authentication and other requirements
    headers = {
        "Authorization": "Bearer <auth_token>",
        "Mcp-Session-Id": "session-" + str(asyncio.current_task().get_name()), 
        "X-chat-session-id": "chat-" + str(asyncio.current_task().get_name())
    }
    
    # MCP server URL
    server_url = "https://ah-api.merge.dev/api/v1/tool-packs/<tool_pack_id>/registered-users/<registered_user_id>/mcp"
Example headers:
  • X-chat-session-id: used to group tool calls that are part of the same end-user chat session
  • X-workflow-id: used to group tool calls that are part of the same workflow
  • X-product-id: used to group tool calls from that were called from the same product
Within the logs dashboard, you can filter on any custom header sent to Merge Agent Handler.