Stealth browser automation for AI agents over MCP and the Chrome DevTools Protocol: navigation, network hooks, DOM extraction, and pixel-accurate UI cloning.
Python ai-agent-toolsai-toolsanthropicanti-bot-bypassautomation-toolsbrowser-automationchrome-devtoolsclaude-mcpcloudflare-bypassdeveloper-toolsfastmcpmcp-servermodel-context-protocolnetwork-interceptionnodriverpythonstealth-browserundetectable-browserweb-automationweb-scraping
fix: mark None-default tool params as Optional so explicit null validates
Vishal Habib097129a328a9
diff --git a/src/server.py b/src/server.pyindex 17c6a34..06147f3 100644--- a/src/server.py+++ b/src/server.py@@ -175,11 +175,11 @@ async def spawn_browser(viewport_width: int = 1920,viewport_height: int = 1080,proxy: Optional[str] = None,- browser_args: List[str] = None,+ browser_args: Optional[List[str]] = None,timezone_id: Optional[str] = None,idle_timeout_seconds: Optional[int] = None,- block_resources: List[str] = None,- extra_headers: Dict[str, str] = None,+ block_resources: Optional[List[str]] = None,+ extra_headers: Optional[Dict[str, str]] = None,user_data_dir: Optional[str] = None,sandbox: Optional[Any] = None) -> Dict[str, Any]:@@ -2336,7 +2336,7 @@ async def list_cdp_commands() -> List[str]:async def execute_cdp_command(instance_id: str,command: str,- params: Dict[str, Any] = None+ params: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:"""Execute any CDP Runtime command with given parameters.@@ -2434,7 +2434,7 @@ async def get_execution_contexts(@section_tool("cdp-functions")async def discover_global_functions(instance_id: str,- context_id: str = None+ context_id: Optional[str] = None) -> List[Dict[str, Any]]:"""Discover all global JavaScript functions available in the page.@@ -2520,7 +2520,7 @@ async def discover_object_methods(async def call_javascript_function(instance_id: str,function_path: str,- args: List[Any] = None+ args: Optional[List[Any]] = None) -> Dict[str, Any]:"""Call a JavaScript function with arguments.@@ -2564,7 +2564,7 @@ async def inspect_function_signature(async def inject_and_execute_script(instance_id: str,script_code: str,- context_id: str = None+ context_id: Optional[str] = None) -> Dict[str, Any]:"""Inject and execute custom JavaScript code.@@ -2693,7 +2693,7 @@ async def execute_python_in_browser(@section_tool("cdp-functions")async def get_function_executor_info(- instance_id: str = None+ instance_id: Optional[str] = None) -> Dict[str, Any]:"""Get information about the CDP function executor state.diff --git a/tests/test_tool_schemas.py b/tests/test_tool_schemas.pynew file mode 100644index 0000000..1ac096e--- /dev/null+++ b/tests/test_tool_schemas.py@@ -0,0 +1,56 @@+import asyncio+import sys+import unittest+from pathlib import Path++ROOT = Path(__file__).resolve().parents[1]+sys.path.insert(0, str(ROOT / "src"))++from fastmcp import Client++import server++# Tool parameters that default to None and must therefore accept an explicit null.+NULL_DEFAULT_PARAMS = {+ "spawn_browser": ["browser_args", "block_resources", "extra_headers"],+ "execute_cdp_command": ["params"],+ "discover_global_functions": ["context_id"],+ "call_javascript_function": ["args"],+ "inject_and_execute_script": ["context_id"],+ "get_function_executor_info": ["instance_id"],+}+++def _accepts_null(schema):+ if schema.get("type") == "null":+ return True+ return any(_accepts_null(option) for option in schema.get("anyOf", []))+++class NullDefaultSchemaTests(unittest.TestCase):+ def test_none_default_params_advertise_nullable_type(self):+ async def run():+ async with Client(server.mcp) as client:+ return {tool.name: tool for tool in await client.list_tools()}++ tools = asyncio.run(run())+ for tool_name, params in NULL_DEFAULT_PARAMS.items():+ properties = tools[tool_name].inputSchema["properties"]+ for param in params:+ with self.subTest(tool=tool_name, param=param):+ self.assertIsNone(properties[param].get("default"))+ self.assertTrue(_accepts_null(properties[param]), properties[param])++ def test_explicit_null_is_accepted(self):+ async def run():+ async with Client(server.mcp) as client:+ return await client.call_tool(+ "get_function_executor_info", {"instance_id": None}, raise_on_error=False+ )++ result = asyncio.run(run())+ self.assertFalse(result.is_error, result.content)+++if __name__ == "__main__":+ unittest.main()