mirror of
https://github.com/NCBM/plyngent.git
synced 2026-11-07 15:37:55 +08:00
cli: fold MCP initialize instructions into agent prompt and /mcp
This commit is contained in:
@@ -1147,6 +1147,9 @@ def plugins_slash_cmd(state: ReplState, action: str | None, name: str | None) ->
|
||||
raise click.UsageError(str(exc)) from exc
|
||||
|
||||
|
||||
_MCP_PREVIEW_MAX_CHARS = 120
|
||||
|
||||
|
||||
def _print_mcp_status(state: ReplState) -> None:
|
||||
manager = state.mcp_manager
|
||||
if manager is None:
|
||||
@@ -1162,6 +1165,14 @@ def _print_mcp_status(state: ReplState) -> None:
|
||||
(conn for conn in manager.connections() if conn.name == name),
|
||||
None,
|
||||
)
|
||||
if connection is not None and connection.instructions:
|
||||
preview = " ".join(connection.instructions.split())
|
||||
if len(preview) > _MCP_PREVIEW_MAX_CHARS:
|
||||
preview = f"{preview[: _MCP_PREVIEW_MAX_CHARS - 3]}..."
|
||||
click.secho(
|
||||
f" instructions ({len(connection.instructions)} chars): {preview}",
|
||||
fg="bright_black",
|
||||
)
|
||||
if connection is not None and connection.error is not None:
|
||||
for line in connection.stderr_tail()[-3:]:
|
||||
click.secho(f" {line}", fg="bright_black")
|
||||
|
||||
@@ -237,14 +237,28 @@ class ReplState:
|
||||
session_state=self.session_state,
|
||||
)
|
||||
|
||||
def _mcp_instructions_text(self) -> str:
|
||||
"""Compose connected MCP servers' initialize ``instructions`` into one block.
|
||||
|
||||
Only meaningful when tools are on (MCP tools are registered under the
|
||||
same condition); the text is attributed per server so the model can
|
||||
weigh its provenance. Gated by ``[agent] mcp_instructions`` in callers.
|
||||
"""
|
||||
if self.mcp_manager is None or not self.tools_enabled:
|
||||
return ""
|
||||
parts = [f"MCP server {name!r} instructions:\n{text}" for name, text in self.mcp_manager.instructions()]
|
||||
return "\n\n".join(parts)
|
||||
|
||||
def _make_agent(self) -> ChatAgent:
|
||||
from plyngent.cli.limits import prompt_continue_limit_async
|
||||
from plyngent.config import compose_agent_system_content
|
||||
|
||||
agent_cfg = self.config.agent_config
|
||||
mcp_text = self._mcp_instructions_text() if agent_cfg.mcp_instructions else ""
|
||||
system_prompt = compose_agent_system_content(
|
||||
agent_cfg.system_prompt,
|
||||
agent_cfg.tool_directives,
|
||||
mcp_text,
|
||||
)
|
||||
on_limit = prompt_continue_limit_async if self.interactive_limits else None
|
||||
peak = 0
|
||||
|
||||
Reference in New Issue
Block a user