Skip to content

fix(adapters): PromptTool returns string instead of raw PromptMessage list#1622

Open
sanmay-codes wants to merge 1 commit into
mcp-use:mainfrom
sanmay-codes:fix/prompt-tool-returns-raw-messages-list
Open

fix(adapters): PromptTool returns string instead of raw PromptMessage list#1622
sanmay-codes wants to merge 1 commit into
mcp-use:mainfrom
sanmay-codes:fix/prompt-tool-returns-raw-messages-list

Conversation

@sanmay-codes

@sanmay-codes sanmay-codes commented Jun 4, 2026

Copy link
Copy Markdown

Problem

`PromptTool._arun` returns `result.messages` directly — a `list[PromptMessage]`. LangGraph wraps this in a `ToolMessage` with `content=[]` (empty list), which AWS Bedrock rejects with:

```
ValidationException: tool_use ids found without tool_result blocks immediately after
```

This affects any MCP server that exposes a prompt alongside a tool with the same name (e.g. Enterpret's `initialize_wisdom`). The LLM calls the prompt tool, gets back an empty list, and Bedrock rejects the next message as malformed.

This is a companion fix to #1620 — that PR addresses `CallToolResult.content=[]` in regular tools; this PR addresses the same class of bug in prompt tools.

Closes #1621

Fix

Convert `result.messages` to a plain string before returning, so LangGraph always creates a `ToolMessage` with non-empty string content:

```python

Before

return result.messages

After

if not result.messages:
return "(no prompt content)"
return "\n".join(str(m.content) for m in result.messages)
```

Testing

Verified end-to-end with:

  • Enterpret Wisdom MCP server (exposes `initialize_wisdom` as both tool and prompt)
  • `ChatBedrock` with `claude-sonnet-4-6` on AWS Bedrock
  • Agent completes full multi-step workflow without `ValidationException`

…lidationException

When a PromptTool is called, _arun returns result.messages directly — a list of
PromptMessage objects. LangGraph wraps this in a ToolMessage with content=[],
which AWS Bedrock rejects with:
  ValidationException: tool_use ids found without tool_result blocks immediately after

Fix: convert result.messages to a plain string. Empty message lists return the
'(no prompt content)' placeholder so Bedrock always receives a non-empty string.

Relates to mcp-use#1604
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PromptTool._arun returns raw PromptMessage list causing Bedrock ValidationException

1 participant