2121from pathlib import Path
2222
2323from .repo_context_models import Application , EntryPoint , UserAction , WebEntryPoint , ApplicationIssue , AuditResult , Base
24+ from .utils import process_repo
2425
2526MEMORY = Path (os .getenv ('REPO_CONTEXT_DIR' , default = '/app/my_data' ))
2627
@@ -90,9 +91,9 @@ def __init__(self, memcache_state_dir: str):
9091 else :
9192 db_dir = f'sqlite:///{ self .memcache_state_dir } /repo_context.db'
9293 self .engine = create_engine (db_dir , echo = False )
93- Base .metadata .create_all (self .engine , tables = [Application .__table__ , EntryPoint .__table__ , UserAction .__table__ ,
94+ Base .metadata .create_all (self .engine , tables = [Application .__table__ , EntryPoint .__table__ , UserAction .__table__ ,
9495 WebEntryPoint .__table__ , ApplicationIssue .__table__ , AuditResult .__table__ ])
95-
96+
9697 def store_new_application (self , repo , location , is_app , is_library , notes ):
9798 with Session (self .engine ) as session :
9899 existing = session .query (Application ).filter_by (repo = repo , location = location ).first ()
@@ -107,7 +108,7 @@ def store_new_application(self, repo, location, is_app, is_library, notes):
107108 session .add (new_application )
108109 session .commit ()
109110 return f"Updated or added application for { location } in { repo } ."
110-
111+
111112 def store_new_component_issue (self , repo , component_id , issue_type , notes ):
112113 with Session (self .engine ) as session :
113114 existing = session .query (ApplicationIssue ).filter_by (repo = repo , component_id = component_id , issue_type = issue_type ).first ()
@@ -155,7 +156,7 @@ def store_new_entry_point(self, repo, app_id, file, user_input, line, notes, upd
155156 session .add (new_entry_point )
156157 session .commit ()
157158 return f"Updated or added entry point for { file } and { line } in { repo } ."
158-
159+
159160 def store_new_web_entry_point (self , repo , entry_point_id , method , path , component , auth , middleware , roles_scopes , notes , update = False ):
160161 with Session (self .engine ) as session :
161162 existing = session .query (WebEntryPoint ).filter_by (repo = repo , entry_point_id = entry_point_id ).first ()
@@ -177,7 +178,7 @@ def store_new_web_entry_point(self, repo, entry_point_id, method, path, componen
177178 if update :
178179 return f"No web entry point exists at repo { repo } with entry_point_id { entry_point_id } ."
179180 new_web_entry_point = WebEntryPoint (
180- repo = repo ,
181+ repo = repo ,
181182 entry_point_id = entry_point_id ,
182183 method = method ,
183184 path = path ,
@@ -190,7 +191,7 @@ def store_new_web_entry_point(self, repo, entry_point_id, method, path, componen
190191 session .add (new_web_entry_point )
191192 session .commit ()
192193 return f"Updated or added web entry point for entry_point_id { entry_point_id } in { repo } ."
193-
194+
194195 def store_new_user_action (self , repo , app_id , file , line , notes , update = False ):
195196 with Session (self .engine ) as session :
196197 existing = session .query (UserAction ).filter_by (repo = repo , file = file , line = line ).first ()
@@ -203,7 +204,7 @@ def store_new_user_action(self, repo, app_id, file, line, notes, update = False)
203204 session .add (new_user_action )
204205 session .commit ()
205206 return f"Updated or added user action for { file } and { line } in { repo } ."
206-
207+
207208 def get_app (self , repo , location ):
208209 with Session (self .engine ) as session :
209210 existing = session .query (Application ).filter_by (repo = repo , location = location ).first ()
@@ -271,7 +272,7 @@ def get_web_entries_for_repo(self, repo):
271272 with Session (self .engine ) as session :
272273 results = session .query (WebEntryPoint ).filter_by (repo = repo ).all ()
273274 return [{
274- 'repo' : r .repo ,
275+ 'repo' : r .repo ,
275276 'entry_point_id' : r .entry_point_id ,
276277 'method' : r .method ,
277278 'path' : r .path ,
@@ -286,7 +287,7 @@ def get_web_entries(self, repo, component_id):
286287 with Session (self .engine ) as session :
287288 results = session .query (WebEntryPoint ).filter_by (repo = repo , component = component_id ).all ()
288289 return [{
289- 'repo' : r .repo ,
290+ 'repo' : r .repo ,
290291 'entry_point_id' : r .entry_point_id ,
291292 'method' : r .method ,
292293 'path' : r .path ,
@@ -313,7 +314,7 @@ def get_user_actions_for_repo(self, repo):
313314 ).filter (UserAction .app_id == Application .id ).all ()
314315 uas = [user_action_to_dict (ua ) for app , ua in results ]
315316 return uas
316-
317+
317318 def clear_repo (self , repo ):
318319 with Session (self .engine ) as session :
319320 session .query (Application ).filter_by (repo = repo ).delete ()
@@ -324,7 +325,7 @@ def clear_repo(self, repo):
324325 session .query (AuditResult ).filter_by (repo = repo ).delete ()
325326 session .commit ()
326327 return f"Cleared results for repo { repo } "
327-
328+
328329 def clear_repo_issues (self , repo ):
329330 with Session (self .engine ) as session :
330331 session .query (ApplicationIssue ).filter_by (repo = repo ).delete ()
@@ -336,13 +337,10 @@ def clear_repo_issues(self, repo):
336337
337338backend = RepoContextBackend (MEMORY )
338339
339- def process_repo (owner , repo ):
340- return f"{ owner } /{ repo } " .lower ()
341-
342340@mcp .tool ()
343- def store_new_component (owner : str , repo : str , location : str = Field (description = "The directory of the component" ),
344- is_app : bool = Field (description = "Is this an application" , default = None ),
345- is_library : bool = Field (description = "Is this a library" , default = None ),
341+ def store_new_component (owner : str , repo : str , location : str = Field (description = "The directory of the component" ),
342+ is_app : bool = Field (description = "Is this an application" , default = None ),
343+ is_library : bool = Field (description = "Is this a library" , default = None ),
346344 notes : str = Field (description = "The notes taken for this component" , default = "" )):
347345 """
348346 Stores a new component in the database.
@@ -386,9 +384,9 @@ def store_new_component_issue(owner: str, repo: str, component_id: int,
386384 return backend .store_new_component_issue (repo , component_id , issue_type , notes )
387385
388386@mcp .tool ()
389- def store_new_audit_result (owner : str , repo : str , component_id : int , issue_type : str , issue_id : int ,
390- has_non_security_error : bool = Field (description = "Set to true if there are security issues or logic error but may not be exploitable" ),
391- has_vulnerability : bool = Field (description = "Set to true if a security vulnerability is identified" ),
387+ def store_new_audit_result (owner : str , repo : str , component_id : int , issue_type : str , issue_id : int ,
388+ has_non_security_error : bool = Field (description = "Set to true if there are security issues or logic error but may not be exploitable" ),
389+ has_vulnerability : bool = Field (description = "Set to true if a security vulnerability is identified" ),
392390 notes : str = Field (description = "The notes for the audit of this issue" )):
393391 """
394392 Stores the audit result for issue with issue_id.
@@ -397,7 +395,7 @@ def store_new_audit_result(owner: str, repo: str, component_id: int, issue_type:
397395 return backend .store_new_audit_result (repo , component_id , issue_type , issue_id , has_non_security_error , has_vulnerability , notes )
398396
399397@mcp .tool ()
400- def store_new_web_entry_point (owner : str , repo : str ,
398+ def store_new_web_entry_point (owner : str , repo : str ,
401399 entry_point_id : int = Field (description = "The ID of the entry point this web entry point refers to" ),
402400 location : str = Field (description = "The directory of the component where the web entry point belongs to" ),
403401 method : str = Field (description = "HTTP method (GET, POST, etc)" , default = "" ),
@@ -432,7 +430,7 @@ def add_entry_point_notes(owner: str, repo: str,
432430@mcp .tool ()
433431def store_new_user_action (owner : str , repo : str , location : str = Field (description = "The directory of the component where the user action belonged to" ),
434432 file : str = Field (description = "The file that contains the user action" ),
435- line : int = Field (description = "The file line that contains the user action" ),
433+ line : int = Field (description = "The file line that contains the user action" ),
436434 notes : str = Field (description = "New notes for this user action" , default = "" )):
437435 """
438436 Stores a new user action in a component to the database.
0 commit comments