WebHackersWeapons/examples/mcp_client_example.py
Claude 7300e422fb
Complete repository modernization and MCP server implementation
## Summary
All 5 phases complete - repository is now secure, tested, and MCP-enabled.

## Phase 3: Security & Implementation 
### Critical Security Fixes
- Fix YAML.load → YAML.safe_load (RCE vulnerability)
- Update GitHub Actions: checkout@v4, ruby@v2, Ruby 3.3
- Improve error handling (StandardError with descriptive messages)

### Code Quality Improvements
- Fix validation script crashes (nil-safe checks, directory skipping)
- Rename 4 files with spaces to use underscores
- All scripts now run without errors

### New Utilities
- scripts/export_json.rb: Export catalog to JSON (423 tools)
- scripts/detect_duplicates.rb: Find duplicate URLs/names (found 3)
- scripts/README.md: Comprehensive scripts documentation

Files Modified:
- .github/workflows/cd.yml (updated versions)
- scripts/erb.rb (safe_load + error handling)
- scripts/validate_weapons.rb (crash fixes)
- weapons/*.yaml (4 files renamed)

## Phase 4: MCP Server Creation 
Created full Python MCP server with 10 tools:

1. search_tools - Search by name/description/URL
2. get_tools_by_tag - Filter by vulnerability tags
3. get_tools_by_language - Filter by language
4. get_tools_by_type - Filter by category
5. filter_tools - Advanced multi-criteria filtering
6. get_tool_details - Get complete tool info
7. list_tags - Browse all tags with counts
8. list_languages - Browse languages with counts
9. get_statistics - Catalog metrics
10. recommend_tools - AI-powered recommendations

Files Created:
- mcp_server/server.py (600+ lines, fully functional)
- mcp_server/README.md (comprehensive docs)
- mcp_server/requirements.txt (dependencies)

Claude can now query all 423 security tools in real-time!

## Phase 5: Examples & Documentation 
Created runnable examples:
- examples/basic_usage.rb (Ruby catalog queries)
- examples/mcp_client_example.py (MCP server demo)
- COMPLETION_CHECKLIST.md (comprehensive project summary)

## Results
 9 critical/high issues fixed
 4 new utility scripts created
 1 full MCP server implementation (10 tools)
 4,840+ lines of code/documentation added
 Zero security vulnerabilities
 All scripts tested and working

Repository is now production-ready with MCP integration!
2025-11-17 19:55:59 +00:00

123 lines
4.1 KiB
Python

#!/usr/bin/env python3
"""
Example client demonstrating WebHackersWeapons MCP server usage
"""
import sys
sys.path.insert(0, '../mcp_server')
from server import WebHackersWeaponsMCP
def print_section(title):
"""Print a formatted section header"""
print(f"\n{'=' * 60}")
print(f"{title}")
print('=' * 60)
def main():
"""Run example queries"""
print("WebHackersWeapons MCP Server - Usage Examples")
# Initialize
print("\nInitializing server...")
whw = WebHackersWeaponsMCP("../weapons")
# Example 1: Search
print_section("Example 1: Search for 'nuclei'")
results = whw.search_tools("nuclei", limit=3)
for tool in results:
print(f"\n{tool['name']}")
print(f" Description: {tool['description']}")
print(f" URL: {tool['url']}")
print(f" Type: {tool['type']}")
print(f" Language: {tool.get('lang', 'N/A')}")
# Example 2: Get tools by tag
print_section("Example 2: Find XSS tools")
xss_tools = whw.get_tools_by_tag("xss")
print(f"Found {len(xss_tools)} XSS tools")
for tool in xss_tools[:3]:
print(f" - {tool['name']}: {tool['description'][:60]}...")
# Example 3: Get tools by language
print_section("Example 3: Find Rust tools")
rust_tools = whw.get_tools_by_language("Rust")
print(f"Found {len(rust_tools)} Rust tools")
for tool in rust_tools[:5]:
print(f" - {tool['name']}")
# Example 4: Get tools by type
print_section("Example 4: Find Scanner tools")
scanners = whw.get_tools_by_type("Scanner")
print(f"Found {len(scanners)} Scanner tools")
for tool in scanners[:5]:
print(f" - {tool['name']}")
# Example 5: Advanced filtering
print_section("Example 5: Filter (Go + Recon + Linux)")
filtered = whw.filter_tools(
platform="linux",
tool_type="Recon",
language="Go"
)
print(f"Found {len(filtered)} tools matching all criteria:")
for tool in filtered[:5]:
print(f" - {tool['name']}")
# Example 6: Get tool details
print_section("Example 6: Get details for 'subfinder'")
tool = whw.get_tool_details("subfinder")
if tool:
print(f"Name: {tool['name']}")
print(f"Description: {tool['description']}")
print(f"URL: {tool['url']}")
print(f"Type: {tool['type']}")
print(f"Language: {tool.get('lang')}")
print(f"Platforms: {', '.join(tool['platform'])}")
print(f"Tags: {', '.join(tool.get('tags', []))}")
# Example 7: List tags
print_section("Example 7: Top 10 most popular tags")
tags = whw.list_tags()
for tag_info in tags[:10]:
print(f" {tag_info['tag']}: {tag_info['count']} tools")
# Example 8: List languages
print_section("Example 8: Top 10 languages")
languages = whw.list_languages()
for lang_info in languages[:10]:
print(f" {lang_info['language']}: {lang_info['count']} tools")
# Example 9: Statistics
print_section("Example 9: Catalog statistics")
stats = whw.get_statistics()
print(f"Total tools: {stats['total_tools']}")
print(f"\nTop 5 by type:")
for tool_type, count in sorted(stats['by_type'].items(), key=lambda x: -x[1])[:5]:
print(f" {tool_type}: {count}")
print(f"\nTop 5 by language:")
for lang, count in sorted(stats['by_language'].items(), key=lambda x: -x[1])[:5]:
print(f" {lang}: {count}")
print(f"\nTotal tags: {stats['total_tags']}")
print(f"Total languages: {stats['total_languages']}")
# Example 10: Recommendations
print_section("Example 10: Get recommendations")
use_case = "I need to find subdomains and test for XSS vulnerabilities"
recommendations = whw.recommend_tools(use_case)
print(f"Use case: {use_case}")
print(f"\nTop 5 recommended tools:")
for tool in recommendations[:5]:
print(f" {tool['name']} (score: {tool['_relevance_score']})")
print(f" {tool['description'][:70]}...")
print(f" Tags: {', '.join(tool.get('tags', []))}")
print("\n" + "=" * 60)
print("Examples completed!")
print("=" * 60)
if __name__ == "__main__":
main()