Skip to content

Commit e426bee

Browse files
committed
fix(deploy/cf): pass through string returns as raw text in tools/call
The Worker template wrapped every result in `JSON.stringify(...)`, so a photon method returning a Markdown string came back to clients as a JSON-quoted string with escaped newlines instead of renderable Markdown. The `read` tool on the deployed `web-lite` was unusable from clients that expect plain text in `content[0].text`. Pass strings through verbatim and only stringify non-string returns. Surface objects via `structuredContent` per the MCP convention so clients that prefer the JSON shape still get it.
1 parent fdedd67 commit e426bee

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

templates/cloudflare/worker.ts.template

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,19 @@ async function handleMCPRequest(request: any, env: Env): Promise<any> {
6060
throw new Error(`Unknown tool: ${name}`);
6161
}
6262
const result = await method.call(photon, args || {});
63+
// String returns (e.g. markdown from `read`) flow through as-is so
64+
// clients receive renderable text. Other shapes are JSON-stringified
65+
// for legibility. Structured shapes are also surfaced via
66+
// `structuredContent` per MCP — clients that prefer JSON pick it up.
67+
const isString = typeof result === 'string';
68+
const text = isString ? result : JSON.stringify(result, null, 2);
69+
const isObject = result !== null && typeof result === 'object';
6370
return {
6471
jsonrpc: '2.0',
6572
id,
6673
result: {
67-
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
74+
content: [{ type: 'text', text }],
75+
...(isObject && { structuredContent: result }),
6876
},
6977
};
7078
} catch (error: any) {

0 commit comments

Comments
 (0)