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

# Android SDK

> Build a native AI assistant in your Android app with the Metabind streaming client and BindJS Compose rendering

The Android Assistant SDK gives you the building blocks for an in-app AI assistant: a streaming client to Metabind's Agent proxy, an MCP client for your project's tools, and native Jetpack Compose rendering of tool results through BindJS. Use the drop-in `MetabindAssistantView` for a complete chat UI, or build your own with the lower-level APIs.

<CardGroup cols={2}>
  <Card title="SDK on GitHub" icon="github" href="https://github.com/metabindai/metabind-ai-android">
    `metabind-ai-android` — the Assistant SDK source.
  </Card>

  <Card title="Demo app" icon="github" href="https://github.com/metabindai/metabind-assistant-demo-android">
    `metabind-assistant-demo-android` — a complete Compose chat app built on the SDK.
  </Card>
</CardGroup>

## Requirements

| Requirement | Version               |
| ----------- | --------------------- |
| Android     | 8.0 (API 26) or later |
| UI toolkit  | Jetpack Compose       |
| JDK         | 21                    |

## Installation

Add the umbrella dependency, which pulls in the MCP client (`mcpappshost-android`) and the BindJS renderer (`bindjs-android`) transitively:

<Tabs>
  <Tab title="build.gradle.kts">
    ```kotlin theme={null}
    dependencies {
        implementation("ai.metabind:metabind-assistant-android:0.1.6")
    }
    ```
  </Tab>

  <Tab title="build.gradle">
    ```groovy theme={null}
    dependencies {
        implementation 'ai.metabind:metabind-assistant-android:0.1.6'
    }
    ```
  </Tab>
</Tabs>

See the [repository README](https://github.com/metabindai/metabind-ai-android) for the Maven repository configuration.

## What you configure

* A **Metabind API key**, sent as a `Bearer` token to both the Agent proxy and the MCP server.
* Your project's **`orgId`** and **`projectId`**.
* The **Agent proxy host** (`https://agent.metabind.ai`) and your project's **MCP server URL** (copy it from the Server tab in MCP App Studio).

## Drop in the chat surface

The SDK ships `MetabindAssistantView`, a complete chat UI:

```kotlin theme={null}
import ai.metabind.assistant.MetabindAssistant
import ai.metabind.assistant.MetabindAssistantView

@Composable
fun AssistantScreen() {
    val assistant = remember {
        MetabindAssistant(
            apiKey = apiKey,
            orgId = orgId,
            projectId = projectId
        )
    }

    MetabindAssistantView(assistant = assistant)
}
```

`MetabindAssistantView` handles message bubbles, streaming indicators, tool rendering, input, and auto-scrolling. It follows your app's Material3 theme.

### MetabindAssistant

`MetabindAssistant` manages the conversation. For custom UIs, observe its state directly:

| Property        | Type                                    | Description                 |
| --------------- | --------------------------------------- | --------------------------- |
| `messages`      | `StateFlow<List<ChatMessage>>`          | Conversation history        |
| `isLoading`     | `StateFlow<Boolean>`                    | True while streaming        |
| `error`         | `StateFlow<String?>`                    | Error message, if any       |
| `toolUIContent` | `StateFlow<Map<String, ToolUIContent>>` | Tool UI payloads by call ID |

| Method       | Description             |
| ------------ | ----------------------- |
| `send(text)` | Send a user message     |
| `cancel()`   | Cancel current response |
| `reset()`    | Clear conversation      |
| `close()`    | Release resources       |

### ChatMessage

```kotlin theme={null}
data class ChatMessage(
    val id: String,
    val role: MessageRole,       // USER, ASSISTANT, or TOOL
    val content: String,
    val toolName: String?,
    val toolStatus: ToolStatus?  // LOADING, COMPLETED, or ERROR
)
```

## Stream a conversation turn

`MetabindAgentProvider` calls the Agent proxy — which holds the LLM key and runs the tool loop server-side — and streams results back as a `Flow<LLMStreamEvent>`:

```kotlin theme={null}
import ai.metabind.assistant.MetabindAgentProvider
import ai.metabind.mcpappshost.LLMMessage
import ai.metabind.mcpappshost.LLMStreamEvent

val provider = MetabindAgentProvider()

provider.streamMessage(
    baseUrl = "https://agent.metabind.ai",
    apiKey = apiKey,
    orgId = orgId,
    projectId = projectId,
    messages = history   // List<LLMMessage>: User / Assistant / ToolResults
).collect { event ->
    when (event) {
        is LLMStreamEvent.TextDelta     -> { /* append streaming text */ }
        is LLMStreamEvent.ToolCallStart -> { /* a tool was invoked */ }
        is LLMStreamEvent.ToolResult    -> { /* tool finished */ }
        is LLMStreamEvent.Done          -> { /* turn complete */ }
        is LLMStreamEvent.Error         -> { /* handle the error */ }
        else -> {}
    }
}
```

The Android SDK is **Agent-proxy only** — there's no bring-your-own-key Anthropic provider. See [LLM provider configuration](/guides/assistant-sdk/llm-provider-configuration) for how the proxy works.

## Discover and fetch tool UIs

Use `MCPAppsClient` to list your project's tools and fetch the UI resource for a tool that renders one:

```kotlin theme={null}
import ai.metabind.mcpappshost.MCPAppsClient
import ai.metabind.assistant.ToolUIContent

val client = MCPAppsClient(
    url = mcpServerUrl,
    headers = mapOf("authorization" to "Bearer $apiKey")
)

val tools = client.listTools()

// When a tool with a UI is called, fetch and parse its resource:
val resource = client.readResource(resourceUri)
val ui = ToolUIContent.fromResource(resource, toolArguments)  // BindJS or Html
```

`MCPAppsClient` also exposes `callTool(name, arguments)` for invoking tools.

## Native rendering of tool output

If you use `MetabindAssistantView`, tool rendering is automatic.

For custom UIs, `ToolUIContent` has two variants:

* `ToolUIContent.BindJS` — render via `BindJSView` from `bindjs-android`
* `ToolUIContent.Html` — render in a WebView

See the demo app's `HomeScreen.kt` for the full wiring.

## Build a custom chat UI

If `MetabindAssistantView` doesn't fit your design, build your own around `MetabindAssistant`. Observe `assistant.messages`, call `assistant.send(text)`, and render tool UIs via `assistant.toolUIContent`. The demo app's `HomeScreen.kt` is a complete reference.

## Next steps

<CardGroup cols={2}>
  <Card title="Demo app" icon="github" href="https://github.com/metabindai/metabind-assistant-demo-android">
    The reference Compose chat app, end to end.
  </Card>

  <Card title="LLM provider configuration" icon="brain" href="/guides/assistant-sdk/llm-provider-configuration">
    How the Agent proxy holds keys and runs the tool loop.
  </Card>

  <Card title="BindJS reference" icon="code" href="/bindjs/introduction">
    The component language the tool UIs are written in.
  </Card>

  <Card title="iOS SDK" icon="apple" href="/guides/assistant-sdk/ios-sdk">
    The iOS equivalent.
  </Card>
</CardGroup>
