Skip to main content
Glama
create_test_page.py•5 kB
#!/home/borjigin/dev/bookstack-mcp/venv/bin/python """ Create a test page in BookStack """ import os import asyncio import httpx from datetime import datetime from dotenv import load_dotenv load_dotenv() BS_URL = os.getenv("BS_URL", "http://192.168.1.193:6875") BS_TOKEN_ID = os.getenv("BS_TOKEN_ID") BS_TOKEN_SECRET = os.getenv("BS_TOKEN_SECRET") async def create_test_page(): """Create a test page in BookStack""" if not BS_TOKEN_ID or not BS_TOKEN_SECRET: print("āŒ ERROR: BS_TOKEN_ID and BS_TOKEN_SECRET must be set in .env file") return None headers = { "Authorization": f"Token {BS_TOKEN_ID}:{BS_TOKEN_SECRET}", "Content-Type": "application/json" } async with httpx.AsyncClient(timeout=30.0) as client: # Step 1: Get or create a book print("šŸ“š Checking for existing books...") try: response = await client.get(f"{BS_URL}/api/books", headers=headers) response.raise_for_status() books = response.json() if books.get('data'): # Use the first book book = books['data'][0] book_id = book['id'] book_name = book['name'] print(f" āœ… Using existing book: '{book_name}' (ID: {book_id})") else: # Create a new book print(" šŸ“˜ No books found, creating a new one...") response = await client.post( f"{BS_URL}/api/books", headers=headers, json={ "name": "Test Book - Created by MCP", "description": "This book was created by the BookStack MCP Server" } ) response.raise_for_status() book = response.json() book_id = book['id'] book_name = book['name'] print(f" āœ… Created new book: '{book_name}' (ID: {book_id})") except httpx.HTTPStatusError as e: print(f"āŒ API Error: {e.response.status_code}") print(f" Response: {e.response.text}") return None except Exception as e: print(f"āŒ Error: {e}") return None # Step 2: Create the test page print("\nšŸ“„ Creating test page...") timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") page_data = { "book_id": book_id, "name": f"Test Page - {timestamp}", "markdown": f"""# Test Page This is a test page created by the BookStack MCP Server! ## Information - **Created:** {timestamp} - **Book:** {book_name} (ID: {book_id}) - **Created by:** MCP Server for Cursor ## Features The MCP server can: - āœ… List books, chapters, and pages - āœ… Search across all content - āœ… Create new pages (like this one!) - āœ… Update existing pages - āœ… Delete pages - āœ… Manage books and chapters ## Next Steps You can now use Cursor to: 1. List all your books: "List all books in BookStack" 2. Search content: "Search for 'test' in BookStack" 3. Create more pages: "Create a page about Docker in book {book_id}" 4. Update this page: "Update page [ID] with new content" Happy documenting! šŸš€ """ } try: response = await client.post( f"{BS_URL}/api/pages", headers=headers, json=page_data ) response.raise_for_status() page = response.json() page_id = page['id'] page_name = page['name'] page_slug = page['slug'] # Construct the page URL page_url = f"{BS_URL}/books/{book['slug']}/page/{page_slug}" print(f" āœ… Page created successfully!") print(f"\n" + "="*70) print(f"šŸ“„ Test Page Created!") print(f"="*70) print(f"Name: {page_name}") print(f"ID: {page_id}") print(f"Book: {book_name}") print(f"URL: {page_url}") print(f"="*70) print(f"\n🌐 Open in browser: {page_url}") print(f"\nšŸ’” Try in Cursor: \"Show me page {page_id}\"") return { 'page_id': page_id, 'page_name': page_name, 'page_url': page_url, 'book_id': book_id, 'book_name': book_name } except httpx.HTTPStatusError as e: print(f"āŒ Failed to create page: {e.response.status_code}") print(f" Response: {e.response.text}") return None except Exception as e: print(f"āŒ Error creating page: {e}") return None if __name__ == "__main__": result = asyncio.run(create_test_page()) exit(0 if result else 1)

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/lborjigi/bookstack-mcp'

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