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

# LlamaIndex

> Connect a LlamaIndex agent to Civic's MCP Hub using streamable HTTP transport

Connect a [LlamaIndex](https://docs.llamaindex.ai/) agent to Civic using `BasicMCPClient` and `McpToolSpec`. LlamaIndex's MCP integration discovers all available tools and exposes them to a `FunctionAgent`.

## Prerequisites

* Python 3.11+
* A Civic account at [app.civic.com](https://app.civic.com) with a configured toolkit
* A Civic token and an Anthropic API key

## Installation

```bash theme={null}
pip install llama-index llama-index-tools-mcp llama-index-llms-anthropic python-dotenv
```

## Environment Variables

```bash theme={null}
CIVIC_URL=https://app.civic.com/hub/mcp?profile=your-toolkit
CIVIC_TOKEN=your-civic-token
ANTHROPIC_API_KEY=your-anthropic-key
```

<Card title="Get Your Credentials" icon="key" href="/civic/quickstart/credentials">
  How to generate a Civic token and configure toolkit URL parameters
</Card>

## Connecting to Civic

Use `BasicMCPClient` to connect (URL is positional, not a keyword argument), then convert tools with `McpToolSpec`:

```python theme={null}
import os
import asyncio
from dotenv import load_dotenv
from llama_index.tools.mcp import BasicMCPClient, McpToolSpec
from llama_index.llms.anthropic import Anthropic
from llama_index.core.agent.workflow import FunctionAgent

load_dotenv()

async def main():
    mcp_client = BasicMCPClient(
        os.environ["CIVIC_URL"],  # positional — not url=
        headers={"Authorization": f"Bearer {os.environ['CIVIC_TOKEN']}"},
    )
    spec = McpToolSpec(client=mcp_client)
    tools = await spec.to_tool_list_async()
    print(f"{len(tools)} tools loaded")

    llm = Anthropic(model="claude-sonnet-4-6")
    agent = FunctionAgent(
        tools=tools,
        llm=llm,
        system_prompt="You are a helpful assistant with access to Civic tools.",
    )
    response = await agent.run("What events do I have today?")
    print(response)

asyncio.run(main())
```

<Note>
  Pass the URL as a positional argument to `BasicMCPClient` — using `url=` as a keyword will raise an error. Use `FunctionAgent` from `llama_index.core.agent.workflow` — `ReActAgent.from_tools` is not available in LlamaIndex v0.14+.
</Note>

## Production Configuration

For production agents, lock to a specific toolkit using the `profile` URL parameter:

```bash theme={null}
CIVIC_URL=https://app.civic.com/hub/mcp?profile=your-production-toolkit
```

## Reference Implementation

<Card title="llamaindex-reference-implementation-civic" icon="github" href="https://github.com/civicteam/llamaindex-reference-implementation-civic">
  Complete implementation with FastAPI chat UI and deployment guide
</Card>

## Next Steps

<CardGroup cols={2}>
  <Card title="Agent Deployment" icon="robot" href="/civic/quickstart/clients/agents">
    Production deployment guide: profile locking, URL params, authentication
  </Card>

  <Card title="Guardrails" icon="shield" href="/civic/concepts/guardrails">
    Constrain what tools your agent can call
  </Card>

  <Card title="Audit Trail" icon="list-check" href="/civic/concepts/audit">
    Query what your agent did via Civic Chat
  </Card>

  <Card title="Get Credentials" icon="key" href="/civic/quickstart/credentials">
    Token generation and URL parameter reference
  </Card>
</CardGroup>
