Structured content return and tool error #93
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
\Mcp\Capability\Tool\ToolCaller::call
added ability to returnCallToolResult
from tool as response.\Mcp\Capability\Tool\ToolCaller::call
we passing formatted result with array of content items to utilize previously unused\Mcp\Schema\Result\CallToolResult::fromArray
\Mcp\Schema\Content\StructuredContent
to representstructuredContent
response node.\Mcp\Schema\Result\CallToolResult
was modified to work correctly with new content type\Mcp\Schema\Content\TextContent::__construct(isError)
to propagate error in case of content item use instead of call result.Motivation and Context
While testing my MCP server I've noticed inconsistencies between output with Python MCP server.
structuredContent
isError=true
Also while
outputSchema
being added in #88 , withoutputSchema
MCP server MUST provide structured content alongside text representation.How Has This Been Tested?
Tested on my MCP server to ensure same response between PHP and Python versions.
Scenarios tested:
I will add unit tests after structure of changes will be approved
Breaking Changes
Tests passing, as far as I tested and understand there will be no breaking changes as
\Mcp\Capability\Registry\ToolReference::formatResult
left intactTypes of changes
Checklist
Additional context
As an additional notes I have few suggestions and explanations.
Is terrible solution and it shouldn't be there, I just didn't found any possibility to add error without usage of \Mcp\Schema\Result\CallToolResult and I will happily remove it.
I think it will interfere and conflict with #73
As a suggestion, we could just remove
\Mcp\Capability\Registry\ToolReference::formatResult
.This method does some heavy processing and can produce unexpected results for user.
It would be more convenient to enforce Tools to return
\Mcp\Schema\Result\CallToolResult
which has enforcements to use properContent
items.One more suggestion about JSON serialization, I know that SDK tries to be agnostic and not use packages, but consider using
serializer
library.Manual serialization via
jsonSerialize
works, but you always need to keep in mind to call child serialization and handle nulls to remove them from results. This makes code more prone to errors.