Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/backend/base/langflow/api/v1/mcp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,9 @@ async def execute_tool(session):
msg = f"Flow '{name}' not found in project {project_id}"
raise ValueError(msg)

# Process inputs
processed_inputs = dict(arguments)
# Convert inputs to tweaks
def transform_arguments(args: dict) -> dict:
return {key: {"input_value": value} for key, value in args.items()}

# Initial progress notification
if mcp_config.enable_progress_notifications and (progress_token := server.request_context.meta.progressToken):
Expand All @@ -203,7 +204,9 @@ async def execute_tool(session):

conversation_id = str(uuid4())
input_request = SimplifiedAPIRequest(
input_value=processed_inputs.get("input_value", ""), session_id=conversation_id
# input_value=processed_inputs.get("input_value", ""),
session_id=conversation_id,
tweaks=transform_arguments(arguments),
)

async def send_progress_updates(progress_token):
Expand Down
39 changes: 15 additions & 24 deletions src/backend/base/langflow/helpers/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from uuid import UUID

from fastapi import HTTPException
from lfx.log.logger import logger
from pydantic.v1 import BaseModel, Field, create_model
from sqlalchemy.orm import aliased
from sqlmodel import asc, desc, select
Expand Down Expand Up @@ -446,35 +445,27 @@ def json_schema_from_flow(flow: Flow) -> dict:

graph = Graph.from_payload(flow_data)
input_nodes = [vertex for vertex in graph.vertices if vertex.is_input]

properties = {}
required = []
for node in input_nodes:
node_data = node.data["node"]
name = node.data["id"]

template = node_data["template"]

properties[name] = {"type": "string", "description": f"Input for {name}"}

for field_name, field_data in template.items():
if field_data != "Component" and field_data.get("show", False) and not field_data.get("advanced", False):
field_type = field_data.get("type", "string")
properties[field_name] = {
"type": field_type,
"description": field_data.get("info", f"Input for {field_name}"),
}
# Update field_type in properties after determining the JSON Schema type
if field_type == "str":
field_type = "string"
elif field_type == "int":
field_type = "integer"
elif field_type == "float":
field_type = "number"
elif field_type == "bool":
field_type = "boolean"
else:
logger.warning(f"Unknown field type: {field_type} defaulting to string")
field_type = "string"
properties[field_name]["type"] = field_type

if field_data.get("required", False):
required.append(field_name)
if field_name.startswith("mcp_"):
if field_name == "mcp_description":
val = field_data.get("value")
properties[name]["description"] = val or f"Input for {name}"

if field_name == "mcp_type" and field_data.get("value") != "":
val = field_data.get("value")
properties[name]["type"] = val or "string"

if field_name == "mcp_required" and field_data.get("value", False):
required.append(name)

return {"type": "object", "properties": properties, "required": required}
4 changes: 4 additions & 0 deletions src/lfx/src/lfx/components/input_output/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ class ChatInput(ChatComponent):
is_list=True,
temp_file=True,
),
MultilineInput(
name="mcp_description", display_name="MCP Description", info="Description to MCP Client", advanced=True
),
BoolInput(name="mcp_required", display_name="MCP Required", info="Required by MCP Server", advanced=True),
]
outputs = [
Output(display_name="Chat Message", name="message", method="message_response"),
Expand Down
6 changes: 5 additions & 1 deletion src/lfx/src/lfx/components/input_output/text.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from lfx.base.io.text import TextComponent
from lfx.io import MultilineInput, Output
from lfx.io import BoolInput, MultilineInput, Output
from lfx.schema.message import Message


Expand All @@ -16,6 +16,10 @@ class TextInputComponent(TextComponent):
display_name="Text",
info="Text to be passed as input.",
),
MultilineInput(
name="mcp_description", display_name="MCP Description", info="Description to MCP Client.", advanced=True
),
BoolInput(name="mcp_required", display_name="MCP Required", info="Required by the MCP Server.", advanced=True),
]
outputs = [
Output(display_name="Output Text", name="text", method="text_response"),
Expand Down
Loading