foodwise-remote-mcp / scripts /list_databases.py
LeoWalker's picture
Use NOTION_SHOPPING_DB_ID across code/docs; add shopping DB setup guidance; update scripts and tests
3fba179
#!/usr/bin/env python3
"""
List all Notion databases accessible to the integration.
This script helps you find the correct database ID for your FoodWise inventory.
Run with: python scripts/list_databases.py
"""
import sys
import os
from pathlib import Path
# Add src to path so we can import our modules
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
from dotenv import load_dotenv
load_dotenv()
from notion_client import Client
def list_databases():
"""List all databases accessible to the Notion integration."""
print("πŸ” Listing all accessible Notion databases...")
try:
# Initialize Notion client
notion_secret = os.getenv("NOTION_SECRET")
if not notion_secret:
print("❌ NOTION_SECRET not found in environment")
print(" Make sure your .env file contains NOTION_SECRET=your_integration_token")
return
client = Client(auth=notion_secret)
print("βœ… Notion client initialized successfully")
# Search for databases
print("\nπŸ“‹ Searching for databases...")
response = client.search(
filter={"property": "object", "value": "database"}
)
databases = response.get("results", [])
if not databases:
print("❌ No databases found!")
print("\nπŸ”§ Possible reasons:")
print(" 1. Your integration doesn't have access to any databases")
print(" 2. You need to share your database with the integration")
print(" 3. The integration token might be invalid")
return
print(f"βœ… Found {len(databases)} database(s):")
print("=" * 80)
for i, db in enumerate(databases, 1):
title = "Untitled"
if db.get("title") and len(db["title"]) > 0:
title = db["title"][0]["text"]["content"]
print(f"\n{i}. πŸ“Š {title}")
print(f" πŸ†” Database ID: {db['id']}")
print(f" πŸ”— URL: {db['url']}")
print(f" πŸ“… Created: {db['created_time']}")
print(f" πŸ“ Last edited: {db['last_edited_time']}")
# Show some properties
if db.get("properties"):
prop_names = list(db["properties"].keys())[:5] # First 5 properties
print(f" 🏷️ Properties: {', '.join(prop_names)}")
if len(db["properties"]) > 5:
print(f" ... and {len(db['properties']) - 5} more")
print("\n" + "=" * 80)
print("πŸ’‘ To use a database with FoodWise:")
print(" 1. Copy the Database ID of your food inventory database")
print(" 2. Add it to your .env file as: NOTION_INVENTORY_DB_ID=your_database_id")
print(" 3. Re-run the manual test: python scripts/manual_test.py")
except Exception as e:
print(f"❌ Failed to list databases: {e}")
print("\nπŸ”§ Troubleshooting:")
print(" 1. Check that NOTION_SECRET is correct in your .env file")
print(" 2. Verify your Notion integration is properly configured")
print(" 3. Make sure you've shared at least one database with your integration")
if __name__ == "__main__":
print("🍽️ FoodWise Database Discovery")
print("=" * 40)
list_databases()