Jeremiah Lowin commited on
Commit
a9a50be
·
unverified ·
2 Parent(s): b5d856c6537199

Merge pull request #253 from jlowin/cli-args

Browse files

Allow customization of inspector proxy port, ui port, and version

Files changed (1) hide show
  1. src/fastmcp/cli/cli.py +36 -3
src/fastmcp/cli/cli.py CHANGED
@@ -223,6 +223,27 @@ def dev(
223
  help="Additional packages to install",
224
  ),
225
  ] = [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
  ) -> None:
227
  """Run a MCP server with the MCP Inspector."""
228
  file, server_object = _parse_file_path(file_spec)
@@ -234,6 +255,8 @@ def dev(
234
  "server_object": server_object,
235
  "with_editable": str(with_editable) if with_editable else None,
236
  "with_packages": with_packages,
 
 
237
  },
238
  )
239
 
@@ -243,7 +266,11 @@ def dev(
243
  if hasattr(server, "dependencies"):
244
  with_packages = list(set(with_packages + server.dependencies))
245
 
246
- uv_cmd = _build_uv_command(file_spec, with_editable, with_packages)
 
 
 
 
247
 
248
  # Get the correct npx command
249
  npx_cmd = _get_npx_command()
@@ -254,13 +281,19 @@ def dev(
254
  )
255
  sys.exit(1)
256
 
 
 
 
 
 
 
257
  # Run the MCP Inspector command with shell=True on Windows
258
  shell = sys.platform == "win32"
259
  process = subprocess.run(
260
- [npx_cmd, "@modelcontextprotocol/inspector"] + uv_cmd,
261
  check=True,
262
  shell=shell,
263
- env=dict(os.environ.items()), # Convert to list of tuples for env update
264
  )
265
  sys.exit(process.returncode)
266
  except subprocess.CalledProcessError as e:
 
223
  help="Additional packages to install",
224
  ),
225
  ] = [],
226
+ inspector_version: Annotated[
227
+ str | None,
228
+ typer.Option(
229
+ "--inspector-version",
230
+ help="Version of the MCP Inspector to use",
231
+ ),
232
+ ] = None,
233
+ ui_port: Annotated[
234
+ int | None,
235
+ typer.Option(
236
+ "--ui-port",
237
+ help="Port for the MCP Inspector UI",
238
+ ),
239
+ ] = None,
240
+ server_port: Annotated[
241
+ int | None,
242
+ typer.Option(
243
+ "--server-port",
244
+ help="Port for the MCP Inspector Proxy server",
245
+ ),
246
+ ] = None,
247
  ) -> None:
248
  """Run a MCP server with the MCP Inspector."""
249
  file, server_object = _parse_file_path(file_spec)
 
255
  "server_object": server_object,
256
  "with_editable": str(with_editable) if with_editable else None,
257
  "with_packages": with_packages,
258
+ "ui_port": ui_port,
259
+ "server_port": server_port,
260
  },
261
  )
262
 
 
266
  if hasattr(server, "dependencies"):
267
  with_packages = list(set(with_packages + server.dependencies))
268
 
269
+ env_vars = {}
270
+ if ui_port:
271
+ env_vars["CLIENT_PORT"] = str(ui_port)
272
+ if server_port:
273
+ env_vars["SERVER_PORT"] = str(server_port)
274
 
275
  # Get the correct npx command
276
  npx_cmd = _get_npx_command()
 
281
  )
282
  sys.exit(1)
283
 
284
+ inspector_cmd = "@modelcontextprotocol/inspector"
285
+ if inspector_version:
286
+ inspector_cmd += f"@{inspector_version}"
287
+
288
+ uv_cmd = _build_uv_command(file_spec, with_editable, with_packages)
289
+
290
  # Run the MCP Inspector command with shell=True on Windows
291
  shell = sys.platform == "win32"
292
  process = subprocess.run(
293
+ [npx_cmd, inspector_cmd] + uv_cmd,
294
  check=True,
295
  shell=shell,
296
+ env=dict(os.environ.items()) | env_vars,
297
  )
298
  sys.exit(process.returncode)
299
  except subprocess.CalledProcessError as e: