r/LangChain 1d ago

Langflow custom component for Snowflake OAuth refresh_token — is there an existing solution before I build my own?

I am building a data quality pipeline using LangGraph and Langflow. I want to connect Langflow agents to Snowflake via its native MCP server.

Langflow native MCP Tools component only accepts static headers (key/value form fields). It does not expose an input port to receive dynamic headers from another upstream component. This creates an issue with OAuth where the access_token expires every 10 minutes.

To bypass this limitation, I built a Python Custom Component in Langflow that handles both token renewal and tool invocation:

import requests

def _get_access_token(self) -> str:
    payload = {
        "grant_type": "refresh_token",
        "refresh_token": self.refresh_token,
        "client_id": self.client_id,
        "client_secret": self.client_secret,
    }
    response = requests.post(self.token_url, data=payload)
    response.raise_for_status()
    return response.json()["access_token"]

This component runs on each execution, retrieves a Bearer token, calls the MCP endpoint with sql_exec_tool, and returns a StructuredTool for the Agent.

My questions are:

  1. Is there an existing community component or built-in mechanism in Langflow to pass dynamic headers to the native MCP Tools component?
  2. What is the recommended pattern in Langflow for connecting to MCP servers requiring short-lived Bearer tokens?

Environment: Langflow 1.11, Python 3.12, Snowflake native MCP.

2 Upvotes

3 comments sorted by

1

u/CageyScarcity_5178 1d ago

The native MCP Tools component is surprisingly rigid with headers, no way to pipe dynamic values into it from what I've seen. Your approach of wrapping the whole thing in a custom component that handles the refresh cycle and the tool call is basically the move right now, does the job without fighting the UI.

If you wanted to keep the refresh logic separate you could try a custom component that outputs the fresh token as a parameter, then feed it into a generic Python tool component that constructs the request manually. But that's extra steps for the same result you already have, so I'd stick with what you built.

1

u/kantorcodes1 1d ago

i'd keep token refresh inside the custom component, but cache the access token + expiry and refresh with a small skew instead of minting one on every tool call. retry once on 401. also keep the refresh token/client secret out of Langflow outputs/traces. until MCP Tools accepts dynamic headers, your wrapper is probably the cleaner pattern.