> For the complete documentation index, see [llms.txt](https://docs.docbits.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.docbits.com/advanced-functions-and-tools/docbits-mcp/edocs-mcp.md). Agents can also search and read this documentation through its [MCP server](https://docs.docbits.com/~gitbook/mcp).

# Electronic Documents (eDocs)

The DocBits API exposes a **Model Context Protocol (MCP)** server with tools for inspecting and customizing electronic document (eDoc) processing. Any MCP-compatible client — Claude Code, Claude Desktop, or custom integrations — can connect and use these tools.

## What Can You Do?

With the eDocs MCP tools you can:

* **Inspect** how any electronic document type is classified and what extraction rules apply
* **Test** documents through the full processing pipeline without saving to the database
* **Create custom rules** for your organization — XSLT previews, extraction paths, transformations
* **Update** a custom rule with a new version (with or without immediately activating it)
* **Delete** a custom rule to revert back to the built-in default
* **Verify** that all supported eDoc fixtures are processed correctly

## Permission Model

DocBits ships with a library of built-in default rules shared across all customers. These defaults use the reserved org ID `00000000-0000-0000-0000-000000000000`.

**The default rules are immutable via MCP.** Every write tool checks your organization ID before making any request. If it resolves to the default org, the operation is immediately rejected — no API call is ever made.

Customers can only create, change, or delete rules **within their own organization**. When a custom rule exists for your org, it takes precedence over the default. Deleting a custom rule restores the default behavior automatically.

```
Your org rule  ──► used if present
      │
      ▼ (if absent)
Default rule   ──► built-in, immutable via MCP
```

## Tools Overview

### Inspection (read-only)

| Tool                             | Description                                                                                                             |
| -------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `test_electronic_document`       | Dry-run the full eDoc pipeline — classification, extraction, preview — without saving                                   |
| `list_electronic_document_types` | List all supported eDoc types with configuration status                                                                 |
| `get_extraction_rules`           | Show the XPath rules used to extract fields for a given document type                                                   |
| `get_extracted_fields`           | Get header fields extracted from a processed document                                                                   |
| `get_extracted_tables`           | Get line items extracted from a processed document                                                                      |
| `get_preview_pdf`                | Retrieve the XSLT-rendered preview PDF for a document                                                                   |
| `get_preview_image`              | Retrieve a rendered page image for a processed document                                                                 |
| `extract_edoc_table`             | Extract an XML/EDI file you pass in and return the fields as a flat table together with the rule that produced each one |
| `compare_edoc_extraction`        | Compare the default and your custom extraction (and optionally a candidate rule) on one document                        |

### Customization (org-scoped, default org blocked)

| Tool                              | Description                                                                                         |
| --------------------------------- | --------------------------------------------------------------------------------------------------- |
| `list_edoc_custom_attributes`     | List your org's custom overrides vs. built-in defaults for a document type                          |
| `create_edoc_custom_attribute`    | Create a new custom rule (EXTRACTION\_PATHS, TRANSFORMATION, or PREVIEW)                            |
| `update_edoc_custom_attribute`    | Add a new version of a custom rule, optionally activating it immediately                            |
| `delete_edoc_custom_attribute`    | Delete a custom rule — the system falls back to the default automatically                           |
| `preview_edoc_custom_xslt`        | Dry-run a XSLT transformation against an XML document before activating                             |
| `get_edoc_attribute_source`       | Fetch the editable source of an attribute (PREVIEW, EXTRACTION\_PATHS, TRANSFORMATION) to change it |
| `list_edoc_attribute_versions`    | Version history of a custom attribute: drafts and the active version                                |
| `activate_edoc_attribute_version` | Activate a specific version or draft (this is how you roll back)                                    |
| `delete_edoc_attribute_draft`     | Delete a draft that was never activated                                                             |

### Verification

| Tool                          | Description                                                                   |
| ----------------------------- | ----------------------------------------------------------------------------- |
| `verify_electronic_documents` | Upload fixtures and verify classification, extraction, and preview end-to-end |
| `validate_all_edocs`          | Run all eDoc fixtures through a dry-run pipeline and report issues            |

## Attribute Types

Each customizable rule has a specific type and format:

| Attribute Name         | Format | Purpose                                                |
| ---------------------- | ------ | ------------------------------------------------------ |
| `EXTRACTION_PATHS`     | JSON   | XPath expressions that map XML nodes to DocBits fields |
| `TRANSFORMATION`       | XSLT   | Stylesheet applied to the XML before extraction        |
| `PREVIEW`              | XSLT   | Stylesheet that renders the human-readable PDF preview |
| `STRUCTURE_DESCRIPTOR` | JSON   | Structure map for EDI documents only                   |

The `create_edoc_custom_attribute` tool infers the correct format from the attribute name automatically.

## Quick Start

### List what your org has customized

```
list_edoc_custom_attributes
  electronic_document_type: "XRECHNUNG 2.1 CII"
```

Returns two lists: `custom` (your org's overrides) and `default` (shared rules you inherit).

### Create a custom preview for XRechnung

```
create_edoc_custom_attribute
  electronic_document_type: "XRECHNUNG 2.1 CII"
  attribute_name: "PREVIEW"
  attribute_value: "<xsl:stylesheet ...>...</xsl:stylesheet>"
```

Returns the new `attribute_id` — save it for updates and deletion.

### Update an existing custom rule

```
update_edoc_custom_attribute
  attribute_id: "069cd17c-673c-7c94-8000-b512417eefe3"
  new_value: "<xsl:stylesheet ...>...</xsl:stylesheet>"
  activate: true
```

Creates a new version and activates it. The previous version is kept in history.

### Revert to the default

```
delete_edoc_custom_attribute
  attribute_id: "069cd17c-673c-7c94-8000-b512417eefe3"
```

Removes the custom override. The system falls back to the built-in default rule immediately.

## Safety Rules

| Action                          | Allowed                            |
| ------------------------------- | ---------------------------------- |
| Read default rules              | ✅ Yes                              |
| Create custom rule for your org | ✅ Yes                              |
| Update custom rule for your org | ✅ Yes                              |
| Delete custom rule for your org | ✅ Yes                              |
| Modify or delete default rules  | ❌ **Never** — blocked at MCP layer |

Attempting to write to `00000000-0000-0000-0000-000000000000` returns:

```json
{
  "error": true,
  "blocked": true,
  "detail": "Writing to the default org is forbidden via MCP. Default rules are immutable and shared across all customers."
}
```

## Effective rules and activation

If an electronic credit note appears as Invoice, follow the [classification troubleshooting guide](https://docs.docbits.com/administration-and-setup/settings/global-settings/document-types/edi/credit-note-recognized-as-invoice.md). It covers the effective custom/default source, type codes, Extraction Paths and safe activation.

[Configure DocBits with Claude or Codex](https://docs.docbits.com/advanced-functions-and-tools/docbits-mcp/configuration-with-claude-or-codex.md): connection, copyable prompts, previews, versioned changes, checks and rollback.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.docbits.com/advanced-functions-and-tools/docbits-mcp/edocs-mcp.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
