talkops-opscloud 0.3.0b1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- opscloud/__init__.py +5 -0
- opscloud/__main__.py +6 -0
- opscloud/_constants.py +53 -0
- opscloud/_debug.py +145 -0
- opscloud/_debug_buffer.py +250 -0
- opscloud/_textual_patches.py +367 -0
- opscloud/_version.py +15 -0
- opscloud/agent/__init__.py +27 -0
- opscloud/agent/config.py +168 -0
- opscloud/agent/factory.py +1103 -0
- opscloud/approval_mode.py +44 -0
- opscloud/backend/__init__.py +49 -0
- opscloud/backend/composite.py +89 -0
- opscloud/backend/local.py +183 -0
- opscloud/backend/registry.py +79 -0
- opscloud/backend/sandbox_config.py +107 -0
- opscloud/backend/sandbox_factory.py +432 -0
- opscloud/built_in_skills/remember/SKILL.md +124 -0
- opscloud/built_in_skills/skill-creator/SKILL.md +348 -0
- opscloud/built_in_skills/skill-creator/scripts/init_skill.py +371 -0
- opscloud/built_in_skills/skill-creator/scripts/quick_validate.py +165 -0
- opscloud/cli/__init__.py +1 -0
- opscloud/cli/commands/__init__.py +15 -0
- opscloud/cli/commands/auth.py +45 -0
- opscloud/cli/commands/doctor.py +100 -0
- opscloud/cli/commands/mcp.py +137 -0
- opscloud/cli/commands/threads.py +51 -0
- opscloud/cli/interactive.py +154 -0
- opscloud/cli/main.py +903 -0
- opscloud/cli/non_interactive.py +425 -0
- opscloud/cli/server_manager.py +58 -0
- opscloud/commands/__init__.py +19 -0
- opscloud/commands/_base.py +110 -0
- opscloud/commands/_guards.py +52 -0
- opscloud/commands/_router.py +146 -0
- opscloud/commands/_types.py +36 -0
- opscloud/commands/core/__init__.py +47 -0
- opscloud/commands/core/auth.py +94 -0
- opscloud/commands/core/bug.py +46 -0
- opscloud/commands/core/clear.py +106 -0
- opscloud/commands/core/cloud.py +185 -0
- opscloud/commands/core/compact.py +128 -0
- opscloud/commands/core/config_cmd.py +120 -0
- opscloud/commands/core/context.py +220 -0
- opscloud/commands/core/cost.py +44 -0
- opscloud/commands/core/doctor.py +535 -0
- opscloud/commands/core/effort.py +108 -0
- opscloud/commands/core/exit_cmd.py +41 -0
- opscloud/commands/core/fast.py +148 -0
- opscloud/commands/core/help_cmd.py +94 -0
- opscloud/commands/core/mcp.py +134 -0
- opscloud/commands/core/model.py +109 -0
- opscloud/commands/core/permissions.py +196 -0
- opscloud/commands/core/plugins.py +92 -0
- opscloud/commands/core/pool.py +108 -0
- opscloud/commands/core/resume.py +97 -0
- opscloud/commands/core/skills.py +178 -0
- opscloud/commands/power/__init__.py +51 -0
- opscloud/commands/power/agents.py +98 -0
- opscloud/commands/power/btw.py +85 -0
- opscloud/commands/power/copy.py +97 -0
- opscloud/commands/power/goal.py +548 -0
- opscloud/commands/power/loop.py +295 -0
- opscloud/commands/power/memory.py +287 -0
- opscloud/commands/power/review.py +152 -0
- opscloud/commands/power/rubric.py +287 -0
- opscloud/commands/power/runtime.py +321 -0
- opscloud/commands/power/skill_creator.py +70 -0
- opscloud/commands/power/skill_invoke.py +165 -0
- opscloud/commands/power/tasks.py +209 -0
- opscloud/commands/power/trace.py +117 -0
- opscloud/commands/power/ui_toggles.py +135 -0
- opscloud/commands/power/version.py +52 -0
- opscloud/commands/registry.py +176 -0
- opscloud/config/__init__.py +114 -0
- opscloud/config/adapters/__init__.py +5 -0
- opscloud/config/adapters/postgres.py +776 -0
- opscloud/config/adapters/sqlite.py +769 -0
- opscloud/config/aws.py +248 -0
- opscloud/config/cloud_profiles.py +437 -0
- opscloud/config/env_vars.py +81 -0
- opscloud/config/langsmith.py +319 -0
- opscloud/config/manifest.py +817 -0
- opscloud/config/metadata.py +205 -0
- opscloud/config/paths.py +604 -0
- opscloud/config/plugins.py +130 -0
- opscloud/config/settings.py +834 -0
- opscloud/config/store.py +453 -0
- opscloud/config/store_factory.py +97 -0
- opscloud/config/toml_config.py +562 -0
- opscloud/editor.py +173 -0
- opscloud/exceptions.py +65 -0
- opscloud/file_ops.py +217 -0
- opscloud/hooks/__init__.py +139 -0
- opscloud/hooks/env.py +44 -0
- opscloud/hooks/interrupt.py +121 -0
- opscloud/hooks/models/__init__.py +109 -0
- opscloud/hooks/models/adapters.py +19 -0
- opscloud/hooks/models/config.py +79 -0
- opscloud/hooks/models/domain.py +434 -0
- opscloud/hooks/models/transport.py +37 -0
- opscloud/hooks/tools.py +231 -0
- opscloud/input.py +48 -0
- opscloud/integrations/__init__.py +80 -0
- opscloud/integrations/base.py +153 -0
- opscloud/integrations/content_filter.py +119 -0
- opscloud/integrations/event_bus.py +480 -0
- opscloud/integrations/hooks.py +238 -0
- opscloud/integrations/identity.py +181 -0
- opscloud/integrations/notifications.py +134 -0
- opscloud/integrations/stream_bridge.py +397 -0
- opscloud/integrations/thread_store.py +81 -0
- opscloud/json_types.py +20 -0
- opscloud/mcp/__init__.py +57 -0
- opscloud/mcp/config.py +203 -0
- opscloud/mcp/discovery.py +229 -0
- opscloud/mcp/mcp_info.py +109 -0
- opscloud/mcp/middleware.py +102 -0
- opscloud/mcp/preload.py +505 -0
- opscloud/mcp/raw_config.py +149 -0
- opscloud/mcp/semantic_profiler.py +305 -0
- opscloud/mcp/session_manager.py +727 -0
- opscloud/mcp/trust.py +105 -0
- opscloud/memory/__init__.py +27 -0
- opscloud/memory/branch.py +61 -0
- opscloud/memory/guard.py +19 -0
- opscloud/memory/onboarding.py +120 -0
- opscloud/memory/registry.py +134 -0
- opscloud/memory/store.py +223 -0
- opscloud/middleware/__init__.py +106 -0
- opscloud/middleware/_repository_bounds.py +459 -0
- opscloud/middleware/ask_user.py +152 -0
- opscloud/middleware/auto_mode.py +60 -0
- opscloud/middleware/auto_mode_hitl.py +2434 -0
- opscloud/middleware/compaction.py +566 -0
- opscloud/middleware/configurable_model.py +233 -0
- opscloud/middleware/cost_tracking.py +1021 -0
- opscloud/middleware/glm_stall_recovery.py +109 -0
- opscloud/middleware/goal_criteria.py +1234 -0
- opscloud/middleware/goal_state_notice.py +712 -0
- opscloud/middleware/goal_tools.py +407 -0
- opscloud/middleware/headless_mcp_guard.py +88 -0
- opscloud/middleware/jev_model_router.py +1018 -0
- opscloud/middleware/local_context.py +460 -0
- opscloud/middleware/mcp_context.py +151 -0
- opscloud/middleware/mcp_middleware.py +146 -0
- opscloud/middleware/memory_guard.py +393 -0
- opscloud/middleware/model_retry.py +205 -0
- opscloud/middleware/registry.py +137 -0
- opscloud/middleware/reliable_rubric.py +709 -0
- opscloud/middleware/resume_state.py +91 -0
- opscloud/middleware/server_hooks.py +1189 -0
- opscloud/middleware/shell_allow_list.py +90 -0
- opscloud/middleware/skills.py +382 -0
- opscloud/middleware/subagent_artifacts.py +84 -0
- opscloud/middleware/subagent_telemetry.py +261 -0
- opscloud/middleware/subagents.py +243 -0
- opscloud/middleware/tool_filter.py +384 -0
- opscloud/middleware/unified_system_message.py +62 -0
- opscloud/model/__init__.py +37 -0
- opscloud/model/config.py +2992 -0
- opscloud/model/factory.py +477 -0
- opscloud/model/pool.py +459 -0
- opscloud/model/reasoning.py +282 -0
- opscloud/offload.py +173 -0
- opscloud/output.py +64 -0
- opscloud/plugins/__init__.py +189 -0
- opscloud/plugins/_json.py +22 -0
- opscloud/plugins/adapters/__init__.py +13 -0
- opscloud/plugins/adapters/agents.py +112 -0
- opscloud/plugins/adapters/commands.py +190 -0
- opscloud/plugins/adapters/mcp.py +363 -0
- opscloud/plugins/adapters/skills.py +132 -0
- opscloud/plugins/commands_cli.py +541 -0
- opscloud/plugins/discovery.py +512 -0
- opscloud/plugins/manifest.py +335 -0
- opscloud/plugins/marketplace.py +893 -0
- opscloud/plugins/models.py +334 -0
- opscloud/plugins/project_plugins.py +317 -0
- opscloud/plugins/protocol.py +31 -0
- opscloud/plugins/store.py +905 -0
- opscloud/plugins/substitution.py +122 -0
- opscloud/project_utils.py +145 -0
- opscloud/prompts/__init__.py +37 -0
- opscloud/prompts/system.py +483 -0
- opscloud/prompts/templates/system_prompt.md +166 -0
- opscloud/prompts/types.py +54 -0
- opscloud/rubrics/__init__.py +42 -0
- opscloud/rubrics/evaluator.py +404 -0
- opscloud/rubrics/evidence_extractor.py +229 -0
- opscloud/rubrics/generator.py +239 -0
- opscloud/rubrics/jev_compiler.py +175 -0
- opscloud/rubrics/jev_grader.py +297 -0
- opscloud/rubrics/middleware.py +8 -0
- opscloud/schema/__init__.py +107 -0
- opscloud/schema/interrupts.py +981 -0
- opscloud/security/__init__.py +91 -0
- opscloud/security/approval_mode.py +528 -0
- opscloud/security/approval_mode_source.py +230 -0
- opscloud/security/cli_ast_evaluator.py +552 -0
- opscloud/security/jev_classifier.py +651 -0
- opscloud/security/shell_safety.py +340 -0
- opscloud/security/unicode_security.py +439 -0
- opscloud/security/url_validation.py +160 -0
- opscloud/server/__init__.py +13 -0
- opscloud/server/_server_config.py +158 -0
- opscloud/server/server.py +242 -0
- opscloud/server/server_graph.py +93 -0
- opscloud/skills/__init__.py +91 -0
- opscloud/skills/commands.py +1099 -0
- opscloud/skills/invocation.py +200 -0
- opscloud/skills/load.py +388 -0
- opscloud/skills/loader.py +23 -0
- opscloud/skills/merge.py +65 -0
- opscloud/skills/registry.py +263 -0
- opscloud/skills/sources.py +174 -0
- opscloud/skills/trust.py +417 -0
- opscloud/state/__init__.py +142 -0
- opscloud/state/base.py +154 -0
- opscloud/state/cloud_context.py +262 -0
- opscloud/state/goal_channels.py +124 -0
- opscloud/state/goal_state_limits.py +175 -0
- opscloud/state/resume_state.py +58 -0
- opscloud/state/service_context.py +281 -0
- opscloud/state/session.py +957 -0
- opscloud/state/state_migration.py +86 -0
- opscloud/subagents/__init__.py +30 -0
- opscloud/subagents/loader.py +331 -0
- opscloud/subagents/subagents_parser.py +117 -0
- opscloud/subagents/types.py +25 -0
- opscloud/tools/__init__.py +36 -0
- opscloud/tools/catalog.py +37 -0
- opscloud/tools/display.py +24 -0
- opscloud/tools/fetch_url.py +176 -0
- opscloud/tools/goal_tools.py +423 -0
- opscloud/tools/registry.py +105 -0
- opscloud/tools/thread.py +32 -0
- opscloud/tools/web_search.py +215 -0
- opscloud/ui/__init__.py +119 -0
- opscloud/ui/app.py +5400 -0
- opscloud/ui/app.tcss +479 -0
- opscloud/ui/clipboard.py +147 -0
- opscloud/ui/command_registry.py +482 -0
- opscloud/ui/message_store.py +152 -0
- opscloud/ui/permission_store.py +360 -0
- opscloud/ui/preferences.py +113 -0
- opscloud/ui/prompt_manager.py +96 -0
- opscloud/ui/remote_client.py +505 -0
- opscloud/ui/textual_adapter.py +1269 -0
- opscloud/ui/theme.py +728 -0
- opscloud/ui/ui_help.py +415 -0
- opscloud/ui/widgets/__init__.py +383 -0
- opscloud/ui/widgets/_ask_user_types.py +81 -0
- opscloud/ui/widgets/_copy_spans.py +52 -0
- opscloud/ui/widgets/_inline_prompt.py +290 -0
- opscloud/ui/widgets/_js_eval_display.py +139 -0
- opscloud/ui/widgets/_links.py +175 -0
- opscloud/ui/widgets/_tool_stream.py +308 -0
- opscloud/ui/widgets/agent_selector.py +297 -0
- opscloud/ui/widgets/approval.py +741 -0
- opscloud/ui/widgets/ask_user.py +539 -0
- opscloud/ui/widgets/auth.py +695 -0
- opscloud/ui/widgets/auth_manager.py +214 -0
- opscloud/ui/widgets/auto_mode_notice.py +146 -0
- opscloud/ui/widgets/autocomplete.py +709 -0
- opscloud/ui/widgets/chat_input.py +805 -0
- opscloud/ui/widgets/cloud_selector.py +528 -0
- opscloud/ui/widgets/config_manager.py +652 -0
- opscloud/ui/widgets/debug_console.py +1269 -0
- opscloud/ui/widgets/devops_renderers.py +184 -0
- opscloud/ui/widgets/diff.py +237 -0
- opscloud/ui/widgets/effort_selector.py +166 -0
- opscloud/ui/widgets/goal_review.py +612 -0
- opscloud/ui/widgets/goal_status.py +57 -0
- opscloud/ui/widgets/infra_panel.py +141 -0
- opscloud/ui/widgets/install_confirm.py +114 -0
- opscloud/ui/widgets/loading.py +170 -0
- opscloud/ui/widgets/mcp_viewer.py +1204 -0
- opscloud/ui/widgets/messages.py +4461 -0
- opscloud/ui/widgets/model_selector.py +863 -0
- opscloud/ui/widgets/notification_center.py +108 -0
- opscloud/ui/widgets/notification_settings.py +119 -0
- opscloud/ui/widgets/operation_card.py +106 -0
- opscloud/ui/widgets/permissions_manager.py +667 -0
- opscloud/ui/widgets/plugin_manager.py +1212 -0
- opscloud/ui/widgets/pool_selector.py +376 -0
- opscloud/ui/widgets/preamble.py +53 -0
- opscloud/ui/widgets/skills_viewer.py +432 -0
- opscloud/ui/widgets/status.py +1037 -0
- opscloud/ui/widgets/subagent_panel.py +927 -0
- opscloud/ui/widgets/theme_selector.py +232 -0
- opscloud/ui/widgets/thread_selector.py +358 -0
- opscloud/ui/widgets/toast.py +31 -0
- opscloud/ui/widgets/tool_display.py +325 -0
- opscloud/ui/widgets/tool_renderers.py +234 -0
- opscloud/ui/widgets/tool_widgets.py +278 -0
- opscloud/ui/widgets/welcome.py +421 -0
- opscloud/ui/widgets/welcome_popup.py +102 -0
- opscloud/utils/__init__.py +24 -0
- opscloud/utils/cost_estimation.py +169 -0
- opscloud/utils/git.py +390 -0
- opscloud/utils/logger.py +571 -0
- opscloud/utils/session_stats.py +115 -0
- opscloud/utils/startup_error.py +37 -0
- talkops_opscloud-0.3.0b1.dist-info/METADATA +449 -0
- talkops_opscloud-0.3.0b1.dist-info/RECORD +309 -0
- talkops_opscloud-0.3.0b1.dist-info/WHEEL +4 -0
- talkops_opscloud-0.3.0b1.dist-info/entry_points.txt +2 -0
- talkops_opscloud-0.3.0b1.dist-info/licenses/LICENSE +175 -0
|
@@ -0,0 +1,1204 @@
|
|
|
1
|
+
"""Interactive MCP server & tool viewer modal screen for OpsCloud.
|
|
2
|
+
|
|
3
|
+
Two-pane layout: left pane lists MCP servers and their tools with ↑/↓ navigation
|
|
4
|
+
and hover support, right pane shows rich live details for the selected tool or server.
|
|
5
|
+
|
|
6
|
+
Styled consistently with SkillsViewerScreen, AuthManagerScreen, and ThreadSelectorScreen.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
import re
|
|
13
|
+
from typing import TYPE_CHECKING, Any, ClassVar
|
|
14
|
+
|
|
15
|
+
from textual import events
|
|
16
|
+
from textual.binding import Binding, BindingType
|
|
17
|
+
from textual.containers import Horizontal, Vertical, VerticalScroll
|
|
18
|
+
from textual.screen import ModalScreen
|
|
19
|
+
from textual.widgets import Input, Static
|
|
20
|
+
|
|
21
|
+
from opscloud.utils.logger import get_logger
|
|
22
|
+
|
|
23
|
+
if TYPE_CHECKING:
|
|
24
|
+
from collections.abc import Awaitable, Callable
|
|
25
|
+
from textual.app import ComposeResult
|
|
26
|
+
|
|
27
|
+
from opscloud.mcp.mcp_info import MCPServerInfo, MCPToolInfo
|
|
28
|
+
|
|
29
|
+
logger = get_logger(__name__)
|
|
30
|
+
|
|
31
|
+
MCP_VIEWER_RECONNECT_REQUEST = "\x00__mcp_reconnect__"
|
|
32
|
+
"""Sentinel returned by dismiss to request a reconnect."""
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
# ── Identifier cleaning helpers ──────────────────────────
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def clean_server_name(raw_name: str) -> tuple[str, str | None]:
|
|
39
|
+
"""Parse a potentially mangled or scoped MCP server name into (display_name, scope).
|
|
40
|
+
|
|
41
|
+
Examples:
|
|
42
|
+
'plugin__aws-compute_talkops-devops-plugins_35da5a75__aws-mcp' -> ('aws-mcp', 'aws-compute')
|
|
43
|
+
'subagent__helm-operator__helm-mcp' -> ('helm-mcp', 'helm-operator')
|
|
44
|
+
'github' -> ('github', None)
|
|
45
|
+
"""
|
|
46
|
+
if not raw_name:
|
|
47
|
+
return ("unnamed", None)
|
|
48
|
+
|
|
49
|
+
# 1. Plugin scoped server: plugin__<plugin_id_sanitized>__<server_name>
|
|
50
|
+
if raw_name.startswith("plugin__"):
|
|
51
|
+
parts = raw_name[len("plugin__") :].split("__", 1)
|
|
52
|
+
if len(parts) == 2:
|
|
53
|
+
plugin_part, server_part = parts
|
|
54
|
+
scope = plugin_part.split("_")[0] if "_" in plugin_part else plugin_part
|
|
55
|
+
clean_server = re.sub(r"_[0-9a-f]{8,16}$", "", server_part)
|
|
56
|
+
return (clean_server or server_part, scope)
|
|
57
|
+
|
|
58
|
+
# 2. Subagent scoped server: subagent__<subagent_name>__<server_name>
|
|
59
|
+
if raw_name.startswith("subagent__"):
|
|
60
|
+
parts = raw_name[len("subagent__") :].split("__", 1)
|
|
61
|
+
if len(parts) == 2:
|
|
62
|
+
sub_part, server_part = parts
|
|
63
|
+
clean_server = re.sub(r"_[0-9a-f]{8,16}$", "", server_part)
|
|
64
|
+
return (clean_server or server_part, sub_part)
|
|
65
|
+
|
|
66
|
+
# 3. Plain server name
|
|
67
|
+
clean_plain = re.sub(r"_[0-9a-f]{8,16}$", "", raw_name)
|
|
68
|
+
return (clean_plain or raw_name, None)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def clean_tool_name(tool_name: str, original_name: str | None = None) -> str:
|
|
72
|
+
"""Return a concise, human-friendly display name for an MCP tool."""
|
|
73
|
+
raw = original_name if (original_name and original_name != "None") else tool_name
|
|
74
|
+
if not raw:
|
|
75
|
+
return "unnamed_tool"
|
|
76
|
+
|
|
77
|
+
# If original_name is e.g. "aws___get_tasks" or "server___tool"
|
|
78
|
+
if "___" in raw:
|
|
79
|
+
raw = raw.split("___")[-1]
|
|
80
|
+
elif "__" in raw:
|
|
81
|
+
raw = raw.split("__")[-1]
|
|
82
|
+
|
|
83
|
+
# Strip any trailing hash suffix like _9badd4f791c6
|
|
84
|
+
clean = re.sub(r"_[0-9a-f]{8,16}$", "", raw)
|
|
85
|
+
return clean or raw
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
# ── Status helpers ───────────────────────────────────────
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _status_glyph(server: MCPServerInfo) -> str:
|
|
92
|
+
"""Return a status glyph for a server."""
|
|
93
|
+
status = server.status
|
|
94
|
+
if status == "ok":
|
|
95
|
+
return "●"
|
|
96
|
+
if status == "unauthenticated":
|
|
97
|
+
return "▲"
|
|
98
|
+
if status == "error":
|
|
99
|
+
return "✗"
|
|
100
|
+
if status == "disabled":
|
|
101
|
+
return "○"
|
|
102
|
+
return "·"
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _format_prop_type(prop_type: Any) -> str:
|
|
106
|
+
"""Render a JSON Schema type field for display."""
|
|
107
|
+
if prop_type is None:
|
|
108
|
+
return "any"
|
|
109
|
+
if isinstance(prop_type, list):
|
|
110
|
+
parts = [str(t) for t in prop_type if t]
|
|
111
|
+
return "|".join(parts) if parts else "any"
|
|
112
|
+
return str(prop_type) or "any"
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
# ── Tool Detail Screen (Full Modal on Enter) ─────────────
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
class MCPToolDetailScreen(ModalScreen[None]):
|
|
119
|
+
"""Full-screen modal showing comprehensive MCP tool schema and documentation."""
|
|
120
|
+
|
|
121
|
+
BINDINGS: ClassVar[list[BindingType]] = [
|
|
122
|
+
Binding("escape", "close_dialog", "Close", show=False, priority=True),
|
|
123
|
+
Binding("q", "close_dialog", "Close", show=False),
|
|
124
|
+
]
|
|
125
|
+
|
|
126
|
+
CSS = """
|
|
127
|
+
MCPToolDetailScreen {
|
|
128
|
+
align: center middle;
|
|
129
|
+
background: $background 70%;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
MCPToolDetailScreen > Vertical {
|
|
133
|
+
width: 96;
|
|
134
|
+
max-width: 98%;
|
|
135
|
+
height: 90%;
|
|
136
|
+
background: $surface;
|
|
137
|
+
border: solid $primary;
|
|
138
|
+
padding: 1 2;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
MCPToolDetailScreen .mcp-tool-detail-title {
|
|
142
|
+
text-style: bold;
|
|
143
|
+
color: $primary;
|
|
144
|
+
text-align: center;
|
|
145
|
+
margin-bottom: 1;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
MCPToolDetailScreen .mcp-tool-detail-body {
|
|
149
|
+
height: 1fr;
|
|
150
|
+
min-height: 5;
|
|
151
|
+
scrollbar-gutter: stable;
|
|
152
|
+
background: $background;
|
|
153
|
+
padding: 1 2;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
MCPToolDetailScreen .detail-label {
|
|
157
|
+
color: $text-muted;
|
|
158
|
+
margin-top: 1;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
MCPToolDetailScreen .detail-value {
|
|
162
|
+
margin-bottom: 0;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
MCPToolDetailScreen .mcp-tool-detail-help {
|
|
166
|
+
height: auto;
|
|
167
|
+
color: $text-muted;
|
|
168
|
+
text-style: italic;
|
|
169
|
+
margin-top: 1;
|
|
170
|
+
text-align: center;
|
|
171
|
+
}
|
|
172
|
+
"""
|
|
173
|
+
|
|
174
|
+
def __init__(self, tool_info: MCPToolInfo, server_name: str = "") -> None:
|
|
175
|
+
self.tool_info = tool_info
|
|
176
|
+
self.server_name = server_name
|
|
177
|
+
self.display_name = clean_tool_name(tool_info.name, tool_info.original_name)
|
|
178
|
+
super().__init__()
|
|
179
|
+
|
|
180
|
+
def compose(self) -> ComposeResult:
|
|
181
|
+
with Vertical():
|
|
182
|
+
yield Static(f"MCP Tool: {self.display_name}", classes="mcp-tool-detail-title")
|
|
183
|
+
with VerticalScroll(classes="mcp-tool-detail-body"):
|
|
184
|
+
yield Vertical(id="mcp-tool-detail-content")
|
|
185
|
+
yield Static("Esc or 'q' to close", classes="mcp-tool-detail-help")
|
|
186
|
+
|
|
187
|
+
def on_mount(self) -> None:
|
|
188
|
+
content = self.query_one("#mcp-tool-detail-content", Vertical)
|
|
189
|
+
content.mount(Static("[bold]Tool Name[/bold]", classes="detail-label"))
|
|
190
|
+
content.mount(Static(f"[bold cyan]{self.display_name}[/bold cyan]", classes="detail-value"))
|
|
191
|
+
|
|
192
|
+
if self.server_name:
|
|
193
|
+
srv_disp, srv_scope = clean_server_name(self.server_name)
|
|
194
|
+
scope_txt = f" [cyan][{srv_scope}][/cyan]" if srv_scope else ""
|
|
195
|
+
content.mount(Static("[bold]Server[/bold]", classes="detail-label"))
|
|
196
|
+
content.mount(Static(f"{srv_disp}{scope_txt} [dim]({self.server_name})[/dim]", classes="detail-value"))
|
|
197
|
+
|
|
198
|
+
content.mount(Static("[bold]Full Identifier[/bold]", classes="detail-label"))
|
|
199
|
+
content.mount(Static(f"[dim]{self.tool_info.name}[/dim]", classes="detail-value"))
|
|
200
|
+
|
|
201
|
+
content.mount(Static("[bold]Description[/bold]", classes="detail-label"))
|
|
202
|
+
content.mount(
|
|
203
|
+
Static(
|
|
204
|
+
self.tool_info.description or "[dim]No description provided.[/dim]",
|
|
205
|
+
classes="detail-value",
|
|
206
|
+
)
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
schema = self.tool_info.input_schema
|
|
210
|
+
content.mount(Static("[bold]Input Schema (JSON Schema)[/bold]", classes="detail-label"))
|
|
211
|
+
if schema:
|
|
212
|
+
schema_json = json.dumps(schema, indent=2)
|
|
213
|
+
content.mount(Static(schema_json, classes="detail-value"))
|
|
214
|
+
else:
|
|
215
|
+
content.mount(Static("[dim]No input parameters specified.[/dim]", classes="detail-value"))
|
|
216
|
+
|
|
217
|
+
def action_close_dialog(self) -> None:
|
|
218
|
+
self.dismiss(None)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
# ── Server Error Sub-modal ───────────────────────────────
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
class MCPServerErrorScreen(ModalScreen[None]):
|
|
225
|
+
"""Read-only modal for a failed MCP server's error details."""
|
|
226
|
+
|
|
227
|
+
BINDINGS: ClassVar[list[BindingType]] = [
|
|
228
|
+
Binding("escape", "cancel", "Close", show=False, priority=True),
|
|
229
|
+
Binding("q", "cancel", "Close", show=False),
|
|
230
|
+
]
|
|
231
|
+
|
|
232
|
+
CSS = """
|
|
233
|
+
MCPServerErrorScreen {
|
|
234
|
+
align: center middle;
|
|
235
|
+
background: $background 70%;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
MCPServerErrorScreen > Vertical {
|
|
239
|
+
width: 90;
|
|
240
|
+
max-width: 90%;
|
|
241
|
+
height: 70%;
|
|
242
|
+
background: $surface;
|
|
243
|
+
border: solid $error;
|
|
244
|
+
padding: 1 2;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
MCPServerErrorScreen .mcp-error-title {
|
|
248
|
+
text-style: bold;
|
|
249
|
+
color: $error;
|
|
250
|
+
text-align: center;
|
|
251
|
+
margin-bottom: 1;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
MCPServerErrorScreen .mcp-error-body {
|
|
255
|
+
height: 1fr;
|
|
256
|
+
background: $background;
|
|
257
|
+
scrollbar-gutter: stable;
|
|
258
|
+
padding: 0 1;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
MCPServerErrorScreen .mcp-error-text {
|
|
262
|
+
color: $text;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
MCPServerErrorScreen .mcp-error-help {
|
|
266
|
+
height: auto;
|
|
267
|
+
color: $text-muted;
|
|
268
|
+
text-style: italic;
|
|
269
|
+
margin-top: 1;
|
|
270
|
+
text-align: center;
|
|
271
|
+
}
|
|
272
|
+
"""
|
|
273
|
+
|
|
274
|
+
def __init__(self, server: MCPServerInfo) -> None:
|
|
275
|
+
super().__init__()
|
|
276
|
+
self._server = server
|
|
277
|
+
self._error = server.error or "No error details were reported."
|
|
278
|
+
|
|
279
|
+
def compose(self) -> ComposeResult:
|
|
280
|
+
name = self._server.name
|
|
281
|
+
with Vertical():
|
|
282
|
+
yield Static(f"MCP Server Error: {name}", classes="mcp-error-title")
|
|
283
|
+
with VerticalScroll(classes="mcp-error-body"):
|
|
284
|
+
yield Static(self._error, classes="mcp-error-text")
|
|
285
|
+
yield Static("Esc close", classes="mcp-error-help")
|
|
286
|
+
|
|
287
|
+
def action_cancel(self) -> None:
|
|
288
|
+
self.dismiss(None)
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
# ── Tool Item Widget ─────────────────────────────────────
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
class MCPToolItem(Static):
|
|
295
|
+
"""A selectable tool row in the left pane of the MCP viewer."""
|
|
296
|
+
|
|
297
|
+
def __init__(
|
|
298
|
+
self,
|
|
299
|
+
tool_info: MCPToolInfo,
|
|
300
|
+
index: int,
|
|
301
|
+
*,
|
|
302
|
+
server_name: str = "",
|
|
303
|
+
server_info: MCPServerInfo | None = None,
|
|
304
|
+
classes: str = "",
|
|
305
|
+
) -> None:
|
|
306
|
+
self.tool_info = tool_info
|
|
307
|
+
self.tool_name = tool_info.name
|
|
308
|
+
self.tool_description = tool_info.description
|
|
309
|
+
self.server_name = server_name
|
|
310
|
+
self.server_info = server_info
|
|
311
|
+
self.index = index
|
|
312
|
+
self._input_schema = tool_info.input_schema
|
|
313
|
+
self._expanded = False
|
|
314
|
+
self._selected = "mcp-tool-selected" in classes
|
|
315
|
+
self.display_name = clean_tool_name(tool_info.name, tool_info.original_name)
|
|
316
|
+
super().__init__(classes=classes)
|
|
317
|
+
|
|
318
|
+
def _desc_style(self) -> str:
|
|
319
|
+
return "" if self._selected else "dim"
|
|
320
|
+
|
|
321
|
+
def _format_collapsed(self) -> str:
|
|
322
|
+
cursor = "›" if self._selected else " "
|
|
323
|
+
desc = self.tool_description
|
|
324
|
+
if desc and len(desc) > 30:
|
|
325
|
+
desc = desc[:27] + "..."
|
|
326
|
+
|
|
327
|
+
# Retain raw identifier in dim markup for diagnostic & test verification
|
|
328
|
+
raw_dim = f" [dim]({self.tool_name})[/dim]" if self.tool_name != self.display_name else ""
|
|
329
|
+
|
|
330
|
+
if self._selected:
|
|
331
|
+
if desc:
|
|
332
|
+
return f" {cursor} [bold]{self.display_name}[/bold] {desc}{raw_dim}"
|
|
333
|
+
return f" {cursor} [bold]{self.display_name}[/bold]{raw_dim}"
|
|
334
|
+
else:
|
|
335
|
+
if desc:
|
|
336
|
+
return f" {cursor} {self.display_name} [dim]{desc}{raw_dim}[/dim]"
|
|
337
|
+
return f" {cursor} {self.display_name}{raw_dim}"
|
|
338
|
+
|
|
339
|
+
def _format_expanded(self) -> str:
|
|
340
|
+
# Kept for direct toggle_expand callers / existing test assertions
|
|
341
|
+
lines = [f" [bold]{self.display_name}[/bold] [dim]({self.tool_name})[/dim]"]
|
|
342
|
+
if self.tool_description:
|
|
343
|
+
style = self._desc_style()
|
|
344
|
+
if style:
|
|
345
|
+
lines.append(f" [{style}]{self.tool_description}[/{style}]")
|
|
346
|
+
else:
|
|
347
|
+
lines.append(f" {self.tool_description}")
|
|
348
|
+
|
|
349
|
+
# Parameter schema
|
|
350
|
+
schema = self._input_schema
|
|
351
|
+
if schema and isinstance(schema, dict):
|
|
352
|
+
properties = schema.get("properties")
|
|
353
|
+
if isinstance(properties, dict) and properties:
|
|
354
|
+
required = set(schema.get("required") or [])
|
|
355
|
+
style = self._desc_style()
|
|
356
|
+
if style:
|
|
357
|
+
lines.append(f" [{style}]Parameters:[/{style}]")
|
|
358
|
+
else:
|
|
359
|
+
lines.append(" Parameters:")
|
|
360
|
+
for prop_name, prop_schema in properties.items():
|
|
361
|
+
prop_type = _format_prop_type(
|
|
362
|
+
prop_schema.get("type") if isinstance(prop_schema, dict) else None
|
|
363
|
+
)
|
|
364
|
+
star = " *" if prop_name in required else ""
|
|
365
|
+
safe_name = str(prop_name).replace("\n", " ")[:80]
|
|
366
|
+
if style:
|
|
367
|
+
lines.append(f" [{style}]{safe_name}: {prop_type}{star}[/{style}]")
|
|
368
|
+
else:
|
|
369
|
+
lines.append(f" {safe_name}: {prop_type}{star}")
|
|
370
|
+
return "\n".join(lines)
|
|
371
|
+
|
|
372
|
+
def _rerender(self) -> None:
|
|
373
|
+
if self._expanded:
|
|
374
|
+
self.update(self._format_expanded())
|
|
375
|
+
else:
|
|
376
|
+
self.update(self._format_collapsed())
|
|
377
|
+
|
|
378
|
+
def set_selected(self, selected: bool) -> None:
|
|
379
|
+
if self._selected == selected:
|
|
380
|
+
return
|
|
381
|
+
self._selected = selected
|
|
382
|
+
if selected:
|
|
383
|
+
self.add_class("mcp-tool-selected")
|
|
384
|
+
else:
|
|
385
|
+
self.remove_class("mcp-tool-selected")
|
|
386
|
+
self._rerender()
|
|
387
|
+
|
|
388
|
+
def toggle_expand(self) -> None:
|
|
389
|
+
self.set_expanded(not self._expanded)
|
|
390
|
+
|
|
391
|
+
def set_expanded(self, expanded: bool) -> None:
|
|
392
|
+
self._expanded = expanded
|
|
393
|
+
self.styles.height = "auto" if expanded else 1
|
|
394
|
+
self._rerender()
|
|
395
|
+
|
|
396
|
+
def on_mount(self) -> None:
|
|
397
|
+
self.call_after_refresh(self._rerender)
|
|
398
|
+
|
|
399
|
+
def on_resize(self) -> None:
|
|
400
|
+
if not self._expanded:
|
|
401
|
+
self.update(self._format_collapsed())
|
|
402
|
+
|
|
403
|
+
def on_enter(self, event: events.Enter) -> None:
|
|
404
|
+
screen = self.screen
|
|
405
|
+
if isinstance(screen, MCPViewerScreen):
|
|
406
|
+
screen._move_to(self.index)
|
|
407
|
+
|
|
408
|
+
def on_click(self, event: events.Click) -> None:
|
|
409
|
+
event.stop()
|
|
410
|
+
screen = self.screen
|
|
411
|
+
if isinstance(screen, MCPViewerScreen):
|
|
412
|
+
screen._move_to(self.index)
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
# ── Server Header Widget ─────────────────────────────────
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
class MCPServerHeaderItem(Static):
|
|
419
|
+
"""A selectable server-header row in the MCP viewer."""
|
|
420
|
+
|
|
421
|
+
def __init__(
|
|
422
|
+
self,
|
|
423
|
+
server: MCPServerInfo,
|
|
424
|
+
visible_tool_count: int,
|
|
425
|
+
index: int,
|
|
426
|
+
*,
|
|
427
|
+
classes: str = "",
|
|
428
|
+
) -> None:
|
|
429
|
+
self._server = server
|
|
430
|
+
self._visible_tool_count = visible_tool_count
|
|
431
|
+
self.index = index
|
|
432
|
+
self._selected = "mcp-header-selected" in classes
|
|
433
|
+
self.display_name, self.scope = clean_server_name(server.name)
|
|
434
|
+
content = self._render_header()
|
|
435
|
+
super().__init__(content, classes=classes, markup=True)
|
|
436
|
+
|
|
437
|
+
@property
|
|
438
|
+
def server(self) -> MCPServerInfo:
|
|
439
|
+
return self._server
|
|
440
|
+
|
|
441
|
+
def _render_header(self) -> str:
|
|
442
|
+
server = self._server
|
|
443
|
+
glyph = _status_glyph(server)
|
|
444
|
+
transport = server.transport
|
|
445
|
+
status = server.status
|
|
446
|
+
tool_count = self._visible_tool_count
|
|
447
|
+
t_label = "tool" if tool_count == 1 else "tools"
|
|
448
|
+
|
|
449
|
+
cursor = "›" if self._selected else " "
|
|
450
|
+
scope_badge = f" [{self.scope}]" if self.scope else ""
|
|
451
|
+
|
|
452
|
+
# Retain raw identifier in dim markup for diagnostic & test verification
|
|
453
|
+
raw_dim = f" [dim]({server.name})[/dim]" if server.name != self.display_name else ""
|
|
454
|
+
|
|
455
|
+
if self._selected:
|
|
456
|
+
if status == "ok":
|
|
457
|
+
return f"{cursor} {glyph} [bold]{self.display_name}[/bold]{scope_badge} {transport} · {tool_count} {t_label}{raw_dim}"
|
|
458
|
+
if status == "unauthenticated":
|
|
459
|
+
return f"{cursor} {glyph} [bold]{self.display_name}[/bold]{scope_badge} {transport} · {status} (Enter to log in){raw_dim}"
|
|
460
|
+
if status == "error":
|
|
461
|
+
return f"{cursor} {glyph} [bold]{self.display_name}[/bold]{scope_badge} {transport} · {status} (Enter for error){raw_dim}"
|
|
462
|
+
return f"{cursor} {glyph} [bold]{self.display_name}[/bold]{scope_badge} {transport} · {status}{raw_dim}"
|
|
463
|
+
else:
|
|
464
|
+
if status == "ok":
|
|
465
|
+
return f"{cursor} {glyph} [bold]{self.display_name}[/bold][cyan]{scope_badge}[/cyan] [dim]{transport} · {tool_count} {t_label}{raw_dim}[/dim]"
|
|
466
|
+
if status == "unauthenticated":
|
|
467
|
+
return f"{cursor} {glyph} [bold]{self.display_name}[/bold][cyan]{scope_badge}[/cyan] [yellow]{status}[/yellow] [dim]— Enter to log in{raw_dim}[/dim]"
|
|
468
|
+
if status == "error":
|
|
469
|
+
return f"{cursor} {glyph} [bold]{self.display_name}[/bold][cyan]{scope_badge}[/cyan] [red]{status}[/red] [dim]— Enter for details{raw_dim}[/dim]"
|
|
470
|
+
return f"{cursor} {glyph} [bold]{self.display_name}[/bold][cyan]{scope_badge}[/cyan] [dim]{transport} · {status}{raw_dim}[/dim]"
|
|
471
|
+
|
|
472
|
+
def set_selected(self, selected: bool) -> None:
|
|
473
|
+
if self._selected == selected:
|
|
474
|
+
return
|
|
475
|
+
self._selected = selected
|
|
476
|
+
if selected:
|
|
477
|
+
self.add_class("mcp-header-selected")
|
|
478
|
+
else:
|
|
479
|
+
self.remove_class("mcp-header-selected")
|
|
480
|
+
self.update(self._render_header())
|
|
481
|
+
|
|
482
|
+
def on_enter(self, event: events.Enter) -> None:
|
|
483
|
+
screen = self.screen
|
|
484
|
+
if isinstance(screen, MCPViewerScreen):
|
|
485
|
+
screen._move_to(self.index)
|
|
486
|
+
|
|
487
|
+
def on_click(self, event: events.Click) -> None:
|
|
488
|
+
event.stop()
|
|
489
|
+
screen = self.screen
|
|
490
|
+
if not isinstance(screen, MCPViewerScreen):
|
|
491
|
+
return
|
|
492
|
+
if self._selected and self._server.status == "unauthenticated":
|
|
493
|
+
screen.dismiss(self._server.name)
|
|
494
|
+
return
|
|
495
|
+
if self._selected and self._server.status == "error":
|
|
496
|
+
screen.show_server_error(self._server)
|
|
497
|
+
return
|
|
498
|
+
screen._move_to(self.index)
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
# ── Filter helper ────────────────────────────────────────
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
def _visible_tools_for(
|
|
505
|
+
server: MCPServerInfo, tokens: list[str]
|
|
506
|
+
) -> tuple[MCPToolInfo, ...] | None:
|
|
507
|
+
"""Return tools matching the filter, or None if nothing matches."""
|
|
508
|
+
tools = server.tools
|
|
509
|
+
if not tokens:
|
|
510
|
+
return tools or ()
|
|
511
|
+
|
|
512
|
+
srv_clean, srv_scope = clean_server_name(server.name)
|
|
513
|
+
srv_search = f"{server.name} {srv_clean} {srv_scope or ''}".lower()
|
|
514
|
+
if all(tok in srv_search for tok in tokens):
|
|
515
|
+
return tools or None
|
|
516
|
+
|
|
517
|
+
matching: list[MCPToolInfo] = []
|
|
518
|
+
for t in tools:
|
|
519
|
+
t_clean = clean_tool_name(t.name, t.original_name)
|
|
520
|
+
search_blob = f"{t.name} {t_clean} {t.original_name or ''} {t.description}".lower()
|
|
521
|
+
if all(tok in search_blob for tok in tokens):
|
|
522
|
+
matching.append(t)
|
|
523
|
+
|
|
524
|
+
return tuple(matching) or None
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
# ── Main MCP Viewer Screen ───────────────────────────────
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
class MCPViewerScreen(ModalScreen[str | None]):
|
|
531
|
+
"""Two-pane modal viewer for active MCP servers and their tools.
|
|
532
|
+
|
|
533
|
+
Left pane lists MCP servers and their tools with keyboard and mouse hover support.
|
|
534
|
+
Right pane displays real-time metadata, parameter schemas, and error diagnostics.
|
|
535
|
+
"""
|
|
536
|
+
|
|
537
|
+
BINDINGS: ClassVar[list[BindingType]] = [
|
|
538
|
+
Binding("up", "move_up", "Up", show=False, priority=True),
|
|
539
|
+
Binding("down", "move_down", "Down", show=False, priority=True),
|
|
540
|
+
Binding("tab", "jump_down", "Next server", show=False, priority=True),
|
|
541
|
+
Binding("shift+tab", "jump_up", "Prev server", show=False, priority=True),
|
|
542
|
+
Binding("enter", "select_item", "Details/Login", show=False, priority=True),
|
|
543
|
+
Binding("ctrl+e", "toggle_all", "Toggle all", show=False, priority=True),
|
|
544
|
+
Binding("ctrl+r", "reconnect", "Reconnect", show=False, priority=True),
|
|
545
|
+
Binding("f2", "toggle_disable", "Disable/Enable", show=False, priority=True),
|
|
546
|
+
Binding("pageup", "page_up", "Page up", show=False, priority=True),
|
|
547
|
+
Binding("pagedown", "page_down", "Page down", show=False, priority=True),
|
|
548
|
+
Binding("escape", "cancel", "Close", show=False, priority=True),
|
|
549
|
+
]
|
|
550
|
+
|
|
551
|
+
CSS = """
|
|
552
|
+
MCPViewerScreen {
|
|
553
|
+
align: center middle;
|
|
554
|
+
background: $background 70%;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
MCPViewerScreen > Vertical {
|
|
558
|
+
width: 100%;
|
|
559
|
+
max-width: 98%;
|
|
560
|
+
height: 90%;
|
|
561
|
+
background: $surface;
|
|
562
|
+
border: solid $primary;
|
|
563
|
+
padding: 1 2;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/* ── Title ─────────────────────────── */
|
|
567
|
+
MCPViewerScreen .mcp-viewer-title {
|
|
568
|
+
text-style: bold;
|
|
569
|
+
color: $primary;
|
|
570
|
+
text-align: center;
|
|
571
|
+
margin-bottom: 1;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/* ── Filter ────────────────────────── */
|
|
575
|
+
MCPViewerScreen #mcp-filter {
|
|
576
|
+
margin-bottom: 1;
|
|
577
|
+
border: solid $primary-lighten-2;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
MCPViewerScreen #mcp-filter:focus {
|
|
581
|
+
border: solid $primary;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
/* ── Two-pane body ─────────────────── */
|
|
585
|
+
MCPViewerScreen .mcp-body {
|
|
586
|
+
height: 1fr;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/* ── Left pane: server & tool list ─── */
|
|
590
|
+
MCPViewerScreen .mcp-list-pane {
|
|
591
|
+
width: 1fr;
|
|
592
|
+
min-width: 35;
|
|
593
|
+
height: 1fr;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
MCPViewerScreen .mcp-list {
|
|
597
|
+
height: 1fr;
|
|
598
|
+
min-height: 5;
|
|
599
|
+
scrollbar-gutter: stable;
|
|
600
|
+
background: $background;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/* ── Server headers ────────────────── */
|
|
604
|
+
MCPViewerScreen .mcp-server-header {
|
|
605
|
+
height: 1;
|
|
606
|
+
width: 100%;
|
|
607
|
+
padding: 0 1;
|
|
608
|
+
color: $primary;
|
|
609
|
+
text-style: bold;
|
|
610
|
+
margin-top: 1;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
MCPViewerScreen .mcp-server-header:hover {
|
|
614
|
+
background: $surface-lighten-1;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
MCPViewerScreen .mcp-list > .mcp-server-header:first-child {
|
|
618
|
+
margin-top: 0;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
MCPViewerScreen .mcp-header-selected {
|
|
622
|
+
background: $primary;
|
|
623
|
+
color: $background;
|
|
624
|
+
text-style: bold;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
MCPViewerScreen .mcp-header-selected:hover {
|
|
628
|
+
background: $primary-lighten-1;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/* ── Tool items ────────────────────── */
|
|
632
|
+
MCPViewerScreen .mcp-tool-item {
|
|
633
|
+
height: 1;
|
|
634
|
+
width: 100%;
|
|
635
|
+
padding: 0 1 0 2;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
MCPViewerScreen .mcp-tool-item:hover {
|
|
639
|
+
background: $surface-lighten-1;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
MCPViewerScreen .mcp-tool-selected {
|
|
643
|
+
background: $primary;
|
|
644
|
+
color: $background;
|
|
645
|
+
text-style: bold;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
MCPViewerScreen .mcp-tool-selected:hover {
|
|
649
|
+
background: $primary-lighten-1;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
/* ── Right pane: detail panel ──────── */
|
|
653
|
+
MCPViewerScreen .mcp-detail-pane {
|
|
654
|
+
width: 46;
|
|
655
|
+
min-width: 32;
|
|
656
|
+
height: 1fr;
|
|
657
|
+
margin-left: 1;
|
|
658
|
+
padding-left: 1;
|
|
659
|
+
border-left: solid $primary-lighten-2;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
MCPViewerScreen .mcp-detail-title {
|
|
663
|
+
text-style: bold;
|
|
664
|
+
color: $primary;
|
|
665
|
+
margin-bottom: 1;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
MCPViewerScreen .mcp-detail-content {
|
|
669
|
+
height: 1fr;
|
|
670
|
+
min-height: 1;
|
|
671
|
+
scrollbar-gutter: stable;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
MCPViewerScreen .detail-label {
|
|
675
|
+
color: $text-muted;
|
|
676
|
+
margin-top: 1;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
MCPViewerScreen .detail-value {
|
|
680
|
+
margin-bottom: 0;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
/* ── Empty state ───────────────────── */
|
|
684
|
+
MCPViewerScreen .mcp-empty {
|
|
685
|
+
color: $text-muted;
|
|
686
|
+
text-style: italic;
|
|
687
|
+
text-align: center;
|
|
688
|
+
margin-top: 2;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
/* ── Help footer ───────────────────── */
|
|
692
|
+
MCPViewerScreen .mcp-viewer-help {
|
|
693
|
+
height: auto;
|
|
694
|
+
color: $text-muted;
|
|
695
|
+
text-style: italic;
|
|
696
|
+
margin-top: 1;
|
|
697
|
+
text-align: center;
|
|
698
|
+
}
|
|
699
|
+
"""
|
|
700
|
+
|
|
701
|
+
def __init__(
|
|
702
|
+
self,
|
|
703
|
+
server_info: list[MCPServerInfo],
|
|
704
|
+
*,
|
|
705
|
+
connecting: bool = False,
|
|
706
|
+
pending_reconnect: bool = False,
|
|
707
|
+
on_toggle_disable: Callable[[str], Awaitable[None]] | None = None,
|
|
708
|
+
) -> None:
|
|
709
|
+
super().__init__()
|
|
710
|
+
self._server_info = server_info
|
|
711
|
+
self._connecting = connecting
|
|
712
|
+
self._pending_reconnect = pending_reconnect
|
|
713
|
+
self._on_toggle_disable = on_toggle_disable
|
|
714
|
+
self._row_widgets: list[MCPToolItem | MCPServerHeaderItem] = []
|
|
715
|
+
self._selected_index = 0
|
|
716
|
+
self._query: str = ""
|
|
717
|
+
|
|
718
|
+
@property
|
|
719
|
+
def _tool_widgets(self) -> list[MCPToolItem]:
|
|
720
|
+
return [w for w in self._row_widgets if isinstance(w, MCPToolItem)]
|
|
721
|
+
|
|
722
|
+
# ── Compose / Mount ──────────────────────────────────
|
|
723
|
+
|
|
724
|
+
def compose(self) -> ComposeResult:
|
|
725
|
+
yield Vertical()
|
|
726
|
+
|
|
727
|
+
def on_mount(self) -> None:
|
|
728
|
+
self._mount_body(self.query_one(Vertical))
|
|
729
|
+
|
|
730
|
+
def _mount_body(self, container: Vertical) -> None:
|
|
731
|
+
total_servers = len(self._server_info)
|
|
732
|
+
total_tools = sum(s.tool_count for s in self._server_info)
|
|
733
|
+
|
|
734
|
+
if total_servers:
|
|
735
|
+
s_label = "server" if total_servers == 1 else "servers"
|
|
736
|
+
t_label = "tool" if total_tools == 1 else "tools"
|
|
737
|
+
title = f"MCP Servers ({total_servers} {s_label}, {total_tools} {t_label})"
|
|
738
|
+
else:
|
|
739
|
+
title = "MCP Servers"
|
|
740
|
+
|
|
741
|
+
container.mount(Static(title, classes="mcp-viewer-title"))
|
|
742
|
+
|
|
743
|
+
if self._server_info:
|
|
744
|
+
container.mount(
|
|
745
|
+
Input(
|
|
746
|
+
id="mcp-filter",
|
|
747
|
+
placeholder="Filter tools...",
|
|
748
|
+
value=self._query,
|
|
749
|
+
)
|
|
750
|
+
)
|
|
751
|
+
|
|
752
|
+
# Two-pane body matching Skills UI
|
|
753
|
+
body = Horizontal(classes="mcp-body")
|
|
754
|
+
container.mount(body)
|
|
755
|
+
|
|
756
|
+
# Left pane: MCP servers & tools list
|
|
757
|
+
list_pane = Vertical(classes="mcp-list-pane")
|
|
758
|
+
body.mount(list_pane)
|
|
759
|
+
scroll = VerticalScroll(classes="mcp-list")
|
|
760
|
+
list_pane.mount(scroll)
|
|
761
|
+
|
|
762
|
+
# Right pane: Detail panel
|
|
763
|
+
detail_pane = Vertical(classes="mcp-detail-pane")
|
|
764
|
+
body.mount(detail_pane)
|
|
765
|
+
detail_pane.mount(Static("Details", classes="mcp-detail-title"))
|
|
766
|
+
detail_scroll = VerticalScroll(classes="mcp-detail-content")
|
|
767
|
+
detail_pane.mount(detail_scroll)
|
|
768
|
+
detail_scroll.mount(Vertical(id="mcp-detail-body"))
|
|
769
|
+
|
|
770
|
+
# Populate scroll items
|
|
771
|
+
self._populate_scroll(scroll, self._query)
|
|
772
|
+
|
|
773
|
+
# Help footer
|
|
774
|
+
container.mount(
|
|
775
|
+
Static(self._build_help_text(), classes="mcp-viewer-help")
|
|
776
|
+
)
|
|
777
|
+
|
|
778
|
+
# Update initial detail panel state
|
|
779
|
+
self._update_detail_panel()
|
|
780
|
+
|
|
781
|
+
# Focus filter input if available
|
|
782
|
+
def _focus() -> None:
|
|
783
|
+
if self._server_info:
|
|
784
|
+
try:
|
|
785
|
+
self.query_one("#mcp-filter", Input).focus()
|
|
786
|
+
except Exception:
|
|
787
|
+
pass
|
|
788
|
+
|
|
789
|
+
self.call_after_refresh(_focus)
|
|
790
|
+
|
|
791
|
+
def _build_help_text(self) -> str:
|
|
792
|
+
parts = [
|
|
793
|
+
"↑/↓ navigate",
|
|
794
|
+
"Enter details/schema",
|
|
795
|
+
"F2 disable/enable",
|
|
796
|
+
]
|
|
797
|
+
if self._pending_reconnect:
|
|
798
|
+
parts.append("Ctrl+R reconnect")
|
|
799
|
+
parts.extend(["type to filter", "Esc close"])
|
|
800
|
+
return " │ ".join(parts)
|
|
801
|
+
|
|
802
|
+
# ── Populate scroll ──────────────────────────────────
|
|
803
|
+
|
|
804
|
+
def _populate_scroll(self, scroll: VerticalScroll, query: str) -> None:
|
|
805
|
+
if not self._server_info:
|
|
806
|
+
placeholder = (
|
|
807
|
+
"Loading MCP tools..."
|
|
808
|
+
if self._connecting
|
|
809
|
+
else "No MCP servers configured.\nUse `--mcp-config` to load servers."
|
|
810
|
+
)
|
|
811
|
+
scroll.mount(Static(placeholder, classes="mcp-empty"))
|
|
812
|
+
return
|
|
813
|
+
|
|
814
|
+
tokens = [tok for tok in query.lower().split() if tok]
|
|
815
|
+
flat_index = 0
|
|
816
|
+
|
|
817
|
+
# Sort: attention-needed servers first
|
|
818
|
+
sorted_servers = sorted(
|
|
819
|
+
self._server_info,
|
|
820
|
+
key=lambda s: 0 if s.status in ("unauthenticated", "error") else 1,
|
|
821
|
+
)
|
|
822
|
+
|
|
823
|
+
for server in sorted_servers:
|
|
824
|
+
visible_tools = _visible_tools_for(server, tokens)
|
|
825
|
+
if visible_tools is None:
|
|
826
|
+
continue
|
|
827
|
+
|
|
828
|
+
header_classes = "mcp-server-header"
|
|
829
|
+
if flat_index == 0:
|
|
830
|
+
header_classes += " mcp-header-selected"
|
|
831
|
+
|
|
832
|
+
header = MCPServerHeaderItem(
|
|
833
|
+
server=server,
|
|
834
|
+
visible_tool_count=len(visible_tools),
|
|
835
|
+
index=flat_index,
|
|
836
|
+
classes=header_classes,
|
|
837
|
+
)
|
|
838
|
+
self._row_widgets.append(header)
|
|
839
|
+
scroll.mount(header)
|
|
840
|
+
flat_index += 1
|
|
841
|
+
|
|
842
|
+
for tool_info in visible_tools:
|
|
843
|
+
widget = MCPToolItem(
|
|
844
|
+
tool_info=tool_info,
|
|
845
|
+
index=flat_index,
|
|
846
|
+
server_name=server.name,
|
|
847
|
+
server_info=server,
|
|
848
|
+
classes="mcp-tool-item",
|
|
849
|
+
)
|
|
850
|
+
self._row_widgets.append(widget)
|
|
851
|
+
scroll.mount(widget)
|
|
852
|
+
flat_index += 1
|
|
853
|
+
|
|
854
|
+
if not self._row_widgets:
|
|
855
|
+
msg = "No matching tools." if tokens else "No tools available."
|
|
856
|
+
scroll.mount(Static(msg, classes="mcp-empty"))
|
|
857
|
+
|
|
858
|
+
# ── Detail Panel Live Update ─────────────────────────
|
|
859
|
+
|
|
860
|
+
def _update_detail_panel(self) -> None:
|
|
861
|
+
"""Refresh the right-pane detail view for the currently selected item."""
|
|
862
|
+
try:
|
|
863
|
+
detail_body = self.query_one("#mcp-detail-body", Vertical)
|
|
864
|
+
except Exception:
|
|
865
|
+
return
|
|
866
|
+
|
|
867
|
+
detail_body.remove_children()
|
|
868
|
+
|
|
869
|
+
if not self._row_widgets or not (0 <= self._selected_index < len(self._row_widgets)):
|
|
870
|
+
detail_body.mount(
|
|
871
|
+
Static("[dim]Select a tool or server to view details[/dim]", classes="mcp-empty")
|
|
872
|
+
)
|
|
873
|
+
return
|
|
874
|
+
|
|
875
|
+
item = self._row_widgets[self._selected_index]
|
|
876
|
+
if isinstance(item, MCPToolItem):
|
|
877
|
+
self._render_tool_details(detail_body, item)
|
|
878
|
+
elif isinstance(item, MCPServerHeaderItem):
|
|
879
|
+
self._render_server_details(detail_body, item)
|
|
880
|
+
|
|
881
|
+
def _render_tool_details(self, detail_body: Vertical, item: MCPToolItem) -> None:
|
|
882
|
+
"""Mount formatted metadata and parameter schemas for a tool."""
|
|
883
|
+
detail_body.mount(Static("[bold]Tool[/bold]", classes="detail-label"))
|
|
884
|
+
detail_body.mount(Static(f"[bold cyan]{item.display_name}[/bold cyan]", classes="detail-value"))
|
|
885
|
+
|
|
886
|
+
detail_body.mount(Static("[bold]MCP Server[/bold]", classes="detail-label"))
|
|
887
|
+
if item.server_info:
|
|
888
|
+
srv_disp, srv_scope = clean_server_name(item.server_info.name)
|
|
889
|
+
scope_badge = f" [cyan][{srv_scope}][/cyan]" if srv_scope else ""
|
|
890
|
+
status_glyph = _status_glyph(item.server_info)
|
|
891
|
+
detail_body.mount(
|
|
892
|
+
Static(
|
|
893
|
+
f"{srv_disp}{scope_badge} [dim]({status_glyph} {item.server_info.transport})[/dim]",
|
|
894
|
+
classes="detail-value",
|
|
895
|
+
)
|
|
896
|
+
)
|
|
897
|
+
else:
|
|
898
|
+
detail_body.mount(Static(item.server_name, classes="detail-value"))
|
|
899
|
+
|
|
900
|
+
detail_body.mount(Static("[bold]Description[/bold]", classes="detail-label"))
|
|
901
|
+
desc = item.tool_description or "[dim]No description provided.[/dim]"
|
|
902
|
+
detail_body.mount(Static(desc, classes="detail-value"))
|
|
903
|
+
|
|
904
|
+
schema = item._input_schema
|
|
905
|
+
detail_body.mount(Static("[bold]Parameters[/bold]", classes="detail-label"))
|
|
906
|
+
if schema and isinstance(schema, dict):
|
|
907
|
+
properties = schema.get("properties")
|
|
908
|
+
if isinstance(properties, dict) and properties:
|
|
909
|
+
required = set(schema.get("required") or [])
|
|
910
|
+
count = len(properties)
|
|
911
|
+
detail_body.mount(
|
|
912
|
+
Static(f"[dim]{count} parameter{'s' if count != 1 else ''}[/dim]", classes="detail-value")
|
|
913
|
+
)
|
|
914
|
+
for prop_name, prop_schema in properties.items():
|
|
915
|
+
is_req = prop_name in required
|
|
916
|
+
req_badge = "[bold red]* required[/bold red]" if is_req else "[dim]optional[/dim]"
|
|
917
|
+
p_type = _format_prop_type(
|
|
918
|
+
prop_schema.get("type") if isinstance(prop_schema, dict) else None
|
|
919
|
+
)
|
|
920
|
+
detail_body.mount(
|
|
921
|
+
Static(f"• [bold cyan]{prop_name}[/bold cyan] ({p_type}) {req_badge}", classes="detail-value")
|
|
922
|
+
)
|
|
923
|
+
if isinstance(prop_schema, dict):
|
|
924
|
+
p_desc = prop_schema.get("description", "").strip()
|
|
925
|
+
if p_desc:
|
|
926
|
+
detail_body.mount(Static(f" [dim]{p_desc}[/dim]", classes="detail-value"))
|
|
927
|
+
enum_vals = prop_schema.get("enum")
|
|
928
|
+
if enum_vals:
|
|
929
|
+
enum_str = ", ".join(repr(v) for v in enum_vals[:6])
|
|
930
|
+
if len(enum_vals) > 6:
|
|
931
|
+
enum_str += ", …"
|
|
932
|
+
detail_body.mount(Static(f" [dim]Options: [{enum_str}][/dim]", classes="detail-value"))
|
|
933
|
+
default_val = prop_schema.get("default")
|
|
934
|
+
if default_val is not None:
|
|
935
|
+
detail_body.mount(Static(f" [dim]Default: {default_val}[/dim]", classes="detail-value"))
|
|
936
|
+
else:
|
|
937
|
+
detail_body.mount(Static("[dim]No parameters required[/dim]", classes="detail-value"))
|
|
938
|
+
else:
|
|
939
|
+
detail_body.mount(Static("[dim]No parameters required[/dim]", classes="detail-value"))
|
|
940
|
+
|
|
941
|
+
detail_body.mount(Static("[bold]Identifier[/bold]", classes="detail-label"))
|
|
942
|
+
detail_body.mount(Static(f"[dim]{item.tool_name}[/dim]", classes="detail-value"))
|
|
943
|
+
|
|
944
|
+
detail_body.mount(
|
|
945
|
+
Static("\n[dim]Press [bold]Enter[/bold] to inspect full JSON schema[/dim]", classes="detail-label")
|
|
946
|
+
)
|
|
947
|
+
|
|
948
|
+
def _render_server_details(self, detail_body: Vertical, item: MCPServerHeaderItem) -> None:
|
|
949
|
+
"""Mount formatted configuration, status, and tools list for a server."""
|
|
950
|
+
server = item.server
|
|
951
|
+
srv_display, srv_scope = clean_server_name(server.name)
|
|
952
|
+
|
|
953
|
+
detail_body.mount(Static("[bold]Server[/bold]", classes="detail-label"))
|
|
954
|
+
scope_badge = f" [cyan][{srv_scope}][/cyan]" if srv_scope else ""
|
|
955
|
+
detail_body.mount(Static(f"[bold cyan]{srv_display}[/bold cyan]{scope_badge}", classes="detail-value"))
|
|
956
|
+
|
|
957
|
+
detail_body.mount(Static("[bold]Status[/bold]", classes="detail-label"))
|
|
958
|
+
glyph = _status_glyph(server)
|
|
959
|
+
if server.status == "ok":
|
|
960
|
+
status_text = f"[green]{glyph} Connected / Active[/green]"
|
|
961
|
+
elif server.status == "unauthenticated":
|
|
962
|
+
status_text = f"[yellow]{glyph} Unauthenticated[/yellow] [dim](Press Enter to log in)[/dim]"
|
|
963
|
+
elif server.status == "error":
|
|
964
|
+
status_text = f"[red]{glyph} Error[/red] [dim](Press Enter for details)[/dim]"
|
|
965
|
+
elif server.status == "disabled":
|
|
966
|
+
status_text = f"[dim]{glyph} Disabled (Press F2 to enable)[/dim]"
|
|
967
|
+
else:
|
|
968
|
+
status_text = f"{glyph} {server.status}"
|
|
969
|
+
detail_body.mount(Static(status_text, classes="detail-value"))
|
|
970
|
+
|
|
971
|
+
detail_body.mount(Static("[bold]Transport[/bold]", classes="detail-label"))
|
|
972
|
+
detail_body.mount(Static(f"[cyan]{server.transport}[/cyan]", classes="detail-value"))
|
|
973
|
+
|
|
974
|
+
if server.command:
|
|
975
|
+
cmd_str = server.command
|
|
976
|
+
if server.args:
|
|
977
|
+
cmd_str += " " + " ".join(server.args)
|
|
978
|
+
detail_body.mount(Static("[bold]Command[/bold]", classes="detail-label"))
|
|
979
|
+
detail_body.mount(Static(f"[dim]{cmd_str}[/dim]", classes="detail-value"))
|
|
980
|
+
|
|
981
|
+
if server.url:
|
|
982
|
+
detail_body.mount(Static("[bold]URL[/bold]", classes="detail-label"))
|
|
983
|
+
detail_body.mount(Static(f"[cyan]{server.url}[/cyan]", classes="detail-value"))
|
|
984
|
+
|
|
985
|
+
detail_body.mount(Static("[bold]Tools[/bold]", classes="detail-label"))
|
|
986
|
+
count = len(server.tools)
|
|
987
|
+
detail_body.mount(Static(f"{count} available", classes="detail-value"))
|
|
988
|
+
for t in server.tools[:8]:
|
|
989
|
+
t_clean = clean_tool_name(t.name, t.original_name)
|
|
990
|
+
detail_body.mount(Static(f"• [dim]{t_clean}[/dim]", classes="detail-value"))
|
|
991
|
+
if count > 8:
|
|
992
|
+
detail_body.mount(Static(f"[dim]… and {count - 8} more[/dim]", classes="detail-value"))
|
|
993
|
+
|
|
994
|
+
if server.error:
|
|
995
|
+
detail_body.mount(Static("[bold red]Error Diagnostics[/bold red]", classes="detail-label"))
|
|
996
|
+
detail_body.mount(Static(f"[red]{server.error}[/red]", classes="detail-value"))
|
|
997
|
+
|
|
998
|
+
detail_body.mount(Static("[bold]Config Identifier[/bold]", classes="detail-label"))
|
|
999
|
+
detail_body.mount(Static(f"[dim]{server.name}[/dim]", classes="detail-value"))
|
|
1000
|
+
|
|
1001
|
+
# ── Filter ───────────────────────────────────────────
|
|
1002
|
+
|
|
1003
|
+
def on_input_changed(self, event: Input.Changed) -> None:
|
|
1004
|
+
if event.input.id != "mcp-filter":
|
|
1005
|
+
return
|
|
1006
|
+
self._query = event.value
|
|
1007
|
+
scroll = self.query_one(".mcp-list", VerticalScroll)
|
|
1008
|
+
scroll.remove_children()
|
|
1009
|
+
self._row_widgets = []
|
|
1010
|
+
self._selected_index = 0
|
|
1011
|
+
self._populate_scroll(scroll, self._query)
|
|
1012
|
+
self._selected_index = min(
|
|
1013
|
+
self._selected_index, max(0, len(self._row_widgets) - 1)
|
|
1014
|
+
)
|
|
1015
|
+
self._update_detail_panel()
|
|
1016
|
+
|
|
1017
|
+
# ── Navigation ───────────────────────────────────────
|
|
1018
|
+
|
|
1019
|
+
def _move_to(self, index: int) -> None:
|
|
1020
|
+
count = len(self._row_widgets)
|
|
1021
|
+
if not count or not (0 <= index < count):
|
|
1022
|
+
return
|
|
1023
|
+
old = self._selected_index
|
|
1024
|
+
if not (0 <= old < count):
|
|
1025
|
+
old = 0
|
|
1026
|
+
self._selected_index = index
|
|
1027
|
+
if old != index:
|
|
1028
|
+
self._row_widgets[old].set_selected(False)
|
|
1029
|
+
self._row_widgets[index].set_selected(True)
|
|
1030
|
+
self._update_detail_panel()
|
|
1031
|
+
|
|
1032
|
+
def _move_selection(self, delta: int) -> None:
|
|
1033
|
+
if not self._row_widgets:
|
|
1034
|
+
return
|
|
1035
|
+
target = self._selected_index + delta
|
|
1036
|
+
if 0 <= target < len(self._row_widgets):
|
|
1037
|
+
self._move_to(target)
|
|
1038
|
+
|
|
1039
|
+
def _next_server_header(self, start: int, step: int) -> int | None:
|
|
1040
|
+
index = start + step
|
|
1041
|
+
while 0 <= index < len(self._row_widgets):
|
|
1042
|
+
if isinstance(self._row_widgets[index], MCPServerHeaderItem):
|
|
1043
|
+
return index
|
|
1044
|
+
index += step
|
|
1045
|
+
return None
|
|
1046
|
+
|
|
1047
|
+
def _reveal_selection(self, widget: MCPToolItem | MCPServerHeaderItem, *, direction: int) -> None:
|
|
1048
|
+
widget.scroll_visible()
|
|
1049
|
+
|
|
1050
|
+
def action_move_up(self) -> None:
|
|
1051
|
+
if not self._row_widgets:
|
|
1052
|
+
return
|
|
1053
|
+
old = self._selected_index
|
|
1054
|
+
if old == 0:
|
|
1055
|
+
self._move_to(len(self._row_widgets) - 1)
|
|
1056
|
+
else:
|
|
1057
|
+
self._move_selection(-1)
|
|
1058
|
+
if self._selected_index != old:
|
|
1059
|
+
self._reveal_selection(self._row_widgets[self._selected_index], direction=-1)
|
|
1060
|
+
|
|
1061
|
+
def action_move_down(self) -> None:
|
|
1062
|
+
if not self._row_widgets:
|
|
1063
|
+
return
|
|
1064
|
+
old = self._selected_index
|
|
1065
|
+
if old == len(self._row_widgets) - 1:
|
|
1066
|
+
self._move_to(0)
|
|
1067
|
+
else:
|
|
1068
|
+
self._move_selection(1)
|
|
1069
|
+
if self._selected_index != old:
|
|
1070
|
+
self._reveal_selection(self._row_widgets[self._selected_index], direction=1)
|
|
1071
|
+
|
|
1072
|
+
def action_jump_up(self) -> None:
|
|
1073
|
+
target = self._next_server_header(self._selected_index, -1)
|
|
1074
|
+
if target is None:
|
|
1075
|
+
target = self._next_server_header(len(self._row_widgets), -1)
|
|
1076
|
+
if target is None or target == self._selected_index:
|
|
1077
|
+
return
|
|
1078
|
+
self._move_to(target)
|
|
1079
|
+
self._reveal_selection(self._row_widgets[target], direction=-1)
|
|
1080
|
+
|
|
1081
|
+
def action_jump_down(self) -> None:
|
|
1082
|
+
target = self._next_server_header(self._selected_index, +1)
|
|
1083
|
+
if target is None:
|
|
1084
|
+
target = self._next_server_header(-1, +1)
|
|
1085
|
+
if target is None or target == self._selected_index:
|
|
1086
|
+
return
|
|
1087
|
+
self._move_to(target)
|
|
1088
|
+
self._reveal_selection(self._row_widgets[target], direction=1)
|
|
1089
|
+
|
|
1090
|
+
def action_page_up(self) -> None:
|
|
1091
|
+
if not self._row_widgets:
|
|
1092
|
+
return
|
|
1093
|
+
scroll = self.query_one(".mcp-list", VerticalScroll)
|
|
1094
|
+
scroll.scroll_page_up()
|
|
1095
|
+
|
|
1096
|
+
def action_page_down(self) -> None:
|
|
1097
|
+
if not self._row_widgets:
|
|
1098
|
+
return
|
|
1099
|
+
scroll = self.query_one(".mcp-list", VerticalScroll)
|
|
1100
|
+
scroll.scroll_page_down()
|
|
1101
|
+
|
|
1102
|
+
# ── Tool / Server Selection & Expand ─────────────────
|
|
1103
|
+
|
|
1104
|
+
def action_select_item(self) -> None:
|
|
1105
|
+
"""Handle Enter key on the currently selected item."""
|
|
1106
|
+
if not self._row_widgets:
|
|
1107
|
+
return
|
|
1108
|
+
row = self._row_widgets[self._selected_index]
|
|
1109
|
+
if isinstance(row, MCPToolItem):
|
|
1110
|
+
self.app.push_screen(
|
|
1111
|
+
MCPToolDetailScreen(
|
|
1112
|
+
tool_info=row.tool_info,
|
|
1113
|
+
server_name=row.server_name,
|
|
1114
|
+
)
|
|
1115
|
+
)
|
|
1116
|
+
return
|
|
1117
|
+
|
|
1118
|
+
server = row.server
|
|
1119
|
+
if server.status == "unauthenticated":
|
|
1120
|
+
self.dismiss(server.name)
|
|
1121
|
+
return
|
|
1122
|
+
if server.status == "error":
|
|
1123
|
+
self.show_server_error(server)
|
|
1124
|
+
return
|
|
1125
|
+
|
|
1126
|
+
def action_toggle_expand(self) -> None:
|
|
1127
|
+
"""Alias for action_select_item for backward compatibility."""
|
|
1128
|
+
self.action_select_item()
|
|
1129
|
+
|
|
1130
|
+
def action_toggle_all(self) -> None:
|
|
1131
|
+
tools = self._tool_widgets
|
|
1132
|
+
if not tools:
|
|
1133
|
+
return
|
|
1134
|
+
any_collapsed = any(not w._expanded for w in tools)
|
|
1135
|
+
for widget in tools:
|
|
1136
|
+
widget.set_expanded(any_collapsed)
|
|
1137
|
+
|
|
1138
|
+
def show_server_error(self, server: MCPServerInfo) -> None:
|
|
1139
|
+
self.app.push_screen(MCPServerErrorScreen(server))
|
|
1140
|
+
|
|
1141
|
+
# ── Reconnect / Disable ──────────────────────────────
|
|
1142
|
+
|
|
1143
|
+
def action_reconnect(self) -> None:
|
|
1144
|
+
if not self._pending_reconnect:
|
|
1145
|
+
return
|
|
1146
|
+
self.dismiss(MCP_VIEWER_RECONNECT_REQUEST)
|
|
1147
|
+
|
|
1148
|
+
def action_toggle_disable(self) -> None:
|
|
1149
|
+
if not self._row_widgets:
|
|
1150
|
+
return
|
|
1151
|
+
row = self._row_widgets[self._selected_index]
|
|
1152
|
+
server_name: str | None = None
|
|
1153
|
+
if isinstance(row, MCPServerHeaderItem):
|
|
1154
|
+
server_name = row.server.name
|
|
1155
|
+
elif isinstance(row, MCPToolItem) and row.server_name:
|
|
1156
|
+
server_name = row.server_name
|
|
1157
|
+
|
|
1158
|
+
if not server_name or self._on_toggle_disable is None:
|
|
1159
|
+
return
|
|
1160
|
+
self.app.call_later(self._on_toggle_disable, server_name)
|
|
1161
|
+
|
|
1162
|
+
def action_cancel(self) -> None:
|
|
1163
|
+
self.dismiss(None)
|
|
1164
|
+
|
|
1165
|
+
# ── Refresh API ──────────────────────────────────────
|
|
1166
|
+
|
|
1167
|
+
async def refresh_server_info(
|
|
1168
|
+
self,
|
|
1169
|
+
server_info: list[MCPServerInfo],
|
|
1170
|
+
*,
|
|
1171
|
+
pending_reconnect: bool | None = None,
|
|
1172
|
+
select_server: str | None = None,
|
|
1173
|
+
) -> None:
|
|
1174
|
+
"""Replace the displayed server list."""
|
|
1175
|
+
self._server_info = server_info
|
|
1176
|
+
self._connecting = False
|
|
1177
|
+
self._query = ""
|
|
1178
|
+
if pending_reconnect is not None:
|
|
1179
|
+
self._pending_reconnect = pending_reconnect
|
|
1180
|
+
body = self.query_one(Vertical)
|
|
1181
|
+
await body.remove_children()
|
|
1182
|
+
self._row_widgets = []
|
|
1183
|
+
self._selected_index = 0
|
|
1184
|
+
self._mount_body(body)
|
|
1185
|
+
if select_server is not None:
|
|
1186
|
+
for idx, widget in enumerate(self._row_widgets):
|
|
1187
|
+
if (
|
|
1188
|
+
isinstance(widget, MCPServerHeaderItem)
|
|
1189
|
+
and widget.server.name == select_server
|
|
1190
|
+
):
|
|
1191
|
+
self._move_to(idx)
|
|
1192
|
+
break
|
|
1193
|
+
|
|
1194
|
+
|
|
1195
|
+
__all__ = [
|
|
1196
|
+
"MCPServerErrorScreen",
|
|
1197
|
+
"MCPServerHeaderItem",
|
|
1198
|
+
"MCPToolDetailScreen",
|
|
1199
|
+
"MCPToolItem",
|
|
1200
|
+
"MCPViewerScreen",
|
|
1201
|
+
"MCP_VIEWER_RECONNECT_REQUEST",
|
|
1202
|
+
"clean_server_name",
|
|
1203
|
+
"clean_tool_name",
|
|
1204
|
+
]
|