> ## Documentation Index
> Fetch the complete documentation index at: https://develop.cotality.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Python example

> Connect to Cotality MCP and call tools programmatically using the MCP Python SDK.

The following is a concise example using the MCP Python SDK to connect to the Cotality MCP server and call a tool.

***

## Prerequisites

* Python 3.10+

```bash theme={null}
pip install mcp httpx python-dotenv
```

***

## Programmatically connect and call MCP tools

Create a `.env` file (or set environment variables) with your credentials and endpoint. See [Authentication](../mcp/authentication) for details on obtaining credentials and [Quick start](../mcp/quickstart) for endpoint URLs.

```ini theme={null}
# .env
TOKEN_URL=https://<token-endpoint>/oauth/token?grant_type=client_credentials
CLIENT_ID=<your-client-id>
CLIENT_SECRET=<your-client-secret>
MCP_ENDPOINT=https://<endpoint>/mcp
```

Then run the following script:

```python theme={null}
import asyncio
import os
import httpx
from dotenv import load_dotenv
from mcp.client.streamable_http import streamable_http_client
from mcp import ClientSession

load_dotenv()


async def main():
    # 1. Obtain an access token
    token_url = os.environ["TOKEN_URL"]
    client_id = os.environ["CLIENT_ID"]
    client_secret = os.environ["CLIENT_SECRET"]

    async with httpx.AsyncClient() as http:
        token_response = await http.post(
            token_url,
            auth=(client_id, client_secret),
            data={"grant_type": "client_credentials"},
        )
        token_response.raise_for_status()
        access_token = token_response.json()["access_token"]

    # 2. Connect to Cotality MCP
    endpoint = os.environ["MCP_ENDPOINT"]
    headers = {"Authorization": f"Bearer {access_token}"}

    async with streamable_http_client(endpoint, http_client=httpx.AsyncClient(headers=headers)) as (read, write, _):
        async with ClientSession(read, write) as session:
            await session.initialize()

            # 3. List available tools
            tools = await session.list_tools()
            print(f"Available tools: {[t.name for t in tools.tools]}")

            # 4. Call a tool
            result = await session.call_tool(
                "clip-find_property_by_full_address",
                arguments={"full_address": "3001 Hackberry Rd, Irving, TX 75063"}
            )
            print(result)


asyncio.run(main())
```

***

## What this does

1. Authenticates using your `client_id` and `client_secret` to obtain an access token
2. Connects to Cotality MCP over Streamable HTTP with the access token
3. Lists your available MCP tools
4. Calls `clip-find_property_by_full_address` with a sample address and prints the result
