Prerequisites

1. Create an Affinity MCP Server

Use the following endpoint to create a new remote Affinity MCP server instance:

Request

from klavis import Klavis
from klavis.types import McpServerName, ConnectionType

klavis_client = Klavis(api_key="<YOUR_API_KEY>")

# Create an Affinity MCP server instance
affinity_server = klavis_client.mcp_server.create_server_instance(
    server_name=McpServerName.AFFINITY,
    user_id="<YOUR_USER_ID>",
    platform_name="<YOUR_PLATFORM_NAME>",
)

Response

{
  "serverUrl": "https://affinity-mcp-server.klavis.ai/sse?instance_id=<instance-id>",
  "instanceId": "<instance-id>"
}
serverUrl specifies the endpoint of the Affinity MCP server, which allows you to interact with your Affinity CRM data.
instanceId is used for authentication and identification of your server instance.

2. Configure Affinity API Key

To use the Affinity MCP Server, you need to configure it with your Affinity API key.

Setting up Affinity API Key

from klavis import Klavis

klavis_client = Klavis(api_key="<YOUR_KLAVIS_API_KEY>")

# Set the Affinity API key for your instance
response = klavis_client.mcp_server.set_instance_auth_token(
    instance_id="<YOUR_INSTANCE_ID>",
    auth_token="<YOUR_AFFINITY_API_KEY>",
)

print(response)

Response

{
  "success": true,
  "message": "<string>"
}

Explore MCP Server Tools