Skip to main content
Glama
test_server.pyโ€ข3.79 kB
#!/usr/bin/env python3 """ Test script for the authenticated Discord MCP Server This script demonstrates how to generate tokens and make authenticated requests """ import requests import json from app import generate_access_token # Configuration SERVER_URL = "http://localhost:8000" YOUR_DISCORD_TOKEN = "YOUR_DISCORD_BOT_TOKEN_HERE" # Replace with your actual Discord bot token TEST_CHANNEL_ID = "1234567890123456789" # Replace with a test channel ID def test_server(): """Test the authenticated Discord MCP server""" print("๐Ÿงช Testing Authenticated Discord MCP Server") print("=" * 50) # Step 1: Generate access token print("๐Ÿ“‹ Step 1: Generating access token...") try: access_token = generate_access_token(YOUR_DISCORD_TOKEN, "test-user") print(f"โœ… Token generated successfully!") print(f"๐Ÿ”‘ Token: {access_token[:50]}...") except Exception as e: print(f"โŒ Failed to generate token: {e}") return # Step 2: Test server health print("\n๐Ÿ“‹ Step 2: Testing server health...") try: response = requests.get(f"{SERVER_URL}/health") if response.status_code == 200: print("โœ… Server is running!") else: print(f"โš ๏ธ Server response: {response.status_code}") except Exception as e: print(f"โŒ Server not reachable: {e}") print("๐Ÿ’ก Make sure to start the server first with: python app.py") return # Step 3: Test authenticated tool call print("\n๐Ÿ“‹ Step 3: Testing authenticated tool call...") headers = { "Authorization": f"Bearer {access_token}", "Content-Type": "application/json" } # Example: Get channel info payload = { "method": "get_channel_info", "params": { "channel_id": TEST_CHANNEL_ID } } try: response = requests.post(f"{SERVER_URL}/mcp/v1/tools/invoke", headers=headers, json=payload) if response.status_code == 200: result = response.json() print("โœ… Tool call successful!") print(f"๐Ÿ“Š Response: {json.dumps(result, indent=2)}") else: print(f"โŒ Tool call failed: {response.status_code}") print(f"๐Ÿ“„ Response: {response.text}") except Exception as e: print(f"โŒ Tool call error: {e}") print("\n๐ŸŽ‰ Test completed!") def show_usage(): """Show how to use the server""" print("\n๐Ÿ“– How to use this authenticated MCP server:") print("=" * 50) print("1. Start the server:") print(" python app.py") print("\n2. Generate a token (replace with your Discord bot token):") print(f" python -c \"from app import generate_access_token; print(generate_access_token('YOUR_DISCORD_TOKEN'))\"") print("\n3. Make authenticated requests:") print(" - Include the token in the Authorization header: 'Bearer <token>'") print(" - Call tools via POST to /mcp/v1/tools/invoke") print(" - Tools available: send_message, get_messages, get_channel_info, search_messages, moderate_content") print("\n๐Ÿ”ง Example curl command:") print(""" curl -X POST http://localhost:8000/mcp/v1/tools/invoke \\ -H "Authorization: Bearer YOUR_JWT_TOKEN" \\ -H "Content-Type: application/json" \\ -d '{ "method": "get_channel_info", "params": { "channel_id": "1234567890123456789" } }' """) if __name__ == "__main__": if YOUR_DISCORD_TOKEN == "YOUR_DISCORD_BOT_TOKEN_HERE": print("โš ๏ธ Please update YOUR_DISCORD_TOKEN in this script first!") show_usage() else: test_server() show_usage()

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/henishshah18/Discord_MCP_Server'

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