Skip to main content
Glama
test_mcp_server.pyโ€ข2.91 kB
#!/usr/bin/env python3 """ Test script for the MCP S3 upload server """ import asyncio import tempfile import os from fastmcp import Client from dotenv import load_dotenv async def test_server(): """Test the MCP server functionality""" # Load environment variables load_dotenv() bucket_name = os.getenv('S3_BUCKET_NAME') if not bucket_name: print("โŒ S3_BUCKET_NAME not found in .env file") return # Create test upload directory upload_dir = os.path.expanduser("~/mcp-uploads") os.makedirs(upload_dir, exist_ok=True) # Create a test file in the upload directory test_content = "Hello, this is a test file for MCP S3 upload!\n" * 100 test_file_path = os.path.join(upload_dir, "test-upload.txt") with open(test_file_path, 'w') as f: f.write(test_content) print(f"๐Ÿ“ Created test file: {test_file_path}") try: # Connect to the server print("๐Ÿ”Œ Connecting to MCP server...") # Connect to the server script - FastMCP will handle launching it from fastmcp.client.transports import StdioTransport from dotenv import dotenv_values # Pass environment variables to the server subprocess env_vars = dotenv_values('.env') transport = StdioTransport( command="python", args=["mcp_s3.py", "--root", upload_dir], env=env_vars ) client = Client(transport) async with client: # List available tools print("๐Ÿ“‹ Available tools:") tools = await client.list_tools() for tool in tools: print(f" โ€ข {tool.name}: {tool.description}") print("\n๐Ÿ“ค Testing file upload...") # Test the upload_file tool result = await client.call_tool("upload_file", { "local_path": "test-upload.txt", # Relative to upload directory "expires_in": 3600 # 1 hour }) print("โœ… Upload successful!") print(f"๐Ÿ“Š Result: {result.data}") print(f"๐Ÿ”— Presigned URL: {result.data.url[:60]}...") print(f"๐Ÿ“ File size: {result.data.size:,} bytes") print(f"๐ŸŽญ MIME type: {result.data.mime_type}") print(f"๐Ÿ”‘ S3 key: {result.data.s3_key}") print(f"๐Ÿชฃ S3 bucket: {bucket_name}") except Exception as e: print(f"โŒ Test failed: {e}") import traceback traceback.print_exc() finally: # Clean up test file if os.path.exists(test_file_path): os.unlink(test_file_path) print("๐Ÿงน Cleaned up test file") if __name__ == "__main__": print("๐Ÿš€ Starting MCP S3 upload server test...") asyncio.run(test_server())

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/dayongd1/mcp-s3'

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