Problem/Motivation
I am testing out the tools in the Tool Belt module for use in an MCP server (MCP Server Drupal module). When I try to call the entity_field_values tool with a valid entity artifact for the entity argument, I get the following PHP error:
Tool execution failed: Drupal\tool\ExecutableResult::success(): Argument #1 ($message) must be of type Drupal\Core\StringTranslation\TranslatableMarkup, string given, called in /tool_belt/modules/tool_belt_content/src/Plugin/tool/Tool/EntityFieldValues.php on line 116
Note that this only occurs if and when the tool call results in one or more fields being denied access. In that scenario, the $message variable sent to the success() method is actually a concatenation of two t() calls, which is likely why the error is hit.
Steps to reproduce
Because this tool requires an entity artifact for the argument, I don't know the best way to reproduce, but the tool can be executed from the Tool explorer in a scenario where there will be fields that are denied access, or as I noted, when the tool is invoked via an MCP server where there will be fields that are denied access.
Proposed resolution
Instead of trying to concatenate two distinct t() calls, there can be an ExecutableResult::success() call when there are field that are defined access and a call when there are not, with the relevant $message string and placeolders used. I have attached a patch with a local fix.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | executable-success-error-3590387-1.patch | 1.51 KB | jaydub |
Issue fork tool_belt-3590387
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
jaydub commentedComment #3
jaydub commentedComment #4
michaellander commentedGood catch, @jaydub! Will test it out next week and pull it in if all looks good.
Comment #6
ajitsI was able to reproduce this with implementation of
hook_entity_field_accessin a custom module for one field and returningAccessResult::forbiddenComment #9
ajitsThank you for the report and the patch! I have committed and pushed it to 1.0.x