fix(fable-mcp): fix send_message to use correct two-step API flow
POST .../messages to start generation, then stream from .../generation/stream. The previous implementation used a non-existent /stream endpoint. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -28,7 +28,8 @@ async def send_message(
|
|||||||
"""Send a message to Fable and return the full assistant response.
|
"""Send a message to Fable and return the full assistant response.
|
||||||
|
|
||||||
Creates a new MCP conversation if conversation_id is None.
|
Creates a new MCP conversation if conversation_id is None.
|
||||||
Streams the SSE response and accumulates token chunks into a single string.
|
Posts the user message to start generation, then streams the SSE buffer
|
||||||
|
and accumulates token chunks into a single string.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Dict with:
|
Dict with:
|
||||||
@@ -41,18 +42,19 @@ async def send_message(
|
|||||||
"/api/chat/conversations",
|
"/api/chat/conversations",
|
||||||
json={"conversation_type": "mcp"},
|
json={"conversation_type": "mcp"},
|
||||||
)
|
)
|
||||||
conversation_id = conv["id"]
|
conversation_id = str(conv["id"])
|
||||||
|
|
||||||
# Build SSE stream URL with message as query param
|
# Start generation
|
||||||
params: dict[str, Any] = {"message": message}
|
await client.post(
|
||||||
if think:
|
f"/api/chat/conversations/{conversation_id}/messages",
|
||||||
params["think"] = "true"
|
json={"content": message, "think": think},
|
||||||
|
)
|
||||||
|
|
||||||
tokens: list[str] = []
|
tokens: list[str] = []
|
||||||
tool_calls: list[Any] = []
|
tool_calls: list[Any] = []
|
||||||
|
|
||||||
stream_path = f"/api/chat/conversations/{conversation_id}/stream"
|
stream_path = f"/api/chat/conversations/{conversation_id}/generation/stream"
|
||||||
async for raw_line in client.stream_get(stream_path, params=params):
|
async for raw_line in client.stream_get(stream_path):
|
||||||
if not raw_line.startswith("data: "):
|
if not raw_line.startswith("data: "):
|
||||||
continue
|
continue
|
||||||
payload_str = raw_line[len("data: "):]
|
payload_str = raw_line[len("data: "):]
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "fable-mcp"
|
name = "fable-mcp"
|
||||||
version = "0.2.1"
|
version = "0.2.2"
|
||||||
description = "MCP server for Fabled Assistant"
|
description = "MCP server for Fabled Assistant"
|
||||||
requires-python = ">=3.12"
|
requires-python = ">=3.12"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
|||||||
Reference in New Issue
Block a user