MCPcopy Create free account
hub / github.com/IBM/mcp-cli / execute

Method execute

src/mcp_cli/commands/sessions/sessions.py:65–150  ·  view source on GitHub ↗

Execute the sessions command.

(self, **kwargs)

Source from the content-addressed store, hash-verified

63 ]
64
65 async def execute(self, **kwargs) -> CommandResult:
66 """Execute the sessions command."""
67 from mcp_cli.chat.session_store import SessionStore
68
69 chat_context = kwargs.get("chat_context")
70
71 # Parse args
72 args = kwargs.get("args", "").strip().split()
73 action = args[0] if args else SessionAction.LIST
74 session_id = args[1] if len(args) > 1 else None
75
76 store = SessionStore(
77 agent_id=getattr(chat_context, "agent_id", "default")
78 if chat_context
79 else "default"
80 )
81
82 if action == SessionAction.LIST:
83 sessions = store.list_sessions()
84 if not sessions:
85 output.info("No saved sessions.")
86 return CommandResult(success=True, output="No saved sessions.")
87
88 table_data = []
89 for s in sessions:
90 table_data.append(
91 {
92 "ID": s.session_id,
93 "Updated": s.updated_at[:19],
94 "Provider/Model": f"{s.provider}/{s.model}",
95 "Messages": str(s.message_count),
96 }
97 )
98
99 table = format_table(
100 table_data,
101 title="Saved Sessions",
102 columns=["ID", "Updated", "Provider/Model", "Messages"],
103 )
104 output.print_table(table)
105 return CommandResult(success=True, data=table_data)
106
107 elif action == SessionAction.SAVE:
108 if not chat_context:
109 return CommandResult(success=False, error="No chat context.")
110 if hasattr(chat_context, "save_session"):
111 path = chat_context.save_session()
112 if path:
113 output.success(f"Session saved: {path}")
114 return CommandResult(success=True, output=f"Saved to {path}")
115 return CommandResult(success=False, error="Failed to save session.")
116
117 elif action == SessionAction.LOAD:
118 if not session_id:
119 return CommandResult(
120 success=False,
121 error="Session ID required. Usage: /sessions load <id>",
122 )

Callers

nothing calls this directly

Calls 8

list_sessionsMethod · 0.95
deleteMethod · 0.95
SessionStoreClass · 0.90
CommandResultClass · 0.90
save_sessionMethod · 0.80
successMethod · 0.80
load_sessionMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected