Skip to main content
Glama
test_connection.py•3.42 kB
#!/home/borjigin/dev/bookstack-mcp/venv/bin/python """ Test script to verify BookStack connection and API access. """ import os import asyncio import httpx 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 test_connection(): """Test basic connectivity and API access""" print("šŸ” Testing BookStack MCP Server Connection\n") print(f"BookStack URL: {BS_URL}") # Check environment variables if not BS_TOKEN_ID or not BS_TOKEN_SECRET: print("\nāŒ ERROR: BS_TOKEN_ID and BS_TOKEN_SECRET must be set in .env file") print("Please copy env.template to .env and fill in your API credentials") return False print(f"Token ID: {BS_TOKEN_ID[:10]}..." if len(BS_TOKEN_ID) > 10 else BS_TOKEN_ID) print("Token Secret: [HIDDEN]\n") # Test basic connectivity print("1ļøāƒ£ Testing basic connectivity...") try: async with httpx.AsyncClient(timeout=10.0) as client: response = await client.get(BS_URL) print(f" āœ… BookStack is reachable (status: {response.status_code})\n") except Exception as e: print(f" āŒ Cannot reach BookStack: {e}\n") return False # Test API access print("2ļøāƒ£ Testing API authentication...") try: headers = { "Authorization": f"Token {BS_TOKEN_ID}:{BS_TOKEN_SECRET}", "Content-Type": "application/json" } async with httpx.AsyncClient(timeout=10.0) as client: response = await client.get(f"{BS_URL}/api/books", headers=headers) response.raise_for_status() data = response.json() print(f" āœ… API authentication successful!") print(f" šŸ“š Found {data.get('total', 0)} books in your BookStack\n") # Show first few books if data.get('data'): print(" First few books:") for book in data['data'][:3]: print(f" - {book.get('name')} (ID: {book.get('id')})") print() except httpx.HTTPStatusError as e: print(f" āŒ API authentication failed: {e.response.status_code}") if e.response.status_code == 401: print(" Check your token ID and secret") elif e.response.status_code == 403: print(" Your token may lack necessary permissions") print() return False except Exception as e: print(f" āŒ API error: {e}\n") return False # Test MCP server import print("3ļøāƒ£ Testing MCP server...") try: from fastmcp import FastMCP print(" āœ… FastMCP is installed\n") except ImportError as e: print(f" āŒ FastMCP not installed: {e}") print(" Run: pip install -r requirements.txt\n") return False print("āœ… All tests passed! Your BookStack MCP server is ready to use.\n") print("Next steps:") print("1. Configure Cursor to use this MCP server (see QUICKSTART.md)") print("2. Run the server: python server.py") print("3. Or use in Cursor: add to MCP settings\n") return True if __name__ == "__main__": success = asyncio.run(test_connection()) exit(0 if success 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