codegraphcontext 0.1.1__tar.gz → 0.1.3__tar.gz

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.
Files changed (27) hide show
  1. {codegraphcontext-0.1.1/src/codegraphcontext.egg-info → codegraphcontext-0.1.3}/PKG-INFO +1 -1
  2. {codegraphcontext-0.1.1 → codegraphcontext-0.1.3}/pyproject.toml +1 -1
  3. {codegraphcontext-0.1.1 → codegraphcontext-0.1.3}/src/codegraphcontext/cli/main.py +1 -6
  4. {codegraphcontext-0.1.1 → codegraphcontext-0.1.3}/src/codegraphcontext/cli/setup_wizard.py +100 -61
  5. {codegraphcontext-0.1.1 → codegraphcontext-0.1.3/src/codegraphcontext.egg-info}/PKG-INFO +1 -1
  6. {codegraphcontext-0.1.1 → codegraphcontext-0.1.3}/LICENSE +0 -0
  7. {codegraphcontext-0.1.1 → codegraphcontext-0.1.3}/README.md +0 -0
  8. {codegraphcontext-0.1.1 → codegraphcontext-0.1.3}/setup.cfg +0 -0
  9. {codegraphcontext-0.1.1 → codegraphcontext-0.1.3}/src/codegraphcontext/__init__.py +0 -0
  10. {codegraphcontext-0.1.1 → codegraphcontext-0.1.3}/src/codegraphcontext/__main__.py +0 -0
  11. {codegraphcontext-0.1.1 → codegraphcontext-0.1.3}/src/codegraphcontext/cli/__init__.py +0 -0
  12. {codegraphcontext-0.1.1 → codegraphcontext-0.1.3}/src/codegraphcontext/core/__init__.py +0 -0
  13. {codegraphcontext-0.1.1 → codegraphcontext-0.1.3}/src/codegraphcontext/core/database.py +0 -0
  14. {codegraphcontext-0.1.1 → codegraphcontext-0.1.3}/src/codegraphcontext/core/jobs.py +0 -0
  15. {codegraphcontext-0.1.1 → codegraphcontext-0.1.3}/src/codegraphcontext/core/watcher.py +0 -0
  16. {codegraphcontext-0.1.1 → codegraphcontext-0.1.3}/src/codegraphcontext/prompts.py +0 -0
  17. {codegraphcontext-0.1.1 → codegraphcontext-0.1.3}/src/codegraphcontext/server.py +0 -0
  18. {codegraphcontext-0.1.1 → codegraphcontext-0.1.3}/src/codegraphcontext/tools/__init__.py +0 -0
  19. {codegraphcontext-0.1.1 → codegraphcontext-0.1.3}/src/codegraphcontext/tools/code_finder.py +0 -0
  20. {codegraphcontext-0.1.1 → codegraphcontext-0.1.3}/src/codegraphcontext/tools/graph_builder.py +0 -0
  21. {codegraphcontext-0.1.1 → codegraphcontext-0.1.3}/src/codegraphcontext/tools/import_extractor.py +0 -0
  22. {codegraphcontext-0.1.1 → codegraphcontext-0.1.3}/src/codegraphcontext/tools/system.py +0 -0
  23. {codegraphcontext-0.1.1 → codegraphcontext-0.1.3}/src/codegraphcontext.egg-info/SOURCES.txt +0 -0
  24. {codegraphcontext-0.1.1 → codegraphcontext-0.1.3}/src/codegraphcontext.egg-info/dependency_links.txt +0 -0
  25. {codegraphcontext-0.1.1 → codegraphcontext-0.1.3}/src/codegraphcontext.egg-info/entry_points.txt +0 -0
  26. {codegraphcontext-0.1.1 → codegraphcontext-0.1.3}/src/codegraphcontext.egg-info/requires.txt +0 -0
  27. {codegraphcontext-0.1.1 → codegraphcontext-0.1.3}/src/codegraphcontext.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codegraphcontext
3
- Version: 0.1.1
3
+ Version: 0.1.3
4
4
  Summary: An MCP server that indexes local code into a graph database to provide context to AI assistants.
5
5
  Author-email: Shashank Shekhar Singh <shashankshekharsingh1205@gmail.com>
6
6
  License: MIT License
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "codegraphcontext"
3
- version = "0.1.1"
3
+ version = "0.1.3"
4
4
  description = "An MCP server that indexes local code into a graph database to provide context to AI assistants."
5
5
  authors = [{ name = "Shashank Shekhar Singh", email = "shashankshekharsingh1205@gmail.com" }]
6
6
  readme = "README.md"
@@ -3,17 +3,12 @@ import typer
3
3
  from rich.console import Console
4
4
  import asyncio
5
5
  import logging
6
- from dotenv import load_dotenv
7
-
8
- from .setup_wizard import run_setup_wizard
9
6
  from codegraphcontext.server import MCPServer
7
+ from .setup_wizard import run_setup_wizard
10
8
 
11
9
  # Set the log level for the noisy neo4j logger to WARNING
12
10
  logging.getLogger("neo4j").setLevel(logging.WARNING) # <-- ADD THIS LINE
13
11
 
14
- # Load environment variables from .env file at the very beginning
15
- load_dotenv()
16
-
17
12
  app = typer.Typer(
18
13
  name="cgc",
19
14
  help="CodeGraphContext: An MCP server for AI-powered code analysis.",
@@ -5,12 +5,63 @@ import platform
5
5
  import os
6
6
  from pathlib import Path
7
7
  import time
8
+ import json
9
+ import sys
10
+ import shutil
8
11
 
9
12
  console = Console()
10
13
 
14
+ def _generate_mcp_json(creds):
15
+ """Generates and prints the MCP JSON configuration."""
16
+ cgc_path = shutil.which("cgc") or sys.executable
17
+
18
+ if "python" in Path(cgc_path).name:
19
+ # fallback to running as module if no cgc binary is found
20
+ command = cgc_path
21
+ args = ["-m", "cgc", "start"]
22
+ else:
23
+ command = cgc_path
24
+ args = ["start"]
25
+
26
+ mcp_config = {
27
+ "mcpServers": {
28
+ "CodeGraphContext": {
29
+ "command": command,
30
+ "args": args,
31
+ "env": {
32
+ "NEO4J_URI": creds.get("uri", ""),
33
+ "NEO4J_USER": creds.get("username", "neo4j"),
34
+ "NEO4J_PASSWORD": creds.get("password", "")
35
+ },
36
+ "tools": {
37
+ "alwaysAllow": [
38
+ "list_imports", "add_code_to_graph", "add_package_to_graph",
39
+ "check_job_status", "list_jobs", "find_code",
40
+ "analyze_code_relationships", "watch_directory",
41
+ "find_dead_code", "execute_cypher_query"
42
+ ],
43
+ "disabled": False
44
+ },
45
+ "disabled": False,
46
+ "alwaysAllow": []
47
+ }
48
+ }
49
+ }
50
+
51
+ console.print("\n[bold green]Configuration successful![/bold green]")
52
+ console.print("Copy the following JSON and add it to your MCP server configuration file:")
53
+ console.print(json.dumps(mcp_config, indent=2))
54
+
55
+ # Also save to a file for convenience
56
+ mcp_file = Path.cwd() / "mcp.json"
57
+ with open(mcp_file, "w") as f:
58
+ json.dump(mcp_config, f, indent=2)
59
+ console.print(f"\n[cyan]For your convenience, the configuration has also been saved to: {mcp_file}[/cyan]")
60
+
61
+
11
62
  def get_project_root() -> Path:
12
- """Returns the project root directory."""
13
- return Path(__file__).resolve().parent.parent.parent.parent
63
+ """Always return the directory where the user runs `cgc` (CWD)."""
64
+ return Path.cwd()
14
65
 
15
66
  def run_command(command, console, shell=False, check=True, input_text=None):
16
67
  """
@@ -78,31 +129,7 @@ def find_latest_neo4j_creds_file():
78
129
  latest_file = max(cred_files, key=lambda f: f.stat().st_mtime)
79
130
  return latest_file
80
131
 
81
- def parse_creds_file(file_path: Path):
82
- """Parses a credentials file and writes to .env."""
83
- try:
84
- creds = {}
85
- with open(file_path, "r") as f:
86
- for line in f:
87
- if "=" in line:
88
- key, value = line.strip().split("=", 1)
89
- if key in ["NEO4J_URI", "NEO4J_USERNAME", "NEO4J_PASSWORD"]:
90
- creds[key] = value
91
-
92
- if all(k in creds for k in ["NEO4J_URI", "NEO4J_USERNAME", "NEO4J_PASSWORD"]):
93
- env_path = get_project_root() / ".env"
94
- with open(env_path, "w") as f:
95
- f.write(f"NEO4J_URI={creds['NEO4J_URI']}\n")
96
- f.write(f"NEO4J_USERNAME={creds['NEO4J_USERNAME']}\n")
97
- f.write(f"NEO4J_PASSWORD={creds['NEO4J_PASSWORD']}\n")
98
- console.print(f"[green]✅ Configuration from {file_path.name} saved to .env file in project root.[/green]")
99
- return True
100
- else:
101
- console.print("[red]❌ The credentials file is missing one or more required keys (NEO4J_URI, NEO4J_USERNAME, NEO4J_PASSWORD).[/red]")
102
- return False
103
- except Exception as e:
104
- console.print(f"[red]❌ Failed to parse credentials file: {e}[/red]")
105
- return False
132
+
106
133
 
107
134
  def setup_hosted_db():
108
135
  """Guides user to configure a remote Neo4j instance."""
@@ -117,8 +144,10 @@ def setup_hosted_db():
117
144
  result = prompt(questions)
118
145
  cred_method = result.get("cred_method")
119
146
 
147
+ creds = {}
120
148
  if cred_method and "file" in cred_method:
121
149
  latest_file = find_latest_neo4j_creds_file()
150
+ file_to_parse = None
122
151
  if latest_file:
123
152
  confirm_questions = [
124
153
  {
@@ -129,38 +158,51 @@ def setup_hosted_db():
129
158
  }
130
159
  ]
131
160
  if prompt(confirm_questions).get("use_latest"):
132
- if parse_creds_file(latest_file):
133
- return
161
+ file_to_parse = latest_file
134
162
 
135
- # If no file was found, or the user chose not to use the found file
136
- path_questions = [
137
- {"type": "input", "message": "Please enter the path to your credentials file:", "name": "cred_file_path"}
138
- ]
139
- file_path_str = prompt(path_questions).get("cred_file_path", "")
140
- file_path = Path(file_path_str.strip())
141
- if file_path.exists() and file_path.is_file():
142
- parse_creds_file(file_path)
143
- else:
144
- console.print("[red]❌ The specified file path does not exist or is not a file.[/red]")
163
+ if not file_to_parse:
164
+ path_questions = [
165
+ {"type": "input", "message": "Please enter the path to your credentials file:", "name": "cred_file_path"}
166
+ ]
167
+ file_path_str = prompt(path_questions).get("cred_file_path", "")
168
+ file_path = Path(file_path_str.strip())
169
+ if file_path.exists() and file_path.is_file():
170
+ file_to_parse = file_path
171
+ else:
172
+ console.print("[red]❌ The specified file path does not exist or is not a file.[/red]")
173
+ return
174
+
175
+ if file_to_parse:
176
+ try:
177
+ with open(file_to_parse, "r") as f:
178
+ for line in f:
179
+ if "=" in line:
180
+ key, value = line.strip().split("=", 1)
181
+ if key == "NEO4J_URI":
182
+ creds["uri"] = value
183
+ elif key == "NEO4J_USERNAME":
184
+ creds["username"] = value
185
+ elif key == "NEO4J_PASSWORD":
186
+ creds["password"] = value
187
+ except Exception as e:
188
+ console.print(f"[red]❌ Failed to parse credentials file: {e}[/red]")
189
+ return
145
190
 
146
- elif cred_method: # Manual entry
191
+ elif cred_method: # Manual entry
147
192
  console.print("Please enter your remote Neo4j connection details.")
148
193
  questions = [
149
194
  {"type": "input", "message": "URI (e.g., neo4j+s://xxxx.databases.neo4j.io):", "name": "uri"},
150
195
  {"type": "input", "message": "Username:", "name": "username", "default": "neo4j"},
151
196
  {"type": "password", "message": "Password:", "name": "password"},
152
197
  ]
153
- creds = prompt(questions)
154
- if not creds: return # User cancelled
155
- try:
156
- env_path = get_project_root() / ".env"
157
- with open(env_path, "w") as f:
158
- f.write(f"NEO4J_URI={creds.get('uri', '')}\n")
159
- f.write(f"NEO4J_USERNAME={creds.get('username', 'neo4j')}\n")
160
- f.write(f"NEO4J_PASSWORD={creds.get('password', '')}\n")
161
- console.print("[green]✅ Configuration for hosted database saved to .env file in project root.[/green]")
162
- except Exception as e:
163
- console.print(f"[red]❌ Failed to write .env file: {e}[/red]")
198
+ manual_creds = prompt(questions)
199
+ if not manual_creds: return # User cancelled
200
+ creds = manual_creds
201
+
202
+ if creds.get("uri") and creds.get("password"):
203
+ _generate_mcp_json(creds)
204
+ else:
205
+ console.print("[red]❌ Incomplete credentials. Please try again.[/red]")
164
206
 
165
207
  def setup_local_db():
166
208
  """Guides user to set up a local Neo4j instance."""
@@ -271,13 +313,10 @@ def setup_local_binary():
271
313
  console.print("\n[yellow]Waiting 10 seconds for the database to become available...""")
272
314
  time.sleep(10)
273
315
 
274
- try:
275
- env_path = get_project_root() / ".env"
276
- with open(env_path, "w") as f:
277
- f.write(f"NEO4J_URI=neo4j://localhost:7687\n")
278
- f.write(f"NEO4J_USERNAME=neo4j\n")
279
- f.write(f"NEO4J_PASSWORD={new_password}\n")
280
- console.print("[green] Configuration for local database saved to .env file in project root.[/green]")
281
- console.print("\n[bold green]All done! Your local Neo4j instance is ready to use.[/bold green]")
282
- except Exception as e:
283
- console.print(f"[bold red]Failed to write .env file:[/bold red] {e}")
316
+ creds = {
317
+ "uri": "neo4j://localhost:7687",
318
+ "username": "neo4j",
319
+ "password": new_password
320
+ }
321
+ _generate_mcp_json(creds)
322
+ console.print("\n[bold green]All done! Your local Neo4j instance is ready to use.[/bold green]")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codegraphcontext
3
- Version: 0.1.1
3
+ Version: 0.1.3
4
4
  Summary: An MCP server that indexes local code into a graph database to provide context to AI assistants.
5
5
  Author-email: Shashank Shekhar Singh <shashankshekharsingh1205@gmail.com>
6
6
  License: MIT License