Skip to content

workflow: unwrap MCP text-block results + discover replicate tools by suffix#448

Open
FMXExpress wants to merge 1 commit into
mainfrom
claude/workflow-mcp-unwrap
Open

workflow: unwrap MCP text-block results + discover replicate tools by suffix#448
FMXExpress wants to merge 1 commit into
mainfrom
claude/workflow-mcp-unwrap

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

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 ResultJSON is the wrapper {content:[{text:"{…prediction…}"}]}id/status/output are 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 flattened Text is itself a JSON object, that is the payload, so select against it. Applied to:

  • each node result (downstream {{nodes.ID.sel}} + the poll's self),
  • every poll result (status / output selectors),
  • the /v1/replicate/* endpoint responses.

New unit test drives the real text-block shape end-to-end (create → poll processingsucceeded → finished URL) — this is what the earlier top-level-only stub was hiding.

2. Model search silently returned nothing

The /v1/replicate/search + /model endpoints hardcoded replicate__search / replicate__get_models, which only resolve if the MCP server is named exactly replicate. Now they discover the tool from the registry by suffix (*__search, *__get_models), preferring a server whose name contains replicate — 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

  • Text-block unit test green (make test-workflow); gateway + skills tests build; binary links.
  • Search with no MCP now returns 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, your generate → upscale replicate nodes should poll to completion and chain the URL.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6


Generated by Claude Code

… 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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants