InvoiceShelf MCP Multitenant Proxy Server
This repository contains a Model Context Protocol (MCP) server that actsas a secure, multi-tenant proxy between an AI Assistant and theInvoiceShelf backend API. It exposes 109 MCP tools covering14 resource domains with full CRUD, search, dashboard,and relationship management.
โจ Features
- ๐ Identity Passthrough โ Extracts the
Authorization: Bearer <token>header from incoming HTTP requests and forwards it to the InvoiceShelfAPI without server-side authentication. - ๐ฅ Multi-Tenancy โ Uses Python
contextvarsto maintain thread-safeuser identity isolation, ensuring all AI-driven actions are scoped tothe authenticated user's permissions. - ๐ Full InvoiceShelf Coverage โ 109 tools mapped to InvoiceShelfAPI endpoints across 14 resource domains.
- โก TOON Optimization โ All list responses are automatically compressedusing TOON (Token-Optimized Object Notation) to reduce token consumptionand maximize context window efficiency.
- โก Efficient Gets โ GET responses return only commonly used fields bydefault. Full objects are available via an
include_all_fieldsflag. - ๐งช Comprehensive Testing โ 208 automated tests covering all tooldomains, run via the test runner pipeline.
๐ง Environment Variables
| Variable | Required | Description |
|---|---|---|
INVOICESHELF_BASE_URL |
Yes | Docker-internal URL of the InvoiceShelf API |
MCP_SERVER_PORT |
Yes | Port number the MCP server listens on |
ALLOW_ALL_AGGREGATE |
No | When true, aggregate listing tools honor the include_all_fields parameter. When false (default), the parameter is silently forced to False for aggregate list operations. |
IS_STATEFUL |
No | When true, uses stateful Streamable HTTP with session tracking. When false (default), uses stateless mode. |
INVOICESHELF_PUBLIC_URL |
No | Public-facing URL to replace internal Docker URLs in responses. Defaults to INVOICESHELF_BASE_URL if not set. |
๐ฆ Installation & Local Development
- Ensure you have Python 3.12+ installed.
- Install dependencies:
pip install fastmcp httpx pydantic uvicorn toon-mcp-server - Run the server:
export INVOICESHELF_BASE_URL=http://localhost:8080 export INVOICESHELF_PUBLIC_URL=https://invoiceshelf.example.com export MCP_SERVER_PORT=80 python -m src.main
๐ณ Docker Deployment
Build and run the server using Docker:
docker build -t invoiceshelf-mcp:latest .
docker run -d --name invoiceshelf-mcp \
-e INVOICESHELF_BASE_URL="http://invoiceshelf-app:8080" \
-e INVOICESHELF_PUBLIC_URL="https://invoiceshelf.example.com" \
-e MCP_SERVER_PORT=80 \
invoiceshelf-mcp:latest
The MCP server serves at `http://invoiceshelf-mcp:80/mcp`
(Streamable HTTP).
โ ๏ธ Important Notes
- ๐
include_all_fieldsโ Theinclude_all_fieldsparameter (availableon allget_*andlist_*tools) controls whether all available fieldsare included in responses. Defaults toFalsefor performance; set toTrueonly when additional fields are needed. - โก TOON Compression โ All list responses are automatically compressedusing TOON (Token-Optimized Object Notation) to reduce tokenconsumption by 30-60%.
- ๐ Required Fields & Defaults โ Each
create_*tool requires specifickey fields (e.g.namefor resources). All other fields default toempty strings or reasonable values. The company assignment isautomatically set to the authenticated user's company for most resources.
๐ ๏ธ API Tool Mapping
The server implements 109 MCP tools organized into the followingcategories:
๐งพ Invoices (10 tools)
list_all_invoicesโ List all invoice recordsget_invoice_by_idโ Get a single invoice by IDcreate_invoiceโ Create a new invoiceupdate_invoiceโ Update an existing invoicedelete_invoices_by_idโ Delete an invoice by IDsend_invoiceโ Send an invoice via emailclone_invoiceโ Clone an existing invoicechange_invoice_statusโ Change an invoice's statuslist_invoice_templatesโ List available invoice templatesget_invoice_send_previewโ Get an invoice send preview
๐ Estimates (11 tools)
list_all_estimatesโ List all estimate recordsget_estimate_by_idโ Get a single estimate by IDcreate_estimateโ Create a new estimateupdate_estimateโ Update an existing estimatedelete_estimates_by_idโ Delete an estimate by IDsend_estimateโ Send an estimate via emailclone_estimateโ Clone an existing estimatechange_estimate_statusโ Change an estimate's statusconvert_estimate_to_invoiceโ Convert an estimate to an invoicelist_estimate_templatesโ List available estimate templatesget_estimate_send_previewโ Get an estimate send preview
๐ฅ Customers (7 tools)
list_all_customersโ List all customer recordsget_customer_by_idโ Get a single customer by IDget_customer_roles_by_idโ Get the roles assigned to a customercreate_customerโ Create a new customerupdate_customerโ Update an existing customerdelete_customers_by_idโ Delete a customer by IDget_customer_statsโ Get statistics for a single customer
๐ฆ Items (5 tools)
list_all_itemsโ List all item recordsget_item_by_idโ Get a single item by IDcreate_itemโ Create a new itemupdate_itemโ Update an existing itemdelete_items_by_idโ Delete an item by ID
๐ Units (5 tools)
list_all_unitsโ List all unit recordsget_unit_by_idโ Get a single unit by IDcreate_unitโ Create a new unitupdate_unitโ Update an existing unitdelete_unit_by_idโ Delete a unit by ID
๐ Recurring Invoices (5 tools)
list_all_recurring_invoicesโ List all recurring invoice recordsget_recurring_invoice_by_idโ Get a single recurring invoice by IDcreate_recurring_invoiceโ Create a new recurring invoiceupdate_recurring_invoiceโ Update an existing recurring invoicedelete_recurring_invoices_by_idโ Delete a recurring invoice by ID
๐ณ Payments (7 tools)
list_all_paymentsโ List all payment recordsget_payment_by_idโ Get a single payment by IDcreate_paymentโ Create a new paymentupdate_paymentโ Update an existing paymentdelete_payments_by_idโ Delete a payment by IDsend_paymentโ Send a payment receipt via emailget_payment_send_previewโ Get a payment send preview
๐ฆ Payment Methods (5 tools)
list_all_payment_methodsโ List all payment method recordsget_payment_method_by_idโ Get a single payment method by IDcreate_payment_methodโ Create a new payment methodupdate_payment_methodโ Update an existing payment methoddelete_payment_method_by_idโ Delete a payment method by ID
๐ธ Expenses (6 tools)
list_all_expensesโ List all expense recordsget_expense_by_idโ Get a single expense by IDcreate_expenseโ Create a new expenseupdate_expenseโ Update an existing expensedelete_expenses_by_idโ Delete an expense by IDduplicate_expenseโ Duplicate an existing expense
๐๏ธ Expense Categories (5 tools)
list_all_expense_categoriesโ List all expense category recordsget_expense_category_by_idโ Get a single expense category by IDcreate_expense_categoryโ Create a new expense categoryupdate_expense_categoryโ Update an existing expense categorydelete_expense_category_by_idโ Delete an expense category by ID
๐งฎ Tax Types (5 tools)
list_all_tax_typesโ List all tax type recordsget_tax_type_by_idโ Get a single tax type by IDcreate_tax_typeโ Create a new tax typeupdate_tax_typeโ Update an existing tax typedelete_tax_type_by_idโ Delete a tax type by ID
๐ Notes (5 tools)
list_all_notesโ List all note recordsget_note_by_idโ Get a single note by IDcreate_noteโ Create a new noteupdate_noteโ Update an existing notedelete_note_by_idโ Delete a note by ID
๐ท๏ธ Custom Fields (5 tools)
list_all_custom_fieldsโ List all custom field recordsget_custom_field_by_idโ Get a single custom field by IDcreate_custom_fieldโ Create a new custom fieldupdate_custom_fieldโ Update an existing custom fielddelete_custom_field_by_idโ Delete a custom field by ID
๐ก๏ธ Roles (5 tools)
list_all_rolesโ List all role recordsget_role_by_idโ Get a single role by IDcreate_roleโ Create a new roleupdate_roleโ Update an existing roledelete_role_by_idโ Delete a role by ID
๐ Domain (23 tools)
check_server_statusโ Check connectivity to the InvoiceShelf backendget_dashboardโ Get dashboard dataget_bootstrapโ Get application bootstrap datasearch_customers_and_usersโ Search across customers and userssearch_usersโ Search users by emaillist_all_currenciesโ List all currencieslist_used_currenciesโ List currencies in uselist_all_countriesโ List all countrieslist_timezonesโ List available timezoneslist_date_formatsโ List available date formatslist_time_formatsโ List available time formatsget_next_numberโ Get the next number for a resourceget_number_placeholdersโ Get number placeholders for a formatget_current_companyโ Get the current companyget_company_roles_by_idโ Get the roles for a companyget_current_user_rolesโ Get the roles assigned to the current userlist_all_companiesโ List all companieslist_abilitiesโ List all available abilitiesget_recurring_invoice_frequencyโ Get the next occurrence for a recurring frequencyget_exchange_rateโ Get an exchange rate for a currencyget_active_exchange_rate_providerโ Get the active exchange-rate providerlist_used_currencies_for_exchangeโ List currencies used for exchangelist_supported_currenciesโ List currencies supported by an exchange-rate provider