Skip to main content

Klavis AI (https://www.klavis.ai)

Project description

Klavis AI Python SDK

PyPI version License: MIT

Klavis AI - Open Source MCP Integrations for AI Applications. This Python package provides a convenient way to interact with the Klavis AI API (https://www.klavis.ai).

Installation

You can install the Klavis AI Python SDK using pip:

pip install klavis

Getting Started

To use the SDK, you need to obtain an API key from Klavis AI.

Here's a basic example of how to configure the client and make an API call:

import os
from pprint import pprint

from klavis import ApiClient, Configuration
from klavis.api import McpServerApi
from klavis.models import CreateServerRequest, ServerName, CallToolRequest

# Replace 'YOUR_API_KEY' with your actual Klavis API key
# You can also set the KLAVIS_API_KEY environment variable
api_key = os.environ.get("KLAVIS_API_KEY", "YOUR_API_KEY") 
if api_key == "YOUR_API_KEY":
    print("Warning: API Key not configured. Please set the KLAVIS_API_KEY environment variable or replace 'YOUR_API_KEY'.")
    # exit(1) # Consider exiting if the key is required for all operations

config = Configuration(
    host="https://api.klavis.ai", # Default production server
    api_key=api_key,
)

# Create an API client instance
api_client = ApiClient(config)

# Example: Using the MCP Server API
mcp_api = McpServerApi(api_client)

try:
    # 1. Create a server instance for a specific MCP (e.g., GitHub)
    print("\n--- Creating a server instance ---")
    create_request = CreateServerRequest(
        server_name=ServerName.GITHUB, 
        user_id="example_user_id",        # Replace with a relevant user identifier
        platform_name="example_platform"  # Replace with your platform name
    )
    instance = mcp_api.create_server_instance(create_request)
    instance_id = instance.instance_id
    server_url = instance.server_url
    print("Instance created:")
    pprint(instance.to_dict())

    # (Optional) Check instance details
    print("\n--- Getting instance details ---")
    instance_details = mcp_api.get_server_instance(instance_id)
    print("Instance details:")
    pprint(instance_details.to_dict())
    
    # (Optional) If the server requires authentication (e.g., PAT for GitHub), 
    # you might need to set it after the OAuth flow or manually.
    # See OAuth endpoints and set_instance_auth_token. 
    # For GitHub, you'd typically complete the OAuth flow first.
    # The server_url obtained above includes the instance_id and handles routing.

    # 2. Call a tool on the created instance
    # Ensure the instance is properly authenticated if required by the tool.
    print("\n--- Calling a tool (GitHub Search Repositories) ---")
    call_request = CallToolRequest(
        server_url=server_url,                # Use the URL from the create step
        tool_name="github_search_repositories", # Tool name for the specific MCP
        tool_args={"query": "klavis ai"}      # Arguments required by the tool
    )
    tool_result = mcp_api.call_server_tool(call_request)
    print("Tool call result:")
    pprint(tool_result.to_dict())

    # 3. Clean up: Delete the instance when done
    print("\n--- Deleting instance ---")
    delete_result = mcp_api.delete_server_instance(instance_id)
    print("Deletion result:")
    pprint(delete_result.to_dict())

except Exception as e:
    print(f"An API error occurred: {e}")

Available APIs

This SDK provides access to the following Klavis AI API functionalities:

  • MCP Server API (klavis.api.McpServerApi): Manage MCP server instances, list and call tools on connected MCPs (like Slack, GitHub, Jira, etc.).
  • OAuth APIs (e.g., klavis.api.SlackOauthApi, klavis.api.GithubOauthApi, etc.): Handle OAuth flows for different services to authenticate MCP instances.
  • White Labeling API (klavis.api.WhiteLabelingApi): Manage OAuth white labeling configurations.

Please refer to the docs and directories or the official Klavis AI API documentation for details on all available methods and models.

Authentication

Authentication is handled via an API key passed as a Bearer token in the Authorization header. The Configuration object manages this automatically when you provide your api_key.

from klavis import Configuration

config = Configuration(
    api_key="YOUR_API_KEY", 
)

Documentation

For more detailed information on the API endpoints and models, please refer to the Klavis AI API Documentation.

Contributing

Contributions are welcome! Please refer to the main repository's contribution guidelines.

License

This SDK is distributed under the terms of the LICENSE file.

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

klavis-0.1.2.tar.gz (36.5 kB view details)

Uploaded Source

Built Distribution

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

klavis-0.1.2-py3-none-any.whl (84.8 kB view details)

Uploaded Python 3

File details

Details for the file klavis-0.1.2.tar.gz.

File metadata

  • Download URL: klavis-0.1.2.tar.gz
  • Upload date:
  • Size: 36.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for klavis-0.1.2.tar.gz
Algorithm Hash digest
SHA256 4c45153f71e1767754ef731f470ea6567c33c16416a891ea00ae3cdd9a627e60
MD5 2f0e5e55be19c73fd8b085ea42b79be7
BLAKE2b-256 f4e2d21e7d26553c40b14f1c65c855204782c9097a1d63fa83ef3d6eff0d7d6c

See more details on using hashes here.

Provenance

The following attestation bundles were made for klavis-0.1.2.tar.gz:

Publisher: python-app.yml on Klavis-AI/klavis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file klavis-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: klavis-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 84.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for klavis-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ec899e5e8c046a11ec4d7ca5a23f59dd9bd70c5ebe63f3a3b10ec444ff6b969c
MD5 defbf64c554ca41e0c7f43a5d3a8cf3b
BLAKE2b-256 709088fafd54e4ee80de3c96501b41dcdf9c6130276cc9cbe35267980483d001

See more details on using hashes here.

Provenance

The following attestation bundles were made for klavis-0.1.2-py3-none-any.whl:

Publisher: python-app.yml on Klavis-AI/klavis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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