Skip to content

Commit e606d82

Browse files
committed
fix render data
MCP-UI-Org/mcp-ui#106
1 parent aea90a5 commit e606d82

File tree

2 files changed

+7
-7
lines changed
  • exercises/05.advanced
    • 02.problem.render-data/app/utils
    • 02.solution.render-data/app/utils

2 files changed

+7
-7
lines changed

exercises/05.advanced/02.problem.render-data/app/utils/mcp.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ export { sendMcpMessage }
9898

9999
// 🐨 export a waitForRenderData function that works like sendMcpMessage, but for render data
100100
// 🐨 it should create a messageId and send it to the parent frame with the type 'ui-request-render-data'
101-
// 🐨 handleMessage should check the event.data.type is 'ui-message-response' and the messageId is the same as the one sent
101+
// 🐨 handleMessage should check the event.data.type is 'ui-lifecycle-iframe-render-data' and the messageId is the same as the one sent
102102
// 🐨 if the event.data.payload.error is present, return reject(error)
103-
// 🐨 if the event.data.payload.response is present, return resolve(response)
104-
// 💯 add schema as an optional parameter and parse the response if it is present
103+
// 🐨 if the event.data.payload.renderData is present, return resolve(renderData)
104+
// 💯 add schema as an optional parameter and parse the renderData if it is present
105105
// 🦺 if you'd like to make it more typesafe, make waitForRenderData a generic (withForRenderData<RenderData>), pass the generic type to the schema (z.ZodSchema<RenderData>) and set it as the return type (Promise<RenderData>)

exercises/05.advanced/02.solution.render-data/app/utils/mcp.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,16 @@ export function waitForRenderData<RenderData>(
108108
)
109109

110110
function handleMessage(event: MessageEvent) {
111-
if (event.data?.type !== 'ui-message-response') return
111+
if (event.data?.type !== 'ui-lifecycle-iframe-render-data') return
112112
if (event.data.messageId !== messageId) return
113113
window.removeEventListener('message', handleMessage)
114114

115-
const { response, error } = event.data.payload
115+
const { renderData, error } = event.data.payload
116116

117117
if (error) return reject(error)
118-
if (!schema) return resolve(response)
118+
if (!schema) return resolve(renderData)
119119

120-
const parseResult = schema.safeParse(response)
120+
const parseResult = schema.safeParse(renderData)
121121
if (!parseResult.success) return reject(parseResult.error)
122122

123123
return resolve(parseResult.data)

0 commit comments

Comments
 (0)