feat: add POST/PUT/DELETE client methods and tools for creating products, suppliers, and invoices#2
Open
ivanhercaz wants to merge 9 commits intocristotodev:mainfrom
Open
Conversation
Adds support for creating, updating, and deleting resources via FacturaScripts API. Implements form-urlencoded serialization with nested object flattening to comply with API requirements. The toFormData method handles arrays and nested objects properly, converting them to the expected field[index][key] format.
Implements create_proveedor tool for creating new suppliers with full validation of required fields (nombre, cifnif). Supports optional contact details, payment methods, and postal address. Automatically updates the associated contact record with address fields when provided, as FacturaScripts stores addresses in the contact entity rather than the supplier entity.
Implements create_factura_proveedor tool for creating supplier invoices with line items. Uses dedicated /crearFacturaProveedor endpoint to ensure totals are calculated atomically. Supports marking invoices as paid via /pagarFacturaProveedor endpoint. Validates all line items before submission to prevent partial failures.
Registers create_proveedor and create_factura_proveedor tools in the MCP server. Adds tool definitions to the list handler and implementation cases to the call handler. Enables clients to discover and invoke the new creation tools through the standard MCP protocol.
Implements a new MCP tool for creating customer invoices (facturas de cliente) with full line item support. Enables atomic invoice creation through a dedicated endpoint that handles document creation, line items, and total calculations in a single operation. Includes comprehensive validation for required fields (customer code, line items) and line-level data (quantities, prices, descriptions). Supports optional parameters for payment terms, series, warehouse, address details, observations, and marking invoices as paid upon creation. Mirrors existing supplier invoice functionality to provide feature parity for customer-facing documents.
Adds a new tool that enables creating products in FacturaScripts with comprehensive configuration options. The implementation supports specifying product reference, description, pricing, family, manufacturer, tax code, and purchase/sale/stock settings. Exports the new tool definition and implementation from the productos module and registers both the tool definition in the tools list and the handler in the request dispatcher to make the functionality available through the API.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi @cristotodev!
First, thanks for building this MCP!
I am working with it successfully and it is helping me to manage the tedious tasks of freelance management. I see the MCP is mainly read-only, but I started working on a workflow in which I create the expenses and invoices based on some queries or documents, so I created some of the tools that I need for this.
Description
Add POST, PUT, and DELETE HTTP methods to the FacturaScripts API client and implement 4 new entity creation tools for the MCP server. This enables write operations (creating suppliers, products, and invoices) in addition to the existing read-only capabilities.
Type of Change
Changes Made
FacturaScriptsClientwithpost(),put(),delete()methods andtoFormData()serializer (FacturaScripts API requiresapplication/x-www-form-urlencoded, not JSON)create_productotool: create products with full field support (reference, description, pricing, family, manufacturer, tax, stock flags)create_proveedortool: create suppliers with a two-step flow (POST supplier + PUT auto-created contact with address fields)create_factura_proveedortool: create supplier invoices via dedicated/crearFacturaProveedorendpoint with line items, calculated totals, and optional payment marking via/pagarFacturaProveedorcreate_factura_clientetool: create customer invoices via dedicated/crearFacturaClienteendpoint with line items and optional payment flagsrc/index.ts(definitions + handler switch cases)Testing
Existing 659 tests continue to pass. Target: ~60 additional tests covering validation, success flows, multi-step operations, and error handling.
Checklist
Related Issues
N/A
Screenshots (if applicable)
N/A
Additional Notes
application/x-www-form-urlencodedencoding for write operations (not JSON). This is handled transparently by thetoFormData()private method in the client./crearFacturaProveedor,/crearFacturaCliente) that atomically create the document, save line items, and runCalculator::calculate()for totals. Direct POST to/facturaproveedoresdoes not compute totals./contactos/{id}./pagarFacturaProveedor/{id}after creation.