Klavis AI - LLM API Documentation
Documents the Klavis MCP integration platform REST API and SDKs for aggregating multiple MCP servers into a single Strata endpoint.
What this file does
Documents the Klavis MCP integration platform REST API and SDKs for aggregating multiple MCP servers into a single Strata endpoint.
When to use it
- Building an AI agent that needs tools from multiple services like GitHub and Slack
- Integrating MCP servers with OpenAI, Anthropic, or Gemini models
- Setting up OAuth flows for third-party tool authentication
- Managing Strata server instances programmatically via Python or TypeScript
Assumes this stack
Klavis AI - LLM API Documentation
Overview
Klavis AI is an open-source MCP (Model Context Protocol) integration platform that that let AI agents use any tools reliably at any scale.
Key Features:
- Instant Integration with Python/TypeScript SDKs or REST API
- Built-in OAuth flows and API key management
- 100+ tools across CRM, GSuite, dev tools, sales, search, etc.
- Multi-platform LLM provider support (OpenAI, Anthropic, Gemini, etc.)
- Strata: One MCP server for AI agents to use tools progressively at any scale
Installation
REST API
Base URL: https://api.klavis.ai
Authentication: Bearer token (API key in Authorization header)
Create Strata Server
curl -X POST https://api.klavis.ai/mcp-server/strata/create \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"userId": "user_123",
"servers": ["GitHub", "Linear"]
}'
Response:
{
"strataServerUrl": "https://strata.klavis.ai/mcp/?strata_id=...",
"strataId": "strata_abc123",
"addedServers": ["GitHub", "Linear"],
"oauthUrls": {
"GitHub": "https://api.klavis.ai/oauth/github/authorize?instance_id=...",
"Linear": "https://api.klavis.ai/oauth/linear/authorize?instance_id=..."
}
}
Add Servers to Strata
curl -X POST https://api.klavis.ai/mcp-server/strata/add \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"strataId": "strata_abc123",
"servers": ["Slack", "Notion"]
}'
Get Available Servers
curl -X GET https://api.klavis.ai/mcp-server/servers \
-H "Authorization: Bearer YOUR_API_KEY"
Python SDK
pip install klavis
TypeScript/JavaScript SDK
npm install klavis
API Key Setup
Sign up at klavis.ai and create your API key.
Quick Start
Python SDK
from klavis import Klavis
from klavis.types import McpServerName, ToolFormat
# Initialize client
klavis_client = Klavis(api_key="your_api_key")
# Create Strata MCP server (aggregates multiple MCP servers)
response = klavis_client.mcp_server.create_strata_server(
servers=[McpServerName.GITHUB, McpServerName.LINEAR],
user_id="user_123"
)
# Handle OAuth if needed
if response.oauth_urls:
for server_name, oauth_url in response.oauth_urls.items():
print(f"Authorize {server_name}: {oauth_url}")
TypeScript SDK
import { Klavis } from 'klavis';
const klavisClient = new Klavis({ apiKey: 'your_api_key' });
// Create Strata MCP server
const response = await klavisClient.mcpServer.createStrataServer({
servers: [Klavis.McpServerName.Github, Klavis.McpServerName.Linear],
userId: "user_123"
});
Use Case - OpenAI Integration
import json
from openai import OpenAI
from klavis import Klavis
from klavis.types import McpServerName, ToolFormat
openai_client = OpenAI(api_key="openai_key")
klavis_client = Klavis(api_key="klavis_key")
# Create Strata server with multiple services
response = klavis_client.mcp_server.create_strata_server(
servers=[McpServerName.GMAIL, McpServerName.SLACK],
user_id="user_123"
)
# Handle OAuth authorization for each service
if response.oauth_urls:
for server_name, oauth_url in response.oauth_urls.items():
print(f"Please open this URL to complete {server_name} OAuth authorization: {oauth_url}")
def openai_with_mcp_server(mcp_server_url: str, user_query: str):
messages = [
{"role": "system", "content": "You are a helpful assistant. Use the available tools to answer the user's question."},
{"role": "user", "content": user_query}
]
tools_info = klavis_client.mcp_server.list_tools(
server_url=mcp_server_url,
format=ToolFormat.OPENAI
)
max_iterations = 20
iteration = 0
while iteration < max_iterations:
iteration += 1
response = openai_client.chat.completions.create(
model="gpt-4o-mini",
messages=messages,
tools=tools_info.tools,
tool_choice="auto",
)
assistant_message = response.choices[0].message
if assistant_message.tool_calls:
messages.append({
"role": "assistant",
"content": assistant_message.content,
"tool_calls": [
{
"id": tc.id,
"type": "function",
"function": {
"name": tc.function.name,
"arguments": tc.function.arguments
}
}
for tc in assistant_message.tool_calls
]
})
for tool_call in assistant_message.tool_calls:
tool_name = tool_call.function.name
tool_args = json.loads(tool_call.function.arguments)
print(f"Calling: {tool_name}")
print(f"Arguments: {json.dumps(tool_args, indent=2)}")
function_result = klavis_client.mcp_server.call_tools(
server_url=mcp_server_url,
tool_name=tool_name,
tool_args=tool_args
)
messages.append({
"role": "tool",
"tool_call_id": tool_call.id,
"content": str(function_result)
})
continue
else:
messages.append({"role": "assistant", "content": assistant_message.content})
return assistant_message.content
return "Max iterations reached without final response"
# Run the integration
result = openai_with_mcp_server(
mcp_server_url=response.strata_server_url,
user_query="Check my latest 5 emails and summarize them in a Slack message to #general"
)
print(f"\n๐ค Final Response: {result}")
Strata Server Management
Add
Add servers to an existing Strata MCP server.
klavis_client.mcp_server.add_servers_to_strata(
strata_id="strata_abc123",
servers=[McpServerName.SLACK, McpServerName.NOTION]
)
Remove
Delete servers from an existing Strata MCP server.
klavis_client.mcp_server.delete_servers_from_strata(
strata_id="strata_abc123",
servers=["Slack"]
)
Get Strata Info
info = klavis_client.mcp_server.get_strata_instance(
strata_id="strata_abc123"
)
print(info.connected_servers) # List of connected servers
print(info.oauth_urls) # OAuth URLs for authentication
Tool Formats
Klavis supports multiple tool formats for different LLM providers:
openai- OpenAI function calling formatanthropic- Anthropic Claude tool formatgemini- Google Gemini function declarationsmcp_native- Standard MCP protocol format
Environment Variables
KLAVIS_API_KEY=your_klavis_api_key
Best Practices
- Use Strata Servers: Aggregate ond or multiple MCP servers into one endpoint for easier management
- Handle OAuth Gracefully: Direct users to OAuth URLs and wait for completion
- Reuse Connections: Create Strata servers once per user and reuse them
- Secure API Keys: Use environment variables and never commit keys to version control
Support & Resources
- Documentation: www.klavis.ai/docs
- OpenAPI klavis
- Website: klavis.ai
- PyPI: klavis
- npm: klavis
What's inside
7 sections covering REST API, Python/TypeScript SDKs, OpenAI integration example, Strata management, tool formats, env vars, and best practices
Change this for your project
- Replace
YOUR_API_KEYwith your actual Klavis API key - Replace
user_123with your user identifier - Replace
strata_abc123with your Strata instance ID - Replace
openai_keywith your OpenAI API key
Where it goes
Use as the system prompt for your model call, or as the base instructions in your agent framework.
Worth borrowing
- Aggregating multiple MCP servers into one Strata endpoint to simplify tool management
- Handling OAuth URLs returned from server creation for user authorization
- Looping tool calls with a max iteration guard to prevent infinite agent loops
Related Documents
Character Persona
Defines a Fallout 2 roleplay persona for an LLM agent: charming rogue with social-first combat and moral code.
Claude Tool Use (Function Calling) Documentation
Teaches how to define and use Claude tool use (function calling) with Python, including schema rules, execution patterns, and best practices.
Gemini by Example
Collects 20+ Gemini API code examples covering text, images, audio, video, PDFs, agents, and token counting.
DiffusionDB
Documents a 14-million-image prompt dataset scraped from the Stable Diffusion Discord server, with metadata and download instructions.