Jeremiah Lowin commited on
Commit
4ef7799
·
1 Parent(s): cf4a899

Ensure fastmcp version copy is plaintext

Browse files
Files changed (3) hide show
  1. src/fastmcp/cli/cli.py +4 -5
  2. tests/cli/test_cli.py +13 -9
  3. uv.lock +0 -0
src/fastmcp/cli/cli.py CHANGED
@@ -113,16 +113,15 @@ def version(
113
  g.add_row(k + ":", str(v).replace("\n", " "))
114
 
115
  if copy:
116
- # Use Rich's capture to get text representation
117
- with console.capture() as capture:
118
- console.print(g)
 
119
  pyperclip.copy(capture.get())
120
  console.print("[green]✓[/green] Version information copied to clipboard")
121
  else:
122
  console.print(g)
123
 
124
- sys.exit(0)
125
-
126
 
127
  @app.command
128
  def dev(
 
113
  g.add_row(k + ":", str(v).replace("\n", " "))
114
 
115
  if copy:
116
+ # Use Rich's plain text rendering for copying
117
+ plain_console = Console(file=None, force_terminal=False, legacy_windows=False)
118
+ with plain_console.capture() as capture:
119
+ plain_console.print(g)
120
  pyperclip.copy(capture.get())
121
  console.print("[green]✓[/green] Version information copied to clipboard")
122
  else:
123
  console.print(g)
124
 
 
 
125
 
126
  @app.command
127
  def dev(
tests/cli/test_cli.py CHANGED
@@ -123,18 +123,22 @@ class TestVersionCommand:
123
  self, mock_console, mock_pyperclip_copy, mock_exit
124
  ):
125
  """Test that the version command copies to clipboard when --copy is used."""
126
- # Mock console.capture
127
- mock_capture = Mock()
128
- mock_capture.get.return_value = "FastMCP version: 1.0.0\nMCP version: 1.10.0"
129
- mock_console.capture.return_value.__enter__.return_value = mock_capture
130
- mock_console.capture.return_value.__exit__.return_value = None
131
-
132
  command, bound, _ = app.parse_args(["version", "--copy"])
133
  command(**bound.arguments)
134
 
135
- mock_pyperclip_copy.assert_called_once_with(
136
- "FastMCP version: 1.0.0\nMCP version: 1.10.0"
137
- )
 
 
 
 
 
 
 
 
 
 
138
  mock_console.print.assert_called_with(
139
  "[green]✓[/green] Version information copied to clipboard"
140
  )
 
123
  self, mock_console, mock_pyperclip_copy, mock_exit
124
  ):
125
  """Test that the version command copies to clipboard when --copy is used."""
 
 
 
 
 
 
126
  command, bound, _ = app.parse_args(["version", "--copy"])
127
  command(**bound.arguments)
128
 
129
+ # Verify pyperclip.copy was called with plain text format
130
+ mock_pyperclip_copy.assert_called_once()
131
+ copied_text = mock_pyperclip_copy.call_args[0][0]
132
+
133
+ # Verify the copied text contains expected version info keys in plain text
134
+ assert "FastMCP version:" in copied_text
135
+ assert "MCP version:" in copied_text
136
+ assert "Python version:" in copied_text
137
+ assert "Platform:" in copied_text
138
+ assert "FastMCP root path:" in copied_text
139
+
140
+ # Verify no ANSI escape codes (terminal control characters)
141
+ assert "\x1b[" not in copied_text
142
  mock_console.print.assert_called_with(
143
  "[green]✓[/green] Version information copied to clipboard"
144
  )
uv.lock CHANGED
The diff for this file is too large to render. See raw diff