Skip to content

AlankritVerma01/anysdk-mcp

Repository files navigation

Universal SDK-to-MCP Converter

Transform any Python SDK into a comprehensive MCP server with automatic discovery, LLM enhancement, and production-ready safety controls.

πŸš€ Quick Start

Option 1: Secure Config File (Recommended)

# 1. Setup environment
uv sync
cp .env.example .env  # Add your API keys

# 2. Launch MCP Inspector with secure config
npx @modelcontextprotocol/inspector --config inspector_config.json

# 3. Select "GitHub Auto-Discovery" and connect
# 4. Test: github.search_repositories with {"query": "python"}

Option 2: Manual Configuration

# 1. Start MCP Inspector
npx @modelcontextprotocol/inspector

# 2. Configure server:
#    Command: uv
#    Arguments: run python /path/to/mcp_server.py --sdk github-auto --debug
#    Working Directory: /path/to/anysdk-mcp
#    Environment: PYTHONPATH=/path/to/anysdk-mcp

🎯 What Makes This Special

πŸ” Universal Auto-Discovery

  • Automatically discovers ALL SDK methods using reflection
  • No manual configuration - Just point it at any Python SDK
  • Rich type extraction - Handles Union, Optional, Enum, datetime, etc.
  • Docstring parsing - Extracts parameter descriptions automatically

πŸ€– LLM-Enhanced Experience

  • OpenAI integration - Improves tool descriptions for better agent UX
  • Risk classification - AI-powered safety assessment
  • Cost controls - $2 budget limit with intelligent caching
  • Smart enhancement - Only uses LLM when confidence β‰₯ 0.7

πŸ›‘οΈ Production-Ready Safety

  • Plan/Apply pattern - Preview dangerous operations before execution
  • Rate limiting - Configurable per-SDK limits
  • Input validation - Sanitization and security controls
  • Comprehensive testing - 52/53 tests passing (98% success rate)

πŸ“Š Coverage Comparison

SDK Typical MCP Server Our Converter Improvement
GitHub 5-10 methods 37+ methods 4-7x more
Kubernetes Core pods/deployments 100+ methods 10x more
Azure Limited compute 200+ methods 20x more

πŸ”§ Supported SDKs

βœ… GitHub Auto-Discovery (github-auto)

  • 37+ methods - Complete GitHub API coverage
  • Authentication - Works with/without GitHub token
  • Examples: github.search_repositories, github.get_user, github.search_code
  • Write operations: github.create_repo.plan β†’ github.create_repo.apply

βœ… Kubernetes Auto-Discovery (k8s-auto)

  • 100+ methods - All K8s API groups (Core, Apps, Networking, etc.)
  • Namespace support - Automatic namespace handling
  • Examples: k8s.CoreV1Api_list_namespaced_pod, k8s.AppsV1Api_scale_namespaced_deployment
  • Safe operations - Dry-run support where available

βœ… Azure Auto-Discovery (azure-auto)

  • 200+ methods - Complete Azure Management SDK coverage
  • LRO handling - Proper async operation support for begin_* methods
  • Examples: azure.VirtualMachinesOperations_begin_create, azure.ResourceGroupsOperations_list
  • Multi-client - Covers Compute, Network, Storage, Resource management

πŸ›‘οΈ Safety Features

Plan/Apply Pattern for Write Operations

Write operations (create, delete, update) use a safe two-step process:

  1. Plan: github.create_repo.plan {"name": "my-repo"} β†’ Returns plan ID
  2. Apply: github.create_repo.apply {"plan_id": "uuid-here"} β†’ Executes operation

This prevents accidental destructive operations and allows review before execution.

Operation Classification

  • Read operations: Execute immediately (low risk)
  • Write operations: Require plan/apply (medium/high risk)
  • Risk levels: Low, Medium, High based on potential impact

Rate Limiting & Safety

  • Configurable rate limiting per SDK
  • Input validation and sanitization
  • Response size limits
  • Execution timeouts
  • Operation logging

Configuration Files

Each SDK can be customized via YAML configuration:

  • configs/github.yaml - GitHub settings, rate limits, safety rules
  • configs/k8s.yaml - Kubernetes settings, namespace restrictions

Environment Variables

  • GITHUB_TOKEN: GitHub personal access token for authenticated requests
  • KUBECONFIG: Path to Kubernetes configuration file
  • MCP_SDK: Default SDK to use (github-auto, k8s-auto, github, k8s)

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   MCP Client    β”‚    β”‚   SDK Bridge     β”‚    β”‚   Target SDK    β”‚
β”‚ (Investigator,  │◄──►│   (FastMCP)      │◄──►│   (GitHub,      β”‚
β”‚   Claude, etc.) β”‚    β”‚                  β”‚    β”‚    K8s, etc.)   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                       β”‚ Auto-Discoveryβ”‚
                       β”‚ + Plan/Apply  β”‚
                       β”‚ + Safety      β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Core Components

  • Auto-Discovery: Automatically finds SDK methods using reflection
  • Schema Generation: Creates MCP tool schemas from method signatures
  • Plan/Apply: Safe execution pattern for write operations
  • Safety Controls: Rate limiting, input validation, risk assessment
  • Multi-SDK Support: GitHub, Kubernetes, extensible to any Python SDK

Troubleshooting

GitHub Issues

# Test GitHub access
python -c "from github import Github; print(Github().get_rate_limit())"

# Test with token  
GITHUB_TOKEN=your_token python -c "from github import Github; print(Github('your_token').get_rate_limit())"

Kubernetes Issues

# Check cluster access
kubectl cluster-info

# Check current context
kubectl config current-context

Server Issues

# Test server startup
python mcp_server.py --sdk github-auto --debug

# Check dependencies
uv run python -c "import mcp_sdk_bridge; print('βœ… Package imported')"

Development

Adding New SDKs

The bridge supports any Python SDK through auto-discovery:

  1. Install the SDK package
  2. Create a minimal auto-adapter (see adapters/auto_github.py)
  3. Add to CLI choices and validation
  4. The bridge will automatically discover methods and create tools

Running Tests

# Run all tests
PYTHONPATH=/path/to/anysdk-mcp uv run pytest

# Run specific tests
PYTHONPATH=/path/to/anysdk-mcp uv run pytest tests/test_e2e.py -v

# Test individual components
python tests/test_e2e.py  # Runs sync tests

Example MCP Investigator Session

Once connected, you can use natural language with the auto-discovered tools:

"List my GitHub repositories" β†’ Uses github.get_user + github.search_repositories

"Show pods in the default namespace" β†’ Uses k8s.CoreV1Api_list_namespaced_pod

"Create a new repository called 'test-project'" β†’ Uses github.create_repo.plan β†’ Review β†’ github.create_repo.apply

The auto-discovery adapters provide comprehensive access to SDK APIs while maintaining safety through the plan/apply pattern for potentially destructive operations.


🎯 Agent-Friendly Tools

Meta Tools for Discovery

  • tools.search - Find tools by name/description: {"query": "repo"}
  • meta.stats - Get comprehensive server statistics
  • meta.export_tools - Export tool catalog in JSON/Markdown
  • tools.validate - Validate all tools and check for issues
  • tools.health_check - Run automated tests on all safe tools

LRO (Long Running Operations)

  • lro.get_status - Check operation status
  • lro.wait - Wait for operation completion
  • lro.list_operations - List all tracked operations

πŸ” Security & Configuration

Environment Variables (Auto-loaded from .env)

# GitHub
GITHUB_TOKEN=ghp_your_token_here

# Kubernetes  
KUBECONFIG=~/.kube/config

# Azure
AZURE_TENANT_ID=your_tenant_id
AZURE_SUBSCRIPTION_ID=your_subscription_id

# LLM Enhancement
OPENAI_API_KEY=sk-proj-your_key_here

Secure Configuration

  • βœ… No API keys in config files - Environment-based secrets
  • βœ… Automatic .env loading - Server loads environment on startup
  • βœ… Shareable configurations - Safe to commit to version control

πŸ§ͺ Testing & Validation

Comprehensive Test Suite

# Run all tests (52/53 passing - 98% success rate)
PYTHONPATH=. uv run pytest

# Test specific SDK
PYTHONPATH=. uv run pytest tests/test_azure_auto.py -v

Built-in Validation Tools

  • tools.validate - Check schemas and generate examples
  • tools.health_check - Automated testing of read-only tools
  • tools.test - Test specific tools with auto-generated parameters

🎨 Adding New SDKs

Example: Adding Stripe SDK (10 lines)

class StripeAutoAdapter:
    def __init__(self, config):
        self.stripe = stripe.Client(api_key=config.api_key)
        self.discoverer = SDKDiscoverer("stripe")
        # Auto-discovery creates 50+ Stripe tools automatically!

Requirements for new SDKs:

  • βœ… Well-documented - Methods have docstrings
  • βœ… Standard Python patterns - Classes, methods, type hints
  • βœ… Introspectable - Works with inspect.signature()

πŸŽ‰ Ready to Use!

Your MCP Inspector is running at: http://localhost:6274

Test the power of universal SDK-to-MCP conversion:

  1. Connect to "GitHub Auto-Discovery"
  2. Try github.search_repositories with {"query": "python"}
  3. Explore meta.stats to see 37+ available tools
  4. Validate with tools.health_check for comprehensive testing

This solution transforms the MCP ecosystem by making ANY Python SDK instantly available to agents with production-grade safety and LLM-enhanced usability! πŸš€

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors