fix(session): stop synthesizing MCP preset prompt context
This commit is contained in:
@@ -238,30 +238,6 @@ class Session:
|
|||||||
if cli_lines:
|
if cli_lines:
|
||||||
breadcrumbs = "\n".join(cli_lines)
|
breadcrumbs = "\n".join(cli_lines)
|
||||||
content = f"{content}\n{breadcrumbs}" if content else breadcrumbs
|
content = f"{content}\n{breadcrumbs}" if content else breadcrumbs
|
||||||
mcp_presets = message.get("mcp_presets")
|
|
||||||
if (
|
|
||||||
include_runtime_context
|
|
||||||
and not has_persisted_runtime_context
|
|
||||||
and role == "user"
|
|
||||||
and isinstance(mcp_presets, list)
|
|
||||||
and mcp_presets
|
|
||||||
and isinstance(content, str)
|
|
||||||
):
|
|
||||||
mcp_lines: list[str] = []
|
|
||||||
for item in mcp_presets[:8]:
|
|
||||||
if not isinstance(item, dict):
|
|
||||||
continue
|
|
||||||
name = str(item.get("name") or "").strip().lower()
|
|
||||||
if not name:
|
|
||||||
continue
|
|
||||||
transport = str(item.get("transport") or "mcp").strip() or "mcp"
|
|
||||||
mcp_lines.append(
|
|
||||||
f"[MCP Preset Attachment: @{name}; tool_prefix=mcp_{name}_; "
|
|
||||||
f"transport={transport}]"
|
|
||||||
)
|
|
||||||
if mcp_lines:
|
|
||||||
breadcrumbs = "\n".join(mcp_lines)
|
|
||||||
content = f"{content}\n{breadcrumbs}" if content else breadcrumbs
|
|
||||||
if role == "assistant" and isinstance(content, str) and not content.strip():
|
if role == "assistant" and isinstance(content, str) and not content.strip():
|
||||||
if not any(key in message for key in ("tool_calls", "reasoning_content", "thinking_blocks")):
|
if not any(key in message for key in ("tool_calls", "reasoning_content", "thinking_blocks")):
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -430,15 +430,12 @@ def test_get_history_synthesizes_cli_app_attachment_breadcrumb():
|
|||||||
}]
|
}]
|
||||||
|
|
||||||
|
|
||||||
def test_get_history_does_not_duplicate_persisted_capability_runtime_context():
|
def test_get_history_does_not_duplicate_persisted_cli_app_runtime_context():
|
||||||
content, marker = append_runtime_context(
|
content, marker = append_runtime_context(
|
||||||
"please use @drawio",
|
"please use @drawio",
|
||||||
[RuntimeContextBlock(
|
[RuntimeContextBlock(
|
||||||
source="cli_apps",
|
source="cli_apps",
|
||||||
content="[Runtime Context]\nCLI App Attachment: @drawio",
|
content="[Runtime Context]\nCLI App Attachment: @drawio",
|
||||||
), RuntimeContextBlock(
|
|
||||||
source="mcp",
|
|
||||||
content="[Runtime Context]\nMCP Preset Attachment: @linear",
|
|
||||||
)],
|
)],
|
||||||
)
|
)
|
||||||
session = Session(key="test:cli-app-persisted")
|
session = Session(key="test:cli-app-persisted")
|
||||||
@@ -449,7 +446,6 @@ def test_get_history_does_not_duplicate_persisted_capability_runtime_context():
|
|||||||
"name": "drawio",
|
"name": "drawio",
|
||||||
"entry_point": "cli-anything-drawio",
|
"entry_point": "cli-anything-drawio",
|
||||||
}],
|
}],
|
||||||
"mcp_presets": [{"name": "linear", "transport": "stdio"}],
|
|
||||||
RUNTIME_CONTEXT_HISTORY_META: marker,
|
RUNTIME_CONTEXT_HISTORY_META: marker,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -461,10 +457,23 @@ def test_get_history_does_not_duplicate_persisted_capability_runtime_context():
|
|||||||
|
|
||||||
assert model_history == [{"role": "user", "content": content}]
|
assert model_history == [{"role": "user", "content": content}]
|
||||||
assert model_history[0]["content"].count("CLI App Attachment: @drawio") == 1
|
assert model_history[0]["content"].count("CLI App Attachment: @drawio") == 1
|
||||||
assert model_history[0]["content"].count("MCP Preset Attachment: @linear") == 1
|
|
||||||
assert public_history == [{"role": "user", "content": "please use @drawio"}]
|
assert public_history == [{"role": "user", "content": "please use @drawio"}]
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_history_does_not_synthesize_mcp_preset_attachment():
|
||||||
|
session = Session(key="test:mcp-preset")
|
||||||
|
session.messages.append({
|
||||||
|
"role": "user",
|
||||||
|
"content": "please use @linear",
|
||||||
|
"mcp_presets": [{"name": "linear", "transport": "stdio"}],
|
||||||
|
})
|
||||||
|
|
||||||
|
assert session.get_history(max_messages=500) == [{
|
||||||
|
"role": "user",
|
||||||
|
"content": "please use @linear",
|
||||||
|
}]
|
||||||
|
|
||||||
|
|
||||||
def test_public_history_does_not_synthesize_legacy_capability_context():
|
def test_public_history_does_not_synthesize_legacy_capability_context():
|
||||||
session = Session(key="test:legacy-capabilities")
|
session = Session(key="test:legacy-capabilities")
|
||||||
session.messages.append({
|
session.messages.append({
|
||||||
|
|||||||
Reference in New Issue
Block a user