Skip to main content
Glama
search_example.py2.02 kB
#!/usr/bin/env python3 """ Example: Searching Best Practices This example demonstrates how to use the search_best_practices tool to find coding guidelines by keyword. """ import sys import os # Add parent directory to path to import modules sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from data_manager import search_practices def main(): """Demonstrate searching for best practices.""" print("=" * 60) print("Example: Searching Best Practices") print("=" * 60) print() # Example 1: Search for async-related practices print("1. Searching for 'async' practices:") print("-" * 60) result = search_practices("async") print(f"Found {result['count']} matches") print() for match in result.get('matches', [])[:2]: # Show first 2 print(f"Category: {match['category']}") print(f"Topic: {match['topic']}") print(f"Description: {match['description'][:100]}...") print(f"Related topics: {', '.join(match['related_topics'][:3])}") print() # Example 2: Search for error handling print("\n2. Searching for 'error handling' practices:") print("-" * 60) result = search_practices("error") print(f"Found {result['count']} matches") if result['count'] > 0: match = result['matches'][0] print(f"\nFirst match:") print(f" Category: {match['category']}") print(f" Topic: {match['topic']}") print(f" Description: {match['description']}") print() # Example 3: Search with no results (demonstrates suggestions) print("\n3. Searching for non-existent term (demonstrates suggestions):") print("-" * 60) result = search_practices("xyz123") if 'suggestions' in result: print(f"No matches found. Suggestions: {', '.join(result['suggestions'])}") print() print("=" * 60) print("Search examples complete!") print("=" * 60) if __name__ == "__main__": main()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/n-ochs/best-practice-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server