This module demonstrates how to integrate Xero accounting operations with Google's Agent Development Kit (ADK) using the Xero MCP (Model Context Protocol) Server.
The google-adk.py file provides a complete implementation of a Xero AI agent that can:
- List and create contacts/customers
- Manage invoices (list, create, view)
- Handle payments and accounting operations
- Process natural language queries about Xero data
- Demonstrate error handling and batch operations
- Real-time Xero Integration: Uses the Xero MCP Server for direct API access
- Natural Language Processing: Handles conversational queries about accounting data
- Comprehensive Error Handling: Graceful handling of API errors and edge cases
- Interactive Demo Mode: Run interactive sessions with the AI agent
- Multiple Demo Scenarios: Pre-built demos for different use cases
-
Node.js and npm: Required for the Xero MCP Server
# Install Node.js from https://nodejs.org/ node --version npm --version -
Xero Developer Account: Get your credentials from Xero Developer Portal
- Client ID
- Client Secret
-
Google AI Configuration: Set up either Google AI Studio or Vertex AI
- For Google AI Studio: Get API key from Google AI Studio
- For Vertex AI: Set up Google Cloud project and authentication
-
Install the required Python dependencies:
pip install -r requirements.txt
-
Set up environment variables in a
.envfile:# Xero API Credentials XERO_CLIENT_ID=your_xero_client_id XERO_CLIENT_SECRET=your_xero_client_secret # Google AI Configuration (choose one) # Option 1: Google AI Studio GOOGLE_API_KEY=your_google_ai_studio_api_key # Option 2: Vertex AI GOOGLE_GENAI_USE_VERTEXAI=TRUE GOOGLE_CLOUD_PROJECT=your_project_id # Optional: Specify model (defaults to gemini-2.0-flash) DEFAULT_MODEL=gemini-2.0-flash
python google-adk.pyThis will present you with several demo options:
- Basic Operations: List contacts, invoices, and account summary
- Invoice Workflow: Complete invoice creation workflow
- Natural Language Processing: Process conversational queries
- Error Handling: Demonstrate error scenarios
- Batch Operations: Multiple operations in sequence
- Interactive Demo: Chat-like interface with the agent
import asyncio
from google-adk import XeroADKAgent
async def example():
async with XeroADKAgent() as agent:
# Ask natural language questions
result = await agent.process("Show me my recent invoices")
print(result)
# Create new contacts
result = await agent.process("Create a new customer named ABC Corp")
print(result)
# Run the example
asyncio.run(example())The agent has access to these Xero MCP tools:
list-contacts: List all contacts/customerscreate-contact: Create new contactslist-invoices: List invoices with filteringcreate-invoice: Create new invoiceslist-accounts: List chart of accountslist-items: List inventory itemslist-tax-rates: List available tax rateslist-tracking-categories: List tracking categoriesupdate-contact: Update existing contactsupdate-invoice: Update draft invoicescreate-payment: Create payments against invoiceslist-payments: List existing paymentslist-organisation-details: Get organization information
The agent can handle natural language queries like:
- "Show me a summary of my Xero account"
- "List my first 5 contacts"
- "Create a new customer named Demo Company Inc with email demo@company.com"
- "Create an invoice for Demo Company Inc for consulting services worth $750"
- "What's the current state of my invoices?"
- "Show me all my customers"
- "I need to bill my client $2,000 for consulting work"
The integration uses:
- Google ADK: For AI agent framework and natural language processing
- Xero MCP Server: For secure, structured access to Xero API
- Model Context Protocol: For tool communication between ADK and Xero
- Async/Await: For non-blocking operations and better performance
The agent includes comprehensive error handling for:
- Missing environment variables
- Network connectivity issues
- Invalid Xero API responses
- Tool execution failures
- Async operation cleanup
-
"npx is not installed"
- Install Node.js from https://nodejs.org/
-
"Missing required environment variables"
- Check your
.envfile has all required Xero credentials
- Check your
-
"Google ADK is not installed"
- Run
pip install -r requirements.txt
- Run
-
"No model configuration found"
- Set either
GOOGLE_API_KEYorGOOGLE_GENAI_USE_VERTEXAI=TRUE
- Set either
Enable debug output by setting:
GOOGLE_GENAI_LOG_LEVEL=DEBUGWhen extending this integration:
- Add new MCP tools to the
tool_filterincreate_xero_mcp_toolset() - Update the agent instructions to include new capabilities
- Add corresponding demo scenarios
- Update this README with new features