heu-mcp 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- heu_mcp-0.1.0/LICENSE +21 -0
- heu_mcp-0.1.0/PKG-INFO +167 -0
- heu_mcp-0.1.0/README.md +140 -0
- heu_mcp-0.1.0/heu_mcp.egg-info/PKG-INFO +167 -0
- heu_mcp-0.1.0/heu_mcp.egg-info/SOURCES.txt +10 -0
- heu_mcp-0.1.0/heu_mcp.egg-info/dependency_links.txt +1 -0
- heu_mcp-0.1.0/heu_mcp.egg-info/entry_points.txt +2 -0
- heu_mcp-0.1.0/heu_mcp.egg-info/requires.txt +3 -0
- heu_mcp-0.1.0/heu_mcp.egg-info/top_level.txt +1 -0
- heu_mcp-0.1.0/pyproject.toml +52 -0
- heu_mcp-0.1.0/server.py +499 -0
- heu_mcp-0.1.0/setup.cfg +4 -0
heu_mcp-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Luca Visconti
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
heu_mcp-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: heu-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MCP Server for HEU Legal API - manage documents and PDFs for e-signature with Claude AI
|
|
5
|
+
Author-email: Luca Visconti <info@heulegal.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Lucav21/heu-mcp
|
|
8
|
+
Project-URL: Repository, https://github.com/Lucav21/heu-mcp
|
|
9
|
+
Project-URL: Issues, https://github.com/Lucav21/heu-mcp/issues
|
|
10
|
+
Project-URL: HEU Legal, https://heulegal.com
|
|
11
|
+
Keywords: mcp,heu,heulegal,e-signature,esignature,documents,pdf,claude,anthropic
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: httpx>=0.27.0
|
|
24
|
+
Requires-Dist: mcp>=1.0.0
|
|
25
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# HEU Legal MCP Server
|
|
29
|
+
|
|
30
|
+
[](https://pypi.org/project/heu-mcp/)
|
|
31
|
+
[](https://pypi.org/project/heu-mcp/)
|
|
32
|
+
[](LICENSE)
|
|
33
|
+
|
|
34
|
+
MCP server (Model Context Protocol) per integrare l'[API HEU Legal](https://heulegal.com) con Claude (Claude Desktop, Claude Code, e altri client MCP). Gestisce documenti nativi HEU e PDF firmabili end-to-end via conversazione: creazione, condivisione per firma elettronica (valida in 180+ paesi), sollecito firmatari, download PDF.
|
|
35
|
+
|
|
36
|
+
## Funzionalità
|
|
37
|
+
|
|
38
|
+
14 tool che coprono l'intera API HEU v1:
|
|
39
|
+
|
|
40
|
+
**Documenti nativi HEU** — `list_heu_documents`, `get_heu_document`, `list_heu_document_placeholders`, `create_heu_document`, `prompt_heu_document_signature`, `download_heu_document_pdf`
|
|
41
|
+
|
|
42
|
+
**PDF caricati** — `list_pdf_documents`, `get_pdf_document`, `list_pdf_document_signers`, `list_pdf_document_signer_placeholders`, `list_pdf_document_placeholders`, `create_pdf_document`, `prompt_pdf_document_signature`
|
|
43
|
+
|
|
44
|
+
**Health** — `get_heu_health`
|
|
45
|
+
|
|
46
|
+
## Requisiti
|
|
47
|
+
|
|
48
|
+
- Python ≥ 3.10
|
|
49
|
+
- Una API key HEU Legal (Profile → API Keys nella UI HEU; richiede subscription **Enterprise**)
|
|
50
|
+
- Almeno un **template** già creato sulla piattaforma HEU (documento nativo o PDF caricato)
|
|
51
|
+
|
|
52
|
+
## Installazione
|
|
53
|
+
|
|
54
|
+
### Da PyPI
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install heu-mcp
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Da sorgenti
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
git clone https://github.com/Lucav21/heu-mcp.git
|
|
64
|
+
cd heu-mcp
|
|
65
|
+
python3 -m venv venv
|
|
66
|
+
source venv/bin/activate
|
|
67
|
+
pip install -r requirements.txt
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Configurazione
|
|
71
|
+
|
|
72
|
+
### Claude Desktop
|
|
73
|
+
|
|
74
|
+
Modifica `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) o `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"mcpServers": {
|
|
79
|
+
"heu": {
|
|
80
|
+
"command": "heu-mcp",
|
|
81
|
+
"args": [],
|
|
82
|
+
"env": {
|
|
83
|
+
"HEU_API_KEY": "la_tua_api_key_qui"
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Se hai installato da sorgenti con venv:
|
|
91
|
+
|
|
92
|
+
```json
|
|
93
|
+
{
|
|
94
|
+
"mcpServers": {
|
|
95
|
+
"heu": {
|
|
96
|
+
"command": "/path/assoluto/heu-mcp/venv/bin/python",
|
|
97
|
+
"args": ["/path/assoluto/heu-mcp/server.py"],
|
|
98
|
+
"env": {
|
|
99
|
+
"HEU_API_KEY": "la_tua_api_key_qui"
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Riavvia Claude Desktop dopo la modifica.
|
|
107
|
+
|
|
108
|
+
### Claude Code (CLI)
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
claude mcp add heu heu-mcp -e HEU_API_KEY=la_tua_api_key_qui
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Variabili d'ambiente
|
|
115
|
+
|
|
116
|
+
| Variabile | Descrizione | Default |
|
|
117
|
+
|-----------|-------------|---------|
|
|
118
|
+
| `HEU_API_KEY` | API key HEU Legal (richiesto) | — |
|
|
119
|
+
| `HEU_BASE_URL` | URL base API | `https://api.heulegal.com/v1` |
|
|
120
|
+
| `HEU_DOWNLOAD_DIR` | Cartella dove salvare i PDF scaricati | `/tmp` |
|
|
121
|
+
|
|
122
|
+
## Esempi d'uso
|
|
123
|
+
|
|
124
|
+
Dopo aver configurato il MCP, chiedi a Claude:
|
|
125
|
+
|
|
126
|
+
- *"Lista i miei template HEU"*
|
|
127
|
+
- *"Mostrami i firmatari del PDF con id 26"*
|
|
128
|
+
- *"Sollecita la firma del documento 15c587e0-1715-45c6-bf72-24bcb86c0f90"*
|
|
129
|
+
- *"Scarica il PDF del documento X con layout 220 e includi indice"*
|
|
130
|
+
- *"Crea un nuovo PDF firmabile dal template 56 per mario.rossi@example.com"*
|
|
131
|
+
|
|
132
|
+
## Note operative
|
|
133
|
+
|
|
134
|
+
- I tool che creano/inviano (`create_*`, `prompt_*`) chiedono sempre **conferma esplicita** all'utente prima dell'esecuzione.
|
|
135
|
+
- Rate limit dell'API: 300 richieste / 5 minuti. Gli header `X-RateLimit-*` sono restituiti nelle risposte.
|
|
136
|
+
- `prompt_*_signature` ha un limite di 1 sollecito ogni 24h per documento (HTTP 429 con `Retry-After`).
|
|
137
|
+
- `download_heu_document_pdf` salva il PDF in `HEU_DOWNLOAD_DIR` e restituisce il path: il binario non passa nel canale stdio.
|
|
138
|
+
- Per `create_pdf_document` con `signature_type=fea` serve avere credito FEA sufficiente per tutti i firmatari (altrimenti HTTP 422).
|
|
139
|
+
|
|
140
|
+
## Sicurezza
|
|
141
|
+
|
|
142
|
+
- Le API key non sono mai loggate.
|
|
143
|
+
- L'API key è letta solo da variabile d'ambiente: non viene mai scritta nel codice o nelle risposte.
|
|
144
|
+
- Il binario PDF è salvato sul filesystem locale, non viene trasmesso via canale MCP.
|
|
145
|
+
|
|
146
|
+
## Sviluppo
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
git clone https://github.com/Lucav21/heu-mcp.git
|
|
150
|
+
cd heu-mcp
|
|
151
|
+
python3 -m venv venv
|
|
152
|
+
source venv/bin/activate
|
|
153
|
+
pip install -e .
|
|
154
|
+
|
|
155
|
+
# Avvio manuale per debug
|
|
156
|
+
HEU_API_KEY=... python server.py
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Licenza
|
|
160
|
+
|
|
161
|
+
MIT — vedi [LICENSE](LICENSE).
|
|
162
|
+
|
|
163
|
+
## Link
|
|
164
|
+
|
|
165
|
+
- [HEU Legal](https://heulegal.com)
|
|
166
|
+
- [Documentazione API HEU](https://api.heulegal.com/v1)
|
|
167
|
+
- [Model Context Protocol](https://modelcontextprotocol.io)
|
heu_mcp-0.1.0/README.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# HEU Legal MCP Server
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/heu-mcp/)
|
|
4
|
+
[](https://pypi.org/project/heu-mcp/)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
MCP server (Model Context Protocol) per integrare l'[API HEU Legal](https://heulegal.com) con Claude (Claude Desktop, Claude Code, e altri client MCP). Gestisce documenti nativi HEU e PDF firmabili end-to-end via conversazione: creazione, condivisione per firma elettronica (valida in 180+ paesi), sollecito firmatari, download PDF.
|
|
8
|
+
|
|
9
|
+
## Funzionalità
|
|
10
|
+
|
|
11
|
+
14 tool che coprono l'intera API HEU v1:
|
|
12
|
+
|
|
13
|
+
**Documenti nativi HEU** — `list_heu_documents`, `get_heu_document`, `list_heu_document_placeholders`, `create_heu_document`, `prompt_heu_document_signature`, `download_heu_document_pdf`
|
|
14
|
+
|
|
15
|
+
**PDF caricati** — `list_pdf_documents`, `get_pdf_document`, `list_pdf_document_signers`, `list_pdf_document_signer_placeholders`, `list_pdf_document_placeholders`, `create_pdf_document`, `prompt_pdf_document_signature`
|
|
16
|
+
|
|
17
|
+
**Health** — `get_heu_health`
|
|
18
|
+
|
|
19
|
+
## Requisiti
|
|
20
|
+
|
|
21
|
+
- Python ≥ 3.10
|
|
22
|
+
- Una API key HEU Legal (Profile → API Keys nella UI HEU; richiede subscription **Enterprise**)
|
|
23
|
+
- Almeno un **template** già creato sulla piattaforma HEU (documento nativo o PDF caricato)
|
|
24
|
+
|
|
25
|
+
## Installazione
|
|
26
|
+
|
|
27
|
+
### Da PyPI
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install heu-mcp
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Da sorgenti
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
git clone https://github.com/Lucav21/heu-mcp.git
|
|
37
|
+
cd heu-mcp
|
|
38
|
+
python3 -m venv venv
|
|
39
|
+
source venv/bin/activate
|
|
40
|
+
pip install -r requirements.txt
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Configurazione
|
|
44
|
+
|
|
45
|
+
### Claude Desktop
|
|
46
|
+
|
|
47
|
+
Modifica `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) o `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
{
|
|
51
|
+
"mcpServers": {
|
|
52
|
+
"heu": {
|
|
53
|
+
"command": "heu-mcp",
|
|
54
|
+
"args": [],
|
|
55
|
+
"env": {
|
|
56
|
+
"HEU_API_KEY": "la_tua_api_key_qui"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Se hai installato da sorgenti con venv:
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
{
|
|
67
|
+
"mcpServers": {
|
|
68
|
+
"heu": {
|
|
69
|
+
"command": "/path/assoluto/heu-mcp/venv/bin/python",
|
|
70
|
+
"args": ["/path/assoluto/heu-mcp/server.py"],
|
|
71
|
+
"env": {
|
|
72
|
+
"HEU_API_KEY": "la_tua_api_key_qui"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Riavvia Claude Desktop dopo la modifica.
|
|
80
|
+
|
|
81
|
+
### Claude Code (CLI)
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
claude mcp add heu heu-mcp -e HEU_API_KEY=la_tua_api_key_qui
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Variabili d'ambiente
|
|
88
|
+
|
|
89
|
+
| Variabile | Descrizione | Default |
|
|
90
|
+
|-----------|-------------|---------|
|
|
91
|
+
| `HEU_API_KEY` | API key HEU Legal (richiesto) | — |
|
|
92
|
+
| `HEU_BASE_URL` | URL base API | `https://api.heulegal.com/v1` |
|
|
93
|
+
| `HEU_DOWNLOAD_DIR` | Cartella dove salvare i PDF scaricati | `/tmp` |
|
|
94
|
+
|
|
95
|
+
## Esempi d'uso
|
|
96
|
+
|
|
97
|
+
Dopo aver configurato il MCP, chiedi a Claude:
|
|
98
|
+
|
|
99
|
+
- *"Lista i miei template HEU"*
|
|
100
|
+
- *"Mostrami i firmatari del PDF con id 26"*
|
|
101
|
+
- *"Sollecita la firma del documento 15c587e0-1715-45c6-bf72-24bcb86c0f90"*
|
|
102
|
+
- *"Scarica il PDF del documento X con layout 220 e includi indice"*
|
|
103
|
+
- *"Crea un nuovo PDF firmabile dal template 56 per mario.rossi@example.com"*
|
|
104
|
+
|
|
105
|
+
## Note operative
|
|
106
|
+
|
|
107
|
+
- I tool che creano/inviano (`create_*`, `prompt_*`) chiedono sempre **conferma esplicita** all'utente prima dell'esecuzione.
|
|
108
|
+
- Rate limit dell'API: 300 richieste / 5 minuti. Gli header `X-RateLimit-*` sono restituiti nelle risposte.
|
|
109
|
+
- `prompt_*_signature` ha un limite di 1 sollecito ogni 24h per documento (HTTP 429 con `Retry-After`).
|
|
110
|
+
- `download_heu_document_pdf` salva il PDF in `HEU_DOWNLOAD_DIR` e restituisce il path: il binario non passa nel canale stdio.
|
|
111
|
+
- Per `create_pdf_document` con `signature_type=fea` serve avere credito FEA sufficiente per tutti i firmatari (altrimenti HTTP 422).
|
|
112
|
+
|
|
113
|
+
## Sicurezza
|
|
114
|
+
|
|
115
|
+
- Le API key non sono mai loggate.
|
|
116
|
+
- L'API key è letta solo da variabile d'ambiente: non viene mai scritta nel codice o nelle risposte.
|
|
117
|
+
- Il binario PDF è salvato sul filesystem locale, non viene trasmesso via canale MCP.
|
|
118
|
+
|
|
119
|
+
## Sviluppo
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
git clone https://github.com/Lucav21/heu-mcp.git
|
|
123
|
+
cd heu-mcp
|
|
124
|
+
python3 -m venv venv
|
|
125
|
+
source venv/bin/activate
|
|
126
|
+
pip install -e .
|
|
127
|
+
|
|
128
|
+
# Avvio manuale per debug
|
|
129
|
+
HEU_API_KEY=... python server.py
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Licenza
|
|
133
|
+
|
|
134
|
+
MIT — vedi [LICENSE](LICENSE).
|
|
135
|
+
|
|
136
|
+
## Link
|
|
137
|
+
|
|
138
|
+
- [HEU Legal](https://heulegal.com)
|
|
139
|
+
- [Documentazione API HEU](https://api.heulegal.com/v1)
|
|
140
|
+
- [Model Context Protocol](https://modelcontextprotocol.io)
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: heu-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MCP Server for HEU Legal API - manage documents and PDFs for e-signature with Claude AI
|
|
5
|
+
Author-email: Luca Visconti <info@heulegal.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Lucav21/heu-mcp
|
|
8
|
+
Project-URL: Repository, https://github.com/Lucav21/heu-mcp
|
|
9
|
+
Project-URL: Issues, https://github.com/Lucav21/heu-mcp/issues
|
|
10
|
+
Project-URL: HEU Legal, https://heulegal.com
|
|
11
|
+
Keywords: mcp,heu,heulegal,e-signature,esignature,documents,pdf,claude,anthropic
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: httpx>=0.27.0
|
|
24
|
+
Requires-Dist: mcp>=1.0.0
|
|
25
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# HEU Legal MCP Server
|
|
29
|
+
|
|
30
|
+
[](https://pypi.org/project/heu-mcp/)
|
|
31
|
+
[](https://pypi.org/project/heu-mcp/)
|
|
32
|
+
[](LICENSE)
|
|
33
|
+
|
|
34
|
+
MCP server (Model Context Protocol) per integrare l'[API HEU Legal](https://heulegal.com) con Claude (Claude Desktop, Claude Code, e altri client MCP). Gestisce documenti nativi HEU e PDF firmabili end-to-end via conversazione: creazione, condivisione per firma elettronica (valida in 180+ paesi), sollecito firmatari, download PDF.
|
|
35
|
+
|
|
36
|
+
## Funzionalità
|
|
37
|
+
|
|
38
|
+
14 tool che coprono l'intera API HEU v1:
|
|
39
|
+
|
|
40
|
+
**Documenti nativi HEU** — `list_heu_documents`, `get_heu_document`, `list_heu_document_placeholders`, `create_heu_document`, `prompt_heu_document_signature`, `download_heu_document_pdf`
|
|
41
|
+
|
|
42
|
+
**PDF caricati** — `list_pdf_documents`, `get_pdf_document`, `list_pdf_document_signers`, `list_pdf_document_signer_placeholders`, `list_pdf_document_placeholders`, `create_pdf_document`, `prompt_pdf_document_signature`
|
|
43
|
+
|
|
44
|
+
**Health** — `get_heu_health`
|
|
45
|
+
|
|
46
|
+
## Requisiti
|
|
47
|
+
|
|
48
|
+
- Python ≥ 3.10
|
|
49
|
+
- Una API key HEU Legal (Profile → API Keys nella UI HEU; richiede subscription **Enterprise**)
|
|
50
|
+
- Almeno un **template** già creato sulla piattaforma HEU (documento nativo o PDF caricato)
|
|
51
|
+
|
|
52
|
+
## Installazione
|
|
53
|
+
|
|
54
|
+
### Da PyPI
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install heu-mcp
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Da sorgenti
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
git clone https://github.com/Lucav21/heu-mcp.git
|
|
64
|
+
cd heu-mcp
|
|
65
|
+
python3 -m venv venv
|
|
66
|
+
source venv/bin/activate
|
|
67
|
+
pip install -r requirements.txt
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Configurazione
|
|
71
|
+
|
|
72
|
+
### Claude Desktop
|
|
73
|
+
|
|
74
|
+
Modifica `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) o `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"mcpServers": {
|
|
79
|
+
"heu": {
|
|
80
|
+
"command": "heu-mcp",
|
|
81
|
+
"args": [],
|
|
82
|
+
"env": {
|
|
83
|
+
"HEU_API_KEY": "la_tua_api_key_qui"
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Se hai installato da sorgenti con venv:
|
|
91
|
+
|
|
92
|
+
```json
|
|
93
|
+
{
|
|
94
|
+
"mcpServers": {
|
|
95
|
+
"heu": {
|
|
96
|
+
"command": "/path/assoluto/heu-mcp/venv/bin/python",
|
|
97
|
+
"args": ["/path/assoluto/heu-mcp/server.py"],
|
|
98
|
+
"env": {
|
|
99
|
+
"HEU_API_KEY": "la_tua_api_key_qui"
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Riavvia Claude Desktop dopo la modifica.
|
|
107
|
+
|
|
108
|
+
### Claude Code (CLI)
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
claude mcp add heu heu-mcp -e HEU_API_KEY=la_tua_api_key_qui
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Variabili d'ambiente
|
|
115
|
+
|
|
116
|
+
| Variabile | Descrizione | Default |
|
|
117
|
+
|-----------|-------------|---------|
|
|
118
|
+
| `HEU_API_KEY` | API key HEU Legal (richiesto) | — |
|
|
119
|
+
| `HEU_BASE_URL` | URL base API | `https://api.heulegal.com/v1` |
|
|
120
|
+
| `HEU_DOWNLOAD_DIR` | Cartella dove salvare i PDF scaricati | `/tmp` |
|
|
121
|
+
|
|
122
|
+
## Esempi d'uso
|
|
123
|
+
|
|
124
|
+
Dopo aver configurato il MCP, chiedi a Claude:
|
|
125
|
+
|
|
126
|
+
- *"Lista i miei template HEU"*
|
|
127
|
+
- *"Mostrami i firmatari del PDF con id 26"*
|
|
128
|
+
- *"Sollecita la firma del documento 15c587e0-1715-45c6-bf72-24bcb86c0f90"*
|
|
129
|
+
- *"Scarica il PDF del documento X con layout 220 e includi indice"*
|
|
130
|
+
- *"Crea un nuovo PDF firmabile dal template 56 per mario.rossi@example.com"*
|
|
131
|
+
|
|
132
|
+
## Note operative
|
|
133
|
+
|
|
134
|
+
- I tool che creano/inviano (`create_*`, `prompt_*`) chiedono sempre **conferma esplicita** all'utente prima dell'esecuzione.
|
|
135
|
+
- Rate limit dell'API: 300 richieste / 5 minuti. Gli header `X-RateLimit-*` sono restituiti nelle risposte.
|
|
136
|
+
- `prompt_*_signature` ha un limite di 1 sollecito ogni 24h per documento (HTTP 429 con `Retry-After`).
|
|
137
|
+
- `download_heu_document_pdf` salva il PDF in `HEU_DOWNLOAD_DIR` e restituisce il path: il binario non passa nel canale stdio.
|
|
138
|
+
- Per `create_pdf_document` con `signature_type=fea` serve avere credito FEA sufficiente per tutti i firmatari (altrimenti HTTP 422).
|
|
139
|
+
|
|
140
|
+
## Sicurezza
|
|
141
|
+
|
|
142
|
+
- Le API key non sono mai loggate.
|
|
143
|
+
- L'API key è letta solo da variabile d'ambiente: non viene mai scritta nel codice o nelle risposte.
|
|
144
|
+
- Il binario PDF è salvato sul filesystem locale, non viene trasmesso via canale MCP.
|
|
145
|
+
|
|
146
|
+
## Sviluppo
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
git clone https://github.com/Lucav21/heu-mcp.git
|
|
150
|
+
cd heu-mcp
|
|
151
|
+
python3 -m venv venv
|
|
152
|
+
source venv/bin/activate
|
|
153
|
+
pip install -e .
|
|
154
|
+
|
|
155
|
+
# Avvio manuale per debug
|
|
156
|
+
HEU_API_KEY=... python server.py
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Licenza
|
|
160
|
+
|
|
161
|
+
MIT — vedi [LICENSE](LICENSE).
|
|
162
|
+
|
|
163
|
+
## Link
|
|
164
|
+
|
|
165
|
+
- [HEU Legal](https://heulegal.com)
|
|
166
|
+
- [Documentazione API HEU](https://api.heulegal.com/v1)
|
|
167
|
+
- [Model Context Protocol](https://modelcontextprotocol.io)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
server
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "heu-mcp"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "MCP Server for HEU Legal API - manage documents and PDFs for e-signature with Claude AI"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = {text = "MIT"}
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "Luca Visconti", email = "info@heulegal.com"}
|
|
14
|
+
]
|
|
15
|
+
keywords = [
|
|
16
|
+
"mcp",
|
|
17
|
+
"heu",
|
|
18
|
+
"heulegal",
|
|
19
|
+
"e-signature",
|
|
20
|
+
"esignature",
|
|
21
|
+
"documents",
|
|
22
|
+
"pdf",
|
|
23
|
+
"claude",
|
|
24
|
+
"anthropic"
|
|
25
|
+
]
|
|
26
|
+
classifiers = [
|
|
27
|
+
"Development Status :: 4 - Beta",
|
|
28
|
+
"Intended Audience :: Developers",
|
|
29
|
+
"License :: OSI Approved :: MIT License",
|
|
30
|
+
"Operating System :: OS Independent",
|
|
31
|
+
"Programming Language :: Python :: 3",
|
|
32
|
+
"Programming Language :: Python :: 3.10",
|
|
33
|
+
"Programming Language :: Python :: 3.11",
|
|
34
|
+
"Programming Language :: Python :: 3.12",
|
|
35
|
+
]
|
|
36
|
+
dependencies = [
|
|
37
|
+
"httpx>=0.27.0",
|
|
38
|
+
"mcp>=1.0.0",
|
|
39
|
+
"python-dotenv>=1.0.0",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[project.urls]
|
|
43
|
+
Homepage = "https://github.com/Lucav21/heu-mcp"
|
|
44
|
+
Repository = "https://github.com/Lucav21/heu-mcp"
|
|
45
|
+
Issues = "https://github.com/Lucav21/heu-mcp/issues"
|
|
46
|
+
"HEU Legal" = "https://heulegal.com"
|
|
47
|
+
|
|
48
|
+
[project.scripts]
|
|
49
|
+
heu-mcp = "server:main"
|
|
50
|
+
|
|
51
|
+
[tool.setuptools]
|
|
52
|
+
py-modules = ["server"]
|
heu_mcp-0.1.0/server.py
ADDED
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""HEU Legal API MCP Server - v0.1.0
|
|
3
|
+
|
|
4
|
+
MCP Server per integrare HEU Legal con Claude AI.
|
|
5
|
+
Gestisce documenti nativi HEU e PDF per firma elettronica via conversazione.
|
|
6
|
+
|
|
7
|
+
API docs: https://api.heulegal.com/v1
|
|
8
|
+
License: MIT
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
import os
|
|
13
|
+
import re
|
|
14
|
+
import traceback
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
import httpx
|
|
18
|
+
|
|
19
|
+
from mcp.server import Server
|
|
20
|
+
from mcp.server.stdio import stdio_server
|
|
21
|
+
from mcp.types import Tool, TextContent
|
|
22
|
+
|
|
23
|
+
API_KEY = os.getenv("HEU_API_KEY", "")
|
|
24
|
+
BASE_URL = os.getenv("HEU_BASE_URL", "https://api.heulegal.com/v1").rstrip("/")
|
|
25
|
+
DOWNLOAD_DIR = Path(os.getenv("HEU_DOWNLOAD_DIR", "/tmp"))
|
|
26
|
+
|
|
27
|
+
DEFAULT_TIMEOUT = 30.0
|
|
28
|
+
DOWNLOAD_TIMEOUT = 120.0
|
|
29
|
+
|
|
30
|
+
app = Server("heu")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _headers():
|
|
34
|
+
return {
|
|
35
|
+
"x-api-key": API_KEY,
|
|
36
|
+
"Accept": "application/json",
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _request(method: str, path: str, **kwargs):
|
|
41
|
+
"""Esegue una richiesta HTTP all'API HEU e ritorna (status, body_or_text, headers).
|
|
42
|
+
|
|
43
|
+
Per risposte JSON ritorna il body parsato; per binari ritorna i bytes grezzi."""
|
|
44
|
+
url = f"{BASE_URL}{path}"
|
|
45
|
+
headers = kwargs.pop("headers", {})
|
|
46
|
+
headers = {**_headers(), **headers}
|
|
47
|
+
timeout = kwargs.pop("timeout", DEFAULT_TIMEOUT)
|
|
48
|
+
with httpx.Client(timeout=timeout) as client:
|
|
49
|
+
resp = client.request(method, url, headers=headers, **kwargs)
|
|
50
|
+
ct = resp.headers.get("content-type", "")
|
|
51
|
+
if "application/json" in ct:
|
|
52
|
+
try:
|
|
53
|
+
body = resp.json()
|
|
54
|
+
except Exception:
|
|
55
|
+
body = resp.text
|
|
56
|
+
elif "application/pdf" in ct or resp.headers.get("content-disposition"):
|
|
57
|
+
body = resp.content
|
|
58
|
+
else:
|
|
59
|
+
try:
|
|
60
|
+
body = resp.json()
|
|
61
|
+
except Exception:
|
|
62
|
+
body = resp.text
|
|
63
|
+
return resp.status_code, body, dict(resp.headers)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _ok(payload) -> list[TextContent]:
|
|
67
|
+
return [TextContent(type="text", text=json.dumps(payload, indent=2, ensure_ascii=False, default=str))]
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _err(status: int, body, hint: str | None = None) -> list[TextContent]:
|
|
71
|
+
msg = {"error": True, "status": status, "body": body}
|
|
72
|
+
if hint:
|
|
73
|
+
msg["hint"] = hint
|
|
74
|
+
return [TextContent(type="text", text=json.dumps(msg, indent=2, ensure_ascii=False, default=str))]
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _check_config() -> str | None:
|
|
78
|
+
if not API_KEY:
|
|
79
|
+
return "HEU_API_KEY non configurata. Imposta la variabile d'ambiente con la tua API key (Profile > API Keys nella UI HEU, richiede subscription Enterprise)."
|
|
80
|
+
return None
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _safe_filename(name: str) -> str:
|
|
84
|
+
name = re.sub(r"[^A-Za-z0-9._-]+", "_", name).strip("_")
|
|
85
|
+
return name or "document"
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
@app.list_tools()
|
|
89
|
+
async def list_tools():
|
|
90
|
+
placeholders_kv_schema = {
|
|
91
|
+
"type": "object",
|
|
92
|
+
"description": "Mappa key->value dei placeholder da sostituire nel template (chiave = nome placeholder)",
|
|
93
|
+
"additionalProperties": {"type": "string"},
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
pdf_signer_schema = {
|
|
97
|
+
"type": "object",
|
|
98
|
+
"properties": {
|
|
99
|
+
"source_id": {"type": "string", "description": "ID del signer nel template sorgente"},
|
|
100
|
+
"email": {"type": "string", "format": "email", "description": "Email del firmatario"},
|
|
101
|
+
"full_name": {"type": "string", "description": "Nome completo del firmatario"},
|
|
102
|
+
},
|
|
103
|
+
"required": ["source_id", "email", "full_name"],
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
pdf_placeholder_schema = {
|
|
107
|
+
"type": "object",
|
|
108
|
+
"properties": {
|
|
109
|
+
"source_id": {"type": "string", "description": "UUID del placeholder nel template"},
|
|
110
|
+
"is_checked": {"type": ["boolean", "null"], "description": "Per checkbox: spuntato o no"},
|
|
111
|
+
"text_value": {"type": ["string", "null"], "description": "Valore testuale da inserire"},
|
|
112
|
+
},
|
|
113
|
+
"required": ["source_id"],
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return [
|
|
117
|
+
Tool(
|
|
118
|
+
name="get_heu_health",
|
|
119
|
+
description="Health check API HEU. Ritorna { message: 'ok', status: 200 } se operativa.",
|
|
120
|
+
inputSchema={"type": "object", "properties": {}},
|
|
121
|
+
),
|
|
122
|
+
# ---------- DOCUMENTS (native HEU) ----------
|
|
123
|
+
Tool(
|
|
124
|
+
name="list_heu_documents",
|
|
125
|
+
description="Lista documenti/template nativi HEU con filtri opzionali.",
|
|
126
|
+
inputSchema={
|
|
127
|
+
"type": "object",
|
|
128
|
+
"properties": {
|
|
129
|
+
"type": {"type": "string", "enum": ["document", "template"], "description": "Filtra per tipo"},
|
|
130
|
+
"sort": {"type": "string", "enum": ["asc", "desc"], "description": "Ordinamento per data"},
|
|
131
|
+
"created_from": {"type": "string", "description": "Data inizio (ISO 8601, es. 2025-01-01T00:00:00Z)"},
|
|
132
|
+
"created_to": {"type": "string", "description": "Data fine (ISO 8601)"},
|
|
133
|
+
"have_editors_signed": {"type": "boolean", "description": "Filtra per: tutti gli editor hanno firmato"},
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
),
|
|
137
|
+
Tool(
|
|
138
|
+
name="get_heu_document",
|
|
139
|
+
description="Dettaglio di un documento o template HEU per ID.",
|
|
140
|
+
inputSchema={
|
|
141
|
+
"type": "object",
|
|
142
|
+
"properties": {
|
|
143
|
+
"document_id": {"type": "string", "description": "ID del documento (UUID per document/template HEU)"},
|
|
144
|
+
},
|
|
145
|
+
"required": ["document_id"],
|
|
146
|
+
},
|
|
147
|
+
),
|
|
148
|
+
Tool(
|
|
149
|
+
name="list_heu_document_placeholders",
|
|
150
|
+
description="Lista i placeholder di un documento/template HEU (chiavi sostituibili nel testo).",
|
|
151
|
+
inputSchema={
|
|
152
|
+
"type": "object",
|
|
153
|
+
"properties": {
|
|
154
|
+
"document_id": {"type": "string", "description": "ID del documento HEU"},
|
|
155
|
+
},
|
|
156
|
+
"required": ["document_id"],
|
|
157
|
+
},
|
|
158
|
+
),
|
|
159
|
+
Tool(
|
|
160
|
+
name="create_heu_document",
|
|
161
|
+
description=(
|
|
162
|
+
"Crea e condivide un nuovo documento HEU partendo da un template esistente. "
|
|
163
|
+
"Invia email ai destinatari. IMPORTANTE: chiedere conferma all'utente prima di eseguire."
|
|
164
|
+
),
|
|
165
|
+
inputSchema={
|
|
166
|
+
"type": "object",
|
|
167
|
+
"properties": {
|
|
168
|
+
"source_document_id": {"type": "string", "description": "ID del template sorgente"},
|
|
169
|
+
"document_name": {"type": "string", "description": "Nome del nuovo documento"},
|
|
170
|
+
"document_type": {"type": "string", "enum": ["document", "template"], "description": "Default: document"},
|
|
171
|
+
"email_subject": {"type": "string", "description": "Oggetto email di condivisione"},
|
|
172
|
+
"email_text": {"type": "string", "description": "Corpo email di condivisione"},
|
|
173
|
+
"email_to": {
|
|
174
|
+
"type": "array",
|
|
175
|
+
"items": {"type": "string"},
|
|
176
|
+
"description": "Lista email destinatari (oppure stringa singola)",
|
|
177
|
+
},
|
|
178
|
+
"placeholders": placeholders_kv_schema,
|
|
179
|
+
},
|
|
180
|
+
"required": ["source_document_id", "email_subject", "email_text", "email_to"],
|
|
181
|
+
},
|
|
182
|
+
),
|
|
183
|
+
Tool(
|
|
184
|
+
name="prompt_heu_document_signature",
|
|
185
|
+
description=(
|
|
186
|
+
"Invia un sollecito di firma per un documento HEU. "
|
|
187
|
+
"Limite: 1 prompt ogni 24h per documento (altrimenti 429). "
|
|
188
|
+
"IMPORTANTE: chiedere conferma all'utente prima di eseguire."
|
|
189
|
+
),
|
|
190
|
+
inputSchema={
|
|
191
|
+
"type": "object",
|
|
192
|
+
"properties": {
|
|
193
|
+
"document_id": {"type": "string", "description": "ID del documento HEU"},
|
|
194
|
+
},
|
|
195
|
+
"required": ["document_id"],
|
|
196
|
+
},
|
|
197
|
+
),
|
|
198
|
+
Tool(
|
|
199
|
+
name="download_heu_document_pdf",
|
|
200
|
+
description=(
|
|
201
|
+
"Scarica il PDF di un documento HEU e lo salva localmente. Ritorna il path del file. "
|
|
202
|
+
"Layout opzionale (codici a 3 cifre della UI HEU)."
|
|
203
|
+
),
|
|
204
|
+
inputSchema={
|
|
205
|
+
"type": "object",
|
|
206
|
+
"properties": {
|
|
207
|
+
"document_id": {"type": "string", "description": "ID del documento HEU"},
|
|
208
|
+
"layout": {
|
|
209
|
+
"type": "string",
|
|
210
|
+
"enum": [
|
|
211
|
+
"100", "200", "201", "202", "203", "204",
|
|
212
|
+
"210", "211", "212", "213", "214",
|
|
213
|
+
"220", "221", "222", "223", "224",
|
|
214
|
+
"230", "231", "232", "233", "234",
|
|
215
|
+
],
|
|
216
|
+
"description": "Codice layout (opzionale)",
|
|
217
|
+
},
|
|
218
|
+
"has_index": {"type": "boolean", "description": "Includi indice (opzionale)"},
|
|
219
|
+
"has_footer": {"type": "boolean", "description": "Includi footer (opzionale)"},
|
|
220
|
+
"output_path": {"type": "string", "description": "Path output personalizzato (opzionale, default: HEU_DOWNLOAD_DIR/heu_<id>.pdf)"},
|
|
221
|
+
},
|
|
222
|
+
"required": ["document_id"],
|
|
223
|
+
},
|
|
224
|
+
),
|
|
225
|
+
# ---------- PDFs (uploaded) ----------
|
|
226
|
+
Tool(
|
|
227
|
+
name="list_pdf_documents",
|
|
228
|
+
description="Lista PDF documenti/template caricati su HEU.",
|
|
229
|
+
inputSchema={
|
|
230
|
+
"type": "object",
|
|
231
|
+
"properties": {
|
|
232
|
+
"type": {"type": "string", "enum": ["document", "template"], "description": "Tipo (richiesto)"},
|
|
233
|
+
"sort": {"type": "string", "enum": ["asc", "desc"], "description": "Ordinamento"},
|
|
234
|
+
},
|
|
235
|
+
"required": ["type"],
|
|
236
|
+
},
|
|
237
|
+
),
|
|
238
|
+
Tool(
|
|
239
|
+
name="get_pdf_document",
|
|
240
|
+
description="Dettaglio di un PDF documento/template HEU per ID.",
|
|
241
|
+
inputSchema={
|
|
242
|
+
"type": "object",
|
|
243
|
+
"properties": {
|
|
244
|
+
"document_id": {"type": "string", "description": "ID del PDF"},
|
|
245
|
+
},
|
|
246
|
+
"required": ["document_id"],
|
|
247
|
+
},
|
|
248
|
+
),
|
|
249
|
+
Tool(
|
|
250
|
+
name="list_pdf_document_signers",
|
|
251
|
+
description="Lista i firmatari di un PDF.",
|
|
252
|
+
inputSchema={
|
|
253
|
+
"type": "object",
|
|
254
|
+
"properties": {
|
|
255
|
+
"document_id": {"type": "string", "description": "ID del PDF"},
|
|
256
|
+
},
|
|
257
|
+
"required": ["document_id"],
|
|
258
|
+
},
|
|
259
|
+
),
|
|
260
|
+
Tool(
|
|
261
|
+
name="list_pdf_document_signer_placeholders",
|
|
262
|
+
description="Lista i placeholder/campi di firma di un signer specifico su un PDF.",
|
|
263
|
+
inputSchema={
|
|
264
|
+
"type": "object",
|
|
265
|
+
"properties": {
|
|
266
|
+
"document_id": {"type": "string", "description": "ID del PDF"},
|
|
267
|
+
"signer_id": {"type": "string", "description": "ID del firmatario"},
|
|
268
|
+
},
|
|
269
|
+
"required": ["document_id", "signer_id"],
|
|
270
|
+
},
|
|
271
|
+
),
|
|
272
|
+
Tool(
|
|
273
|
+
name="list_pdf_document_placeholders",
|
|
274
|
+
description="Lista tutti i placeholder/campi di firma di un PDF.",
|
|
275
|
+
inputSchema={
|
|
276
|
+
"type": "object",
|
|
277
|
+
"properties": {
|
|
278
|
+
"document_id": {"type": "string", "description": "ID del PDF"},
|
|
279
|
+
},
|
|
280
|
+
"required": ["document_id"],
|
|
281
|
+
},
|
|
282
|
+
),
|
|
283
|
+
Tool(
|
|
284
|
+
name="create_pdf_document",
|
|
285
|
+
description=(
|
|
286
|
+
"Crea e condivide un nuovo PDF firmabile partendo da un template PDF esistente. "
|
|
287
|
+
"Richiede signers e (opzionalmente) i valori dei placeholder. "
|
|
288
|
+
"Con signature_type='fea' serve avere credito FEA sufficiente. "
|
|
289
|
+
"IMPORTANTE: chiedere conferma all'utente prima di eseguire."
|
|
290
|
+
),
|
|
291
|
+
inputSchema={
|
|
292
|
+
"type": "object",
|
|
293
|
+
"properties": {
|
|
294
|
+
"source_document_id": {"type": "string", "description": "ID del template PDF sorgente"},
|
|
295
|
+
"document_name": {"type": "string", "description": "Nome del nuovo documento"},
|
|
296
|
+
"signature_type": {"type": "string", "enum": ["fes", "fea"], "description": "Tipo firma. Default: fes"},
|
|
297
|
+
"email_subject": {"type": "string", "description": "Oggetto email di condivisione"},
|
|
298
|
+
"email_body": {"type": "string", "description": "Corpo email di condivisione"},
|
|
299
|
+
"signers": {
|
|
300
|
+
"type": "array",
|
|
301
|
+
"items": pdf_signer_schema,
|
|
302
|
+
"description": "Lista firmatari (richiesto)",
|
|
303
|
+
},
|
|
304
|
+
"placeholders": {
|
|
305
|
+
"type": "array",
|
|
306
|
+
"items": pdf_placeholder_schema,
|
|
307
|
+
"description": "Valori dei placeholder (opzionale)",
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
"required": ["source_document_id", "email_subject", "email_body", "signers"],
|
|
311
|
+
},
|
|
312
|
+
),
|
|
313
|
+
Tool(
|
|
314
|
+
name="prompt_pdf_document_signature",
|
|
315
|
+
description=(
|
|
316
|
+
"Invia un sollecito di firma per un PDF. "
|
|
317
|
+
"IMPORTANTE: chiedere conferma all'utente prima di eseguire."
|
|
318
|
+
),
|
|
319
|
+
inputSchema={
|
|
320
|
+
"type": "object",
|
|
321
|
+
"properties": {
|
|
322
|
+
"document_id": {"type": "string", "description": "ID del PDF"},
|
|
323
|
+
},
|
|
324
|
+
"required": ["document_id"],
|
|
325
|
+
},
|
|
326
|
+
),
|
|
327
|
+
]
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
@app.call_tool()
|
|
331
|
+
async def call_tool(name: str, arguments: dict) -> list[TextContent]:
|
|
332
|
+
cfg_err = _check_config()
|
|
333
|
+
if cfg_err and name != "get_heu_health":
|
|
334
|
+
return [TextContent(type="text", text=cfg_err)]
|
|
335
|
+
|
|
336
|
+
try:
|
|
337
|
+
if name == "get_heu_health":
|
|
338
|
+
if not API_KEY:
|
|
339
|
+
return [TextContent(type="text", text="HEU_API_KEY non configurata.")]
|
|
340
|
+
status, body, _ = _request("GET", "/health")
|
|
341
|
+
return _ok(body) if status == 200 else _err(status, body)
|
|
342
|
+
|
|
343
|
+
# ---------- DOCUMENTS ----------
|
|
344
|
+
if name == "list_heu_documents":
|
|
345
|
+
params = {}
|
|
346
|
+
for k in ("type", "sort", "created_from", "created_to"):
|
|
347
|
+
if k in arguments and arguments[k] is not None:
|
|
348
|
+
params[k] = arguments[k]
|
|
349
|
+
if "have_editors_signed" in arguments and arguments["have_editors_signed"] is not None:
|
|
350
|
+
params["have_editors_signed"] = "true" if arguments["have_editors_signed"] else "false"
|
|
351
|
+
status, body, _ = _request("GET", "/documents", params=params)
|
|
352
|
+
return _ok(body) if status == 200 else _err(status, body)
|
|
353
|
+
|
|
354
|
+
if name == "get_heu_document":
|
|
355
|
+
doc_id = arguments["document_id"]
|
|
356
|
+
status, body, _ = _request("GET", f"/documents/{doc_id}")
|
|
357
|
+
return _ok(body) if status == 200 else _err(status, body)
|
|
358
|
+
|
|
359
|
+
if name == "list_heu_document_placeholders":
|
|
360
|
+
doc_id = arguments["document_id"]
|
|
361
|
+
status, body, _ = _request("GET", f"/documents/{doc_id}/placeholders")
|
|
362
|
+
return _ok(body) if status == 200 else _err(status, body)
|
|
363
|
+
|
|
364
|
+
if name == "create_heu_document":
|
|
365
|
+
to_addr = arguments["email_to"]
|
|
366
|
+
if isinstance(to_addr, list) and len(to_addr) == 1:
|
|
367
|
+
to_addr = to_addr[0]
|
|
368
|
+
payload = {
|
|
369
|
+
"source_document_id": arguments["source_document_id"],
|
|
370
|
+
"email": {
|
|
371
|
+
"subject": arguments["email_subject"],
|
|
372
|
+
"text": arguments["email_text"],
|
|
373
|
+
"to_addresses": to_addr,
|
|
374
|
+
},
|
|
375
|
+
}
|
|
376
|
+
if "document_name" in arguments:
|
|
377
|
+
payload["document_name"] = arguments["document_name"]
|
|
378
|
+
if "document_type" in arguments:
|
|
379
|
+
payload["document_type"] = arguments["document_type"]
|
|
380
|
+
if "placeholders" in arguments and arguments["placeholders"]:
|
|
381
|
+
payload["placeholders"] = arguments["placeholders"]
|
|
382
|
+
status, body, _ = _request("POST", "/documents", json=payload)
|
|
383
|
+
return _ok(body) if status in (200, 201) else _err(status, body)
|
|
384
|
+
|
|
385
|
+
if name == "prompt_heu_document_signature":
|
|
386
|
+
doc_id = arguments["document_id"]
|
|
387
|
+
status, body, headers = _request("POST", f"/documents/{doc_id}/signatures/prompts")
|
|
388
|
+
if status in (200, 201):
|
|
389
|
+
return _ok(body)
|
|
390
|
+
hint = None
|
|
391
|
+
if status == 429:
|
|
392
|
+
retry = headers.get("retry-after")
|
|
393
|
+
hint = f"Sollecito già inviato di recente. Riprova tra {retry}s." if retry else "Sollecito già inviato di recente. Limite 1/24h."
|
|
394
|
+
return _err(status, body, hint=hint)
|
|
395
|
+
|
|
396
|
+
if name == "download_heu_document_pdf":
|
|
397
|
+
doc_id = arguments["document_id"]
|
|
398
|
+
payload = {}
|
|
399
|
+
for k in ("layout", "has_index", "has_footer"):
|
|
400
|
+
if k in arguments and arguments[k] is not None:
|
|
401
|
+
payload[k] = arguments[k]
|
|
402
|
+
kwargs = {"timeout": DOWNLOAD_TIMEOUT}
|
|
403
|
+
if payload:
|
|
404
|
+
kwargs["json"] = payload
|
|
405
|
+
status, body, headers = _request("POST", f"/documents/{doc_id}/download", **kwargs)
|
|
406
|
+
if status != 200:
|
|
407
|
+
return _err(status, body)
|
|
408
|
+
if not isinstance(body, (bytes, bytearray)):
|
|
409
|
+
return _err(status, body, hint="Atteso PDF binario, ricevuto altro contenuto.")
|
|
410
|
+
output_path = arguments.get("output_path")
|
|
411
|
+
if output_path:
|
|
412
|
+
out = Path(output_path)
|
|
413
|
+
else:
|
|
414
|
+
DOWNLOAD_DIR.mkdir(parents=True, exist_ok=True)
|
|
415
|
+
out = DOWNLOAD_DIR / f"heu_{_safe_filename(doc_id)}.pdf"
|
|
416
|
+
out.write_bytes(body)
|
|
417
|
+
return _ok({
|
|
418
|
+
"saved_to": str(out.resolve()),
|
|
419
|
+
"size_bytes": len(body),
|
|
420
|
+
"content_disposition": headers.get("content-disposition"),
|
|
421
|
+
})
|
|
422
|
+
|
|
423
|
+
# ---------- PDFs ----------
|
|
424
|
+
if name == "list_pdf_documents":
|
|
425
|
+
params = {"type": arguments["type"]}
|
|
426
|
+
if "sort" in arguments and arguments["sort"]:
|
|
427
|
+
params["sort"] = arguments["sort"]
|
|
428
|
+
status, body, _ = _request("GET", "/pdfs", params=params)
|
|
429
|
+
return _ok(body) if status == 200 else _err(status, body)
|
|
430
|
+
|
|
431
|
+
if name == "get_pdf_document":
|
|
432
|
+
doc_id = arguments["document_id"]
|
|
433
|
+
status, body, _ = _request("GET", f"/pdfs/{doc_id}")
|
|
434
|
+
return _ok(body) if status == 200 else _err(status, body)
|
|
435
|
+
|
|
436
|
+
if name == "list_pdf_document_signers":
|
|
437
|
+
doc_id = arguments["document_id"]
|
|
438
|
+
status, body, _ = _request("GET", f"/pdfs/{doc_id}/signers")
|
|
439
|
+
return _ok(body) if status == 200 else _err(status, body)
|
|
440
|
+
|
|
441
|
+
if name == "list_pdf_document_signer_placeholders":
|
|
442
|
+
doc_id = arguments["document_id"]
|
|
443
|
+
signer_id = arguments["signer_id"]
|
|
444
|
+
status, body, _ = _request("GET", f"/pdfs/{doc_id}/signers/{signer_id}/placeholders")
|
|
445
|
+
return _ok(body) if status == 200 else _err(status, body)
|
|
446
|
+
|
|
447
|
+
if name == "list_pdf_document_placeholders":
|
|
448
|
+
doc_id = arguments["document_id"]
|
|
449
|
+
status, body, _ = _request("GET", f"/pdfs/{doc_id}/placeholders")
|
|
450
|
+
return _ok(body) if status == 200 else _err(status, body)
|
|
451
|
+
|
|
452
|
+
if name == "create_pdf_document":
|
|
453
|
+
payload = {
|
|
454
|
+
"source_document_id": arguments["source_document_id"],
|
|
455
|
+
"email": {
|
|
456
|
+
"subject": arguments["email_subject"],
|
|
457
|
+
"body": arguments["email_body"],
|
|
458
|
+
},
|
|
459
|
+
"signers": arguments["signers"],
|
|
460
|
+
}
|
|
461
|
+
if "document_name" in arguments:
|
|
462
|
+
payload["document_name"] = arguments["document_name"]
|
|
463
|
+
if "signature_type" in arguments:
|
|
464
|
+
payload["signature_type"] = arguments["signature_type"]
|
|
465
|
+
if "placeholders" in arguments and arguments["placeholders"]:
|
|
466
|
+
payload["placeholders"] = arguments["placeholders"]
|
|
467
|
+
status, body, _ = _request("POST", "/pdfs", json=payload)
|
|
468
|
+
if status in (200, 201):
|
|
469
|
+
return _ok(body)
|
|
470
|
+
hint = None
|
|
471
|
+
if status == 422:
|
|
472
|
+
hint = "Crediti FEA insufficienti per il numero di firmatari."
|
|
473
|
+
return _err(status, body, hint=hint)
|
|
474
|
+
|
|
475
|
+
if name == "prompt_pdf_document_signature":
|
|
476
|
+
doc_id = arguments["document_id"]
|
|
477
|
+
status, body, _ = _request("POST", f"/pdfs/{doc_id}/signatures/prompts")
|
|
478
|
+
return _ok(body) if status in (200, 201) else _err(status, body)
|
|
479
|
+
|
|
480
|
+
return [TextContent(type="text", text=f"Tool sconosciuto: {name}")]
|
|
481
|
+
|
|
482
|
+
except httpx.HTTPError as e:
|
|
483
|
+
return [TextContent(type="text", text=f"Errore HTTP: {str(e)}")]
|
|
484
|
+
except Exception as e:
|
|
485
|
+
return [TextContent(type="text", text=f"Errore: {str(e)}\n{traceback.format_exc()}")]
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
async def _run():
|
|
489
|
+
async with stdio_server() as (read, write):
|
|
490
|
+
await app.run(read, write, app.create_initialization_options())
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
def main():
|
|
494
|
+
import asyncio
|
|
495
|
+
asyncio.run(_run())
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
if __name__ == "__main__":
|
|
499
|
+
main()
|
heu_mcp-0.1.0/setup.cfg
ADDED