fix fastmcp version ,python path valueError

run fastmcp version  , when codes in other volume
```
ValueError: '/Volumes/Codes/../.venv/lib/python3.13' is not in the subpath of '/Users/<user home>'
```
This commit is contained in:
Krasus.Chen 2025-04-21 13:25:54 +08:00 committed by GitHub
commit 296f1c312e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -180,13 +180,17 @@ def _import_server(file: Path, server_object: str | None = None):
def version(ctx: Context):
if ctx.resilient_parsing:
return
try:
fastmcp_path = f"~/{Path(__file__).resolve().parents[3].relative_to(Path.home())}"
except ValueError:
fastmcp_path = str(Path(__file__).resolve().parents[3])
info = {
"FastMCP version": fastmcp.__version__,
"MCP version": importlib.metadata.version("mcp"),
"Python version": platform.python_version(),
"Platform": platform.platform(),
"FastMCP root path": f"~/{Path(__file__).resolve().parents[3].relative_to(Path.home())}",
"FastMCP root path": fastmcp_path,
}
g = Table.grid(padding=(0, 1))