Skip to content

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
ivanhercaz:feature/add-post-put-methods
Open

feat: add POST/PUT/DELETE client methods and tools for creating products, suppliers, and invoices#2
ivanhercaz wants to merge 9 commits intocristotodev:mainfrom
ivanhercaz:feature/add-post-put-methods

Conversation

@ivanhercaz
Copy link
Copy Markdown

@ivanhercaz ivanhercaz commented Mar 22, 2026

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (code change that neither fixes a bug nor adds a feature)
  • Performance improvement
  • Test improvement

Changes Made

  • Extended FacturaScriptsClient with post(), put(), delete() methods and toFormData() serializer (FacturaScripts API requires application/x-www-form-urlencoded, not JSON)
  • Added create_producto tool: create products with full field support (reference, description, pricing, family, manufacturer, tax, stock flags)
  • Added create_proveedor tool: create suppliers with a two-step flow (POST supplier + PUT auto-created contact with address fields)
  • Added create_factura_proveedor tool: create supplier invoices via dedicated /crearFacturaProveedor endpoint with line items, calculated totals, and optional payment marking via /pagarFacturaProveedor
  • Added create_factura_cliente tool: create customer invoices via dedicated /crearFacturaCliente endpoint with line items and optional payment flag
  • Registered all 4 new tools in src/index.ts (definitions + handler switch cases)

Testing

  • Unit tests pass
  • Integration tests pass
  • Manual testing completed
  • New tests added (if applicable)

Existing 659 tests continue to pass. Target: ~60 additional tests covering validation, success flows, multi-step operations, and error handling.

Checklist

  • My code follows the project's coding standards
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Related Issues

N/A

Screenshots (if applicable)

N/A

Additional Notes

  • The FacturaScripts API requires application/x-www-form-urlencoded encoding for write operations (not JSON). This is handled transparently by the toFormData() private method in the client.
  • Invoice creation uses dedicated endpoints (/crearFacturaProveedor, /crearFacturaCliente) that atomically create the document, save line items, and run Calculator::calculate() for totals. Direct POST to /facturaproveedores does not compute totals.
  • Supplier creation auto-generates a contact in FacturaScripts; address fields must be updated separately via PUT to /contactos/{id}.
  • Payment marking for supplier invoices requires a separate POST to /pagarFacturaProveedor/{id} after creation.

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.
@ivanhercaz ivanhercaz changed the title feat: add POST/PUT/DELETE client methods and entity creation tools feat: add POST/PUT/DELETE client methods and tools for creating products, suppliers, and invoices Mar 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant