Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
1. Replace All Wildcard (
from ... import *) Imports with Explicit ExportsEliminates all 25 wildcard imports across all 391 tracked Python files in the repository:
server/secops/secops_mcp/tools/__init__.py: Replaces all 17from .<module> import *lines with explicit imports of all 69@server.tool()functions and an alphabetically sorted__all__export list (preventing transitive symbol leakage such aslogger,logging,datetime, andget_chronicle_clientontosecops_mcp.tools).server/gti/gti_mcp/tools/__init__.py: Replaces all 6from .<module> import *lines with explicit imports of all 13 relationship constants,url_to_base64, and 36@server.tool()functions, plus an alphabetically sorted__all__export list.2. Preserve Direct
__main__Script Execution (server.py)server/secops/secops_mcp/server.py&server/gti/gti_mcp/server.py:server.pydirectly as a script (python server.pyoruv run secops_mcp/server.py) loadedserver.pyas__main__, and importingtoolsloaded a second module copy (secops_mcp.server/gti_mcp.server) where@server.tool()decorators registered. Only the accidental leakage ofserverthroughfrom <pkg>.tools import *overwrote__main__.serverwith the populated second instance.from <pkg>.tools import *withfrom <pkg> import tools # noqa: E402, F401and aliasessys.modules.setdefault("<pkg>.server", sys.modules[__name__])prior to importingtoolsso all@server.tool()decorators register on the single activeFastMCPinstance without double-loadingserver.py.3. AST Tool Import/Export Audits & Negative Unit Tests
server/secops/tests/test_secops_tools_unit.py(_audit_secops_tools_exports) &server/gti/tests/test_tools.py(_audit_gti_tools_exports):tools/*.pyfile on disk viaast.parseto enforce:from ... import *wildcard imports inserver.py,tools/__init__.py, or anytools/*.pysubmodule.tools/<submodule>.pyis explicitly imported viafrom .<submodule> import ...intools/__init__.pyand listed in sortedtools.__all__, reportingfile.py:linenoon any missing import or export.@server.tool()function discovered intools/*.pyis registered onserver._tool_manager._toolsboth on standard module import (test_tools_init_explicit_exports_without_splat_imports,test_gti_tools_explicit_exports_without_splat_imports) and when runningserver.pyas__main__(test_server_main_script_execution_registers_all_tools,test_gti_server_main_script_execution_registers_all_tools).server/secops/secops_mcp/tools/*.pycarries@server.tool()(requiring internal helpers to be prefixed with_).test_tools_init_flags_unimported_new_function,test_gti_tools_init_flags_unimported_new_function):tools/totmp_path, appends a new@server.tool()function to a submodule without updatingtools/__init__.py, and verifies that the audit flags the exactfile.py:linenoand symbol name for both the missing submodule import and missing__all__entry.4. GitHub Actions CI Workflow (
.github/workflows/verify-tool-exports.yml)ubuntu-latest(Python3.11) with pinned test dependencies (pytest==9.1.1,pytest-asyncio==1.4.0,pytest-httpserver==1.2.0,pytest-mock==3.17.0) that executes:pytest tests/*_unit.py -vinserver/secops(41 passed)pytest tests/ -vinserver/gti(61 passed)Verification
0wildcard imports remain across all 391 tracked.pyfiles andgit diff --checkreports zero whitespace errors.server/secops:41 passed(tests/*_unit.py)server/gti:61 passed(tests/)direnvMCP Verification (dandye-0324-chronicle):tools/list(69tools forsecops_mcp,36tools forgti_mcp) and live Chronicle API tool execution (list_security_rules,search_security_events,get_security_alerts,get_ioc_matches,list_feeds,lookup_entity) in both-m <pkg>.servermodule mode and direct__main__script mode.