stream_chat
Stream a chat message to a workspace and receive a real-time response, supporting modes like chat and query for interactive conversations.
Instructions
Stream a chat message to a workspace
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| workspace | Yes | ||
| message | Yes | ||
| mode | No | ||
| userId | No | ||
| threadSlug | No |
Implementation Reference
- src/index.ts:98-103 (handler)Handler for the chat_stream tool - calls the /workspace/{workspace}/stream-chat API endpoint with POST method, passing the user's message as the body.
else if (name === "chat_stream") { result = await apiRequest("/workspace/" + args?.workspace + "/stream-chat", "POST", { message: args?.message }); } else if (name === "thread_list") { result = await apiRequest("/workspace/" + args?.workspace); result = { threads: result?.workspace?.threads || [] }; } else if (name === "document_list") { result = await apiRequest("/documents"); } else if (name === "openai_list_models") { result = await apiRequest("/openai/models"); } else if (name === "openai_chat_completion") { result = await apiRequest("/openai/chat/completions", "POST", { model: args?.model, messages: args?.messages }); } else { throw new McpError(ErrorCode.MethodNotFound, "Unknown tool: " + name); } - src/index.ts:75-75 (registration)Registration of the chat_stream tool in the ListToolsRequestSchema handler, defining its name, description ("Stream chat"), and input schema requiring workspace and message strings.
{ name: "chat_stream", description: "Stream chat", inputSchema: { type: "object", properties: { workspace: { type: "string" }, message: { type: "string" } }, required: ["workspace", "message"] } }, - src/index.ts:23-55 (helper)Helper function apiRequest that handles HTTP/HTTPS requests to the AnythingLLM API, used by chat_stream to make the POST request.
function apiRequest(path: string, method = "GET", body?: any, extraHeaders = {}): Promise<any> { return new Promise((resolve, reject) => { const baseUrl = new URL(ANYTHING_LLM_BASE); const fullUrl = new URL(path, baseUrl); const options: any = { hostname: fullUrl.hostname, port: fullUrl.port || (fullUrl.protocol === "https:" ? 443 : 80), path: fullUrl.pathname + fullUrl.search, method, headers: Object.assign({ "Authorization": "Bearer " + ANYTHING_LLM_API_KEY, "Content-Type": "application/json", "Accept": "application/json", }, extraHeaders), }; const lib = fullUrl.protocol === "https:" ? https : http; const req = lib.request(options, (res: any) => { let data = ""; res.on("data", (chunk: string) => { data += chunk; }); res.on("end", () => { try { resolve(data ? JSON.parse(data) : {}); } catch { resolve({ raw: data }); } }); }); req.on("error", reject); if (body) req.write(JSON.stringify(body)); req.end(); }); }