# MCP server

Connect your AI assistant (Claude, Cursor, VS Code…) to the Ticketbai WS API with the [Model Context Protocol](https://modelcontextprotocol.io/). Every API method is a tool: issue, query and cancel TicketBAI and Verifactu invoices from the chat.

## Server URLs

| Environment | MCP server URL |
| --- | --- |
| Test | `https://api-test.ticketbaiws.eus/mcp-api` |
| Production | `https://api.ticketbaiws.eus/mcp-api` |

**Company and license management:** these methods authenticate with the **developer token of your customer account** (not with a company's token), so they have their own server: `https://api.ticketbaiws.eus/mcp-api/cuenta`, with the developer token and the account's NIF in the same headers. Add it as a second connector.

**Always start in the test environment.** In production, invoices are legally valid and are sent to the tax authority (Hacienda): ask the assistant to confirm each invoice with you before issuing it.

## Connect your assistant

**All you need is the URL.** When you add the connector, your assistant opens a Ticketbai WS window: you log in with your account, choose the company and grant access. No tokens to copy, no headers to configure.

### Claude (claude.ai and Claude Desktop)

1. In **Settings → Connectors**, add a custom connector with the MCP server URL.
2. Click **Connect**, log in with your Ticketbai WS account and choose the company.

### ChatGPT

1. Add a custom connector with the MCP server URL (depending on your plan, you may need to enable developer mode for connectors).
2. Choose **OAuth** authentication, log in with your Ticketbai WS account and choose the company.

### Claude Code

```
claude mcp add --transport http ticketbaiws-test https://api-test.ticketbaiws.eus/mcp-api
```

Then, inside Claude Code, type `/mcp` and choose **Authenticate** to log in.

### Cursor, VS Code and other clients

Add the MCP server URL. If your client supports OAuth, it will ask you to log in; if not, use headers (see below).

**One connection per company and environment.** The access you grant applies only to the company you choose and only to the environment of the URL (test or production). If you manage several companies, add one connector per company. For company and license management, use `https://api.ticketbaiws.eus/mcp-api/cuenta` and log in with your customer account.

### Alternative: headers with your token

For clients without OAuth or for automations, the server still accepts the company's token in HTTP headers, just like the REST API: `Token` and `Nif`. If your client only lets you pick headers from a list, use `X-API-Token` and `X-Client-ID`; if it only allows `Authorization`, send `Authorization: Bearer YOUR_NIF:YOUR_TOKEN`.

```
claude mcp add --transport http ticketbaiws-test https://api-test.ticketbaiws.eus/mcp-api \
  --header "Token: YOUR_TEST_TOKEN" \
  --header "Nif: YOUR_NIF"
```

The server does not store your token or access anything you couldn't do with the API: each tool makes the same REST call you would make, with the same usage limits.

### Examples of what you can ask

See complete conversations, including the tools the assistant uses, in the [MCP server use cases](https://ticketbaiws.eus/en/desarrolladores/casos-de-uso-mcp/).

- “Issue a receipt for €12.10 including VAT, series T, for a coffee and a sandwich.”
- “What was the tax authority's response to invoice A-2026-0042?”
- “List yesterday's invoices that have errors.”
- “Cancel invoice T-118 and give me the fingerprint of the cancellation.”

## Tools

They are the methods in the [API documentation](https://ticketbaiws.eus/en/api-documentation/), with the same parameters. Some management methods only exist in production.

### TicketBAI / Verifactu invoices

- `ticketbai_post`: New TicketBAI / Verifactu invoice (POST /tbai/)
- `ticketbai_get`: Get TicketBAI invoice (GET /tbai/)
- `ticketbai_del`: Cancel TicketBAI invoice (DELETE /tbai/)
- `tbai_completar_post`: TicketBAI - Complete simplified invoice (POST /tbai-completar/)
- `ticketbai_list_get`: List TicketBAI invoices (GET /tbai-list/)
- `ticketbai_xml_get`: Download TicketBAI XML (GET /tbai-xml/)
- `facturae_get`: Download in FacturaE format (GET /facturae/, production only)
- `tbai_pdf_get`: Download in PDF format (GET /tbai-pdf/)
- `status_get`: System status (GET /status/)
- `reset_tbai_put`: Reset TBAI submission (PUT /reset-tbai/)
- `validar_nif_post`: Validate NIF with the AEAT (POST /validar-nif/, production only)
- `validar_nif_vies_post`: Validate NIF in VIES (POST /validar-nif-vies/, production only)

### Representation document (Verifactu, Bizkaia, Gipuzkoa)

- `doc_representante_modelo_get`: Representation document - Download template (GET /doc-representante/modelo/)
- `doc_representante_post`: Representation document - Upload document (POST /doc-representante/)
- `doc_representante_get`: Representation document - Download uploaded document (GET /doc-representante/)
- `doc_representante_delete`: Representation document - Revoke uploaded document (DELETE /doc-representante/)

### Batuz Bizkaia (LROE)

- `epigrafes_get`: List IAE activity codes (GET /epigrafes/, production only)
- `lroe_recibidas_post`: LROE - Submit received invoices (POST /lroe-recibidas/)
- `lroe_recibidas_put`: LROE - Modify received invoices (PUT /lroe-recibidas/)
- `lroe_recibidas_get`: LROE - Query received invoices (GET /lroe-recibidas/)
- `lroe_recibidas_del`: LROE - Cancel received invoices (DELETE /lroe-recibidas/)
- `lroe_gastos_sin_factura_post`: LROE - Submit expenses without invoice (POST /lroe-gastos-sinfactura/)
- `lroe_gastos_sin_factura_put`: LROE - Modify expenses without invoice (PUT /lroe-gastos-sinfactura/)
- `lroe_gastos_sin_factura_get`: LROE - Query expenses without invoice (GET /lroe-gastos-sinfactura/)
- `lroe_gastos_sin_factura_del`: LROE - Cancel expenses without invoice (DELETE /lroe-gastos-sinfactura/)
- `lroe_critcaja_cobros_post`: LROE - Cash accounting - COLLECTIONS - Submit collections (POST /lroe-critcaja-cobros/)
- `lroe_critcaja_cobros_put`: LROE - Cash accounting - COLLECTIONS - Modify collections (PUT /lroe-critcaja-cobros/)
- `lroe_critcaja_cobros_get`: LROE - Cash accounting - COLLECTIONS - Query collections (GET /lroe-critcaja-cobros/)
- `lroe_critcaja_cobros_del`: LROE - Cash accounting - COLLECTIONS - Cancel collections (DELETE /lroe-critcaja-cobros/)
- `lroe_critcaja_pagos_post`: LROE - Cash accounting - PAYMENTS - Submit payments (POST /lroe-critcaja-pagos/)
- `lroe_critcaja_pagos_put`: LROE - Cash accounting - PAYMENTS - Modify payments (PUT /lroe-critcaja-pagos/)
- `lroe_critcaja_pagos_get`: LROE - Cash accounting - PAYMENTS - Query payments (GET /lroe-critcaja-pagos/)
- `lroe_critcaja_pagos_del`: LROE - Cash accounting - PAYMENTS - Cancel payments (DELETE /lroe-critcaja-pagos/)

### Webhooks, companies and licenses

- `webhooks_post`: Webhooks - New webhook (POST /webhooks/)
- `webhooks_get`: Webhooks - List webhooks (GET /webhooks/)
- `webhooks_get_uno`: Webhooks - Get one webhook (GET /webhooks/{codigo_webhook}/)
- `webhooks_put`: Webhooks - Modify webhook (PUT /webhooks/{codigo_webhook}/)
- `webhooks_delete`: Webhooks - Delete webhook (DELETE /webhooks/{codigo_webhook}/)
- `empresas_post`: New company (POST /empresas/, account server)
- `empresas_get`: List companies (GET /empresas/, account server)
- `licencias_post`: New license (POST /licencias/, account server)
- `licencias_get`: Query licenses (GET /licencias/, account server)
- `empresas_put`: Edit company details (PUT /empresas/{nif}/, account server)

### B2B e-invoicing (SPFE)

- `spfe_estados_post`: SPFE - Report payment, collection, rejection or non-payment (POST /spfe-estados/)
- `spfe_estados_get`: SPFE - Query payments, collections, rejections and non-payments (GET /spfe-estados/)
- `spfe_recibidas_get`: SPFE - Received invoices (GET /spfe-recibidas/)

### SII (AEAT)

- `sii_envios_get`: SII - Consulta del libro de facturas emitidas (GET /sii-envios/)
- `sii_recibidas_post`: SII - Facturas recibidas (POST /sii-recibidas/)
- `sii_recibidas_get`: SII - Consulta de facturas recibidas (GET /sii-recibidas/)
- `sii_recibidas_delete`: SII - Baja de facturas recibidas (DELETE /sii-recibidas/)

### Customers and products (invoicing tool)

- `clientes_get`: Customers - Search customers (GET /clientes/)
- `clientes_post`: Customers - New customer (POST /clientes/)
- `cliente_get`: Customers - Get one customer (GET /clientes/{id}/)
- `cliente_put`: Customers - Modify one customer (PUT /clientes/{id}/)
- `productos_get`: Products - Search products (GET /productos/)
- `producto_get`: Products - Get one product (GET /productos/{codigo}/)

## Best practices

- If a tool returns `TOKEN error`, ask the assistant to use `comprobar_conexion` (check connection): it will tell you the environment, which headers arrived, the NIF received and the last 4 characters of the token.
- Submission to the tax authority is asynchronous: after issuing an invoice, the assistant should check its status with `ticketbai_get` (or you can set up a webhook).
- Line amounts are excluding VAT and dates use the dd/mm/yyyy format. The [examples](https://ticketbaiws.eus/en/desarrolladores/ejemplos/) also work as a reference for the assistant.
- If you get HTTP 429, the request limit has been exceeded: wait before retrying.
- The full specification is in [openapi.json](https://api.ticketbaiws.eus/openapi.json).

Source: https://ticketbaiws.eus/en/desarrolladores/mcp/
