docs/versioned_docs/version-1.8.0/Agents/mcp-client.mdx
import Icon from "@site/src/components/icon"; import McpIcon from '@site/static/logos/mcp-icon.svg'; import PartialMcpNodeTip from '@site/docs/_partial-mcp-node-tip.mdx'; import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';
Langflow integrates with the Model Context Protocol (MCP) as both an MCP server and an MCP client.
This page describes how to use Langflow as an MCP client with the MCP Tools component and connected MCP servers.
For information about using Langflow as an MCP server, see Use Langflow as an MCP server.
The MCP Tools component connects to an MCP server so that a Langflow agent can use the server's tools when responding to user queries.
This component has two modes, depending on the type of server you want to access:
Add an MCP Tools component to your flow.
In the MCP Server field, select a previously connected server or click <Icon name="Plus" aria-hidden="true"/> Add MCP Server.
There are multiple ways to add a new server:
uvx mcp-server-fetch.http://localhost:7860/api/v1/mcp/project/PROJECT_ID/streamable or http://localhost:7860/api/v1/mcp/streamable. For more information, see Connect to a Langflow MCP server.To configure headers for your MCP server, enter each header in the Headers fields as key-value pairs. You can use global variables in header values by entering the global variable name as the header value. For more information, see Use global variables in MCP server headers.
To use environment variables in your server command, enter each variable in the Env fields as key-value pairs.
In the Tool field, select a tool that you want this component to use, or leave the field blank to allow access to all tools provided by the MCP server.
If you select a specific tool, you might need to configure additional tool-specific fields. For information about tool-specific fields, see your MCP server's documentation.
At this point, the MCP Tools component is serving a tool from the connected server, but nothing is using the tool. The next steps explain how to make the tool available to an Agent component so that the agent can use the tool in its responses.
In the component's header menu, enable Tool mode so you can use the component with an agent.
Connect the MCP Tools component's Toolset port to an Agent component's Tools port.
If not already present in your flow, make sure you also attach Chat Input and Chat Output components to the Agent component.
Test your flow to make sure the MCP server is connected and the selected tool is used by the agent. Open the Playground, and then enter a prompt that uses the tool you connected through the MCP Tools component.
For example, if you use mcp-server-fetch with the fetch tool, you could ask the agent to summarize recent tech news. The agent calls the MCP server function fetch, and then returns the response.
If you want the agent to be able to use more tools, repeat these steps to add more tools components with different servers or tools.
Every Langflow project runs a separate MCP server that exposes the project's flows as MCP tools. For more information about your projects' MCP servers, including exposing flows as MCP tools, see Use Langflow as an MCP server.
Langflow MCP servers support both the streamable HTTP transport and Server-Sent Events (SSE) as a fallback.
To leverage flows-as-tools, use the MCP Tools component to connect to a project's MCP endpoint:
Add an MCP Tools component to your flow, click <Icon name="Plus" aria-hidden="true"/> Add MCP Server, and then select HTTP/SSE mode.
In the MCP URL field, enter your Langflow server's MCP endpoint.
http://localhost:7860/api/v1/mcp/project/PROJECT_ID/streamablehttp://localhost:7860/api/v1/mcp/streamablehttp://localhost:7868/All flows available from the targeted server are treated as tools.
In the component's header menu, enable Tool Mode so you can use the component with an agent.
Connect the MCP Tools component's Toolset port to an Agent component's Tools port.
If not already present in your flow, make sure you also attach Chat Input and Chat Output components to the Agent component.
Test your flow to make sure the agent uses your flows to respond to queries. Open the Playground, and then enter a prompt that uses a flow that you connected through the MCP Tools component.
If you want the agent to be able to use more tools, repeat these steps to add more tools components with different servers or tools.
| Name | Type | Description |
|---|---|---|
| mcp_server | String | Input parameter. The MCP server to connect to. Select from previously configured servers or add a new one. |
| tool | String | Input parameter. The specific tool to execute from the connected MCP server. Leave blank to allow access to all tools. |
| use_cache | Boolean | Input parameter. Enable caching of MCP server and tools to improve performance. Default: false. |
| verify_ssl | Boolean | Input parameter. Enable SSL certificate verification for HTTPS connections. Default: true. |
| response | DataFrame | Output parameter. DataFrame containing the response from the executed tool. |
To manage all MCP server connections for your Langflow client, click <McpIcon /> MCP servers in the visual editor, or click your profile icon, select Settings, and then click MCP Servers.
To add a new MCP server, click Add MCP Server, and then follow the steps in Use the MCP Tools component to configure the connection and use the server in a flow.
Click <Icon name="Ellipsis" aria-hidden="true"/> More to edit or delete an MCP server connection.
You can modify MCP server environment variables at runtime when running flows through the Langflow API by tweaking the MCP Tools component.
You can include tweaks with any Langflow API request that supports the tweaks parameter, such as POST requests to the /run or /webhook endpoints.
For more information, see Input schema (tweaks).
To modify the MCP Tools component's environment variables with tweaks, do the following:
Open the flow that contains your MCP Tools component.
To find the MCP Tools component's unique ID, in your MCP Tools component, click <Icon name="SlidersHorizontal" aria-hidden="true"/> Controls.
The component's ID is displayed in the Controls pane, such as MCPTools-Bzahc.
Send a POST request to the Langflow server's /run endpoint, and include tweaks to the MCP Tools component.
The following examples demonstrate a request structure with the env object nested under mcp_server in the tweaks payload:
import requests
import os
LANGFLOW_SERVER_ADDRESS = "http://localhost:7860"
FLOW_ID = "your-flow-id"
LANGFLOW_API_KEY = os.getenv("LANGFLOW_API_KEY")
MCP_TOOLS_COMPONENT_ID = "MCPTools-Bzahc"
url = f"{LANGFLOW_SERVER_ADDRESS}/api/v1/run/{FLOW_ID}?stream=false"
headers = {
"Content-Type": "application/json",
"x-api-key": LANGFLOW_API_KEY
}
payload = {
"output_type": "chat",
"input_type": "chat",
"input_value": "What sales data is available to me?",
"tweaks": {
MCP_TOOLS_COMPONENT_ID: {
"mcp_server": {
"env": {
"API_URL": "https://api.example.com",
"API_KEY": "your-mcp-server-api-key",
"ENVIRONMENT": "production"
}
}
}
}
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const LANGFLOW_SERVER_ADDRESS = "http://localhost:7860";
const FLOW_ID = "your-flow-id";
const LANGFLOW_API_KEY = process.env.LANGFLOW_API_KEY || "";
const MCP_TOOLS_COMPONENT_ID = "MCPTools-Bzahc";
const url = `${LANGFLOW_SERVER_ADDRESS}/api/v1/run/${FLOW_ID}?stream=false`;
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": LANGFLOW_API_KEY,
},
body: JSON.stringify({
output_type: "chat",
input_type: "chat",
input_value: "What sales data is available to me?",
tweaks: {
[MCP_TOOLS_COMPONENT_ID]: {
mcp_server: {
env: {
API_URL: "https://api.example.com",
API_KEY: "your-mcp-server-api-key",
ENVIRONMENT: "production",
},
},
},
},
}),
});
const data = await response.json();
console.log(data);
curl --request POST \
--url "http://LANGFLOW_SERVER_ADDRESS/api/v1/run/FLOW_ID?stream=false" \
--header "Content-Type: application/json" \
--header "x-api-key: LANGFLOW_API_KEY" \
--data '{
"output_type": "chat",
"input_type": "chat",
"input_value": "What sales data is available to me?",
"tweaks": {
"MCP_TOOLS_COMPONENT_ID": {
"mcp_server": {
"env": {
"API_URL": "https://api.example.com",
"API_KEY": "your-mcp-server-api-key",
"ENVIRONMENT": "production"
}
}
}
}
}'
Replace MCP_TOOLS_COMPONENT_ID, LANGFLOW_API_KEY, LANGFLOW_SERVER_ADDRESS, and FLOW_ID with the actual values from your Langflow deployment.
Langflow doesn't automatically discover or expose which environment variables your MCP server accepts from the MCP Tools component.
To determine which environment variables your MCP server accepts, see the MCP server's documentation. For example, the Astra DB MCP server requires ASTRA_DB_APPLICATION_TOKEN and ASTRA_DB_API_ENDPOINT, with an optional variable for ASTRA_DB_KEYSPACE, as documented in its repository.
You can use global variables in MCP server header values to securely store and reference API keys, authentication tokens, and other sensitive values. This is particularly useful for deployment scenarios where you need to pass user-specific credentials at runtime.
Enter a global variable name as the header value, and Langflow resolves the global variable name to its actual value before making the MCP server request. Langflow only passes the token value to your server; it doesn't validate tokens on behalf of your MCP server.
For example, to create a global variable named TEST_BEARER_TOKEN for MCP server bearer authentication, do the following:
To open the Global Variables pane, click your profile icon, select Settings, and then click <Icon name="Globe" aria-hidden="true"/> Global Variables.
Create a Credential global variable named TEST_BEARER_TOKEN.
In the Value field, enter your MCP server's bearer token value. The value must include the Bearer prefix with a space, for example: Bearer eyJhbG....
Click Save Variable.
To manage MCP server connections for your Langflow client, click <McpIcon /> MCP servers in the visual editor, or click your profile icon, select Settings, and then click MCP Servers.
Click <Icon name="Plus" aria-hidden="true"/> Add MCP Server.
Select the following:
http://127.0.0.1:8000/mcp.Authorization. For the key's value, enter TEST_BEARER_TOKEN, or the exact name of your global variable.Click Create Server.
If the connection succeeds, Langflow shows the number of tools exposed by the server.
After creating the server and global variable, you can connect to the server with the MCP Tools component, as explained in the next steps.
Add the MCP Tools component to a flow.
In the MCP Tools component, select the MCP Server you created.
The MCP server configuration already includes the headers you configured earlier, so no further configuration is needed in the component. The global variable TEST_BEARER_TOKEN is automatically resolved when the component makes requests to the MCP server.
Optional: To override headers or add additional headers to the MCP Tools component, click the component to view the Headers parameter in the component inspection panel, and then add header key values. Headers configured in the component take precedence over the headers configured in the MCP server settings.
Test your flow to make sure the agent uses your server to respond to queries. Open the Playground, and then enter a prompt that uses a tool that you connected through the MCP Tools component.
Langflow automatically resolves TEST_BEARER_TOKEN to its actual value before sending the request to the MCP server. When your MCP server receives the request, the Authorization header contains the resolved token value.