Skip to main content
Glama

File System MCP Server

setup_kiro_integration.py12.2 kB
#!/usr/bin/env python3 """Complete setup for Kiro integration with File System MCP Server.""" import json import sys import os from pathlib import Path # Add src to Python path sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src')) from file_system_mcp_server.cli_utils import create_example_config def setup_kiro_integration(): """Set up complete Kiro integration.""" print("🚀 Setting up File System MCP Server for Kiro Chat Interface") print("=" * 60) current_dir = Path.cwd() # Step 1: Create optimized configuration for Kiro config_path = current_dir / "kiro-fs-config.json" print(f"\n📝 Step 1: Creating Kiro-optimized configuration") # Create a more permissive config for file editing kiro_config = { "backup_directory": str(current_dir / ".kiro_file_backups"), "max_file_size": 50 * 1024 * 1024, # 50MB - larger files for code projects "max_recursion_depth": 8, # Deeper recursion for project exploration "allowed_extensions": None, # Allow all file types "protected_paths": [ "/etc", "/usr", "/bin", "/sbin", "/System", # System paths "/Windows", "/Program Files", "/Program Files (x86)" # Windows paths ], "enable_backups": True, "log_level": "INFO" } try: with open(config_path, 'w') as f: json.dump(kiro_config, f, indent=2) print(f"✅ Configuration created: {config_path}") except Exception as e: print(f"❌ Failed to create config: {e}") return False # Step 2: Create Kiro MCP server configuration kiro_mcp_path = current_dir / ".kiro" / "settings" / "mcp.json" print(f"\n⚙️ Step 2: Creating Kiro MCP server configuration") # Ensure .kiro/settings directory exists kiro_mcp_path.parent.mkdir(parents=True, exist_ok=True) # Check if mcp.json already exists existing_config = {} if kiro_mcp_path.exists(): try: with open(kiro_mcp_path, 'r') as f: existing_config = json.load(f) print("📄 Found existing MCP configuration, will merge") except: print("⚠️ Existing MCP config found but couldn't read, creating new") # Create/update MCP configuration if "mcpServers" not in existing_config: existing_config["mcpServers"] = {} existing_config["mcpServers"]["file-system-operations"] = { "command": "python3", "args": [ "-m", "file_system_mcp_server.main", "--config", str(config_path) ], "cwd": str(current_dir), "env": { "PYTHONPATH": str(current_dir / "src") }, "disabled": False, "autoApprove": [ "read_file", "get_file_info", "list_directory" ] } try: with open(kiro_mcp_path, 'w') as f: json.dump(existing_config, f, indent=2) print(f"✅ Kiro MCP configuration updated: {kiro_mcp_path}") except Exception as e: print(f"❌ Failed to create Kiro MCP config: {e}") return False # Step 3: Create example files for testing print(f"\n📄 Step 3: Creating example files for testing") examples_dir = current_dir / "kiro_test_files" examples_dir.mkdir(exist_ok=True) # Create various test files test_files = { "empty_file.txt": "", "sample_note.md": """# Sample Note This is a sample markdown file that you can edit through Kiro chat. ## Tasks - [ ] Edit this file through Kiro - [ ] Add more content - [ ] Test file operations ## Code Example ```python def hello_world(): print("Hello from Kiro!") ``` """, "config_example.json": json.dumps({ "name": "My Project", "version": "1.0.0", "settings": { "debug": True, "theme": "dark" } }, indent=2), "todo_list.txt": """TODO List - Edit me through Kiro! [ ] Learn MCP server integration [ ] Test file editing through chat [ ] Create more complex projects [ ] Explore automation possibilities Notes: - This file can be edited through natural language - Kiro can read, modify, and update this content - All changes are automatically backed up """, "python_script.py": """#!/usr/bin/env python3 \"\"\"Sample Python script for Kiro editing.\"\"\" def main(): print("This script can be edited through Kiro chat!") # Add your code here pass if __name__ == "__main__": main() """ } created_files = [] for filename, content in test_files.items(): file_path = examples_dir / filename try: file_path.write_text(content) created_files.append(filename) print(f" ✅ Created: {filename}") except Exception as e: print(f" ❌ Failed to create {filename}: {e}") # Step 4: Create usage examples usage_examples_path = current_dir / "KIRO_USAGE_EXAMPLES.md" print(f"\n📚 Step 4: Creating usage examples") usage_content = f"""# Kiro File System MCP Server - Usage Examples ## 🚀 How to Use File Operations Through Kiro Chat Once the MCP server is set up, you can use natural language to interact with files: ### 📖 Reading Files **Chat with Kiro:** - "Read the contents of README.md" - "Show me what's in the todo_list.txt file" - "Can you read the config_example.json file?" **What happens:** Kiro uses the `read_file` tool to get file contents and metadata. ### 📝 Creating Files **Chat with Kiro:** - "Create a new file called 'my_notes.txt' with the content 'Hello World'" - "Make a Python script called 'test.py' with a simple hello world function" - "Create a JSON config file with basic settings" **What happens:** Kiro uses the `write_file` tool to create new files safely. ### 🔄 Updating Files **Chat with Kiro:** - "Add a new task to my todo_list.txt file" - "Update the Python script to include error handling" - "Modify the JSON config to enable debug mode" **What happens:** Kiro uses the `update_file` tool with automatic backup creation. ### 📋 Listing Files **Chat with Kiro:** - "List all Python files in this directory" - "Show me all markdown files recursively" - "What files are in the src directory?" **What happens:** Kiro uses the `list_directory` tool with pattern matching. ### 🗑️ Deleting Files **Chat with Kiro:** - "Delete the temporary file temp.txt" - "Remove the old backup directory" **What happens:** Kiro uses the `delete_file` tool (files moved to backup, not permanently deleted). ### ℹ️ Getting File Information **Chat with Kiro:** - "What's the size of my README.md file?" - "When was the config file last modified?" - "Show me details about the Python script" **What happens:** Kiro uses the `get_file_info` tool to get comprehensive metadata. ## 🎯 Example Conversations ### Example 1: Creating and Editing a Note File **You:** "Create a new file called 'project_ideas.md' with a heading and a few bullet points about project ideas" **Kiro:** *Uses write_file tool to create the file with structured content* **You:** "Now add a new section about AI projects to that file" **Kiro:** *Uses read_file to get current content, then update_file to add the new section* ### Example 2: Working with Code Files **You:** "Read the python_script.py file and tell me what it does" **Kiro:** *Uses read_file to analyze the code and explains its functionality* **You:** "Add error handling and logging to that script" **Kiro:** *Uses update_file to enhance the script with proper error handling* ### Example 3: Project Organization **You:** "List all Python files in this project and tell me their sizes" **Kiro:** *Uses list_directory with *.py pattern to find and analyze Python files* **You:** "Create a summary file listing all the main components of this project" **Kiro:** *Uses multiple list_directory calls and write_file to create a project summary* ## 🛠️ Available MCP Tools 1. **read_file** - Read any text file with metadata 2. **write_file** - Create new files with content 3. **update_file** - Modify existing files (with backup) 4. **list_directory** - Browse directories with filtering 5. **delete_file** - Safe deletion (moves to backup) 6. **get_file_info** - Get detailed file information ## 📁 Test Files Created The following test files are available in `{examples_dir}`: {chr(10).join(f"- **{filename}** - {('Empty file for testing' if not content else content.split(chr(10))[0][:50] + '...')}" for filename, content in test_files.items())} ## 🔒 Safety Features - **Automatic Backups**: All file changes create timestamped backups - **Protected Paths**: System directories are protected from modification - **File Size Limits**: Large files are handled safely - **Path Validation**: Prevents directory traversal attacks - **Rollback on Failure**: Failed operations restore from backup ## 🚀 Getting Started 1. **Restart Kiro** to load the new MCP server 2. **Test the connection**: "List files in the current directory" 3. **Try file operations**: "Read the sample_note.md file" 4. **Create something new**: "Create a file called 'test.txt' with hello world" ## 💡 Pro Tips - **Be specific**: "Add a function called 'calculate_sum' to math_utils.py" - **Use natural language**: "Make the JSON config more readable with better formatting" - **Ask for explanations**: "Read this code file and explain what it does" - **Combine operations**: "List all Python files, then read the largest one" ## 🔧 Troubleshooting If tools aren't working: 1. Check that the MCP server is running: Look for "file-system-operations" in Kiro's MCP panel 2. Verify configuration: The server should be enabled and not disabled 3. Check logs: Look for any error messages in Kiro's output 4. Test manually: Run `python3 test_real_filesystem.py` to verify core functionality ## 🎊 Have Fun! You can now edit files, create projects, and manage your file system entirely through natural language conversation with Kiro! """ try: with open(usage_examples_path, 'w') as f: f.write(usage_content) print(f"✅ Usage examples created: {usage_examples_path}") except Exception as e: print(f"❌ Failed to create usage examples: {e}") # Step 5: Final instructions print(f"\n" + "=" * 60) print("🎉 Kiro Integration Setup Complete!") print(f"\n📁 Files Created:") print(f" • {config_path.name} - MCP server configuration") print(f" • {kiro_mcp_path} - Kiro MCP settings (updated)") print(f" • {examples_dir.name}/ - Test files for editing") print(f" • {usage_examples_path.name} - Usage examples and guide") print(f"\n🚀 Next Steps:") print(f"1. **Install dependencies**: pip install mcp python-magic") print(f"2. **Restart Kiro** to load the new MCP server") print(f"3. **Test connection**: In Kiro chat, say 'List files in current directory'") print(f"4. **Try file editing**: 'Read the sample_note.md file'") print(f"5. **Create new content**: 'Create a file called test.txt with hello world'") print(f"\n💬 Example Chat Commands:") print(f" • 'Read the empty_file.txt and add some content to it'") print(f" • 'List all Python files in this project'") print(f" • 'Update the todo_list.txt with a new task'") print(f" • 'Create a new markdown file with project documentation'") print(f"\n🔧 Verification:") print(f" • Check Kiro's MCP panel for 'file-system-operations' server") print(f" • Server should show as 'Connected' and 'Enabled'") print(f" • Test with: python3 test_real_filesystem.py") print(f"\n📚 Read {usage_examples_path.name} for detailed usage examples!") return True if __name__ == "__main__": success = setup_kiro_integration() if not success: sys.exit(1) print(f"\n🎊 Ready to edit files through Kiro chat interface!")

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/chidvilas1234/Project-MCP'

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