-
Notifications
You must be signed in to change notification settings - Fork 326
feat: Add MCP structuredContent support (fixes #283) #300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: Add MCP structuredContent support (fixes #283) #300
Conversation
|
Can confirm this works . And I need it as well |
|
How is your application consuming this information? Do you have an agent or is it a fixed workflow where you access the results of the tool call? If it's an agent, do you loop through the message history and check the artifacts field? |
81f6de3 to
00be302
Compare
|
@eyurtsev Thanks for asking. async def tool_node(state: AgentState) -> dict[str, list[ToolMessage]]:
"""Execute tool calls by constructing ToolCall objects for each call."""
last = state["messages"][-1]
outputs: list[ToolMessage] = []
for call in getattr(last, "tool_calls", []) or []:
# Build ToolCall to satisfy adapters requiring ToolCall input.
name = call["name"]
args = call["args"]
if call.get("id") is None:
call_id = str(uuid.uuid4())
else:
call_id = call["id"]
tool_call = ToolCall(name=name, args=args, id=call_id, type="tool_call")
tool = tools_by_name[name]
if hasattr(tool, "ainvoke"):
result = await tool.ainvoke(tool_call) # type: ignore[attr-defined]
else:
# Fall back to sync execution if async not available
result = tool.invoke(tool_call)
output = "some post-processing......."
return {"messages": outputs}
workflow = StateGraph(AgentState)
workflow.add_node("tools", tool_node) |
|
@eyurtsev Any feedback for this one? Thanks |
|
@eyurtsev we are also waiting for this PR, is it possible to review it and merge it? |
Implement MCP structuredContent support to resolve data loss issue
This branch addresses Issue #283 by implementing proper support for MCP's
structuredContent field in CallToolResult responses. Previously, the
langchain-mcp-adapters library ignored the structuredContent
field.
Key Changes:
• Refactored _convert_call_tool_result() to handle structuredContent
• Updated return format to use LangChain's content_and_artifact pattern
The implementation ensures:
Example:
Fixes: #283