Skip to content

Commit 66cf050

Browse files
committed
feat: add -v/--version CLI flag with dynamic version from pyproject.toml
- Add argparse support to main server entry point - Create get_version() function to read version from pyproject.toml - Support both tomllib (Python 3.11+) and tomli (Python 3.10) - Add tomli as conditional dependency for Python < 3.11 - Bump version to 1.2.1
1 parent 1accf99 commit 66cf050

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "cortexgraph"
3-
version = "1.2.0"
3+
version = "1.2.1"
44
description = "CortexGraph: Temporal memory management for AI assistants with human-like dynamics"
55
readme = "README.md"
66
requires-python = ">=3.10"
@@ -27,6 +27,7 @@ dependencies = [
2727
"fastapi>=0.100.0",
2828
"uvicorn>=0.20.0",
2929
"slowapi>=0.1.9",
30+
"tomli>=2.0.0; python_version < '3.11'",
3031
]
3132

3233
[project.optional-dependencies]

src/cortexgraph/server.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""MCP Server entry point for CortexGraph."""
22

3+
import argparse
34
import logging
45
import sys
56
from pathlib import Path
@@ -55,6 +56,30 @@
5556
logger = logging.getLogger(__name__)
5657

5758

59+
def get_version() -> str:
60+
"""Get version from pyproject.toml."""
61+
try:
62+
# Try Python 3.11+ built-in tomllib
63+
try:
64+
import tomllib
65+
except ImportError:
66+
# Fall back to toml package for older Python
67+
import tomli as tomllib # type: ignore
68+
69+
# Find pyproject.toml relative to this file
70+
project_root = Path(__file__).parent.parent.parent
71+
pyproject_path = project_root / "pyproject.toml"
72+
73+
if pyproject_path.exists():
74+
with open(pyproject_path, "rb") as f:
75+
pyproject_data = tomllib.load(f)
76+
return pyproject_data.get("project", {}).get("version", "unknown")
77+
except Exception as e:
78+
logger.debug(f"Could not read version from pyproject.toml: {e}")
79+
80+
return "unknown"
81+
82+
5883
def initialize_server() -> None:
5984
"""Initialize logging and database connections."""
6085
config = get_config()
@@ -145,6 +170,18 @@ def initialize_server() -> None:
145170

146171
def main_sync() -> None:
147172
"""Synchronous entry point for the server."""
173+
parser = argparse.ArgumentParser(
174+
description="CortexGraph: Temporal memory management for AI assistants"
175+
)
176+
parser.add_argument(
177+
"-v",
178+
"--version",
179+
action="version",
180+
version=f"cortexgraph {get_version()}",
181+
)
182+
183+
parser.parse_args()
184+
148185
try:
149186
initialize_server()
150187
mcp.run()

0 commit comments

Comments
 (0)