workflow: unwrap MCP text-block results + discover replicate tools by suffix#448
workflow: unwrap MCP text-block results + discover replicate tools by suffix#448FMXExpress wants to merge 1 commit into
Conversation
… suffix
Two field bugs against the live Replicate MCP:
1. Replicate returns a tool's payload as a JSON STRING inside a text content
block, so the bridge's ResultJSON is the wrapper { content:[{text:"…"}] } --
id/status/output are NOT at the top level. The replicate node's poll then
failed with `{{self.id}}: selector "id" did not resolve`, and the model
search "returned nothing". Add UnwrapResult(RawJSON, Text): when the
flattened Text is itself a JSON object, THAT is the payload -- use it. Apply
it to each node result (downstream selectors + the poll's self) and to every
poll result (status/output). New test drives the real text-block shape end
to end (create->poll->finished URL).
2. The /v1/replicate/{search,model} endpoints hardcoded `replicate__search` /
`replicate__get_models`, which only resolve if the MCP server is named
exactly "replicate". Discover the tool from the registry by suffix
(`*__search`, `*__get_models`), preferring a server whose name contains
"replicate", so it works whatever the operator named it. On no match, return
a clear error (surfaced in the UI) instead of silent-empty; endpoints also
return the UNWRAPPED payload so the picker parses models/schema.
Verified: text-block unit test green; search with no MCP returns a clear
"no *__search tool registered" diagnostic; binary + gateway/skills tests build.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9fb2d07315
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| begin | ||
| Q := Trim(ARequest.Params.Values['q']); | ||
| if Q = '' then begin WriteJSON(AResp, 400, '{"error":"missing q"}'); Exit; end; | ||
| Tool := FindMCPToolBySuffix('search'); |
There was a problem hiding this comment.
Preserve the discovered Replicate namespace for runs
When the Replicate MCP server is named anything other than exactly replicate, this endpoint can now successfully discover and return models via e.g. custom__search, but the workflow node the UI creates still runs as the synthetic tool:"replicate"; PlanNode then hardcodes execution to replicate__create_predictions and polling to replicate__get_predictions. That means the newly-supported renamed-server path lets users build/select a model, but the workflow fails at runtime because those hardcoded tools are not registered under that namespace.
Useful? React with 👍 / 👎.
Two field bugs against the live Replicate MCP (both fixed here, one branch off main)
1.
{{self.id}}: selector "id" did not resolve+ "search returned nothing"Root cause: the Replicate MCP returns a tool's payload as a JSON string inside a text content block, so the bridge's
ResultJSONis the wrapper{content:[{text:"{…prediction…}"}]}—id/status/outputare not at the top level. My REST probe showed top-level fields, but the MCP wraps them, so the replicate node's poll ({{self.id}}) and the model-search parser both missed.Fix:
UnwrapResult(RawJSON, Text)— when the flattenedTextis itself a JSON object, that is the payload, so select against it. Applied to:{{nodes.ID.sel}}+ the poll'sself),status/outputselectors),/v1/replicate/*endpoint responses.New unit test drives the real text-block shape end-to-end (create → poll
processing→succeeded→ finished URL) — this is what the earlier top-level-only stub was hiding.2. Model search silently returned nothing
The
/v1/replicate/search+/modelendpoints hardcodedreplicate__search/replicate__get_models, which only resolve if the MCP server is named exactlyreplicate. Now they discover the tool from the registry by suffix (*__search,*__get_models), preferring a server whose name containsreplicate— so it works whatever you named the server. On no match they return a clear error (now surfaced in the search box) instead of an empty list, and they return the unwrapped payload so the picker parses the models/schema.Validation
make test-workflow); gateway + skills tests build; binary links.no MCP "*__search" tool registered — is the Replicate MCP connected & authorized?(clear, not silent-empty).Live search/run still needs your OAuth-connected Replicate MCP (the
r8_REST key can't drive the hosted MCP headlessly), but this makes the whole path shape- and name-robust. After merging, yourgenerate → upscalereplicatenodes should poll to completion and chain the URL.🤖 Generated with Claude Code
https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6
Generated by Claude Code