Skip to content

Commit 49b76b3

Browse files
committed
add timeouts to tools
1 parent 67ddaf8 commit 49b76b3

4 files changed

Lines changed: 56 additions & 28 deletions

File tree

src/tools/code_browsing_tools.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ def register_code_browsing_tools(mcp, services: dict):
5151
5252
Examples:
5353
list_methods(codebase_hash="abc", name_pattern=".*auth.*")
54-
list_methods(codebase_hash="abc", callee_pattern="memcpy")"""
54+
list_methods(codebase_hash="abc", callee_pattern="memcpy")""",
55+
timeout=30,
5556
)
5657
def list_methods(
5758
codebase_hash: Annotated[str, Field(description="The codebase hash from generate_cpg")],
@@ -118,7 +119,8 @@ def list_methods(
118119
Examples:
119120
list_files(codebase_hash="abc")
120121
list_files(codebase_hash="abc", local_path="src/lib")
121-
list_files(codebase_hash="abc", page=2)"""
122+
list_files(codebase_hash="abc", page=2)""",
123+
timeout=30,
122124
)
123125
def list_files(
124126
codebase_hash: Annotated[str, Field(description="The codebase hash from generate_cpg")],
@@ -183,7 +185,8 @@ def list_files(
183185
184186
Examples:
185187
get_method_source(codebase_hash="abc", method_name="main")
186-
get_method_source(codebase_hash="abc", method_name="init", filename="driver.c")"""
188+
get_method_source(codebase_hash="abc", method_name="init", filename="driver.c")""",
189+
timeout=30,
187190
)
188191
def get_method_source(
189192
codebase_hash: Annotated[str, Field(description="The codebase hash from generate_cpg")],
@@ -351,7 +354,8 @@ def get_method_source(
351354
352355
Examples:
353356
list_calls(codebase_hash="abc", callee_pattern="strcpy")
354-
list_calls(codebase_hash="abc", caller_pattern="main")"""
357+
list_calls(codebase_hash="abc", caller_pattern="main")""",
358+
timeout=30,
355359
)
356360
def list_calls(
357361
codebase_hash: Annotated[str, Field(description="The codebase hash from generate_cpg")],
@@ -423,7 +427,8 @@ def list_calls(
423427
424428
Examples:
425429
get_call_graph(codebase_hash="abc", method_name="main", direction="outgoing")
426-
get_call_graph(codebase_hash="abc", method_name="vuln_func", direction="incoming")"""
430+
get_call_graph(codebase_hash="abc", method_name="vuln_func", direction="incoming")""",
431+
timeout=120,
427432
)
428433
def get_call_graph(
429434
codebase_hash: Annotated[str, Field(description="The codebase hash from generate_cpg")],
@@ -514,7 +519,8 @@ def get_call_graph(
514519
- Useful for understanding function signatures.
515520
516521
Examples:
517-
list_parameters(codebase_hash="abc", method_name="login")"""
522+
list_parameters(codebase_hash="abc", method_name="login")""",
523+
timeout=30,
518524
)
519525
def list_parameters(
520526
codebase_hash: Annotated[str, Field(description="The codebase hash from generate_cpg")],
@@ -565,7 +571,8 @@ def list_parameters(
565571
- Useful as a first step when exploring a new codebase.
566572
567573
Examples:
568-
get_codebase_summary(codebase_hash="abc")"""
574+
get_codebase_summary(codebase_hash="abc")""",
575+
timeout=30,
569576
)
570577
def get_codebase_summary(
571578
codebase_hash: Annotated[str, Field(description="The codebase hash from generate_cpg")]
@@ -727,7 +734,8 @@ def get_codebase_summary(
727734
- filename should be relative to the project root (e.g., 'src/main.c' not '/absolute/path/src/main.c').
728735
729736
Examples:
730-
get_code_snippet(codebase_hash="abc", filename="main.c", start_line=10, end_line=20)"""
737+
get_code_snippet(codebase_hash="abc", filename="main.c", start_line=10, end_line=20)""",
738+
timeout=30,
731739
)
732740
def get_code_snippet(
733741
codebase_hash: Annotated[str, Field(description="The codebase hash from generate_cpg")],
@@ -850,7 +858,8 @@ def get_code_snippet(
850858
- Use get_cpgql_syntax_help for reference.
851859
852860
Examples:
853-
run_cpgql_query(codebase_hash="abc", query="cpg.method.name.l")"""
861+
run_cpgql_query(codebase_hash="abc", query="cpg.method.name.l")""",
862+
timeout=120,
854863
)
855864
def run_cpgql_query(
856865
codebase_hash: Annotated[str, Field(description="The codebase hash from generate_cpg")],
@@ -956,7 +965,8 @@ def run_cpgql_query(
956965
- filename in buffer_access_location should be relative to the project root (e.g., 'src/parser.c:100').
957966
958967
Examples:
959-
find_bounds_checks(codebase_hash="abc", buffer_access_location="parser.c:3393")"""
968+
find_bounds_checks(codebase_hash="abc", buffer_access_location="parser.c:3393")""",
969+
timeout=120,
960970
)
961971
def find_bounds_checks(
962972
codebase_hash: Annotated[str, Field(description="The codebase hash from generate_cpg")],
@@ -1035,7 +1045,8 @@ def find_bounds_checks(
10351045
- Use this to learn how to write queries for run_cpgql_query.
10361046
10371047
Examples:
1038-
get_cpgql_syntax_help()"""
1048+
get_cpgql_syntax_help()""",
1049+
timeout=30,
10391050
)
10401051
def get_cpgql_syntax_help() -> Dict[str, Any]:
10411052
"""Get CPGQL syntax documentation and common query patterns."""
@@ -1158,7 +1169,8 @@ def get_cpgql_syntax_help() -> Dict[str, Any]:
11581169
- Returns plain text.
11591170
11601171
Examples:
1161-
get_cfg(codebase_hash="abc", method_name="main")"""
1172+
get_cfg(codebase_hash="abc", method_name="main")""",
1173+
timeout=120,
11621174
)
11631175
def get_cfg(
11641176
codebase_hash: Annotated[str, Field(description="The codebase hash from generate_cpg")],
@@ -1237,7 +1249,8 @@ def get_cfg(
12371249
- Does not read header files; uses CPG type info.
12381250
12391251
Examples:
1240-
get_type_definition(codebase_hash="abc", type_name=".*request_t.*")"""
1252+
get_type_definition(codebase_hash="abc", type_name=".*request_t.*")""",
1253+
timeout=30,
12411254
)
12421255
def get_type_definition(
12431256
codebase_hash: Annotated[str, Field(description="The codebase hash from generate_cpg")],
@@ -1331,7 +1344,8 @@ def get_type_definition(
13311344
- filename should be relative to the project root (e.g., 'src/main.c').
13321345
13331346
Examples:
1334-
get_macro_expansion(codebase_hash="abc", filename="main.c", line_number=42)"""
1347+
get_macro_expansion(codebase_hash="abc", filename="main.c", line_number=42)""",
1348+
timeout=30,
13351349
)
13361350
def get_macro_expansion(
13371351
codebase_hash: Annotated[str, Field(description="The codebase hash from generate_cpg")],
@@ -1483,7 +1497,8 @@ def get_macro_expansion(
14831497
14841498
Examples:
14851499
discover_fixed_vulnerabilities(codebase_hash="abc")
1486-
discover_fixed_vulnerabilities(codebase_hash="abc", limit=100)"""
1500+
discover_fixed_vulnerabilities(codebase_hash="abc", limit=100)""",
1501+
timeout=120,
14871502
)
14881503
def discover_fixed_vulnerabilities(
14891504
codebase_hash: Annotated[str, Field(description="The codebase hash from generate_cpg")],

src/tools/core_tools.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,8 @@ def register_core_tools(mcp, services: dict):
386386
source_type="github",
387387
source_path="https://github.com/joernio/sample-repo",
388388
language="java"
389-
)"""
389+
)""",
390+
timeout=600,
390391
)
391392
async def generate_cpg(
392393
source_type: Annotated[str, Field(description="Either 'local' or 'github'")],
@@ -629,7 +630,8 @@ async def generate_cpg(
629630
- If status is 'generating', wait and retry.
630631
631632
Examples:
632-
get_cpg_status(codebase_hash="abc123456789")"""
633+
get_cpg_status(codebase_hash="abc123456789")""",
634+
timeout=30,
633635
)
634636
def get_cpg_status(
635637
codebase_hash: Annotated[str, Field(description="The hash identifier of the codebase")]

src/tools/export_tools.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,8 @@ def register_export_tools(mcp, services: dict):
758758
- Parses text outputs into structured data
759759
- Assigns HIGH confidence to confirmed vulnerabilities
760760
- Maps findings to CWE IDs
761-
- Determines severity based on vulnerability type"""
761+
- Determines severity based on vulnerability type""",
762+
timeout=60,
762763
)
763764
def store_findings(
764765
codebase_hash: Annotated[str, Field(description="The codebase hash from generate_cpg")],
@@ -919,7 +920,8 @@ def store_findings(
919920
- Only exports findings matching severity/confidence filters
920921
- Includes code flow paths for taint flows
921922
- Maps findings to CWE IDs
922-
- Compatible with GitHub Code Scanning upload"""
923+
- Compatible with GitHub Code Scanning upload""",
924+
timeout=60,
923925
)
924926
def export_sarif(
925927
codebase_hash: Annotated[str, Field(description="The codebase hash from generate_cpg")],

src/tools/taint_analysis_tools.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,8 @@ def register_taint_analysis_tools(mcp, services: dict):
422422
423423
Examples:
424424
find_taint_sources(codebase_hash="abc", language="c")
425-
find_taint_sources(codebase_hash="abc", source_patterns=["read_from_socket"])"""
425+
find_taint_sources(codebase_hash="abc", source_patterns=["read_from_socket"])""",
426+
timeout=120,
426427
)
427428
def find_taint_sources(
428429
codebase_hash: Annotated[str, Field(description="The codebase hash from generate_cpg")],
@@ -548,7 +549,8 @@ def _execute():
548549
549550
Examples:
550551
find_taint_sinks(codebase_hash="abc", language="c")
551-
find_taint_sinks(codebase_hash="abc", sink_patterns=["custom_exec"])"""
552+
find_taint_sinks(codebase_hash="abc", sink_patterns=["custom_exec"])""",
553+
timeout=120,
552554
)
553555
def find_taint_sinks(
554556
codebase_hash: Annotated[str, Field(description="The codebase hash from generate_cpg")],
@@ -697,7 +699,8 @@ def _execute():
697699
698700
# Manual mode — specific source and sink
699701
find_taint_flows(codebase_hash="...", source_location="main.c:42", sink_location="utils.c:100")
700-
find_taint_flows(codebase_hash="...", source_node_id=12345, sink_node_id=67890)"""
702+
find_taint_flows(codebase_hash="...", source_node_id=12345, sink_node_id=67890)""",
703+
timeout=300,
701704
)
702705
def find_taint_flows(
703706
codebase_hash: Annotated[str, Field(description="The codebase hash from generate_cpg")],
@@ -932,7 +935,8 @@ def _execute():
932935
Examples:
933936
get_program_slice(codebase_hash="abc", location="main.c:42")
934937
get_program_slice(codebase_hash="abc", location="parser.c:500:memcpy", direction="backward", max_depth=3)
935-
get_program_slice(codebase_hash="abc", location="module/file.c:100", direction="forward")"""
938+
get_program_slice(codebase_hash="abc", location="module/file.c:100", direction="forward")""",
939+
timeout=300,
936940
)
937941
def get_program_slice(
938942
codebase_hash: Annotated[str, Field(description="The codebase hash from generate_cpg")],
@@ -1046,7 +1050,8 @@ def _execute():
10461050
- location filename should be relative to the project root.
10471051
10481052
Examples:
1049-
get_variable_flow(codebase_hash="abc", location="main.c:50", variable="len", direction="backward")"""
1053+
get_variable_flow(codebase_hash="abc", location="main.c:50", variable="len", direction="backward")""",
1054+
timeout=120,
10501055
)
10511056
def get_variable_flow(
10521057
codebase_hash: str,
@@ -1159,7 +1164,8 @@ def _execute():
11591164
Notes:
11601165
- Deep interprocedural analysis can be slow (~2 min for large codebases).
11611166
- Use get_program_slice to understand control flow around specific locations.
1162-
- Use find_taint_flows for alternative dataflow analysis approach."""
1167+
- Use find_taint_flows for alternative dataflow analysis approach.""",
1168+
timeout=300,
11631169
)
11641170
def find_use_after_free(
11651171
codebase_hash: Annotated[str, Field(description="The codebase hash from generate_cpg")],
@@ -1244,7 +1250,8 @@ def _execute():
12441250
Human-readable text showing:
12451251
- Each potential double-free issue with pointer name
12461252
- First and second free locations with [file:line]
1247-
- Flow type (same-ptr, alias, or [CROSS-FUNC])"""
1253+
- Flow type (same-ptr, alias, or [CROSS-FUNC])""",
1254+
timeout=300,
12481255
)
12491256
def find_double_free(
12501257
codebase_hash: Annotated[str, Field(description="The codebase hash from generate_cpg")],
@@ -1340,7 +1347,8 @@ def _execute():
13401347
Notes:
13411348
- Includes deep interprocedural analysis using Joern's dataflow engine.
13421349
- Use get_program_slice for deeper control-flow context around specific locations.
1343-
- Use find_taint_flows to check if allocation arguments come from external input."""
1350+
- Use find_taint_flows to check if allocation arguments come from external input.""",
1351+
timeout=300,
13441352
)
13451353
def find_null_pointer_deref(
13461354
codebase_hash: Annotated[str, Field(description="The codebase hash from generate_cpg")],
@@ -1438,7 +1446,8 @@ def _execute():
14381446
Notes:
14391447
- Includes deep interprocedural analysis using Joern's dataflow engine.
14401448
- Use get_program_slice for deeper control-flow context around specific locations.
1441-
- Use find_taint_flows to check if arithmetic operands come from external input."""
1449+
- Use find_taint_flows to check if arithmetic operands come from external input.""",
1450+
timeout=300,
14421451
)
14431452
def find_integer_overflow(
14441453
codebase_hash: Annotated[str, Field(description="The codebase hash from generate_cpg")],

0 commit comments

Comments
 (0)