chat
Send a chat message to a workspace in chat or query mode to interact with AI-powered document chat and retrieve answers.
Instructions
Send a chat message to a workspace (mode: chat or query)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| workspace | Yes | ||
| message | Yes | ||
| mode | No | ||
| userId | No |
Implementation Reference
- src/index.ts:97-102 (handler)Handler logic for both chat_send and chat_stream tools. Sends POST to AnythingLLM API with workspace and message.
else if (name === "chat_send") { result = await apiRequest("/workspace/" + args?.workspace + "/chat", "POST", { message: args?.message }); } 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 }); } - src/index.ts:74-75 (schema)Input schema definitions for chat_send and chat_stream tools, requiring workspace and message string properties.
{ name: "chat_send", description: "Send chat message", inputSchema: { type: "object", properties: { workspace: { type: "string" }, message: { type: "string" } }, required: ["workspace", "message"] } }, { name: "chat_stream", description: "Stream chat", inputSchema: { type: "object", properties: { workspace: { type: "string" }, message: { type: "string" } }, required: ["workspace", "message"] } }, - src/index.ts:64-82 (registration)Registration of all tools including chat_send and chat_stream via ListToolsRequestSchema handler.
tools: [ { name: "auth_verify", description: "Verify API token", inputSchema: { type: "object", properties: {}, required: [] } }, { name: "system_check_token", description: "Check API token", inputSchema: { type: "object", properties: {}, required: [] } }, { name: "system_generate_api_key", description: "Generate API key", inputSchema: { type: "object", properties: {}, required: [] } }, { name: "system_env_dump", description: "Get system environment", inputSchema: { type: "object", properties: {}, required: [] } }, { name: "workspace_list", description: "List all workspaces", inputSchema: { type: "object", properties: {}, required: [] } }, { name: "workspace_get", description: "Get workspace details", inputSchema: { type: "object", properties: { slug: { type: "string" } }, required: ["slug"] } }, { name: "workspace_create", description: "Create workspace", inputSchema: { type: "object", properties: { name: { type: "string" }, slug: { type: "string" } }, required: ["name"] } }, { name: "workspace_update", description: "Update workspace", inputSchema: { type: "object", properties: { slug: { type: "string" }, name: { type: "string" } }, required: ["slug"] } }, { name: "workspace_delete", description: "Delete workspace", inputSchema: { type: "object", properties: { slug: { type: "string" } }, required: ["slug"] } }, { name: "chat_send", description: "Send chat message", inputSchema: { type: "object", properties: { workspace: { type: "string" }, message: { type: "string" } }, required: ["workspace", "message"] } }, { name: "chat_stream", description: "Stream chat", inputSchema: { type: "object", properties: { workspace: { type: "string" }, message: { type: "string" } }, required: ["workspace", "message"] } }, { name: "thread_list", description: "List threads", inputSchema: { type: "object", properties: { workspace: { type: "string" } }, required: ["workspace"] } }, { name: "document_list", description: "List documents", inputSchema: { type: "object", properties: {}, required: [] } }, { name: "openai_list_models", description: "List models", inputSchema: { type: "object", properties: {}, required: [] } }, { name: "openai_chat_completion", description: "Chat completion", inputSchema: { type: "object", properties: { model: { type: "string" }, messages: { type: "array" } }, required: ["model", "messages"] } }, ], }; }); - src/index.ts:23-55 (helper)Generic HTTP request helper used by all tool handlers including chat_send and chat_stream to make API calls.
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(); }); }