# LlamaIndex

> Read pages and crawls as LlamaIndex documents, and connect LlamaIndex agents to our MCP tools.

**TL;DR**: [install](#install) `llama-index-readers-megalania`, then
`MegalaniaReader().load_data(urls)`. The key comes from `MEG_API_KEY`.
Blocked pages and errors are free.

## Install

Python 3.10 or newer.

```sh
pip install llama-index-readers-megalania
```

## Documents

```python
from llama_index.readers.megalania import MegalaniaReader

docs = MegalaniaReader().load_data(["https://docs.megalania.io/"])
print(docs[0].metadata["credits_charged"], docs[0].text[:200])
```

Each document holds Markdown, with `source`, `request_id`, `credits_charged`
and `target_status` in its metadata. Pass any key of the
[JSON envelope](/guides/fetch) as a keyword, for example `country_code="DE"`.
A blocked page raises `MegalaniaError`. `MegalaniaReader(continue_on_failure=True)`
skips it instead.

A whole site, through a [batch](/guides/batches) crawl:

```python
from llama_index.readers.megalania import MegalaniaReader

docs = MegalaniaReader().load_data("https://docs.megalania.io/", crawl={"max_pages": 20})
print(len(docs))
```

Then index them as usual:

```python
from llama_index.core import VectorStoreIndex

index = VectorStoreIndex.from_documents(docs)
print(index.as_query_engine().query("What does Megalania sell?"))
```

## Agents

LlamaIndex agents use our [MCP server](/guides/mcp) through
`llama-index-tools-mcp`. They get every tool, with no extra package:

```python
import asyncio
import os

from llama_index.tools.mcp import BasicMCPClient, McpToolSpec

client = BasicMCPClient("https://mcp.megalania.io/", headers={"Authorization": f"Bearer {os.environ['MEG_API_KEY']}"})
tools = asyncio.run(McpToolSpec(client=client).to_tool_list_async())
```

The code is MIT licensed at https://github.com/megalania/megalania-python.
