Skip to main content

Convert any SaaS API into an MCP server with multiple transport support

Project description

SaasToMCP

A FastMCP server that dynamically creates MCP (Model Context Protocol) servers from web API configurations. This allows you to easily integrate any REST API, GraphQL endpoint, or web service into an MCP-compatible tool that can be used by AI assistants like Claude.

Features

  • 🚀 Dynamic API Registration: Register any web API at runtime
  • 🔐 Multiple Authentication Methods: Bearer tokens, API keys, Basic auth, OAuth2, and custom headers
  • 🛠️ All HTTP Methods: Support for GET, POST, PUT, DELETE, PATCH, and more
  • 📝 Flexible Parameters: Query params, path params, headers, and request bodies
  • 🔄 Automatic Tool Generation: Each API endpoint becomes an MCP tool
  • 🧪 Built-in Testing: Test API connections before using them
  • 📊 Response Handling: Automatic JSON parsing with fallback to text
  • 🌐 Multiple Transport Types: STDIO, SSE, and Streamable HTTP transport support

Transport Types

SaasToMCP supports three different transport types to accommodate various deployment scenarios:

STDIO Transport (Default)

  • Usage: saas-to-mcp run or saas-to-mcp run --transport stdio
  • Best for: Local tools, command-line usage, and MCP clients that connect via standard input/output
  • Characteristics: Direct process communication, lowest latency, suitable for desktop applications
  • Endpoint: N/A (uses stdin/stdout)

SSE Transport (Legacy)

  • Usage: saas-to-mcp run --transport sse --host 127.0.0.1 --port 8000
  • Best for: Legacy MCP clients that only support Server-Sent Events
  • Characteristics: HTTP-based, one-way streaming from server to client
  • Endpoint: http://host:port/mcp
  • Note: This transport is deprecated in favor of Streamable HTTP

Streamable HTTP Transport (Recommended)

  • Usage: saas-to-mcp run --transport streamable-http --host 127.0.0.1 --port 8000
  • Best for: Modern web deployments, cloud environments, and new MCP clients
  • Characteristics: Full HTTP-based communication, bidirectional streaming, better error handling
  • Endpoint: http://host:port/mcp
  • Recommended: This is the preferred transport for new deployments

Installation

# Clone or download this repository
cd ~/Desktop/SaasToMCP

# Install dependencies
pip install -r requirements.txt

Usage

Claude Desktop

{
  "mcpServers": {
    "saas-to-mcp": {
      "command": "uvx",
      "args": ["saas-to-mcp", "run"]
    }
  }
}

### Starting the Server

There are several ways to run the SaasToMCP server with different transport types:

**1. After installation (recommended):**

If you have installed the package (e.g., using `pip install .` from the project root after installing requirements):

```bash
# Default STDIO transport
saas-to-mcp run

# Streamable HTTP transport (recommended for web deployments)
saas-to-mcp run --transport streamable-http --host 127.0.0.1 --port 8000

# SSE transport (legacy compatibility)
saas-to-mcp run --transport sse --host 127.0.0.1 --port 8000

2. Directly from the repository (for development):

# From the root of the repository
python -m saas_to_mcp.cli run [OPTIONS]

Transport Options:

  • --transport: Choose from stdio (default), sse, or streamable-http
  • --host: Host address for HTTP transports (default: 127.0.0.1)
  • --port: Port for HTTP transports (default: 8000)
  • --path: URL path for MCP endpoint (default: /mcp)

Run saas-to-mcp run --help for all available options.

Using with AI Assistants (like Claude Desktop)

SaasToMCP is designed to expose web APIs as tools for AI assistants that support the Model Context Protocol (MCP). Here's how to use it:

  1. Start the SaasToMCP Server:

    For modern MCP clients (recommended):

    saas-to-mcp run --transport streamable-http --host 127.0.0.1 --port 8000
    

    For legacy compatibility:

    saas-to-mcp run --transport sse --host 127.0.0.1 --port 8000
    

    For local desktop applications:

    saas-to-mcp run  # Uses STDIO transport
    
  2. Configure Your AI Assistant: The MCP endpoint will be available at:

    • Streamable HTTP: http://127.0.0.1:8000/mcp
    • SSE: http://127.0.0.1:8000/mcp
    • STDIO: Direct process communication
  3. Register APIs and Use Tools: Once connected, use the built-in register_api tool to define web APIs, then use the generated endpoint tools.

Core Tools

The server provides these built-in tools:

  1. register_api - Register a new API and create tools for its endpoints
  2. list_apis - List all registered APIs and their endpoints
  3. unregister_api - Remove an API and its tools
  4. test_api_connection - Test connectivity to a registered API
  5. call_api - Generic tool to call any registered API endpoint
  6. get_api_schema - Get schema information for APIs and endpoints

API Configuration Format

{
  "name": "my_api",
  "base_url": "https://api.example.com",
  "description": "Example API integration",
  "auth": {
    "type": "bearer",
    "bearer_token": "your-token-here"
  },
  "headers": {
    "Accept": "application/json"
  },
  "endpoints": [
    {
      "name": "list_users",
      "description": "Get all users",
      "method": "GET",
      "path": "/users",
      "params": [
        {
          "name": "limit",
          "type": "integer",
          "location": "query",
          "required": false,
          "default": 10,
          "description": "Number of users to return"
        }
      ]
    }
  ]
}

Examples

Example 1: OpenWeatherMap API

{
  "name": "weather",
  "base_url": "https://api.openweathermap.org/data/2.5",
  "description": "OpenWeatherMap API",
  "auth": {
    "type": "api_key",
    "api_key": "your-api-key",
    "api_key_param": "appid"
  },
  "endpoints": [
    {
      "name": "get_current_weather",
      "description": "Get current weather for a city",
      "method": "GET",
      "path": "/weather",
      "params": [
        {
          "name": "q",
          "type": "string",
          "location": "query",
          "required": true,
          "description": "City name"
        },
        {
          "name": "units",
          "type": "string",
          "location": "query",
          "required": false,
          "default": "metric",
          "enum": ["metric", "imperial", "kelvin"]
        }
      ]
    }
  ]
}

Example 2: GitHub API

{
  "name": "github",
  "base_url": "https://api.github.com",
  "description": "GitHub REST API",
  "auth": {
    "type": "bearer",
    "bearer_token": "ghp_your_token_here"
  },
  "headers": {
    "Accept": "application/vnd.github.v3+json"
  },
  "endpoints": [
    {
      "name": "get_user",
      "description": "Get a GitHub user's information",
      "method": "GET",
      "path": "/users/{username}",
      "params": [
        {
          "name": "username",
          "type": "string",
          "location": "path",
          "required": true,
          "description": "GitHub username"
        }
      ]
    }
  ]
}

Authentication Types

Bearer Token

{
  "auth": {
    "type": "bearer",
    "bearer_token": "your-token-here"
  }
}

API Key (Header)

{
  "auth": {
    "type": "api_key",
    "api_key": "your-key-here",
    "api_key_header": "X-API-Key"
  }
}

API Key (Query Parameter)

{
  "auth": {
    "type": "api_key",
    "api_key": "your-key-here",
    "api_key_param": "api_key"
  }
}

Basic Authentication

{
  "auth": {
    "type": "basic",
    "username": "your-username",
    "password": "your-password"
  }
}

Custom Headers

{
  "auth": {
    "type": "custom",
    "custom_headers": {
      "X-Custom-Auth": "custom-value",
      "X-Client-ID": "client-123"
    }
  }
}

Parameter Locations

  • query: Query string parameters (?param=value)
  • path: Path parameters (/users/{id})
  • header: HTTP headers
  • body: Request body (for POST, PUT, PATCH)

Parameter Types

  • string: Text values
  • integer: Whole numbers
  • number: Decimal numbers
  • boolean: true/false
  • array: Lists of values
  • object: JSON objects

Advanced Features

Custom Timeouts

{
  "timeout": 60.0  // Timeout in seconds
}

Enum Values

{
  "name": "status",
  "type": "string",
  "enum": ["active", "inactive", "pending"]
}

Default Values

{
  "name": "page",
  "type": "integer",
  "default": 1
}

Claude Desktop Configuration

For Streamable HTTP Transport (Recommended)

{
  "mcpServers": {
    "saas-to-mcp": {
      "command": "saas-to-mcp",
      "args": ["run", "--transport", "streamable-http", "--host", "127.0.0.1", "--port", "8000"]
    }
  }
}

For STDIO Transport (Traditional)

{
  "mcpServers": {
    "saas-to-mcp": {
      "command": "saas-to-mcp",
      "args": ["run"]
    }
  }
}

Error Handling

The server provides detailed error messages for:

  • Missing required parameters
  • HTTP errors (with status codes)
  • Connection failures
  • Authentication errors
  • Invalid configurations

Tips

  1. Choose the Right Transport: Use streamable-http for modern deployments, stdio for local tools
  2. Test First: Always use test_api_connection after registering an API
  3. Start Simple: Begin with GET endpoints before moving to complex POST requests
  4. Check Auth: Ensure your authentication credentials are correct
  5. Use Descriptions: Provide clear descriptions for better AI understanding
  6. Handle Errors: The server will report HTTP errors with details

Troubleshooting

Common Issues

  1. 401 Unauthorized: Check your authentication credentials
  2. 404 Not Found: Verify the base URL and endpoint paths
  3. Timeout Errors: Increase the timeout value for slow APIs
  4. SSL Errors: Some APIs may require specific SSL configurations

Debug Mode

Run with verbose logging (if installed):

saas-to-mcp run --verbose

Transport-Specific Issues

  • STDIO: Ensure the client properly handles stdin/stdout communication
  • SSE: Check that the HTTP endpoint is accessible and CORS is configured
  • Streamable HTTP: Verify the MCP endpoint responds to HTTP requests

Contributing

Feel free to extend this server with additional features:

  • OAuth2 token refresh
  • GraphQL support
  • WebSocket endpoints
  • Response caching
  • Rate limiting
  • Request retries

License

MIT License - feel free to use and modify as needed.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

saas_to_mcp-0.2.0.tar.gz (30.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

saas_to_mcp-0.2.0-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file saas_to_mcp-0.2.0.tar.gz.

File metadata

  • Download URL: saas_to_mcp-0.2.0.tar.gz
  • Upload date:
  • Size: 30.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for saas_to_mcp-0.2.0.tar.gz
Algorithm Hash digest
SHA256 db75c2b568d62a151a4c6ba202a48167c9a6a519fa600860b21b909017d868d0
MD5 fb8db87e7fa8d069dc4cb015fe395284
BLAKE2b-256 a74553b00301a000f3adf3be06d9c2bfcac5cb343bdf1e07db9b0b722efbf4b6

See more details on using hashes here.

File details

Details for the file saas_to_mcp-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: saas_to_mcp-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 14.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for saas_to_mcp-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f6b5dce7c7cdb0a6039cb370eb104dd8c18ea475328cb0ec6569cfc865b1f34b
MD5 4f7b5a64552d51f565b7afcd503c9ae0
BLAKE2b-256 5889a81d1eb0732d3166334faef64ec62b15ed4d998624e5a58caf980e20ba1e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page