MCPcopy Create free account
hub / github.com/FlowiseAI/Flowise / chatflowCallback

Function chatflowCallback

packages/server/src/services/mcp-endpoint/index.ts:184–218  ·  view source on GitHub ↗

* Callback function for MCP tool execution * @return The tool response content, extracted from the utilBuildChatflow result

(
    chatflow: ChatFlow,
    chatId: string,
    req: Request,
    args: any
)

Source from the content-addressed store, hash-verified

182 * @return The tool response content, extracted from the utilBuildChatflow result
183 */
184async function chatflowCallback(
185 chatflow: ChatFlow,
186 chatId: string,
187 req: Request,
188 args: any
189): Promise<{ content: { type: 'text'; text: string }[]; isError?: boolean }> {
190 const inputType = getToolInputType(chatflow)
191 const body = inputType === 'form' ? { form: args.form || {} } : { question: args.question || '' }
192 const mockReq = createMockRequest({
193 chatflowId: chatflow.id,
194 body: {
195 ...body,
196 chatId
197 },
198 sourceRequest: req
199 })
200
201 const result = await utilBuildChatflow(mockReq, true, ChatType.MCP)
202
203 // Extract the text response from the result
204 let textContent: string
205 if (typeof result === 'string') {
206 textContent = result
207 } else if (result?.text) {
208 textContent = result.text
209 } else if (result?.json) {
210 textContent = JSON.stringify(result.json)
211 } else {
212 textContent = JSON.stringify(result)
213 }
214
215 return {
216 content: [{ type: 'text' as const, text: textContent }]
217 }
218}
219
220/**
221 * Handle an InternalFlowiseError from getChatflowByIdAndVerifyToken.

Callers 1

handleMcpRequestFunction · 0.85

Calls 4

createMockRequestFunction · 0.90
utilBuildChatflowFunction · 0.90
getToolInputTypeFunction · 0.85
stringifyMethod · 0.80

Tested by

no test coverage detected