LlamaIndex
Connect a LlamaIndex 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 with a configured toolkit
- A Civic token and an Anthropic API key
Installation
pip install llama-index llama-index-tools-mcp llama-index-llms-anthropic python-dotenv
Environment Variables
CIVIC_URL=https://app.civic.com/hub/mcp?profile=your-toolkit
CIVIC_TOKEN=your-civic-token
ANTHROPIC_API_KEY=your-anthropic-key
Get Your Credentials
How to generate a Civic token and configure toolkit URL parameters
Connecting to Civic
Use BasicMCPClient to connect (URL is positional, not a keyword argument), then convert tools with McpToolSpec:
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+.
Production Configuration
For production agents, lock to a specific toolkit using the profile URL parameter:
CIVIC_URL=https://app.civic.com/hub/mcp?profile=your-production-toolkit
Reference Implementation
llamaindex-reference-implementation-civic
Complete implementation with FastAPI chat UI and deployment guide