Skip to main content
Glama

Agent Knowledge MCP

test_simple_file_ops.pyโ€ข6.31 kB
#!/usr/bin/env python3 """ Simple test for unified edit_file functionality Tests the underlying functions directly without FastMCP decoration. """ import tempfile from pathlib import Path # Add the project root to the path import sys sys.path.append(str(Path(__file__).parent.parent)) def test_unified_file_operations(): """Test basic file operations without using the FastMCP tool directly.""" print("๐Ÿงช Testing Unified File Operations\n") # Create a temporary directory for testing with tempfile.TemporaryDirectory() as temp_dir: test_dir = Path(temp_dir) test_file = test_dir / "test.txt" print(f"๐Ÿ“ Test directory: {test_dir}\n") # Test 1: Write file print("1๏ธโƒฃ Testing write operation...") content = "Hello, this is a test file!\nLine 2\nLine 3" try: with open(test_file, 'w', encoding='utf-8') as f: f.write(content) print(f"โœ… File written successfully: {test_file}") print(f"๐Ÿ“ Content length: {len(content)} characters") except Exception as e: print(f"โŒ Write failed: {e}") print() # Test 2: Read file print("2๏ธโƒฃ Testing read operation...") try: with open(test_file, 'r', encoding='utf-8') as f: read_content = f.read() print(f"โœ… File read successfully:") print(f"๐Ÿ“„ Content:\n{read_content}") except Exception as e: print(f"โŒ Read failed: {e}") print() # Test 3: Append to file print("3๏ธโƒฃ Testing append operation...") append_content = "\nAppended line 4\nAppended line 5" try: with open(test_file, 'a', encoding='utf-8') as f: f.write(append_content) file_size = test_file.stat().st_size print(f"โœ… Content appended successfully") print(f"๐Ÿ“ Added: {len(append_content)} characters") print(f"๐Ÿ“Š Total file size: {file_size} bytes") except Exception as e: print(f"โŒ Append failed: {e}") print() # Test 4: File info print("4๏ธโƒฃ Testing file info...") try: stat_info = test_file.stat() size_bytes = stat_info.st_size print(f"โœ… File info retrieved:") print(f"๐Ÿ“ Path: {test_file}") print(f"๐Ÿ“Š Type: File") print(f"๐Ÿ“ Size: {size_bytes} bytes") print(f"๐Ÿ” Permissions: {oct(stat_info.st_mode)[-3:]}") except Exception as e: print(f"โŒ File info failed: {e}") print() # Test 5: Copy file print("5๏ธโƒฃ Testing copy operation...") test_copy = test_dir / "test_copy.txt" try: import shutil shutil.copy2(test_file, test_copy) source_size = test_file.stat().st_size dest_size = test_copy.stat().st_size print(f"โœ… File copied successfully:") print(f"๐Ÿ“‚ From: {test_file}") print(f"๐Ÿ“ To: {test_copy}") print(f"๐Ÿ“ Size: {source_size} bytes") print(f"๐Ÿ” Verified: Source and destination match ({dest_size} bytes)") except Exception as e: print(f"โŒ Copy failed: {e}") print() # Test 6: Move file print("6๏ธโƒฃ Testing move operation...") test_move = test_dir / "test_moved.txt" try: test_file.rename(test_move) print(f"โœ… File moved successfully:") print(f"๐Ÿ“‚ From: {test_file}") print(f"๐Ÿ“ To: {test_move}") except Exception as e: print(f"โŒ Move failed: {e}") print() # Test 7: Create directory print("7๏ธโƒฃ Testing directory creation...") test_subdir = test_dir / "subdir" try: test_subdir.mkdir(parents=True, exist_ok=False) if test_subdir.exists() and test_subdir.is_dir(): print(f"โœ… Directory created successfully:") print(f"๐Ÿ“ Path: {test_subdir}") else: print(f"โŒ Directory creation failed") except Exception as e: print(f"โŒ Directory creation failed: {e}") print() # Test 8: List directory print("8๏ธโƒฃ Testing directory listing...") try: items = [] for item in sorted(test_dir.iterdir()): item_type = "๐Ÿ“" if item.is_dir() else "๐Ÿ“„" size_info = f" ({item.stat().st_size} bytes)" if item.is_file() else "" items.append(f"{item_type} {item.name}{size_info}") if not items: print(f"โœ… Directory is empty") else: print(f"โœ… Directory listing:") print(f"๐Ÿ“ Path: {test_dir}") print(f"๐Ÿ“‹ Items ({len(items)}):") for item in items: print(f" {item}") except Exception as e: print(f"โŒ Directory listing failed: {e}") print() # Test 9: Delete file print("9๏ธโƒฃ Testing file deletion...") try: if test_copy.exists(): test_copy.unlink() print(f"โœ… File deleted successfully:") print(f"๐Ÿ“ Path: {test_copy}") else: print(f"โŒ File not found: {test_copy}") except Exception as e: print(f"โŒ File deletion failed: {e}") print() # Test 10: Remove directory print("๐Ÿ”Ÿ Testing directory removal...") try: if test_subdir.exists() and test_subdir.is_dir(): test_subdir.rmdir() print(f"โœ… Directory deleted successfully:") print(f"๐Ÿ“ Path: {test_subdir}") else: print(f"โŒ Directory not found: {test_subdir}") except Exception as e: print(f"โŒ Directory deletion failed: {e}") print() print("โœ… All basic file operation tests completed!") if __name__ == "__main__": test_unified_file_operations()

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/itshare4u/AgentKnowledgeMCP'

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