This project demonstrates how to use the OpenAI Agents SDK with the Xero MCP (Model Context Protocol) Server to create AI agents that can manage Xero accounting operations.
The integration provides several specialized AI agents that can perform Xero accounting tasks:
- General Xero Assistant: A comprehensive agent with access to all Xero tools
- Invoice Specialist: Focused on invoice creation, management, and workflows
- Contact Manager: Specialized in customer and supplier contact management
- 🤖 Multiple Agent Types: Choose from specialized agents or a general-purpose assistant
- 📝 Invoice Management: Create, find, and manage invoices with natural language
- 👥 Contact Operations: Create and manage customers and suppliers
- 🔄 Multi-Agent Workflows: Demonstrate complex workflows using multiple specialized agents
- 💬 Interactive Mode: Chat directly with agents using natural language
- 🔍 Comprehensive Examples: Pre-built demos showing various use cases
- Python 3.8+
- Node.js and npm/npx (for the Xero MCP Server)
- OpenAI API Key: Get from OpenAI Platform
- Xero Custom Connection Credentials:
- Xero Client ID
- Xero Client Secret
- Get these by creating a custom connection Xero app at Xero Developer Portal
-
Install Python dependencies:
pip install -r requirements.txt
-
Install Node.js (if not already installed):
- Download from nodejs.org
- The Xero MCP Server will be installed automatically via npx
-
Set up environment variables: Create a
.envfile in this directory with:OPENAI_API_KEY=your_openai_api_key_here XERO_CLIENT_ID=your_xero_client_id_here XERO_CLIENT_SECRET=your_xero_client_secret_here
Execute the main script to see the available demos:
python openai_agents.py- Basic Agent Demo: Shows general Xero operations
- Invoice Specialist Demo: Focused on invoice operations
- Contact Manager Demo: Customer and supplier management
- Multi-Agent Workflow: Demonstrates agent collaboration
- Comprehensive Workflow: End-to-end process (Recommended)
- Interactive Agent: Chat with agents in real-time
# The agent can understand natural language requests:
"Create a new customer named 'Tech Solutions Inc' with email tech@solutions.com"
# Find customers to get contact IDs:
"Find customers with 'Tech' in their name and show me their contact IDs"
# Create an invoice using the contact ID:
"Create an invoice for contact ID 12345678-1234-1234-1234-123456789abc with line item: Consulting for $1000"# Find invoices by status:
"Find all draft invoices"
"Find all invoices with status AUTHORISED"
# Search by date:
"Find invoices from the last 30 days"agent = create_basic_xero_agent(mcp_server)
# Has access to all Xero tools and operationsagent = create_invoice_specialist_agent(mcp_server)
# Optimized for invoice creation and managementagent = create_contact_manager_agent(mcp_server)
# Specialized in customer and supplier operationscreate_basic_xero_agent(): Creates a general-purpose Xero agentcreate_invoice_specialist_agent(): Creates an invoice-focused agentcreate_contact_manager_agent(): Creates a contact management agentdemo_*()functions: Various demonstration scenariosinteractive_demo(): Real-time chat interface
- Xero uses UUID format for contact IDs (e.g.,
12345678-1234-1234-1234-123456789abc) - Always find customers first to get valid contact IDs before creating invoices
- Contact IDs are required for invoice creation
- Always verify contact IDs before creating invoices
- Use natural language - the agents understand conversational requests
- Start with contact creation if you need new customers/suppliers
- Check agent responses for confirmation of successful operations
The script includes comprehensive error handling for:
- Missing environment variables
- Missing dependencies (openai-agents, npx)
- API connection issues
- Invalid user inputs
-
"Please install openai-agents" error:
pip install openai-agents
-
"npx is not installed" error:
- Install Node.js from nodejs.org
- npx comes bundled with Node.js
-
Environment variable errors:
- Ensure
.envfile exists with all required variables - Check that API keys are valid and active
- Ensure
-
Xero authentication issues:
- Verify Xero app credentials are correct
- Ensure your Xero app has proper permissions
-
Create Customer:
"Create a new customer named 'Demo Corp' with email billing@democorp.com" -
Find Customer ID:
"Find customers with 'Demo' in their name and show their contact IDs" -
Create Invoice:
"Create an invoice for contact ID [uuid-from-step-2] with line item: Consulting Services for $1500"
# Use Contact Manager to create customer
contact_agent = create_contact_manager_agent(mcp_server)
result = await Runner.run(contact_agent, "Create customer ABC Corp")
# Use Invoice Specialist to create invoice
invoice_agent = create_invoice_specialist_agent(mcp_server)
result = await Runner.run(invoice_agent, "Create invoice for ABC Corp")| Variable | Description | Required |
|---|---|---|
OPENAI_API_KEY |
Your OpenAI API key | Yes |
XERO_CLIENT_ID |
Xero app client ID | Yes |
XERO_CLIENT_SECRET |
Xero app client secret | Yes |
| Package | Version | Purpose |
|---|---|---|
openai-agents |
≥0.1.0 | OpenAI Agents SDK |
python-dotenv |
≥1.0.0 | Environment variable management |
To extend this integration:
- Add new agent types by creating specialized agent functions
- Implement additional demo scenarios in new
demo_*()functions - Add error handling for specific Xero API scenarios
- Create custom workflows for specific business processes
This project is part of the Xero Agent Toolkit. Please refer to the main project license.
For issues related to:
- OpenAI Agents SDK: Check OpenAI documentation
- Xero API: Visit Xero Developer Portal
- This Integration: Create an issue in the main repository