Skip to main content

Python SDK for Astha AI platform

Project description

Astha Client

RBAC-controlled MCP (Model Context Protocol) tool access for AI agents. A clean, simple Python package for integrating MCP tools with LangChain agents while enforcing role-based access control.

Features

  • RBAC Policy Enforcement: Automatically fetch and apply access policies from Astha API
  • LangChain Integration: Seamless integration with LangChain and Anthropic models
  • Clean API: Simple, Composio-like interface for MCP tool access
  • Flexible Configuration: Support for custom MCP server configs (dict or file)
  • Async Context Manager: Automatic resource cleanup

Installation

uv sync

Quick Start

import asyncio
from astha_client import Astha
from langchain_anthropic import ChatAnthropic

MCP_CONFIG = {
    "mcpServers": {
        "my-server": {
            "command": "uvx",
            "args": [
                "mcp-proxy",
                "http://mcp.astha.ai/sse",
                "--headers", "X-User-Access-Token", "your-token",
                "--headers", "X-Aztp-ID", "aztp://your-aztp-id",
            ],
        }
    }
}

async def main():
    async with Astha(
        user_access_token="your-token",
        aztp_id="aztp://your-aztp-id",
        mcp_config=MCP_CONFIG,
    ) as astha:
        # View allowed tools from RBAC policy
        print(f"Allowed tools: {astha.get_tools()}")

        # Create agent with RBAC-filtered tools
        llm = ChatAnthropic(model="claude-sonnet-4-5-20250929")
        agent = await astha.create_agent(llm=llm)

        # Run queries
        result = await agent.run("Send SMS to +1234567890")
        print(result)

asyncio.run(main())

Configuration

Environment Variables

Create a .env file:

ANTHROPIC_API_KEY=your-anthropic-api-key
ASTHA_USER_ACCESS_TOKEN=your-user-access-token
ASTHA_AZTP_ID=aztp://aztp.network/workload/your-workload

MCP Server Configuration

You can provide MCP config in three ways:

1. Dictionary:

Astha(
    user_access_token="...",
    aztp_id="...",
    mcp_config={"mcpServers": {...}}
)

2. Config file:

Astha(
    user_access_token="...",
    aztp_id="...",
    mcp_config_file="mcp_config.json"
)

3. Default (uses Astha gateway):

Astha(
    user_access_token="...",
    aztp_id="..."
)

API Reference

Astha

class Astha:
    def __init__(
        self,
        user_access_token: str,
        aztp_id: str,
        *,
        mcp_config: dict | None = None,
        mcp_config_file: str | Path | None = None,
        policy_service_url: str = "https://api.astha.ai/...",
    )

    async def initialize(self) -> None
    async def create_agent(self, llm, max_steps=15, memory_enabled=True) -> MCPAgent
    def get_tools(self) -> list[str]
    async def close(self) -> None

    # Properties
    policy: Policy | None
    mcp_url: str | None
    allowed_tools: frozenset[str]
    denied_tools: frozenset[str]

Context Manager

async with Astha(...) as astha:
    agent = await astha.create_agent(llm=llm)
    result = await agent.run("your query")
# Resources automatically cleaned up

How It Works

  1. Policy Fetch: Astha fetches RBAC policy from api.astha.ai using your credentials
  2. Tool Filtering: Only tools allowed by your policy are exposed to the agent
  3. MCP Connection: Connects to MCP server via mcp-proxy using stdio transport
  4. Agent Creation: Creates a LangChain-compatible MCPAgent with filtered tools

Requirements

  • Python 3.11+
  • uv package manager
  • Anthropic API key
  • Astha user access token and AZTP ID

License

MIT

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

astha_client-0.1.1.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

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

astha_client-0.1.1-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file astha_client-0.1.1.tar.gz.

File metadata

  • Download URL: astha_client-0.1.1.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for astha_client-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1f69cb5c72db07861c3d0769263e62c322f2cb0d958be419fb981b98a2455597
MD5 32ecced5f5cdf80878865ada8c658158
BLAKE2b-256 155546c8e8e1d0f3a760b9f9fa81a32d4e592551270976146c7922a057782b1d

See more details on using hashes here.

File details

Details for the file astha_client-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: astha_client-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for astha_client-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d2770fce7df23c05f04bf77a4e070a40303cfe7752ee399660a662902132103d
MD5 6f28041d8fc3e3e274575f576e5d3dbd
BLAKE2b-256 57ca419fcc35c020deda68978dd068c8d9177fb0918a1117c1f25eabf50ee456

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