mcp-ksef-pl
This server enables AI agents to work with Polish electronic invoicing (KSeF) and cross-border Peppol invoices, and to validate Polish tax identifiers.
Generate FA(2) invoices (
generate_fa2_invoice): Create KSeF-compliant FA(2) XML invoices from structured data (seller/buyer info, line items, VAT summary, payment details)Generate FA(3) invoices (
generate_fa3_invoice): Create KSeF-compliant FA(3) XML invoices required for KSeF API v2 submissions, supporting Polish NIP, EU VAT numbers, and absent buyer IDsValidate FA(2) invoices (
validate_fa2_invoice): Run XSD schema validation and Polish business rule checks, returning errors and warningsParse FA(2) invoices (
parse_fa2_invoice): Parse FA(2) XML into a structured dictionary (header, seller, buyer, line items)Submit invoices to KSeF (
submit_invoice_to_ksef): Send FA(3) XML to the KSeF platform (API v2) and receive a reference number (requires an external session token)Check KSeF invoice status (
get_ksef_invoice_status): Retrieve the processing status of a submitted invoice by reference numberSearch KSeF invoices (
search_ksef_invoices): Query invoices in KSeF by date range and subject type (seller/buyer direction)Validate Polish NIP (
validate_polish_nip): Verify a 10-digit Polish tax identification number using the official checksum algorithmValidate Polish REGON (
validate_polish_regon): Verify a 9- or 14-digit Polish business registry number using the official checksum algorithmGenerate Peppol invoices (
generate_peppol_invoice): Create Peppol BIS Billing 3.0 / EN 16931 compliant UBL 2.1 XML invoices for cross-border B2B invoicing
mcp-ksef-pl ๐ต๐ฑ
A Python MCP server providing tools for Polish electronic invoicing compliant with KSeF (FA(2)) and Peppol BIS Billing 3.0 / EN 16931. It enables AI agents (Claude, IDEs) to generate, validate, and submit invoices to the Krajowy System e-Faktur (KSeF), as well as validate Polish tax identifiers (NIP and REGON).
Built on
This package is built on mcp-einvoicing-core, the shared base library for European e-invoicing MCP servers. It provides an OAuth2 HTTP client, token cache, data models, logging utilities, and an exception hierarchy.
mcp-einvoicing-core is installed automatically as a dependency, no additional step is required.
Related MCP server: mcp-fattura-elettronica-it
๐๏ธ Architecture
The server acts as an intelligent communication interface between the AI agent and the KSeF platform and the Peppol network:
[ ERP System / Application ] <--> [ MCP Server ] <--> [ KSeF (MF) / Peppol Network ]
^ |
| v
[ AI Agent (Claude) ] <--- (FA(2) / EN 16931)๐ ๏ธ Available tools
FA(2) invoice handling
Tool | Description |
| Generates a KSeF-compliant FA(2) XML invoice from input data |
| Validates FA(2) XML: XSD validation (if the schema is available) and business rules |
| Parses FA(2) XML into a structured dictionary |
KSeF lifecycle
Tool | Description |
| Submits an FA(2) invoice to the KSeF platform and returns a reference number |
| Retrieves the processing status of an invoice by its reference number |
| Searches invoices in KSeF by date range and direction (seller/buyer) |
Identifier validation
Tool | Description |
| Validates a NIP (10-digit tax identification number) using a checksum algorithm |
| Validates a REGON (9- or 14-digit registry number) using a checksum algorithm |
Peppol / EN 16931
Tool | Description |
| Generates a UBL 2.1 invoice compliant with Peppol BIS Billing 3.0 / EN 16931 |
๐ Installation
Via PyPI (recommended)
pip install mcp-ksef-plOr without prior installation using uvx:
uvx mcp-ksef-plFrom source
git clone https://github.com/cmendezs/mcp-ksef-pl.git
cd mcp-ksef-pl
uv sync --all-extrasโ๏ธ Configuration (environment variables)
Variable | Default | Description |
|
| KSeF environment: |
| โ | KSeF session token (obtained through the challenge-response flow with MF) |
| โ | NIP of the entity submitting invoices |
|
| HTTP request timeout in seconds |
๐ KSeF authentication
KSeF requires signed XML (challenge-response) to obtain a session token. Signing
requires a qualified electronic signature or credentials from the MF portal and cannot
be automated by this MCP server. The session token must be obtained outside the server
and passed via KSEF_SESSION_TOKEN or the session_token parameter of the
submit_invoice_to_ksef tool.
Technical documentation for KSeF: https://www.podatki.gov.pl/ksef/dokumentacja-techniczna-ksef/
๐ค Claude Desktop integration
Add the following configuration to your claude_desktop_config.json file:
{
"mcpServers": {
"ksef-pl": {
"command": "uvx",
"args": ["mcp-ksef-pl"],
"env": {
"KSEF_ENVIRONMENT": "test",
"KSEF_SESSION_TOKEN": "<your-ksef-session-token>",
"KSEF_NIP": "<your-nip>"
}
}
}
}โจ๏ธ Cursor integration
Cursor supports MCP servers via stdio. Add the configuration to:
Globally (all projects):
~/.cursor/mcp.jsonPer project (this repository only):
.cursor/mcp.json
{
"mcpServers": {
"ksef-pl": {
"command": "uvx",
"args": ["mcp-ksef-pl"],
"env": {
"KSEF_ENVIRONMENT": "test",
"KSEF_SESSION_TOKEN": "<your-ksef-session-token>",
"KSEF_NIP": "<your-nip>"
}
}
}
}Reload the Cursor window (Ctrl+Shift+P โ Reload Window) after saving changes.
๐ช Kiro integration
Kiro supports MCP servers through a dedicated configuration file:
Globally:
~/.kiro/settings/mcp.jsonWorkspace:
.kiro/settings/mcp.json
{
"mcpServers": {
"ksef-pl": {
"command": "uvx",
"args": ["mcp-ksef-pl"],
"env": {
"KSEF_ENVIRONMENT": "test",
"KSEF_SESSION_TOKEN": "<your-ksef-session-token>",
"KSEF_NIP": "<your-nip>"
},
"disabled": false,
"autoApprove": []
}
}
}Security tip: instead of entering the token directly, use the syntax
"KSEF_SESSION_TOKEN": "${KSEF_SESSION_TOKEN}", as Kiro resolves shell environment variables at startup.
๐ XSD schema (FA_VAT_v1-0E.xsd)
Full XSD validation requires the official schema from the Ministry of Finance.
Without it, validate_fa2_invoice only executes business rules.
Go to: https://www.podatki.gov.pl/ksef/dokumentacja-techniczna-ksef/
Download the FA(2) technical documentation package
Place the
FA_VAT_v1-0E.xsdfile in thesrc/mcp_ksef_pl/schemas/directory
The file is excluded from the repository (.gitignore), it must be downloaded manually.
Helper script: scripts/download_schemas.sh
๐งช Tests
# Run unit tests
uv run pytest tests/ -vOther e-invoicing MCP servers
Country | Server |
๐ Global | |
๐ง๐ช Belgium | |
๐ง๐ท Brazil | |
๐ซ๐ท France | |
๐ฉ๐ช Germany | |
๐ฎ๐น Italy | |
๐ต๐ฑ Poland | |
๐ช๐ธ Spain |
๐ License
This project is distributed under the Apache 2.0 license. See the LICENSE file for details.
Project maintained by cmendezs. For questions about the KSeF or Peppol implementation, open an Issue.
Maintenance
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/cmendezs/mcp-ksef-pl'
If you have feedback or need assistance with the MCP directory API, please join our Discord server