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
- Policy Fetch: Astha fetches RBAC policy from
api.astha.aiusing your credentials - Tool Filtering: Only tools allowed by your policy are exposed to the agent
- MCP Connection: Connects to MCP server via
mcp-proxyusing stdio transport - Agent Creation: Creates a LangChain-compatible MCPAgent with filtered tools
Requirements
- Python 3.11+
uvpackage manager- Anthropic API key
- Astha user access token and AZTP ID
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e17e9813acdac7a69f148ddf686d4b4fab7d7a3f469915147b589519debb20af
|
|
| MD5 |
fde90deaae7d50e0b2611e792a43e76e
|
|
| BLAKE2b-256 |
dabf6450facd7b934a7c2f6c768f1e8edc098cb6697bf32e65b4ea60a541fdf4
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
340d20d77278206f638da74a747e1c8576f3a737b571aea781f424d61967b583
|
|
| MD5 |
1447ddf72410e0594d56aeb223de1de6
|
|
| BLAKE2b-256 |
ffacf90ff71d5f5d30f61c590b6f054bb3b027ece44adcf73568a379e5d0c27d
|