Skip to content

Your lightweight open-source personal agent.

fix(session): stop synthesizing MCP preset prompt context

chengyongru54b250430d18
diff --git a/nanobot/session/manager.py b/nanobot/session/manager.py
index 71a1cae75..bc702a52c 100644
--- a/nanobot/session/manager.py
+++ b/nanobot/session/manager.py
@@ -238,30 +238,6 @@ class Session:
if cli_lines:
breadcrumbs = "\n".join(cli_lines)
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 not any(key in message for key in ("tool_calls", "reasoning_content", "thinking_blocks")):
continue
diff --git a/tests/agent/test_session_manager_history.py b/tests/agent/test_session_manager_history.py
index d382787bf..f00bc7874 100644
--- a/tests/agent/test_session_manager_history.py
+++ b/tests/agent/test_session_manager_history.py
@@ -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(
"please use @drawio",
[RuntimeContextBlock(
source="cli_apps",
content="[Runtime Context]\nCLI App Attachment: @drawio",
- ), RuntimeContextBlock(
- source="mcp",
- content="[Runtime Context]\nMCP Preset Attachment: @linear",
)],
)
session = Session(key="test:cli-app-persisted")
@@ -449,7 +446,6 @@ def test_get_history_does_not_duplicate_persisted_capability_runtime_context():
"name": "drawio",
"entry_point": "cli-anything-drawio",
}],
- "mcp_presets": [{"name": "linear", "transport": "stdio"}],
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[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"}]
+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():
session = Session(key="test:legacy-capabilities")
session.messages.append({