Kotlin MCP Server

Kotlin MCP Server

Kotlin MCP Server for Android app development using OpenAI, Gemini, or OpenRouter. Enables AI-assisted coding via Aider, Gradle build/test integration, Kotlin LSP, and Docker-based portability.

Category
访问服务器

README

Enterprise Kotlin Android MCP Server

A comprehensive Model Context Protocol (MCP) server that provides AI agents with enterprise-grade access to Kotlin-based Android development projects. This server enables context-aware assistance with advanced security, privacy compliance, AI integration, and comprehensive development tools.


🌟 Enterprise Features Overview

🔒 Security & Privacy Compliance

  • GDPR Compliance - Complete implementation with consent management, data portability, right to erasure
  • HIPAA Compliance - Healthcare-grade security with audit logging, access controls, encryption
  • Data Encryption - AES-256 encryption with PBKDF2 key derivation for sensitive data
  • Audit Trails - Comprehensive logging with compliance flags and security event tracking
  • Privacy by Design - Built-in privacy protection for all operations

🤖 AI/ML Integration

  • Local LLM Support - Ollama, LocalAI, and self-hosted transformers
  • External LLM APIs - OpenAI GPT-4, Anthropic Claude, custom endpoints
  • AI-Powered Code Analysis - Security, performance, and complexity analysis
  • Intelligent Code Generation - Context-aware Kotlin/Android code creation
  • ML Model Integration - TensorFlow Lite, ONNX, PyTorch Mobile for Android apps

📁 Advanced File Management

  • Enterprise File Operations - Backup, restore, sync, encrypt, decrypt with audit trails
  • Real-time Synchronization - File system watchers with automatic sync
  • Cloud Storage Integration - AWS S3, Google Cloud, Azure with end-to-end encryption
  • Smart File Classification - Automatic sensitive data detection and encryption
  • Version Control - Git-aware operations with conflict resolution

🌐 External API Integration

  • Comprehensive Auth Support - API Keys, OAuth 2.0, JWT, Basic Auth
  • Security Features - Rate limiting, request logging, response validation
  • Real-time Monitoring - API usage metrics, performance tracking, cost analysis
  • Compliance Validation - GDPR/HIPAA compliant API handling

🏗️ Advanced Android Development

  • Architecture Patterns - MVVM, Clean Architecture, Dependency Injection
  • Modern UI Development - Jetpack Compose, custom views, complex layouts
  • Database Integration - Room with encryption, migration handling
  • Network Layer - Retrofit, GraphQL, WebSocket support
  • Testing Framework - Comprehensive test generation and execution

🚀 Quick Start & Installation

What's New in v2.0

🎯 Zero-Configuration Setup: Our enhanced installation script eliminates all manual configuration steps!

Before (v1.x):

  • ❌ Manual path editing in config files
  • ❌ Environment variable setup required
  • ❌ Platform-specific configuration steps
  • ❌ Risk of configuration errors

After (v2.0):

  • One Command Setup: python3 install.py
  • Automatic Path Detection: No manual editing needed
  • Platform-Specific Configs: Optimized for Claude, VS Code, etc.
  • Interactive & Non-Interactive: Works for all user types
  • Smart Environment Variables: Uses ${workspaceFolder}, ${workspaceRoot} correctly

📋 System Requirements

  • Python 3.8+ (3.9+ recommended)
  • pip (Python package manager)
  • Git (for cloning repository)
  • IDE with MCP support (VS Code, JetBrains IDEs, Claude Desktop)

🔧 Installation Steps

1. Clone Repository

git clone <your-repo-url>
cd kotlin-mcp-server

2. Automated Installation & Configuration

The project includes an enhanced installation script that handles all configuration automatically:

# Interactive installation (recommended for first-time users)
python3 install.py

# Non-interactive installation with specific configuration
python3 install.py [install_type] [project_path] [server_name] [use_env_vars]

# Show all available options
python3 install.py --help

Installation Types:

  • 1 - Portable: Run directly from project directory
  • 2 - System: Install command to PATH (kotlin-android-mcp)
  • 3 - Module: Enable python -m kotlin_mcp_server

Configuration Examples:

# Interactive setup (asks for your preferences)
python3 install.py 1

# Portable with fixed Android project path
python3 install.py 1 /Users/yourname/AndroidStudioProjects/MyApp

# System installation with dynamic environment variables
python3 install.py 2 none my-android-server true

# Module installation with custom server name
python3 install.py 3 /path/to/project kotlin-dev false

What the installer does:

  • Installs all Python dependencies from requirements.txt
  • Creates platform-specific config files (Claude, VS Code, generic)
  • Sets up proper file permissions for scripts
  • Configures environment variables based on your choices
  • Eliminates manual path updates in configuration files
  • Provides clear integration instructions for your setup

3. Manual Installation (Alternative)

If you prefer manual installation:

# Install core dependencies
pip install -r requirements.txt

# Optional: Install AI/ML dependencies for advanced features
pip install openai anthropic transformers torch

# Verify installation
python3 -c "import kotlin_mcp_server; print('✅ Installation successful')"

Key Dependencies Installed:

  • Core MCP: python-dotenv, pydantic
  • Security: cryptography, bcrypt, PyJWT
  • Database: aiosqlite, sqlalchemy
  • HTTP Clients: aiohttp, httpx
  • File Management: aiofiles, watchdog
  • Testing: pytest, pytest-asyncio, coverage
  • Code Quality: black, flake8, pylint, mypy
  • Security Tools: bandit, safety

4. IDE Integration Setup

After installation, the script generates ready-to-use configuration files:

  • mcp_config_claude.json - For Claude Desktop
  • mcp_config_vscode.json - For VS Code and Cursor
  • mcp_config.json - For other MCP clients

Integration Instructions:

🔹 Claude Desktop: Copy content from mcp_config_claude.json to:

  • Mac: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/claude/claude_desktop_config.json

🔹 VS Code/Cursor: Add to your VS Code settings.json:

{
  "mcp.server.configFiles": [
    "/absolute/path/to/mcp_config_vscode.json"
  ]
}

🔹 Other IDEs: Use mcp_config.json with your MCP client

5. Environment Configuration (Advanced)

For advanced users who need custom environment setup: Create a .env file in the project root (only needed for advanced configurations):

# Copy the example file and customize
cp .env.example .env

# Edit with your settings
nano .env  # or your preferred editor

Optional Variables:

# Security (generate strong password)
MCP_ENCRYPTION_PASSWORD=$(openssl rand -base64 32)
COMPLIANCE_MODE=gdpr,hipaa

# Optional: AI Integration
OPENAI_API_KEY=your-openai-api-key-here
ANTHROPIC_API_KEY=your-anthropic-api-key-here

💡 Note: The installation script automatically configures project paths and server settings, so manual environment configuration is only needed for advanced features like AI integration or custom security settings.

6. Install Required IDE Extensions/Plugins

See the Plugin Requirements section below for IDE-specific extensions.

7. Test Installation

# Test the server with your configured setup
# If you used a fixed project path during installation:
python3 kotlin_mcp_server.py

# If you're using dynamic/environment variables:
python3 kotlin_mcp_server.py /path/to/android/project

# For system installation:
kotlin-android-mcp

# For module installation:
python3 -m kotlin_mcp_server

# Validate configuration (optional)
python3 validate_config.py

# Run comprehensive tests (optional)
python test_mcp_comprehensive.py

# Test VS Code bridge server (optional)
python3 vscode_bridge.py &
sleep 2
curl http://localhost:8080/health
# Should return: {"status": "healthy", ...}
kill %1  # Stop background bridge server

Quick Setup Commands

# Complete setup with one command (interactive)
python3 install.py

# Quick setup for development environment
make setup-dev

# Quick validation
make dev-check

# Full quality pipeline
make ci

# Test VS Code bridge server (optional)
python3 vscode_bridge.py --test-mode

🎯 Installation Summary

The enhanced installation process has eliminated the need for manual configuration:

Before (Manual): Users had to manually edit config files, find paths, update environment variables
After (Automated): One command creates everything ready-to-use

Key Improvements:

  • 🚀 Zero Manual Configuration: No more path updates or variable editing
  • 🎛️ Interactive & Non-Interactive: Works in both modes for all users
  • 🔧 Platform-Specific Configs: Generates optimized files for each IDE/client
  • 📋 Clear Instructions: Provides exact integration steps for your setup
  • Smart Defaults: Handles environment variables intelligently

📚 Comprehensive Usage Guide

Complete Tool Reference

The Kotlin MCP Server provides 31 comprehensive tools for Android development, organized by category:

Core Development Tools

1. gradle_build - Build Android Projects

Executes Gradle build tasks for your Android project.

{
  "name": "gradle_build",
  "arguments": {
    "task": "assembleDebug",
    "clean_build": false,
    "parallel": true
  }
}

Parameters:

  • task (string): Gradle task to execute (e.g., "assembleDebug", "build", "test")
  • clean_build (boolean, optional): Whether to clean before building
  • parallel (boolean, optional): Enable parallel execution

Usage Examples:

# Build debug APK
{"name": "gradle_build", "arguments": {"task": "assembleDebug"}}

# Clean and build release
{"name": "gradle_build", "arguments": {"task": "assembleRelease", "clean_build": true}}

# Run all tests
{"name": "gradle_build", "arguments": {"task": "test"}}
2. run_tests - Execute Test Suites

Runs unit tests, integration tests, or UI tests with comprehensive reporting.

{
  "name": "run_tests",
  "arguments": {
    "test_type": "unit",
    "test_class": "UserRepositoryTest",
    "generate_report": true
  }
}

Parameters:

  • test_type (string): "unit", "integration", "ui", or "all"
  • test_class (string, optional): Specific test class to run
  • generate_report (boolean, optional): Generate HTML test report
3. create_kotlin_file - Generate Kotlin Files

Creates structured Kotlin files with proper package declaration and imports.

{
  "name": "create_kotlin_file",
  "arguments": {
    "file_path": "src/main/kotlin/com/example/User.kt",
    "class_name": "User",
    "class_type": "data_class",
    "properties": ["id: String", "name: String", "email: String"],
    "package_name": "com.example.model"
  }
}

Parameters:

  • file_path (string): Relative path for the new file
  • class_name (string): Name of the main class
  • class_type (string): "class", "data_class", "sealed_class", "object", "interface"
  • properties (array, optional): List of properties for data classes
  • package_name (string, optional): Package declaration
4. create_layout_file - Generate XML Layouts

Creates Android XML layout files with proper structure.

{
  "name": "create_layout_file",
  "arguments": {
    "file_path": "src/main/res/layout/activity_main.xml",
    "layout_type": "activity",
    "root_element": "LinearLayout",
    "include_common_attributes": true
  }
}
5. analyze_project - Project Analysis

Provides comprehensive analysis of your Android project structure, dependencies, and architecture.

{
  "name": "analyze_project",
  "arguments": {
    "analysis_type": "architecture",
    "include_dependencies": true,
    "check_best_practices": true
  }
}

Analysis Types:

  • architecture: Overall project structure and patterns
  • dependencies: Gradle dependencies and versions
  • security: Security vulnerabilities and best practices
  • performance: Performance bottlenecks and optimizations
6. format_code - Code Formatting

Formats Kotlin code according to style guidelines.

{
  "name": "format_code",
  "arguments": {
    "file_path": "src/main/kotlin/MainActivity.kt",
    "style_guide": "ktlint"
  }
}
7. run_lint - Static Code Analysis

Runs lint analysis to detect code issues.

{
  "name": "run_lint",
  "arguments": {
    "lint_tool": "detekt",
    "fail_on_warnings": false,
    "generate_report": true
  }
}
8. generate_docs - Documentation Generation

Generates project documentation in various formats.

{
  "name": "generate_docs",
  "arguments": {
    "doc_type": "kdoc",
    "output_format": "html",
    "include_private": false
  }
}

UI Development Tools

9. create_compose_component - Jetpack Compose Components

Generates Jetpack Compose UI components with best practices.

{
  "name": "create_compose_component",
  "arguments": {
    "component_name": "UserCard",
    "component_type": "composable",
    "file_path": "src/main/kotlin/ui/components/UserCard.kt",
    "parameters": [
      "user: User",
      "onClick: () -> Unit"
    ],
    "include_preview": true,
    "material_design": "material3"
  }
}

Component Types:

  • composable: Standard composable function
  • stateful: Composable with internal state
  • stateless: Pure UI composable
  • layout: Layout composable with children
10. create_custom_view - Custom Android Views

Creates custom View classes with proper lifecycle management.

{
  "name": "create_custom_view",
  "arguments": {
    "view_name": "CircularProgressView",
    "base_class": "View",
    "file_path": "src/main/kotlin/ui/views/CircularProgressView.kt",
    "custom_attributes": [
      {"name": "progressColor", "type": "color"},
      {"name": "strokeWidth", "type": "dimension"}
    ]
  }
}

Architecture & Pattern Tools

11. setup_mvvm_architecture - MVVM Implementation

Sets up complete MVVM architecture with ViewModel, Repository, and UI layers.

{
  "name": "setup_mvvm_architecture",
  "arguments": {
    "feature_name": "UserProfile",
    "package_name": "com.example.userprofile",
    "include_repository": true,
    "include_use_cases": true,
    "state_management": "compose"
  }
}

Generated Files:

  • ViewModel with state management
  • Repository with data source abstraction
  • Use cases for business logic
  • UI composables or fragments
  • State classes and sealed classes for events
12. setup_dependency_injection - DI Framework Setup

Configures dependency injection using Hilt or Dagger.

{
  "name": "setup_dependency_injection",
  "arguments": {
    "di_framework": "hilt",
    "modules": ["DatabaseModule", "NetworkModule", "RepositoryModule"],
    "application_class": "MyApplication"
  }
}
13. setup_room_database - Database Setup

Creates Room database implementation with entities, DAOs, and migrations.

{
  "name": "setup_room_database",
  "arguments": {
    "database_name": "AppDatabase",
    "entities": [
      {
        "name": "User",
        "fields": [
          {"name": "id", "type": "String", "primaryKey": true},
          {"name": "name", "type": "String"},
          {"name": "email", "type": "String"}
        ]
      }
    ],
    "version": 1,
    "enable_encryption": true
  }
}
14. setup_retrofit_api - Network Layer

Sets up Retrofit API interfaces with proper error handling and interceptors.

{
  "name": "setup_retrofit_api",
  "arguments": {
    "base_url": "https://api.example.com/",
    "endpoints": [
      {
        "name": "getUser",
        "method": "GET",
        "path": "users/{id}",
        "response_type": "User"
      }
    ],
    "include_interceptors": ["logging", "auth", "retry"],
    "enable_cache": true
  }
}

Security & Compliance Tools

15. encrypt_sensitive_data - Data Encryption

Encrypts sensitive data using industry-standard encryption.

{
  "name": "encrypt_sensitive_data",
  "arguments": {
    "data": "Patient: John Doe, SSN: 123-45-6789",
    "data_type": "phi",
    "compliance_level": "hipaa",
    "encryption_algorithm": "AES-256"
  }
}
16. implement_gdpr_compliance - GDPR Implementation

Implements complete GDPR compliance framework.

{
  "name": "implement_gdpr_compliance",
  "arguments": {
    "package_name": "com.example.app",
    "features": [
      "consent_management",
      "data_portability",
      "right_to_erasure",
      "privacy_policy",
      "data_breach_notification"
    ],
    "supported_languages": ["en", "de", "fr"],
    "include_ui": true
  }
}

Generated Components:

  • Consent management UI and logic
  • Data export functionality
  • User data deletion workflows
  • Privacy policy templates
  • Audit logging system
17. implement_hipaa_compliance - HIPAA Implementation

Implements HIPAA-compliant security measures.

{
  "name": "implement_hipaa_compliance",
  "arguments": {
    "package_name": "com.healthcare.app",
    "features": [
      "audit_logging",
      "access_controls",
      "encryption",
      "secure_messaging",
      "risk_assessment"
    ],
    "minimum_password_strength": "high",
    "session_timeout": 900
  }
}
18. setup_secure_storage - Secure Data Storage

Configures encrypted storage for sensitive data.

{
  "name": "setup_secure_storage",
  "arguments": {
    "storage_type": "room_encrypted",
    "package_name": "com.example.app",
    "data_classification": "restricted",
    "key_management": "android_keystore"
  }
}

AI/ML Integration Tools

19. query_llm - Language Model Queries

Queries local or remote language models for code assistance.

{
  "name": "query_llm",
  "arguments": {
    "prompt": "Generate a Kotlin data class for User with validation",
    "llm_provider": "local",
    "model": "codellama",
    "privacy_mode": true,
    "max_tokens": 1000,
    "temperature": 0.2
  }
}

Supported Providers:

  • local: Ollama, LocalAI
  • openai: GPT-4, GPT-3.5
  • anthropic: Claude models
  • custom: Custom API endpoints
20. analyze_code_with_ai - AI Code Analysis

Uses AI to analyze code for various aspects.

{
  "name": "analyze_code_with_ai",
  "arguments": {
    "file_path": "src/main/kotlin/UserManager.kt",
    "analysis_type": "security",
    "use_local_model": true,
    "detailed_report": true
  }
}

Analysis Types:

  • security: Security vulnerabilities and best practices
  • performance: Performance optimization suggestions
  • bugs: Potential bug detection
  • style: Code style improvements
  • complexity: Code complexity analysis
  • maintainability: Maintainability assessment
21. generate_code_with_ai - AI Code Generation

Generates code using AI based on natural language descriptions.

{
  "name": "generate_code_with_ai",
  "arguments": {
    "description": "Login screen with biometric authentication and error handling",
    "code_type": "compose_screen",
    "framework": "compose",
    "compliance_requirements": ["gdpr"],
    "include_tests": true,
    "style_guide": "material3"
  }
}

File Management Tools

22. manage_project_files - Advanced File Operations

Performs comprehensive file management operations.

{
  "name": "manage_project_files",
  "arguments": {
    "operation": "backup",
    "include_build_files": false,
    "compression": "zip",
    "encryption": true,
    "backup_location": "/path/to/backup",
    "exclude_patterns": ["*.tmp", "build/", ".gradle/"]
  }
}

Operations:

  • backup: Create encrypted backups
  • restore: Restore from backup
  • sync: Synchronize with cloud storage
  • encrypt: Encrypt sensitive files
  • decrypt: Decrypt files (with proper authorization)
  • organize: Organize files by type/category
23. setup_cloud_sync - Cloud Storage Integration

Configures cloud storage synchronization with encryption.

{
  "name": "setup_cloud_sync",
  "arguments": {
    "cloud_provider": "aws_s3",
    "bucket_name": "my-app-backup",
    "encryption_in_transit": true,
    "encryption_at_rest": true,
    "sync_frequency": "hourly",
    "compliance_mode": "gdpr"
  }
}

API Integration Tools

24. setup_external_api - API Configuration

Sets up external API integrations with security and monitoring.

{
  "name": "setup_external_api",
  "arguments": {
    "api_name": "PaymentAPI",
    "base_url": "https://api.payment.com/v1/",
    "auth_type": "oauth2",
    "auth_config": {
      "client_id": "your_client_id",
      "scopes": ["payments", "users"]
    },
    "rate_limiting": {
      "requests_per_minute": 100,
      "burst_limit": 10
    },
    "security_features": ["request_signing", "response_validation"],
    "monitoring": true
  }
}
25. call_external_api - API Calls

Makes secured API calls with comprehensive monitoring.

{
  "name": "call_external_api",
  "arguments": {
    "api_name": "PaymentAPI",
    "endpoint": "/charges",
    "method": "POST",
    "data": {
      "amount": 1000,
      "currency": "USD",
      "description": "Test payment"
    },
    "headers": {
      "Content-Type": "application/json"
    },
    "timeout": 30,
    "retry_config": {
      "max_retries": 3,
      "backoff_strategy": "exponential"
    }
  }
}

Testing Tools

26. generate_unit_tests - Unit Test Generation

Generates comprehensive unit tests for Kotlin classes.

{
  "name": "generate_unit_tests",
  "arguments": {
    "file_path": "src/main/kotlin/UserRepository.kt",
    "test_framework": "junit5",
    "mocking_framework": "mockk",
    "include_edge_cases": true,
    "test_coverage_target": 90
  }
}
27. setup_ui_testing - UI Test Configuration

Sets up UI testing framework with Espresso or Compose testing.

{
  "name": "setup_ui_testing",
  "arguments": {
    "testing_framework": "compose",
    "include_accessibility_tests": true,
    "include_screenshot_tests": true,
    "test_data_setup": "in_memory_database"
  }
}

🚀 Quick Start Tool Examples

Complete Project Setup Workflow

Here's a step-by-step workflow to set up a new Android project with enterprise features:

# 1. Analyze existing project structure
{
  "name": "analyze_project",
  "arguments": {
    "analysis_type": "architecture",
    "include_dependencies": true
  }
}

# 2. Set up MVVM architecture
{
  "name": "setup_mvvm_architecture", 
  "arguments": {
    "feature_name": "UserManagement",
    "package_name": "com.example.users",
    "include_repository": true,
    "state_management": "compose"
  }
}

# 3. Configure dependency injection
{
  "name": "setup_dependency_injection",
  "arguments": {
    "di_framework": "hilt",
    "modules": ["DatabaseModule", "NetworkModule"]
  }
}

# 4. Set up secure database
{
  "name": "setup_room_database",
  "arguments": {
    "database_name": "AppDatabase",
    "entities": [
      {
        "name": "User",
        "fields": [
          {"name": "id", "type": "String", "primaryKey": true},
          {"name": "name", "type": "String"},
          {"name": "email", "type": "String"}
        ]
      }
    ],
    "enable_encryption": true
  }
}

# 5. Implement compliance (if required)
{
  "name": "implement_gdpr_compliance",
  "arguments": {
    "package_name": "com.example.app",
    "features": ["consent_management", "data_portability"],
    "include_ui": true
  }
}

# 6. Generate UI components
{
  "name": "create_compose_component",
  "arguments": {
    "component_name": "UserListScreen",
    "component_type": "stateful",
    "include_preview": true,
    "material_design": "material3"
  }
}

# 7. Set up API integration
{
  "name": "setup_retrofit_api",
  "arguments": {
    "base_url": "https://api.example.com/",
    "endpoints": [
      {
        "name": "getUsers",
        "method": "GET", 
        "path": "users",
        "response_type": "List<User>"
      }
    ],
    "include_interceptors": ["logging", "auth"]
  }
}

# 8. Generate comprehensive tests
{
  "name": "generate_unit_tests",
  "arguments": {
    "file_path": "src/main/kotlin/UserRepository.kt",
    "test_framework": "junit5",
    "include_edge_cases": true
  }
}

# 9. Build and test
{
  "name": "gradle_build",
  "arguments": {
    "task": "assembleDebug",
    "clean_build": true
  }
}

{
  "name": "run_tests",
  "arguments": {
    "test_type": "all",
    "generate_report": true
  }
}

AI-Powered Development Examples

# Generate a complete login feature using AI
{
  "name": "generate_code_with_ai",
  "arguments": {
    "description": "Complete login feature with email/password, biometric authentication, remember me option, forgot password flow, and proper error handling",
    "code_type": "feature",
    "framework": "compose",
    "compliance_requirements": ["gdpr"],
    "include_tests": true
  }
}

# Analyze existing code for security issues
{
  "name": "analyze_code_with_ai",
  "arguments": {
    "file_path": "src/main/kotlin/AuthManager.kt",
    "analysis_type": "security",
    "detailed_report": true
  }
}

# Get AI assistance for complex implementation
{
  "name": "query_llm",
  "arguments": {
    "prompt": "How do I implement secure biometric authentication in Android with fallback to PIN? Include error handling for different biometric states.",
    "llm_provider": "local",
    "privacy_mode": true
  }
}

🛠️ Tool Usage Best Practices

File Path Conventions

Always use relative paths from your project root:

# ✅ Correct
"file_path": "src/main/kotlin/com/example/User.kt"

# ❌ Incorrect  
"file_path": "/absolute/path/to/User.kt"

Package Naming

Follow Android package naming conventions:

# ✅ Correct
"package_name": "com.company.app.feature.user"

# ❌ Incorrect
"package_name": "User.Package"

Security Best Practices

  • Always use encryption for sensitive data
  • Implement proper compliance features from the start
  • Use secure storage for API keys and secrets
  • Enable audit logging for compliance requirements

Performance Optimization

  • Use parallel: true for Gradle builds when possible
  • Generate tests incrementally rather than all at once
  • Use local LLM providers for privacy-sensitive code analysis
  • Enable caching for API setups

Error Handling

All tools provide comprehensive error information:

{
  "success": false,
  "error": "File already exists",
  "details": {
    "file_path": "src/main/kotlin/User.kt",
    "suggestion": "Use a different file name or set overwrite: true"
  }
}

📊 Tool Response Formats

Success Response

{
  "success": true,
  "result": {
    "files_created": ["User.kt", "UserTest.kt"],
    "lines_of_code": 125,
    "compilation_status": "success"
  },
  "metadata": {
    "execution_time": "2.3s",
    "tools_used": ["kotlin_compiler", "test_generator"]
  }
}

Error Response

{
  "success": false,
  "error": "Compilation failed",
  "details": {
    "error_type": "compilation_error",
    "line_number": 23,
    "message": "Unresolved reference: undefinedVariable",
    "suggestions": [
      "Check variable declaration",
      "Verify imports"
    ]
  }
}

�🔒 Security & Privacy Features

GDPR Compliance Implementation

{
  "name": "implement_gdpr_compliance",
  "arguments": {
    "package_name": "com.example.app",
    "features": [
      "consent_management",
      "data_portability", 
      "right_to_erasure",
      "privacy_policy"
    ]
  }
}

Generated Features:

  • Consent management UI components
  • Data export functionality
  • User data deletion workflows
  • Privacy policy templates
  • Legal basis tracking

HIPAA Compliance Implementation

{
  "name": "implement_hipaa_compliance",
  "arguments": {
    "package_name": "com.healthcare.app",
    "features": [
      "audit_logging",
      "access_controls",
      "encryption",
      "secure_messaging"
    ]
  }
}

Generated Features:

  • Comprehensive audit logging system
  • Role-based access control framework
  • PHI encryption utilities
  • Secure messaging infrastructure
  • Risk assessment tools

Data Encryption

{
  "name": "encrypt_sensitive_data",
  "arguments": {
    "data": "Patient: John Doe, SSN: 123-45-6789",
    "data_type": "phi",
    "compliance_level": "hipaa"
  }
}

Secure Storage Setup

{
  "name": "setup_secure_storage",
  "arguments": {
    "storage_type": "room_encrypted",
    "package_name": "com.example.app",
    "data_classification": "restricted"
  }
}

🤖 AI Integration Features

Local LLM Queries

{
  "name": "query_llm", 
  "arguments": {
    "prompt": "Generate a Kotlin data class for User with validation",
    "llm_provider": "local",
    "privacy_mode": true,
    "max_tokens": 1000
  }
}

AI-Powered Code Analysis

{
  "name": "analyze_code_with_ai",
  "arguments": {
    "file_path": "src/main/UserManager.kt",
    "analysis_type": "security",
    "use_local_model": true
  }
}

Analysis Types:

  • security - Vulnerability and security best practices
  • performance - Performance optimization suggestions
  • bugs - Potential bug detection
  • style - Code style and formatting improvements
  • complexity - Code complexity analysis

AI Code Generation

{
  "name": "generate_code_with_ai",
  "arguments": {
    "description": "Login screen with biometric authentication",
    "code_type": "component",
    "framework": "compose",
    "compliance_requirements": ["gdpr", "hipaa"]
  }
}

Code Types:

  • class - Kotlin classes with methods
  • function - Standalone functions
  • layout - XML layout files
  • test - Unit and integration tests
  • component - Jetpack Compose components

📁 File Management Operations

Advanced Backup

{
  "name": "manage_project_files",
  "arguments": {
    "operation": "backup",
    "target_path": "./src",
    "destination": "./backups",
    "encryption_level": "high"
  }
}

Real-time Synchronization

{
  "name": "manage_project_files",
  "arguments": {
    "operation": "sync",
    "target_path": "./src",
    "destination": "./remote-sync",
    "sync_strategy": "real_time"
  }
}

Cloud Storage Sync

{
  "name": "setup_cloud_sync",
  "arguments": {
    "cloud_provider": "aws",
    "sync_strategy": "scheduled",
    "encryption_in_transit": true,
    "compliance_mode": "gdpr"
  }
}

Supported Operations:

  • backup - Create encrypted backups with manifests
  • restore - Restore from backup with integrity checking
  • sync - Two-way synchronization with conflict resolution
  • encrypt - Encrypt sensitive files in place
  • decrypt - Decrypt files with proper authorization
  • archive - Create compressed archives
  • extract - Extract archives with validation
  • search - Content-based file discovery
  • analyze - File structure and usage analysis

🌐 External API Integration

API Integration Setup

{
  "name": "integrate_external_api",
  "arguments": {
    "api_name": "HealthRecordsAPI",
    "base_url": "https://api.healthrecords.com",
    "auth_type": "oauth",
    "security_features": [
      "rate_limiting",
      "request_logging", 
      "response_validation"
    ],
    "compliance_requirements": ["hipaa"]
  }
}

API Usage Monitoring

{
  "name": "monitor_api_usage",
  "arguments": {
    "api_name": "HealthRecordsAPI",
    "metrics": [
      "latency",
      "error_rate",
      "usage_volume",
      "cost"
    ],
    "alert_thresholds": {
      "error_rate": 5.0,
      "latency_ms": 2000
    }
  }
}

Authentication Types:

  • none - No authentication required
  • api_key - API key in header or query
  • oauth - OAuth 2.0 flow
  • jwt - JSON Web Token
  • basic - Basic HTTP authentication

🏗️ Advanced Android Development

MVVM Architecture Setup

{
  "name": "setup_mvvm_architecture",
  "arguments": {
    "feature_name": "UserProfile",
    "package_name": "com.example.app",
    "include_repository": true,
    "include_use_cases": true,
    "data_source": "both"
  }
}

Jetpack Compose Components

{
  "name": "create_compose_component",
  "arguments": {
    "file_path": "ui/components/LoginForm.kt",
    "component_name": "LoginForm",
    "component_type": "component",
    "package_name": "com.example.ui",
    "uses_state": true,
    "uses_navigation": false
  }
}

Room Database Setup

{
  "name": "setup_room_database",
  "arguments": {
    "database_name": "AppDatabase",
    "package_name": "com.example.data",
    "entities": ["User", "Profile", "Settings"],
    "include_migration": true
  }
}

Retrofit API Client

{
  "name": "setup_retrofit_api",
  "arguments": {
    "api_name": "UserApiService",
    "package_name": "com.example.network",
    "base_url": "https://api.example.com",
    "endpoints": [
      {
        "method": "GET",
        "path": "/users/{id}",
        "name": "getUser"
      }
    ],
    "include_interceptors": true
  }
}

Dependency Injection (Hilt)

{
  "name": "setup_dependency_injection",
  "arguments": {
    "module_name": "NetworkModule",
    "package_name": "com.example.di",
    "injection_type": "network"
  }
}

ML Model Integration

{
  "name": "integrate_ml_model",
  "arguments": {
    "model_type": "tflite",
    "model_path": "assets/model.tflite",
    "use_case": "image_classification",
    "privacy_preserving": true
  }
}

🛠️ Tool-Specific Troubleshooting

Gradle Build Issues

# Tool: gradle_build
# Common solutions:

# 1. Clear Gradle cache
{
  "name": "gradle_build",
  "arguments": {
    "task": "clean",
    "clean_build": true
  }
}

# 2. Check Java version
echo $JAVA_HOME
java -version

# 3. Fix permission issues (macOS/Linux)
chmod +x gradlew

# 4. Enable verbose output for debugging
{
  "name": "gradle_build",
  "arguments": {
    "task": "assembleDebug",
    "gradle_args": ["--debug", "--stacktrace"]
  }
}

AI Integration Issues

# Tool: query_llm, analyze_code_with_ai, generate_code_with_ai

# Local LLM not responding
curl http://localhost:11434/api/generate -d '{"model":"codellama","prompt":"test"}'

# API key issues
python3 -c "import os; print('OpenAI:', bool(os.getenv('OPENAI_API_KEY')))"

# Privacy mode for sensitive code
{
  "name": "query_llm",
  "arguments": {
    "prompt": "Your prompt here",
    "llm_provider": "local",  # Force local processing
    "privacy_mode": true      # No external API calls
  }
}

File Creation Issues

# Tool: create_kotlin_file, create_layout_file, create_compose_component

# Permission denied
sudo chown -R $(whoami):$(whoami) src/

# File already exists
{
  "name": "create_kotlin_file",
  "arguments": {
    "file_path": "src/main/kotlin/User.kt",
    "overwrite": true  # Force overwrite
  }
}

# Invalid package structure
# Ensure your file path matches package structure:
# File: src/main/kotlin/com/example/User.kt
# Package: com.example

Security Tool Issues

# Tool: encrypt_sensitive_data, implement_gdpr_compliance

# Cryptography not available
pip install cryptography>=41.0.0

# Test encryption
python3 -c "from cryptography.fernet import Fernet; print('✅ Encryption available')"

# GDPR compliance setup
{
  "name": "implement_gdpr_compliance",
  "arguments": {
    "package_name": "com.example.app",
    "features": ["consent_management"],  # Start with basic features
    "dry_run": true  # Test mode first
  }
}

Database Setup Issues

# Tool: setup_room_database, setup_secure_storage

# Check Android Room version compatibility
grep "room_version" build.gradle

# Test database creation
{
  "name": "setup_room_database",
  "arguments": {
    "database_name": "TestDB",
    "entities": [{"name": "TestEntity", "fields": [{"name": "id", "type": "String", "primaryKey": true}]}],
    "validate_only": true  # Check schema without creating files
  }
}

Network/API Issues

# Tool: setup_retrofit_api, call_external_api

# Test network connectivity
curl -I https://api.example.com/

# Verify SSL certificates
openssl s_client -connect api.example.com:443

# Debug API calls
{
  "name": "call_external_api",
  "arguments": {
    "api_name": "TestAPI",
    "endpoint": "/health",
    "method": "GET",
    "debug_mode": true,  # Enable detailed logging
    "timeout": 10        # Shorter timeout for testing
  }
}

🧪 Testing & Quality Assurance

Comprehensive Test Generation

{
  "name": "generate_test_suite",
  "arguments": {
    "class_to_test": "UserRepository",
    "test_type": "unit",
    "include_mockito": true,
    "test_coverage": "comprehensive"
  }
}

Test Types:

  • unit - Unit tests with mocking
  • integration - Integration tests with real dependencies
  • ui - UI tests with Espresso

🏥 Industry-Specific Examples

Healthcare Application

# 1. Implement HIPAA compliance
{
  "name": "implement_hipaa_compliance",
  "arguments": {
    "package_name": "com.health.tracker",
    "features": ["audit_logging", "encryption", "access_controls"]
  }
}

# 2. Setup secure storage for PHI
{
  "name": "setup_secure_storage", 
  "arguments": {
    "storage_type": "room_encrypted",
    "data_classification": "restricted"
  }
}

# 3. Generate patient form with AI
{
  "name": "generate_code_with_ai",
  "arguments": {
    "description": "Patient intake form with validation",
    "compliance_requirements": ["hipaa"]
  }
}

Financial Application

# 1. Implement GDPR compliance
{
  "name": "implement_gdpr_compliance",
  "arguments": {
    "features": ["consent_management", "data_portability"]
  }
}

# 2. Setup secure API integration
{
  "name": "integrate_external_api",
  "arguments": {
    "api_name": "PaymentAPI",
    "auth_type": "oauth",
    "security_features": ["rate_limiting", "request_logging"]
  }
}

# 3. Enable cloud backup with encryption
{
  "name": "setup_cloud_sync",
  "arguments": {
    "cloud_provider": "aws",
    "encryption_in_transit": true,
    "compliance_mode": "gdpr"
  }
}

🔧 Configuration & Deployment

Docker Deployment

# Build and run with Docker
docker-compose up -d

# Or build manually
docker build -t kotlin-mcp-server .
docker run -p 8000:8000 -v $(pwd):/workspace kotlin-mcp-server

AI Agent Integration

Claude Desktop

Add to ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "kotlin-android": {
      "command": "python",
      "args": ["/path/to/kotlin-mcp-server/kotlin_mcp_server.py"],
      "env": {
        "WORKSPACE_PATH": "/path/to/your/android/project"
      }
    }
  }
}

VS Code Extension

Use the configuration from mcp_config_vscode.json


⚙️ Configuration & Plugin Requirements

This section provides detailed instructions on configuring the MCP server for different IDEs and the required plugins.

🔌 Required Plugins/Extensions

VS Code Extensions

# Install required VS Code extensions
code --install-extension ms-python.python
code --install-extension ms-python.pylint
code --install-extension ms-python.black-formatter
code --install-extension ms-python.isort
code --install-extension ms-python.mypy-type-checker
code --install-extension ms-toolsai.jupyter

Manual Installation via VS Code Marketplace:

  • Python (ms-python.python) - Core Python support
  • Pylint (ms-python.pylint) - Code linting
  • Black Formatter (ms-python.black-formatter) - Code formatting
  • isort (ms-python.isort) - Import sorting
  • Jupyter (ms-toolsai.jupyter) - Notebook support (optional)
  • MCP for VS Code - Model Context Protocol support (if available)

JetBrains IDEs (IntelliJ IDEA, Android Studio)

Required Plugins:

  • Python Plugin - For Python script execution
  • MCP Plugin - Model Context Protocol support (check JetBrains marketplace)
  • Kotlin Plugin - Built-in for Android Studio, install for IntelliJ
  • Android Plugin - Built-in for Android Studio

Claude Desktop Integration

No additional plugins required - uses built-in MCP support.

🛠️ IDE Configuration

Visual Studio Code

  1. Install Python Extension Pack:

    code --install-extension ms-python.python
    
  2. Configure MCP Server: The installation script generates mcp_config_vscode.json with the correct paths. Simply add to VS Code settings.json (Cmd/Ctrl + Shift + P → "Preferences: Open Settings (JSON)"):

    {
      "mcp.server.configFiles": [
        "/absolute/path/to/your/kotlin-mcp-server/mcp_config_vscode.json"
      ],
      "python.defaultInterpreterPath": "/usr/bin/python3",
      "python.linting.enabled": true,
      "python.formatting.provider": "black",
      "python.sortImports.path": "isort"
    }
    

    💡 Pro Tip: The installation script provides the exact path you need to use.

  3. Workspace Settings (.vscode/settings.json):

    {
      "python.pythonPath": "python3",
      "mcp.server.autoStart": true,
      "mcp.server.logLevel": "info"
    }
    

JetBrains IDEs (IntelliJ IDEA, Android Studio)

  1. Install Required Plugins:

    • Go to File > Settings > Plugins (Windows/Linux) or IntelliJ IDEA > Preferences > Plugins (Mac)
    • Search and install "MCP" plugin from marketplace
    • Install "Python" plugin if not already available
  2. Configure MCP Server: The installation script generates mcp_config.json with proper configuration. In your IDE:

    • Go to File > Settings > Tools > MCP Server
    • Click + to add new server:
      • Name: Your custom server name (as configured during installation)
      • Configuration File: Select the generated mcp_config.json
      • Auto Start: Enable
  3. Android Studio Specific:

    <!-- Add to .idea/workspace.xml -->
    <component name="MCPServerManager">
      <option name="servers">
        <server name="your-server-name" configFile="mcp_config.json" autoStart="true"/>
      </option>
    </component>
    

    💡 Note: Replace your-server-name with the server name you chose during installation.

Claude Desktop

  1. Configuration File Location:

    • Mac: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: %APPDATA%\Claude\claude_desktop_config.json
    • Linux: ~/.config/claude/claude_desktop_config.json
  2. Configuration Content: Simply copy the content from the generated mcp_config_claude.json file to your Claude Desktop configuration file. The installation script has already configured all paths and settings correctly.

    Example of generated configuration:

    {
      "mcpServers": {
        "your-server-name": {
          "command": "python3",
          "args": ["kotlin_mcp_server.py"],
          "cwd": "/absolute/path/to/kotlin-mcp-server",
          "env": {
            "PROJECT_PATH": "${workspaceRoot}"
          }
        }
      }
    }
    

    ✅ Ready to Use: No manual path updates needed - everything is pre-configured!

Cursor IDE

  1. Install Extensions:

    • Same extensions as VS Code (Cursor is VS Code-based)
    • Python, Pylint, Black Formatter, isort
  2. Configuration: Use the same mcp_config_vscode.json configuration as VS Code. Add to Cursor's settings.json:

    {
      "mcp.server.configFiles": [
        "/absolute/path/to/your/kotlin-mcp-server/mcp_config_vscode.json"
      ]
    }
    

VS Code Bridge Server (Alternative Integration)

For VS Code extensions that need HTTP API access to MCP tools, the project includes a bridge server.

1. Start the Bridge Server:

# Default port (8080)
python3 vscode_bridge.py

# Custom port
python3 vscode_bridge.py 8081

# With environment configuration
MCP_BRIDGE_HOST=0.0.0.0 MCP_BRIDGE_PORT=8080 python3 vscode_bridge.py

2. Health Check:

# Test server is running
curl http://localhost:8080/health

# Expected response:
{
  "status": "healthy",
  "current_workspace": "/path/to/current/workspace",
  "available_tools": [
    "gradle_build",
    "run_tests", 
    "create_kotlin_file",
    "create_layout_file",
    "analyze_project"
  ]
}

3. Using the Bridge API:

# Call MCP tools via HTTP
curl -X POST http://localhost:8080/ \
  -H "Content-Type: application/json" \
  -d '{
    "tool": "create_kotlin_file",
    "arguments": {
      "file_path": "src/main/MyClass.kt",
      "content": "class MyClass { }"
    }
  }'

4. VS Code Extension Integration:

// In your VS Code extension
const response = await fetch('http://localhost:8080/', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    tool: 'analyze_project',
    arguments: { analysis_type: 'architecture' }
  })
});

const result = await response.json();

5. Configuration:

# Environment variables for bridge server
MCP_BRIDGE_HOST=localhost     # Server host
MCP_BRIDGE_PORT=8080          # Server port
VSCODE_WORKSPACE_FOLDER=/path # Override workspace detection

Other IDEs

For IDEs with MCP support:

  • Vim/Neovim: Use coc-mcp or similar MCP plugins
  • Emacs: Install mcp-mode package
  • Sublime Text: Install MCP package via Package Control

�️ Troubleshooting

Common Installation Issues

Python Version Compatibility

# Check Python version (must be 3.8+)
python3 --version

# If using older Python, install newer version
# macOS with Homebrew:
brew install python@3.11

# Ubuntu/Debian:
sudo apt update && sudo apt install python3.11

Dependency Installation Errors

# Upgrade pip first
python3 -m pip install --upgrade pip

# Install with verbose output for debugging
pip install -r requirements.txt -v

# Use alternative index if needed
pip install -r requirements.txt -i https://pypi.org/simple/

Import Errors

# Verify installation
python3 -c "import kotlin_mcp_server; print('Import successful')"

# Check Python path
python3 -c "import sys; print(sys.path)"

# Install in development mode
pip install -e .

Configuration Issues

Using the New Installer (Recommended)

Most configuration issues are now resolved automatically:

# Regenerate configuration with the enhanced installer
python3 install.py

# For specific setup types:
python3 install.py 1 /your/android/project my-server false
python3 install.py --help  # See all options

Legacy Manual Configuration Issues

If you're still using manual configuration from older versions:

# 1. Update to the new installer (recommended)
python3 install.py

# 2. Or manually find your actual paths (legacy method)
cd /path/to/kotlin-mcp-server && pwd
cd /path/to/android/project && pwd

# 3. Update config files - replace ${MCP_SERVER_DIR} with actual path
# Example: Change this
"cwd": "${MCP_SERVER_DIR}"
# To this (your actual path)  
"cwd": "/Users/yourusername/Documents/kotlin-mcp-server"

💡 Pro Tip: The new installer eliminates these manual steps entirely!

Environment Variable Issues

# Check if variables are set
env | grep MCP
env | grep WORKSPACE

# Load environment file manually if needed
source .env

# Test variable expansion
echo $MCP_SERVER_DIR
echo $WORKSPACE_PATH

MCP Server Not Starting

  1. Check configuration file paths in your IDE settings
  2. Verify Python interpreter path in IDE settings
  3. Ensure environment variables are set correctly
  4. Check logs for specific error messages

IDE Plugin Issues

# VS Code: Reset extension
code --uninstall-extension ms-python.python
code --install-extension ms-python.python

# JetBrains: Clear caches
File > Invalidate Caches and Restart

VS Code Bridge Server Issues

# Test bridge server is running
curl http://localhost:8080/health

# Check if port is in use
netstat -an | grep 8080
lsof -i :8080

# Start bridge server with debug
MCP_BRIDGE_HOST=0.0.0.0 MCP_BRIDGE_PORT=8080 python3 vscode_bridge.py

# Test specific tool call
curl -X POST http://localhost:8080/ \
  -H "Content-Type: application/json" \
  -d '{"tool": "list_tools", "arguments": {}}'

# Common fixes:
# 1. Check firewall settings for port 8080
# 2. Ensure python3 vscode_bridge.py is running
# 3. Verify VSCODE_WORKSPACE_FOLDER environment variable
# 4. Check bridge server logs for errors

Permission Errors

# macOS/Linux: Fix permissions
chmod +x *.py
chmod 755 servers/mcp-process/

# Windows: Run as administrator or check file permissions

Runtime Issues

AI Integration Failures

# Test local LLM connection
curl http://localhost:11434/api/generate -d '{"model":"llama2","prompt":"test"}'

# Verify API keys are set
python3 -c "import os; print('OpenAI key:', os.getenv('OPENAI_API_KEY', 'Not set'))"

File Operation Errors

# Check disk space
df -h

# Verify write permissions
touch test_file.txt && rm test_file.txt

# Check workspace path
ls -la "${WORKSPACE_PATH}"

Security/Compliance Errors

# Test encryption setup
python3 -c "from cryptography.fernet import Fernet; print('Encryption available')"

# Verify compliance mode
python3 -c "import os; print('Compliance:', os.getenv('COMPLIANCE_MODE', 'None'))"

Known Issues & Fixes

GitHub Actions Build Failures

If you encounter CI/CD issues:

  1. Configuration Files: Ensure .flake8 exists (not in pyproject.toml)
  2. GitHub Actions: Update to latest versions:
    • actions/checkout@v4
    • actions/setup-python@v4
    • actions/cache@v4
  3. Code Formatting: Run make format to fix style issues

Deprecated Dependencies

# Update all dependencies
pip install --upgrade -r requirements.txt

# Check for security vulnerabilities
pip audit

# Update Python tools
pip install --upgrade black isort flake8 pylint mypy

Performance Issues

Slow Server Response

# Enable performance monitoring
export LOG_LEVEL=DEBUG

# Run performance tests
make perf

# Profile server startup
python3 -m cProfile kotlin_mcp_server.py

Memory Usage

# Monitor memory usage
python3 -c "import psutil; print(f'Memory: {psutil.virtual_memory().percent}%')"

# Run memory-efficient mode
export MCP_LOW_MEMORY_MODE=true

Getting Help

  1. Check Logs: Look in mcp_security.log for detailed error information

  2. Run Diagnostics: Use python3 comprehensive_test.py --verbose

  3. Validate Configuration: Run python3 breaking_change_monitor.py

  4. Test Individual Components:

    # Test core server
    python3 kotlin_mcp_server.py --test
    
    # Test enhanced features
    python3 kotlin_mcp_server.py --test
    
    # Test AI integration
    python3 kotlin_mcp_server.py --test
    
  5. Contact Support: Include logs, system info, and error messages when reporting issues


🌉 VS Code Bridge Server

The VS Code Bridge Server provides HTTP API access to MCP tools for VS Code extensions and other applications that can't directly use the MCP protocol.

When to Use the Bridge Server

  • VS Code Extensions: When building custom VS Code extensions that need MCP functionality
  • HTTP Clients: When integrating with tools that only support HTTP APIs
  • Remote Access: When you need to access MCP tools from another machine
  • Testing: For easy testing of MCP tools using curl or Postman
  • Web Applications: For web-based interfaces to MCP functionality

Bridge Server Features

Workspace Detection

  • Automatically detects current VS Code workspace
  • Uses VSCODE_WORKSPACE_FOLDER environment variable
  • Falls back to current working directory

Available Endpoints

Health Check:

GET /health
# Returns: server status, workspace info, available tools

Tool Execution:

POST /
Content-Type: application/json

{
  "tool": "tool_name",
  "arguments": {
    "param1": "value1",
    "param2": "value2"
  }
}

Supported Tools via Bridge

  • gradle_build - Build Android project
  • run_tests - Execute tests
  • create_kotlin_file - Create Kotlin source files
  • create_layout_file - Create Android layout files
  • analyze_project - Project structure analysis
  • All other MCP tools (see full list via /health)

Configuration

Environment Variables

# Bridge server configuration
MCP_BRIDGE_HOST=localhost          # Server host (default: localhost)
MCP_BRIDGE_PORT=8080              # Server port (default: 8080)

# Workspace configuration  
VSCODE_WORKSPACE_FOLDER=/path/to/project   # Override workspace detection
PROJECT_PATH=/path/to/project              # Fallback project path

Security Considerations

# For remote access (use with caution)
MCP_BRIDGE_HOST=0.0.0.0           # Allow external connections

# For local development only (recommended)
MCP_BRIDGE_HOST=127.0.0.1         # Local connections only

Usage Examples

Start Bridge Server

# Basic startup
python3 vscode_bridge.py

# With custom configuration
MCP_BRIDGE_HOST=localhost MCP_BRIDGE_PORT=8081 python3 vscode_bridge.py

# Background mode
python3 vscode_bridge.py &

Health Check

curl http://localhost:8080/health

# Response:
{
  "status": "healthy",
  "current_workspace": "/Users/you/AndroidProject",
  "available_tools": ["gradle_build", "run_tests", ...]
}

Create Kotlin File

curl -X POST http://localhost:8080/ \
  -H "Content-Type: application/json" \
  -d '{
    "tool": "create_kotlin_file",
    "arguments": {
      "file_path": "src/main/kotlin/MainActivity.kt",
      "package_name": "com.example.app",
      "class_name": "MainActivity"
    }
  }'

Run Gradle Build

curl -X POST http://localhost:8080/ \
  -H "Content-Type: application/json" \
  -d '{
    "tool": "gradle_build",
    "arguments": {
      "task": "assembleDebug",
      "clean_first": true
    }
  }'

Format Kotlin Code

curl -X POST http://localhost:8080/ \
  -H "Content-Type: application/json" \
  -d '{
    "tool": "format_code",
    "arguments": {}
  }'

Run Static Analysis

curl -X POST http://localhost:8080/ \
  -H "Content-Type: application/json" \
  -d '{
    "tool": "run_lint",
    "arguments": { "lint_tool": "detekt" }
  }'

Generate Documentation

curl -X POST http://localhost:8080/ \
  -H "Content-Type: application/json" \
  -d '{
    "tool": "generate_docs",
    "arguments": { "doc_type": "html" }
  }'

VS Code Extension Integration

TypeScript/JavaScript Example

interface MCPRequest {
  tool: string;
  arguments: Record<string, any>;
}

interface MCPResponse {
  success?: boolean;
  result?: any;
  error?: string;
}

class MCPBridgeClient {
  private baseUrl: string;

  constructor(host = 'localhost', port = 8080) {
    this.baseUrl = `http://${host}:${port}`;
  }

  async healthCheck(): Promise<any> {
    const response = await fetch(`${this.baseUrl}/health`);
    return response.json();
  }

  async callTool(tool: string, arguments: Record<string, any>): Promise<MCPResponse> {
    const response = await fetch(this.baseUrl, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ tool, arguments })
    });
    return response.json();
  }

  async createKotlinFile(filePath: string, className: string): Promise<MCPResponse> {
    return this.callTool('create_kotlin_file', {
      file_path: filePath,
      class_name: className
    });
  }

  async buildProject(task = 'assembleDebug'): Promise<MCPResponse> {
    return this.callTool('gradle_build', { task });
  }
}

// Usage in VS Code extension
const mcpClient = new MCPBridgeClient();

// In extension activation
const health = await mcpClient.healthCheck();
console.log('MCP Bridge Status:', health.status);

// Create new Kotlin file
const result = await mcpClient.createKotlinFile(
  'src/main/kotlin/NewClass.kt',
  'NewClass'
);

Troubleshooting Bridge Server

Common Issues

# Port already in use
netstat -tulpn | grep 8080
# Kill process using port: sudo kill -9 <PID>

# Permission denied
sudo ufw allow 8080  # Ubuntu
sudo firewall-cmd --add-port=8080/tcp  # CentOS

# Connection refused
# Check if server is running:
ps aux | grep vscode_bridge.py

# Test with verbose curl:
curl -v http://localhost:8080/health

Debug Mode

# Enable debug logging
DEBUG=true python3 vscode_bridge.py

# Check server logs
tail -f /tmp/mcp-bridge.log

Performance Notes

  • Lightweight: Minimal HTTP server with low memory footprint
  • Workspace-aware: Automatically uses current VS Code workspace
  • Error handling: Graceful error responses with details
  • CORS support: Includes CORS headers for web applications

🧪 Testing & Quality Assurance

This project includes a comprehensive testing and quality assurance system. For detailed testing information, see TESTING_GUIDE.md.

Quick Testing Commands

# Run all tests
make test

# Run tests with coverage
make coverage

# Run quality checks
make lint

# Full CI pipeline
make ci

# Check for breaking changes
python breaking_change_monitor.py

Quality Metrics

  • Test Coverage: 80% minimum
  • Performance: < 5s tool listing, < 2s file operations
  • Security: Zero high-severity vulnerabilities
  • Code Quality: Pylint score 8.0+/10.0

�📊 Monitoring & Analytics

The server provides comprehensive monitoring:

  • Security Events - Real-time security monitoring and alerts
  • API Usage - Request/response metrics, error rates, costs
  • File Operations - Backup status, sync health, storage usage
  • Compliance Status - GDPR/HIPAA compliance reporting
  • Performance Metrics - Response times, throughput, resource usage

🛡️ Security Best Practices

  1. Environment Variables - Store sensitive data in .env files
  2. Encryption Keys - Use strong, unique encryption passwords
  3. API Keys - Rotate API keys regularly
  4. Audit Logs - Review security logs periodically
  5. Access Controls - Implement least privilege principles
  6. Data Classification - Properly classify and handle sensitive data

📄 License & Compliance

This MCP server is designed to help you build compliant applications:

  • GDPR Ready - Full Article 25 "Privacy by Design" implementation
  • HIPAA Compatible - Meets Technical Safeguards requirements
  • SOC 2 Type II - Security controls framework
  • ISO 27001 - Information security management standards

🤝 Contributing

We welcome contributions! Please see our contributing guidelines for:

  • Code style and standards
  • Security review process
  • Testing requirements
  • Documentation standards

🆘 Support & Resources

  • Documentation - Complete API documentation in /docs
  • Examples - Industry-specific examples in /examples
  • Issues - Report bugs and feature requests
  • Security - Report security issues privately

🚀 Getting Started Checklist

Installation & Setup

  • [ ] Install Python 3.8+ and pip
  • [ ] Clone repository: git clone <repo-url>
  • [ ] Install dependencies: pip install -r requirements.txt
  • [ ] Configure environment variables in .env file
  • [ ] Install required IDE plugins/extensions
  • [ ] Validate installation: python3 validate_config.py

Basic Tool Testing

  • [ ] Test project analysis: {"name": "analyze_project", "arguments": {"analysis_type": "architecture"}}
  • [ ] Test file creation: {"name": "create_kotlin_file", "arguments": {"file_path": "Test.kt", "class_name": "Test"}}
  • [ ] Test build: {"name": "gradle_build", "arguments": {"task": "assembleDebug"}}
  • [ ] Test AI integration: {"name": "query_llm", "arguments": {"prompt": "Hello world", "llm_provider": "local"}}

Advanced Features

  • [ ] Set up MVVM architecture: setup_mvvm_architecture
  • [ ] Configure dependency injection: setup_dependency_injection
  • [ ] Implement security features: encrypt_sensitive_data
  • [ ] Set up compliance (if needed): implement_gdpr_compliance or implement_hipaa_compliance
  • [ ] Configure cloud sync: setup_cloud_sync
  • [ ] Set up external APIs: setup_external_api

Testing & Quality

  • [ ] Generate unit tests: generate_unit_tests
  • [ ] Run comprehensive tests: run_tests
  • [ ] Perform code analysis: analyze_code_with_ai
  • [ ] Run lint checks: run_lint
  • [ ] Generate documentation: generate_docs

Optional Integrations

  • [ ] Test VS Code bridge server: python3 vscode_bridge.py
  • [ ] Configure Claude Desktop integration
  • [ ] Set up cloud storage backup
  • [ ] Enable AI code generation features

🎉 Ready to build enterprise-grade Android applications with 27 comprehensive tools at your disposal!

📚 Next Steps

  1. Explore the Tools: Start with basic tools like analyze_project and create_kotlin_file
  2. Set Up Architecture: Use setup_mvvm_architecture for clean code structure
  3. Add Security: Implement encrypt_sensitive_data and compliance features
  4. Generate Code: Leverage AI tools for rapid development
  5. Test Everything: Use generate_unit_tests and run_tests for quality assurance

🆘 Getting Help

  • Tool Reference: Each tool has detailed parameter documentation above
  • Examples: Industry-specific examples in the README
  • Troubleshooting: Comprehensive troubleshooting section included
  • Best Practices: Follow the tool usage guidelines for optimal results

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选