snyk_monitor_project
Set up continuous security monitoring for a project directory to detect vulnerabilities and maintain protection over time.
Instructions
Set up continuous monitoring for a project with Snyk.
Args:
project_path: Path to the project directory
Returns:
Status of monitoring setup and project details
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_path | No | . |
Implementation Reference
- Main handler function for the 'snyk_monitor_project' MCP tool. Registers the tool with @mcp.tool(), handles input validation via signature, tests Snyk connection, and delegates to SnykIntegration.monitor_project for core logic.async def snyk_monitor_project(project_path: str = "."): """ Set up continuous monitoring for a project with Snyk. Args: project_path: Path to the project directory Returns: Status of monitoring setup and project details """ from .snyk_integration import snyk_integration try: # Test connection and get organization info connection_test = await snyk_integration.test_connection() if connection_test["status"] != "connected": return { "error": "Snyk integration not configured", "details": connection_test.get("error", "Unknown error"), "setup_required": [ "Set SNYK_API_KEY environment variable", "Set SNYK_ORG_ID environment variable", "Ensure you have organization admin privileges", ], } # Set up monitoring monitor_result = await snyk_integration.monitor_project(project_path) if "error" in monitor_result: return monitor_result return { "status": "success", "monitoring_enabled": True, "project_details": monitor_result, "organization": connection_test.get("organizations", []), "next_steps": [ "π Configure alert preferences in Snyk dashboard", "π Review security reports regularly", "π Enable automatic PRs for security updates", "π Set up integration with CI/CD pipeline", ], "dashboard_url": "https://app.snyk.io/org/your-org/projects", } except Exception as e: return { "error": f"Monitoring setup failed: {str(e)}", "project_path": project_path, }
- Core helper method in SnykIntegration class that implements project monitoring by parsing dependencies, generating manifest, and calling Snyk REST API to import the project for continuous monitoring.async def monitor_project(self, project_path: str) -> Dict[str, Any]: """Set up continuous monitoring for a project""" # Find project dependencies dep_result = find_and_parse_dependencies(project_path) if not dep_result: return {"error": "No supported dependency files found"} filename, ecosystem, dependencies = dep_result try: async with httpx.AsyncClient(timeout=self.timeout) as client: # Import project for monitoring import_payload = { "target": { "files": [ { "path": filename, "contents": self._generate_manifest_content( dependencies, ecosystem ), } ] } } if not self.org_id: return { "error": "SNYK_ORG_ID environment variable is required for monitoring" } response = await client.post( f"{self.rest_api_url}/orgs/{self.org_id}/projects", headers=self._get_headers(), json=import_payload, ) if response.status_code == 201: project_data = response.json() return { "status": "monitoring_enabled", "project_id": project_data.get("data", {}).get("id"), "project_name": os.path.basename(project_path), "dependencies_count": len(dependencies), } else: return { "error": f"Failed to enable monitoring: {response.status_code}", "details": response.text, } except Exception as e: return {"error": f"Monitoring setup failed: {str(e)}"}
- src/documentation_search_enhanced/main.py:2110-2111 (registration)MCP tool registration decorator @mcp.tool() that registers the snyk_monitor_project function as an MCP tool.@mcp.tool() async def snyk_monitor_project(project_path: str = "."):
- Tool schema/arguments documentation defining input (project_path: str) and expected output format.""" Set up continuous monitoring for a project with Snyk. Args: project_path: Path to the project directory Returns: Status of monitoring setup and project details """