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.0.tar.gz (12.8 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.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: astha_client-0.1.0.tar.gz
  • Upload date:
  • Size: 12.8 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.0.tar.gz
Algorithm Hash digest
SHA256 e17e9813acdac7a69f148ddf686d4b4fab7d7a3f469915147b589519debb20af
MD5 fde90deaae7d50e0b2611e792a43e76e
BLAKE2b-256 dabf6450facd7b934a7c2f6c768f1e8edc098cb6697bf32e65b4ea60a541fdf4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: astha_client-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.9 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 340d20d77278206f638da74a747e1c8576f3a737b571aea781f424d61967b583
MD5 1447ddf72410e0594d56aeb223de1de6
BLAKE2b-256 ffacf90ff71d5f5d30f61c590b6f054bb3b027ece44adcf73568a379e5d0c27d

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