The Extend AI Toolkit provides integration with Extend APIs for multiple AI frameworks, including Model Context Protocol (MCP), OpenAI, LangChain, and CrewAI. This toolkit enables AI agents to perform spend management tasks such as managing virtual cards, viewing credit cards, and handling transactions.
Install the package using pip:
pip install extend_ai_toolkit
langchain
and langchain-openai
packagesopenai
packagecrewai
packageanthropic
package (for Claude)Configure the library with your Extend API credentials using either command-line arguments:
--api-key=your_api_key_here --api-secret=your_api_secret_here
Or environment variables:
EXTEND_API_KEY=your_api_key_here
EXTEND_API_SECRET=your_api_secret_here
get_virtual_cards
: Fetch virtual cards with optional filtersget_virtual_card_detail
: Get detailed information about a specific virtual cardget_credit_cards
: List all credit cardsget_credit_card_detail
: Get detailed information about a specific credit cardget_transactions
: Fetch transactions with various filtersget_transaction_detail
: Get detailed information about a specific transactionupdate_transaction_expense_data
: Update expense-related data for a transactionget_expense_categories
: List all expense categoriesget_expense_category
: Get details of a specific expense categoryget_expense_category_labels
: Get labels for an expense categorycreate_expense_category
: Create a new expense categorycreate_expense_category_label
: Add a label to an expense categoryupdate_expense_category
: Modify an existing expense categorycreate_receipt_attachment
: Upload a receipt (and optionally attach to a transaction)automatch_receipts
: Initiate async job to automatch uploaded receipts to transactionsget_automatch_status
: Get the status of an automatch jobsend_receipt_reminder
: Send a reminder (via email) for a transaction missing a receiptTest the Extend MCP server locally using MCP Inspector:
npx @modelcontextprotocol/inspector python extend_ai_toolkit/modelcontextprotocol/main.py --tools=all
Add the MCP server to Claude Desktop by editing the configuration file:
~/Library/Application\ Support/Claude/claude_desktop_config.json
%APPDATA%/Claude/claude_desktop_config.json
Add this configuration:
{
"extend-mcp": {
"command": "python",
"args": [
"-m",
"extend_ai_toolkit.modelcontextprotocol.main",
"--tools=all"
],
"env": {
"EXTEND_API_KEY": "apik_XXXX",
"EXTEND_API_SECRET": "XXXXX"
}
}
}
For receipt attachment functionality, install the filesystem MCP server:
npm install @modelcontextprotocol/server-filesystem
Then add this to your config file:
{
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/path/to/receipts/folder"
]
}
}
Run the server remotely using SSE transport:
python -m extend_ai_toolkit.modelcontextprotocol.main_sse --tools=all --api-key="apikey" --api-secret="apisecret"
Connect using the MCP terminal client:
python -m extend_ai_toolkit.modelcontextprotocol.client.mcp_client --mcp-server-host localhost --mcp-server-port 8000 --llm-provider=anthropic --llm-model=claude-3-5-sonnet-20241022
import os
from langchain_openai import ChatOpenAI
from extend_ai_toolkit.openai.toolkit import ExtendOpenAIToolkit
from extend_ai_toolkit.shared import Configuration, Scope, Product, Actions
# Initialize the OpenAI toolkit
extend_openai_toolkit = ExtendOpenAIToolkit.default_instance(
api_key=os.environ.get("EXTEND_API_KEY"),
api_secret=os.environ.get("EXTEND_API_SECRET"),
configuration=Configuration(
scope=[
Scope(Product.VIRTUAL_CARDS, actions=Actions(read=True)),
Scope(Product.CREDIT_CARDS, actions=Actions(read=True)),
Scope(Product.TRANSACTIONS, actions=Actions(read=True)),
]
)
)
# Create an agent with the tools
extend_agent = Agent(
name="Extend Agent",
instructions="You are an expert at integrating with Extend",
tools=extend_openai_toolkit.get_tools()
)
import os
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
from extend_ai_toolkit.langchain.toolkit import ExtendLangChainToolkit
from extend_ai_toolkit.shared import Configuration, Scope, Product, Actions
# Initialize the LangChain toolkit
extend_langchain_toolkit = ExtendLangChainToolkit.default_instance(
api_key=os.environ.get("EXTEND_API_KEY"),
api_secret=os.environ.get("EXTEND_API_SECRET"),
configuration=Configuration(
scope=[
Scope(Product.VIRTUAL_CARDS, actions=Actions(read=True)),
Scope(Product.CREDIT_CARDS, actions=Actions(read=True)),
Scope(Product.TRANSACTIONS, actions=Actions(read=True)),
]
)
)
# Create tools for the agent
tools = extend_langchain_toolkit.get_tools()
# Create the agent executor
langgraph_agent_executor = create_react_agent(
ChatOpenAI(model="gpt-4"),
tools
)
import os
from extend_ai_toolkit.crewai.toolkit import ExtendCrewAIToolkit
from extend_ai_toolkit.shared import Configuration, Scope, Product, Actions
# Initialize the CrewAI toolkit
toolkit = ExtendCrewAIToolkit.default_instance(
api_key=os.environ.get("EXTEND_API_KEY"),
api_secret=os.environ.get("EXTEND_API_SECRET"),
configuration=Configuration(
scope=[
Scope(Product.VIRTUAL_CARDS, actions=Actions(read=True)),
Scope(Product.CREDIT_CARDS, actions=Actions(read=True)),
Scope(Product.TRANSACTIONS, actions=Actions(read=True)),
]
)
)
# Configure the LLM (using Claude)
toolkit.configure_llm(
model="claude-3-opus-20240229",
api_key=os.environ.get("ANTHROPIC_API_KEY")
)
# Create the Extend agent
extend_agent = toolkit.create_agent(
role="Extend Integration Expert",
goal="Help users manage virtual cards, view credit cards, and check transactions efficiently",
backstory="You are an expert at integrating with Extend, with deep knowledge of virtual cards, credit cards, and transaction management.",
verbose=True
)
# Create a task for handling user queries
query_task = toolkit.create_task(
description="Process and respond to user queries about Extend services",
agent=extend_agent,
expected_output="A clear and helpful response addressing the user's query",
async_execution=True
)
# Create a crew with the agent and task
crew = toolkit.create_crew(
agents=[extend_agent],
tasks=[query_task],
verbose=True
)
# Run the crew
result = crew.kickoff()
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "extend-mcp" '{"command":"python","args":["-m","extend_ai_toolkit.modelcontextprotocol.main","--tools=all"],"env":{"EXTEND_API_KEY":"apik_XXXX","EXTEND_API_SECRET":"XXXXX"}}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"extend-mcp": {
"command": "python",
"args": [
"-m",
"extend_ai_toolkit.modelcontextprotocol.main",
"--tools=all"
],
"env": {
"EXTEND_API_KEY": "apik_XXXX",
"EXTEND_API_SECRET": "XXXXX"
}
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"extend-mcp": {
"command": "python",
"args": [
"-m",
"extend_ai_toolkit.modelcontextprotocol.main",
"--tools=all"
],
"env": {
"EXTEND_API_KEY": "apik_XXXX",
"EXTEND_API_SECRET": "XXXXX"
}
}
}
}
3. Restart Claude Desktop for the changes to take effect