@albertomarturelo/sii-mcp 0.5.0
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.
- package/LICENSE +21 -0
- package/README.md +55 -0
- package/dist/main.d.ts +3 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +15 -0
- package/dist/main.js.map +1 -0
- package/dist/server.d.ts +5 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +134 -0
- package/dist/server.js.map +1 -0
- package/dist/tool-helpers.d.ts +10 -0
- package/dist/tool-helpers.d.ts.map +1 -0
- package/dist/tool-helpers.js +15 -0
- package/dist/tool-helpers.js.map +1 -0
- package/dist/tools/bte.d.ts +4 -0
- package/dist/tools/bte.d.ts.map +1 -0
- package/dist/tools/bte.js +83 -0
- package/dist/tools/bte.js.map +1 -0
- package/dist/tools/dte.d.ts +4 -0
- package/dist/tools/dte.d.ts.map +1 -0
- package/dist/tools/dte.js +15 -0
- package/dist/tools/dte.js.map +1 -0
- package/dist/tools/f22.d.ts +4 -0
- package/dist/tools/f22.d.ts.map +1 -0
- package/dist/tools/f22.js +79 -0
- package/dist/tools/f22.js.map +1 -0
- package/dist/tools/f29.d.ts +4 -0
- package/dist/tools/f29.d.ts.map +1 -0
- package/dist/tools/f29.js +38 -0
- package/dist/tools/f29.js.map +1 -0
- package/dist/tools/peticiones.d.ts +4 -0
- package/dist/tools/peticiones.d.ts.map +1 -0
- package/dist/tools/peticiones.js +20 -0
- package/dist/tools/peticiones.js.map +1 -0
- package/dist/tools/rcv.d.ts +4 -0
- package/dist/tools/rcv.d.ts.map +1 -0
- package/dist/tools/rcv.js +32 -0
- package/dist/tools/rcv.js.map +1 -0
- package/dist/tools/whoami.d.ts +4 -0
- package/dist/tools/whoami.d.ts.map +1 -0
- package/dist/tools/whoami.js +14 -0
- package/dist/tools/whoami.js.map +1 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Alberto Marturelo Lorenzo
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# @albertomarturelo/sii-mcp
|
|
2
|
+
|
|
3
|
+
**MCP (Model Context Protocol) server** — over stdio — that exposes Chile's **SII**
|
|
4
|
+
(Servicio de Impuestos Internos) to **Claude Desktop** and **Claude Code**.
|
|
5
|
+
Authenticated **reads** — RCV, F22, F29, boletas de honorarios (BHE),
|
|
6
|
+
DTE-authorized (public), peticiones administrativas, whoami — as `readOnly` tools,
|
|
7
|
+
plus a `destructive`, confirm-gated BHE **emit**. A thin surface over
|
|
8
|
+
[`@albertomarturelo/sii-core`](https://www.npmjs.com/package/@albertomarturelo/sii-core);
|
|
9
|
+
all the guardrails live in the core, and **no tool ever receives your password**
|
|
10
|
+
(login delegates to a browser flow — ADR-006).
|
|
11
|
+
|
|
12
|
+
> ⚠️ **Unofficial.** Not affiliated with or endorsed by the SII. Provided "as is"
|
|
13
|
+
> (MIT, no warranty). You are responsible for the SII's terms of service and
|
|
14
|
+
> Chilean law.
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm i -g @albertomarturelo/sii-mcp @albertomarturelo/sii-cli
|
|
20
|
+
# the browser login needs Chromium once (~100–150 MB):
|
|
21
|
+
npx playwright install chromium
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Requires **Node ≥ 20**. (The `sii` CLI is handy for the first `sii auth login`;
|
|
25
|
+
the login can also run through the `auth_login` tool.)
|
|
26
|
+
|
|
27
|
+
## Connect to Claude
|
|
28
|
+
|
|
29
|
+
**Claude Desktop** — add to `claude_desktop_config.json` and restart the app
|
|
30
|
+
(macOS: `~/Library/Application Support/Claude/`; Windows: `%APPDATA%\Claude\`):
|
|
31
|
+
|
|
32
|
+
```json
|
|
33
|
+
{
|
|
34
|
+
"mcpServers": {
|
|
35
|
+
"sii": { "command": "sii-mcp" }
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**Claude Code**:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
claude mcp add sii -- sii-mcp
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Then ask in natural language — e.g. «muéstrame el RCV de compras de 2026-05» or
|
|
47
|
+
«¿tengo peticiones administrativas detenidas?». Read tools change nothing; issuing
|
|
48
|
+
a BHE (`bte_emit`) requires an explicit confirmation + amount echo.
|
|
49
|
+
|
|
50
|
+
Tools, resources, prompts, and the identity model are documented in the
|
|
51
|
+
[project README](https://github.com/albertomarturelo/sii#readme).
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
[MIT](./LICENSE) © Alberto Marturelo Lorenzo.
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":""}
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// @albertomarturelo/sii-mcp entry point. Wires the Node runtime into the server and serves over
|
|
3
|
+
// stdio. STDOUT is the JSON-RPC channel — diagnostics go to STDERR only.
|
|
4
|
+
import { createNodeRuntime } from '@albertomarturelo/sii-core/node';
|
|
5
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
6
|
+
import { buildServer } from './server.js';
|
|
7
|
+
async function main() {
|
|
8
|
+
const server = buildServer(createNodeRuntime());
|
|
9
|
+
await server.connect(new StdioServerTransport());
|
|
10
|
+
}
|
|
11
|
+
main().catch((error) => {
|
|
12
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
13
|
+
process.exit(1);
|
|
14
|
+
});
|
|
15
|
+
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";AACA,gGAAgG;AAChG,yEAAyE;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,KAAK,UAAU,IAAI;IACjB,MAAM,MAAM,GAAG,WAAW,CAAC,iBAAiB,EAAE,CAAC,CAAC;IAChD,MAAM,MAAM,CAAC,OAAO,CAAC,IAAI,oBAAoB,EAAE,CAAC,CAAC;AACnD,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;IAC9B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACpF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { type Runtime } from '@albertomarturelo/sii-core';
|
|
3
|
+
/** Build the MCP server over an injected Runtime (tests pass fakes; no SII). */
|
|
4
|
+
export declare function buildServer(runtime: Runtime): McpServer;
|
|
5
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,OAAO,EAaL,KAAK,OAAO,EACb,MAAM,4BAA4B,CAAC;AAoBpC,gFAAgF;AAChF,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,SAAS,CA8JvD"}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// The `sii` MCP stdio server (ADR-003): every Resource/Tool is a thin call into a
|
|
2
|
+
// @albertomarturelo/sii-core task — it never reaches past the task layer. The Clave NEVER crosses
|
|
3
|
+
// this boundary: auth_login delegates to the browser flow and takes no password
|
|
4
|
+
// argument (ADR-006). consoleLogin is deliberately unreachable here — it lives in
|
|
5
|
+
// the CLI-only `@albertomarturelo/sii-core/cli` subpath, which this package never imports.
|
|
6
|
+
import { createRequire } from 'node:module';
|
|
7
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
import { HOSTS, authStatus, describeOperating, formatOperableEntry, formatRut as fmt, listOperable, login, logout, operate, operateSelf, operatingStatus, statusRefresh, } from '@albertomarturelo/sii-core';
|
|
10
|
+
import { toolText } from './tool-helpers.js';
|
|
11
|
+
// Domain read surfaces — each module owns a tools/<mod>.ts register fn (append-only).
|
|
12
|
+
import { registerWhoamiTools } from './tools/whoami.js';
|
|
13
|
+
import { registerRcvTools } from './tools/rcv.js';
|
|
14
|
+
import { registerF22Tools } from './tools/f22.js';
|
|
15
|
+
import { registerF29Tools } from './tools/f29.js';
|
|
16
|
+
import { registerDteTools } from './tools/dte.js';
|
|
17
|
+
import { registerBteTools } from './tools/bte.js';
|
|
18
|
+
import { registerPeticionesTools } from './tools/peticiones.js';
|
|
19
|
+
const jsonResource = (uri, value) => ({
|
|
20
|
+
contents: [{ uri: uri.href, mimeType: 'application/json', text: JSON.stringify(value, null, 2) }],
|
|
21
|
+
});
|
|
22
|
+
// The published version, read from this package's own package.json at runtime (one
|
|
23
|
+
// level up from dist/) so the MCP handshake reports the real release, never drifting.
|
|
24
|
+
const pkgVersion = createRequire(import.meta.url)('../package.json')
|
|
25
|
+
.version;
|
|
26
|
+
/** Build the MCP server over an injected Runtime (tests pass fakes; no SII). */
|
|
27
|
+
export function buildServer(runtime) {
|
|
28
|
+
const server = new McpServer({ name: 'sii', version: pkgVersion });
|
|
29
|
+
// --- Resources: read-only context the model reads to orient (ROADMAP) ---
|
|
30
|
+
server.registerResource('session', 'sii://session', {
|
|
31
|
+
title: 'Sesión SII',
|
|
32
|
+
description: 'Estado LOCAL de la sesión (autenticado, RUT, fuente). No toca el portal.',
|
|
33
|
+
mimeType: 'application/json',
|
|
34
|
+
}, async (uri) => jsonResource(uri, await authStatus(runtime)));
|
|
35
|
+
server.registerResource('operating', 'sii://operating', {
|
|
36
|
+
title: 'Operando como',
|
|
37
|
+
description: 'RUT operativo actual (tú mismo o una empresa representada). null si no hay sesión.',
|
|
38
|
+
mimeType: 'application/json',
|
|
39
|
+
}, async (uri) => jsonResource(uri, await operatingStatus(runtime)));
|
|
40
|
+
server.registerResource('operable', 'sii://operable', {
|
|
41
|
+
title: 'Conjunto operable',
|
|
42
|
+
description: 'RUT que la cuenta puede operar (tú mismo + empresas representadas). null si no hay sesión.',
|
|
43
|
+
mimeType: 'application/json',
|
|
44
|
+
}, async (uri) => jsonResource(uri, await listOperable(runtime)));
|
|
45
|
+
server.registerResource('config', 'sii://config', {
|
|
46
|
+
title: 'Configuración SII',
|
|
47
|
+
description: 'Hostnames de producción del SII (única fuente de verdad, ADR-004).',
|
|
48
|
+
mimeType: 'application/json',
|
|
49
|
+
}, async (uri) => jsonResource(uri, HOSTS));
|
|
50
|
+
// --- Tools: actions, each a thin call into a @albertomarturelo/sii-core task ---
|
|
51
|
+
// NOTE: auth_login can block up to the browser-login budget (~180s) while the
|
|
52
|
+
// user types the Clave into SII's page. Some MCP clients enforce a shorter
|
|
53
|
+
// tool-call timeout — confirm/tune the budget when live-validating in Claude
|
|
54
|
+
// Desktop (a credential-free, CLI-only fast path stays out of MCP by design).
|
|
55
|
+
server.registerTool('auth_login', {
|
|
56
|
+
title: 'Iniciar sesión (navegador)',
|
|
57
|
+
description: 'Abre el navegador en la página del SII para que el usuario escriba su Clave Tributaria. ' +
|
|
58
|
+
'NUNCA recibe la Clave como argumento (ADR-006); persiste solo cookies. Idempotente sobre una sesión viva.',
|
|
59
|
+
annotations: { readOnlyHint: false, openWorldHint: true },
|
|
60
|
+
}, () => toolText(async () => {
|
|
61
|
+
const r = await login(runtime);
|
|
62
|
+
return r.reason === 'already_authenticated'
|
|
63
|
+
? `Ya tienes una sesión activa como ${fmt(r.rut)}.`
|
|
64
|
+
: `Sesión iniciada como ${fmt(r.rut)}.`;
|
|
65
|
+
}));
|
|
66
|
+
server.registerTool('auth_status', {
|
|
67
|
+
title: 'Estado de sesión',
|
|
68
|
+
description: 'Lectura LOCAL de la sesión (quién soy, operando-como). refresh=true lee la identidad desde el portal (requiere sesión viva).',
|
|
69
|
+
inputSchema: { refresh: z.boolean().optional() },
|
|
70
|
+
annotations: { readOnlyHint: true },
|
|
71
|
+
}, ({ refresh }) => toolText(async () => {
|
|
72
|
+
if (refresh) {
|
|
73
|
+
const id = await statusRefresh(runtime);
|
|
74
|
+
return `RUT: ${fmt(id.rut)}\nNombre: ${id.nombre ?? '—'}\nTipo: ${id.accountType}`;
|
|
75
|
+
}
|
|
76
|
+
const s = await authStatus(runtime);
|
|
77
|
+
if (!s.authenticated || !s.rut)
|
|
78
|
+
return 'No autenticado. Usa la tool auth_login.';
|
|
79
|
+
const ctx = await operatingStatus(runtime);
|
|
80
|
+
const op = ctx && !ctx.isSelf ? `\n${describeOperating(ctx)}` : '';
|
|
81
|
+
return `Autenticado (sesión local) como ${fmt(s.rut)}.${op}`;
|
|
82
|
+
}));
|
|
83
|
+
// logout carries NO secret (best-effort server close + local cookie wipe), so
|
|
84
|
+
// ADR-006 does not bar it from MCP — switching accounts is logout→login (ADR-005).
|
|
85
|
+
server.registerTool('auth_logout', {
|
|
86
|
+
title: 'Cerrar sesión',
|
|
87
|
+
description: 'Cierra la sesión: intenta cerrarla en el servidor (mejor esfuerzo) y borra las cookies locales. ' +
|
|
88
|
+
'No recibe argumentos. Para cambiar de cuenta: auth_logout y luego auth_login.',
|
|
89
|
+
// Touches SII: the best-effort server-side close is a real portal call (like auth_login).
|
|
90
|
+
annotations: { readOnlyHint: false, openWorldHint: true },
|
|
91
|
+
}, () => toolText(async () => {
|
|
92
|
+
const r = await logout(runtime);
|
|
93
|
+
if (!r.loggedOut)
|
|
94
|
+
return 'No había sesión activa.';
|
|
95
|
+
return r.serverClosed ? 'Sesión cerrada (servidor y local).' : 'Sesión cerrada (local).';
|
|
96
|
+
}));
|
|
97
|
+
server.registerTool('operate', {
|
|
98
|
+
title: 'Operar como',
|
|
99
|
+
description: 'Selecciona el RUT bajo el que operas: una empresa representada (rut) o tú mismo (self=true). ' +
|
|
100
|
+
'list=true LISTA los RUT que puedes operar (tú mismo + empresas representadas). ' +
|
|
101
|
+
'Validado contra el conjunto operable. Sin argumentos, reporta el contexto actual.',
|
|
102
|
+
inputSchema: {
|
|
103
|
+
rut: z.string().optional(),
|
|
104
|
+
self: z.boolean().optional(),
|
|
105
|
+
list: z.boolean().optional(),
|
|
106
|
+
},
|
|
107
|
+
annotations: { readOnlyHint: false },
|
|
108
|
+
}, ({ rut, self, list }) => toolText(async () => {
|
|
109
|
+
if (list) {
|
|
110
|
+
const result = await listOperable(runtime);
|
|
111
|
+
if (!result)
|
|
112
|
+
return 'No hay sesión activa. Usa la tool auth_login.';
|
|
113
|
+
return result.operable.map((e) => formatOperableEntry(e, result.operatingRut)).join('\n');
|
|
114
|
+
}
|
|
115
|
+
if (self) {
|
|
116
|
+
const r = await operateSelf(runtime);
|
|
117
|
+
return describeOperating(r.context);
|
|
118
|
+
}
|
|
119
|
+
if (rut)
|
|
120
|
+
return describeOperating((await operate(runtime, rut)).context);
|
|
121
|
+
const ctx = await operatingStatus(runtime);
|
|
122
|
+
return ctx ? describeOperating(ctx) : 'No hay sesión activa. Usa la tool auth_login.';
|
|
123
|
+
}));
|
|
124
|
+
// --- domain read surfaces (one register call per module — append-only) ---
|
|
125
|
+
registerWhoamiTools(server, runtime);
|
|
126
|
+
registerRcvTools(server, runtime);
|
|
127
|
+
registerF22Tools(server, runtime);
|
|
128
|
+
registerF29Tools(server, runtime);
|
|
129
|
+
registerDteTools(server, runtime);
|
|
130
|
+
registerBteTools(server, runtime);
|
|
131
|
+
registerPeticionesTools(server, runtime);
|
|
132
|
+
return server;
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,kGAAkG;AAClG,gFAAgF;AAChF,kFAAkF;AAClF,2FAA2F;AAC3F,OAAO,EAAE,aAAa,EAA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 -0,0 +1,10 @@
|
|
|
1
|
+
/** Run a task and wrap its text as a tool result; domain errors come back as an
|
|
2
|
+
* error result carrying SII's Spanish message verbatim (CONVENTIONS). */
|
|
3
|
+
export declare function toolText(fn: () => Promise<string>): Promise<{
|
|
4
|
+
content: {
|
|
5
|
+
type: 'text';
|
|
6
|
+
text: string;
|
|
7
|
+
}[];
|
|
8
|
+
isError?: boolean;
|
|
9
|
+
}>;
|
|
10
|
+
//# sourceMappingURL=tool-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-helpers.d.ts","sourceRoot":"","sources":["../src/tool-helpers.ts"],"names":[],"mappings":"AAMA;0EAC0E;AAC1E,wBAAsB,QAAQ,CAAC,EAAE,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC;IACjE,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC1C,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC,CAMD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Shared MCP tool helpers. Each domain module owns a `tools/<mod>.ts` exporting a
|
|
2
|
+
// `register<Mod>Tools(server, runtime)`; they all reuse `toolText` so SII's Spanish
|
|
3
|
+
// error messages surface verbatim and the registration stays uniform across modules.
|
|
4
|
+
const messageOf = (e) => (e instanceof Error ? e.message : String(e));
|
|
5
|
+
/** Run a task and wrap its text as a tool result; domain errors come back as an
|
|
6
|
+
* error result carrying SII's Spanish message verbatim (CONVENTIONS). */
|
|
7
|
+
export async function toolText(fn) {
|
|
8
|
+
try {
|
|
9
|
+
return { content: [{ type: 'text', text: await fn() }] };
|
|
10
|
+
}
|
|
11
|
+
catch (e) {
|
|
12
|
+
return { content: [{ type: 'text', text: messageOf(e) }], isError: true };
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=tool-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-helpers.js","sourceRoot":"","sources":["../src/tool-helpers.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,oFAAoF;AACpF,qFAAqF;AAErF,MAAM,SAAS,GAAG,CAAC,CAAU,EAAU,EAAE,CAAC,CAAC,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAEvF;0EAC0E;AAC1E,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,EAAyB;IAItD,IAAI,CAAC;QACH,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;IAC3D,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC5E,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bte.d.ts","sourceRoot":"","sources":["../../src/tools/bte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEzE,OAAO,EAOL,KAAK,OAAO,EACb,MAAM,4BAA4B,CAAC;AAgDpC,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAwE1E"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { bteEmit, bteEmitPreview, bteList, } from '@albertomarturelo/sii-core';
|
|
3
|
+
import { toolText } from '../tool-helpers.js';
|
|
4
|
+
const sideOf = (recibidas) => (recibidas ? 'RECIBIDAS' : 'EMITIDAS');
|
|
5
|
+
// Shared emit input fields (zod raw shape). The emisor fields are read from the live form; the
|
|
6
|
+
// caller supplies only receptor + líneas + fecha + who-withholds.
|
|
7
|
+
const emitFields = {
|
|
8
|
+
receptor: z.string(),
|
|
9
|
+
nombre: z.string(),
|
|
10
|
+
domicilio: z.string(),
|
|
11
|
+
region: z.number().int(),
|
|
12
|
+
comuna: z.number().int(),
|
|
13
|
+
lineas: z
|
|
14
|
+
.array(z.object({ glosa: z.string(), monto: z.number().int().positive() }))
|
|
15
|
+
.min(1)
|
|
16
|
+
.max(4),
|
|
17
|
+
fecha: z
|
|
18
|
+
.object({ dia: z.number().int(), mes: z.number().int(), anio: z.number().int() })
|
|
19
|
+
.optional(),
|
|
20
|
+
retiene: z.enum(['receptor', 'emisor']),
|
|
21
|
+
mostrarDetalle: z.boolean().optional(),
|
|
22
|
+
};
|
|
23
|
+
const toArgs = (i) => ({
|
|
24
|
+
receptor: i.receptor,
|
|
25
|
+
receptorNombre: i.nombre,
|
|
26
|
+
receptorDomicilio: i.domicilio,
|
|
27
|
+
region: i.region,
|
|
28
|
+
comuna: i.comuna,
|
|
29
|
+
lineas: i.lineas,
|
|
30
|
+
retiene: (i.retiene === 'emisor' ? 'EMISOR' : 'RECEPTOR'),
|
|
31
|
+
...(i.fecha ? { fecha: i.fecha } : {}),
|
|
32
|
+
...(i.mostrarDetalle !== undefined ? { mostrarDetalle: i.mostrarDetalle } : {}),
|
|
33
|
+
});
|
|
34
|
+
export function registerBteTools(server, runtime) {
|
|
35
|
+
server.registerTool('bte_list', {
|
|
36
|
+
title: 'BHE/BTE — boletas de honorarios',
|
|
37
|
+
description: 'Lista las boletas de honorarios electrónicas de un período (YYYYMM/YYYY-MM). ' +
|
|
38
|
+
'EMITIDAS por defecto; recibidas=true para las RECIBIDAS. SESSION-KEYED: lee SIEMPRE el ' +
|
|
39
|
+
'titular de la sesión (no acepta otro RUT; para las BHE de una empresa, inicia sesión como ella).',
|
|
40
|
+
inputSchema: { periodo: z.string(), recibidas: z.boolean().optional() },
|
|
41
|
+
annotations: { readOnlyHint: true },
|
|
42
|
+
}, ({ periodo, recibidas }) => toolText(async () => JSON.stringify(await bteList(runtime, { periodo, side: sideOf(recibidas) }), null, 2)));
|
|
43
|
+
// --- emit preview (does NOT issue) — safe to call freely ---
|
|
44
|
+
server.registerTool('bte_emit_preview', {
|
|
45
|
+
title: 'BHE — vista previa de emisión (NO emite)',
|
|
46
|
+
description: 'Calcula una boleta de honorarios (total, retención de PPM y líquido) SIN EMITIRLA. Usa ' +
|
|
47
|
+
'esto para cotizar/preparar antes de emitir. Recibe: receptor (RUT), nombre, domicilio, ' +
|
|
48
|
+
'region+comuna (códigos SII), lineas [{glosa, monto bruto}] (1–4), retiene ' +
|
|
49
|
+
'("receptor"|"emisor"), fecha opcional. SESSION-KEYED: emite como el titular de la sesión.',
|
|
50
|
+
inputSchema: emitFields,
|
|
51
|
+
annotations: { readOnlyHint: true },
|
|
52
|
+
}, (input) => toolText(async () => JSON.stringify(await bteEmitPreview(runtime, toArgs(input)), null, 2)));
|
|
53
|
+
// --- emit (ISSUES a legally-binding boleta) — destructive, requires explicit confirmation ---
|
|
54
|
+
server.registerTool('bte_emit', {
|
|
55
|
+
title: 'BHE — EMITIR boleta de honorarios (acto legal)',
|
|
56
|
+
description: 'EMITE una boleta de honorarios electrónica: un DOCUMENTO CON VALOR LEGAL, reportado al SII ' +
|
|
57
|
+
'y que solo se revierte con una anulación posterior. Llama primero a bte_emit_preview y ' +
|
|
58
|
+
'muéstrale al usuario el total/retención/líquido. Para emitir DEBES pasar confirmar=true y ' +
|
|
59
|
+
'montoTotalConfirmacion = la suma exacta de los montos brutos (doble verificación). ' +
|
|
60
|
+
'Devuelve el código de barras (folio) + el PDF. SESSION-KEYED. Opcional: enviarA (email).',
|
|
61
|
+
inputSchema: {
|
|
62
|
+
...emitFields,
|
|
63
|
+
confirmar: z.literal(true),
|
|
64
|
+
montoTotalConfirmacion: z.number().int(),
|
|
65
|
+
enviarA: z.string().optional(),
|
|
66
|
+
copiaEmisor: z.boolean().optional(),
|
|
67
|
+
},
|
|
68
|
+
annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: true },
|
|
69
|
+
}, (input) => toolText(async () => {
|
|
70
|
+
const total = input.lineas.reduce((s, l) => s + l.monto, 0);
|
|
71
|
+
if (input.montoTotalConfirmacion !== total) {
|
|
72
|
+
throw new Error(`montoTotalConfirmacion (${input.montoTotalConfirmacion}) no coincide con la suma de ` +
|
|
73
|
+
`los montos brutos (${total}). Repite el total exacto para emitir.`);
|
|
74
|
+
}
|
|
75
|
+
const args = {
|
|
76
|
+
...toArgs(input),
|
|
77
|
+
...(input.enviarA ? { enviarA: input.enviarA } : {}),
|
|
78
|
+
...(input.copiaEmisor !== undefined ? { copiaEmisor: input.copiaEmisor } : {}),
|
|
79
|
+
};
|
|
80
|
+
return JSON.stringify(await bteEmit(runtime, args), null, 2);
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=bte.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bte.js","sourceRoot":"","sources":["../../src/tools/bte.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,OAAO,EACP,cAAc,EACd,OAAO,GAKR,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,MAAM,MAAM,GAAG,CAAC,SAAmB,EAAW,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;AAExF,+FAA+F;AAC/F,kEAAkE;AAClE,MAAM,UAAU,GAAG;IACjB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,SAAS,EAAE,CAAC,CAAC,MAAM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AAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC/E,CAAC;QACF,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAC/D,CAAC,CAAC,CACL,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dte.d.ts","sourceRoot":"","sources":["../../src/tools/dte.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEzE,OAAO,EAAiB,KAAK,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAGzE,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAgB1E"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { dteAuthorized } from '@albertomarturelo/sii-core';
|
|
3
|
+
import { toolText } from '../tool-helpers.js';
|
|
4
|
+
export function registerDteTools(server, runtime) {
|
|
5
|
+
server.registerTool('dte_authorized', {
|
|
6
|
+
title: 'DTE autorizados (consulta pública)',
|
|
7
|
+
description: 'Consulta PÚBLICA (sin login) de los tipos de DTE que un RUT está autorizado a emitir. ' +
|
|
8
|
+
'Funciona para CUALQUIER RUT (no requiere sesión, no toca ninguna cuenta). Devuelve el ' +
|
|
9
|
+
'detalle curado (razón social, resolución, documentos autorizados) o, si el RUT no es ' +
|
|
10
|
+
'emisor, autorizado=false con el mensaje verbatim del SII.',
|
|
11
|
+
inputSchema: { rut: z.string() },
|
|
12
|
+
annotations: { readOnlyHint: true },
|
|
13
|
+
}, ({ rut }) => toolText(async () => JSON.stringify(await dteAuthorized(runtime, { rut }), null, 2)));
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=dte.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dte.js","sourceRoot":"","sources":["../../src/tools/dte.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,aAAa,EAAgB,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,MAAM,UAAU,gBAAgB,CAAC,MAAiB,EAAE,OAAgB;IAClE,MAAM,CAAC,YAAY,CACjB,gBAAgB,EAChB;QACE,KAAK,EAAE,oCAAoC;QAC3C,WAAW,EACT,wFAAwF;YACxF,wFAAwF;YACxF,uFAAuF;YACvF,2DAA2D;QAC7D,WAAW,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE;QAChC,WAAW,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE;KACpC,EACD,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CACV,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,aAAa,CAAC,OAAO,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CACvF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"f22.d.ts","sourceRoot":"","sources":["../../src/tools/f22.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEzE,OAAO,EAML,KAAK,OAAO,EACb,MAAM,4BAA4B,CAAC;AAGpC,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAqG1E"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { f22Historial, f22Observaciones, f22Overview, f22Status, ValidationError, } from '@albertomarturelo/sii-core';
|
|
3
|
+
import { toolText } from '../tool-helpers.js';
|
|
4
|
+
export function registerF22Tools(server, runtime) {
|
|
5
|
+
server.registerTool('f22_status', {
|
|
6
|
+
title: 'F22 estado (Renta anual)',
|
|
7
|
+
description: 'Estado de la Declaración Anual de Renta (F22). CON `anio` (YYYY): detalle del año ' +
|
|
8
|
+
'(folio/estado + grilla de códigos curada, sin PII de identidad/banco). SIN `anio`: ' +
|
|
9
|
+
'resumen multi-año del estado. Para el formulario completo agrupado usa `f22_formulario`. ' +
|
|
10
|
+
'Session-keyed: lee tu propia renta; para una empresa, inicia sesión como ella.',
|
|
11
|
+
inputSchema: {
|
|
12
|
+
anio: z.string().optional(),
|
|
13
|
+
folio: z.string().optional(),
|
|
14
|
+
years: z.number().optional(),
|
|
15
|
+
},
|
|
16
|
+
annotations: { readOnlyHint: true },
|
|
17
|
+
}, ({ anio, folio, years }) => toolText(async () => {
|
|
18
|
+
if (anio === undefined) {
|
|
19
|
+
// `folio` selects a declaración within a year; meaningless for the overview.
|
|
20
|
+
if (folio !== undefined) {
|
|
21
|
+
throw new ValidationError('`folio` requiere indicar `anio` (YYYY).');
|
|
22
|
+
}
|
|
23
|
+
const ov = await f22Overview(runtime, years !== undefined ? { years } : {});
|
|
24
|
+
return JSON.stringify(ov, null, 2);
|
|
25
|
+
}
|
|
26
|
+
const e = await f22Status(runtime, { anio, ...(folio ? { folio } : {}) });
|
|
27
|
+
return JSON.stringify(e, null, 2);
|
|
28
|
+
}));
|
|
29
|
+
server.registerTool('f22_formulario', {
|
|
30
|
+
title: 'F22 formulario completo (Renta anual)',
|
|
31
|
+
description: 'El formulario completo de la Declaración Anual de Renta (F22) de un año, sin PII de ' +
|
|
32
|
+
'identidad/banco, agrupado en `grupos`: `ingresos`, `deducciones`, `creditos` ' +
|
|
33
|
+
'(grupo COMBINADO retenciones·PPM·créditos — p.ej. 162 es crédito/retención IUSC de ' +
|
|
34
|
+
'origen, 36/1905 son PPM), `calculo` (subtotales intermedios del IGC/IUSC: 157/158/304, ' +
|
|
35
|
+
'no son resultados finales), `resultado` (desenlaces finales: impuesto/devolución/giro) ' +
|
|
36
|
+
'y `otros` (red de seguridad: cualquier código tributario no-PII aún sin clasificar; ' +
|
|
37
|
+
'vacío = todos clasificados, nunca se oculta nada). La unión de los seis = la grilla ' +
|
|
38
|
+
'completa. Session-keyed: lee tu propia renta; para una empresa, inicia sesión como ella.',
|
|
39
|
+
inputSchema: {
|
|
40
|
+
anio: z.string(),
|
|
41
|
+
folio: z.string().optional(),
|
|
42
|
+
},
|
|
43
|
+
annotations: { readOnlyHint: true },
|
|
44
|
+
}, ({ anio, folio }) => toolText(async () => {
|
|
45
|
+
const e = await f22Status(runtime, { anio, full: true, ...(folio ? { folio } : {}) });
|
|
46
|
+
return JSON.stringify(e, null, 2);
|
|
47
|
+
}));
|
|
48
|
+
server.registerTool('f22_observaciones', {
|
|
49
|
+
title: 'F22 observaciones (inconsistencias)',
|
|
50
|
+
description: 'Observaciones/inconsistencias de la Declaración Anual de Renta (F22) de un año: ' +
|
|
51
|
+
'código (B102, G37…), glosa y URL de ayuda del SII para corregir. Session-keyed: ' +
|
|
52
|
+
'lee tu propia renta; para una empresa, inicia sesión como ella.',
|
|
53
|
+
inputSchema: {
|
|
54
|
+
anio: z.string(),
|
|
55
|
+
folio: z.string().optional(),
|
|
56
|
+
},
|
|
57
|
+
annotations: { readOnlyHint: true },
|
|
58
|
+
}, ({ anio, folio }) => toolText(async () => {
|
|
59
|
+
const r = await f22Observaciones(runtime, { anio, ...(folio ? { folio } : {}) });
|
|
60
|
+
return JSON.stringify(r, null, 2);
|
|
61
|
+
}));
|
|
62
|
+
server.registerTool('f22_historial', {
|
|
63
|
+
title: 'F22 historial (eventos de Renta anual)',
|
|
64
|
+
description: 'Historial de eventos de la Declaración Anual de Renta (F22) de un año: la línea de ' +
|
|
65
|
+
'tiempo (declaración recibida, devolución autorizada, giros de Tesorería, ' +
|
|
66
|
+
'rectificatorias) con fecha y glosa verbatim del SII, más reciente primero. Por ' +
|
|
67
|
+
'defecto cubre todos los folios del año; `folio` acota a uno. Session-keyed: lee tu ' +
|
|
68
|
+
'propia renta; para una empresa, inicia sesión como ella.',
|
|
69
|
+
inputSchema: {
|
|
70
|
+
anio: z.string(),
|
|
71
|
+
folio: z.string().optional(),
|
|
72
|
+
},
|
|
73
|
+
annotations: { readOnlyHint: true },
|
|
74
|
+
}, ({ anio, folio }) => toolText(async () => {
|
|
75
|
+
const r = await f22Historial(runtime, { anio, ...(folio ? { folio } : {}) });
|
|
76
|
+
return JSON.stringify(r, null, 2);
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=f22.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"f22.js","sourceRoot":"","sources":["../../src/tools/f22.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,SAAS,EACT,eAAe,GAEhB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,MAAM,UAAU,gBAAgB,CAAC,MAAiB,EAAE,OAAgB;IAClE,MAAM,CAAC,YAAY,CACjB,YAAY,EACZ;QACE,KAAK,EAAE,0BAA0B;QACjC,WAAW,EACT,oFAAoF;YACpF,qFAAqF;YACrF,2FAA2F;YAC3F,gFAAgF;QAClF,WAAW,EAAE;YACX,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;YAC3B,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;YAC5B,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;SAC7B;QACD,WAAW,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE;KACpC,EACD,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,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SAC7B;QACD,WAAW,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE;KACpC,EACD,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,CAClB,QAAQ,CAAC,KAAK,IAAI,EAAE;QAClB,MAAM,CAAC,GAAG,MAAM,YAAY,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QAC7E,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IACpC,CAAC,CAAC,CACL,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"f29.d.ts","sourceRoot":"","sources":["../../src/tools/f29.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEzE,OAAO,EAAyC,KAAK,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAGjG,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAsD1E"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { f29Formulario, f29Overview, f29Status } from '@albertomarturelo/sii-core';
|
|
3
|
+
import { toolText } from '../tool-helpers.js';
|
|
4
|
+
export function registerF29Tools(server, runtime) {
|
|
5
|
+
server.registerTool('f29_formulario', {
|
|
6
|
+
title: 'F29 formulario (propuesta IVA, agrupado)',
|
|
7
|
+
description: 'Propuesta de IVA de un período (YYYYMM o YYYY-MM): los códigos del F29 etiquetados con ' +
|
|
8
|
+
'su glosa y agrupados (débitos/ventas, créditos/compras, retenciones·PPM, otros, ' +
|
|
9
|
+
'determinación). `fuente: "propuesta"` — es la sugerencia del SII, no el formulario ' +
|
|
10
|
+
'presentado. Session-keyed: lee tu propio F29; para una empresa, inicia sesión como ella.',
|
|
11
|
+
inputSchema: { periodo: z.string() },
|
|
12
|
+
annotations: { readOnlyHint: true },
|
|
13
|
+
}, ({ periodo }) => toolText(async () => JSON.stringify(await f29Formulario(runtime, { periodo }), null, 2)));
|
|
14
|
+
server.registerTool('f29_overview', {
|
|
15
|
+
title: 'F29 overview (posición IVA por mes)',
|
|
16
|
+
description: 'Posición de IVA por mes en un rango: por cada mes, estado, folio, fecha y el total a ' +
|
|
17
|
+
'pagar declarado ("lo que pagué"). Indica el rango con `desde`/`hasta` (YYYY-MM) o con ' +
|
|
18
|
+
'`anio` (YYYY) para el año completo; sin argumentos, el año en curso a la fecha. ' +
|
|
19
|
+
'Session-keyed: lee tu propio F29.',
|
|
20
|
+
inputSchema: {
|
|
21
|
+
desde: z.string().optional(),
|
|
22
|
+
hasta: z.string().optional(),
|
|
23
|
+
anio: z.string().optional(),
|
|
24
|
+
},
|
|
25
|
+
annotations: { readOnlyHint: true },
|
|
26
|
+
}, ({ desde, hasta, anio }) =>
|
|
27
|
+
// Range semantics live in the task (one policy for CLI + MCP): `anio` → whole
|
|
28
|
+
// year; `desde` alone → that month; nothing → current calendar year to date.
|
|
29
|
+
toolText(async () => JSON.stringify(await f29Overview(runtime, { desde, hasta, anio }), null, 2)));
|
|
30
|
+
server.registerTool('f29_status', {
|
|
31
|
+
title: 'F29 estado (declaraciones del mes)',
|
|
32
|
+
description: 'Estado de las declaraciones F29 presentadas/guardadas de un período (YYYYMM o YYYY-MM): ' +
|
|
33
|
+
'estado, folio, fecha y total. Vacío = nada presentado. Session-keyed: lee tu propio F29.',
|
|
34
|
+
inputSchema: { periodo: z.string() },
|
|
35
|
+
annotations: { readOnlyHint: true },
|
|
36
|
+
}, ({ periodo }) => toolText(async () => JSON.stringify(await f29Status(runtime, { periodo }), null, 2)));
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=f29.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,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8E;IAC9E,6EAA6E;IAC7E,QAAQ,CAAC,KAAK,IAAI,EAAE,CAClB,IAAI,CAAC,SAAS,CAAC,MAAM,WAAW,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAC5E,CACJ,CAAC;IAEF,MAAM,CAAC,YAAY,CACjB,YAAY,EACZ;QACE,KAAK,EAAE,oCAAoC;QAC3C,WAAW,EACT,0FAA0F;YAC1F,0FAA0F;QAC5F,WAAW,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE;QACpC,WAAW,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE;KACpC,EACD,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CACd,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,SAAS,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CACvF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"peticiones.d.ts","sourceRoot":"","sources":["../../src/tools/peticiones.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEzE,OAAO,EAAkB,KAAK,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAK1E,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAoBjF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { peticionesList } from '@albertomarturelo/sii-core';
|
|
3
|
+
import { toolText } from '../tool-helpers.js';
|
|
4
|
+
const rutOpt = (rut) => (rut ? { rut } : {});
|
|
5
|
+
export function registerPeticionesTools(server, runtime) {
|
|
6
|
+
server.registerTool('peticiones_list', {
|
|
7
|
+
title: 'Peticiones administrativas',
|
|
8
|
+
description: 'Lista las peticiones administrativas del contribuyente ante el SII (SISPAD) con su ' +
|
|
9
|
+
'timeline de estados (ingresada → … → cerrada) y las fechas. Útil para detectar ' +
|
|
10
|
+
'trámites detenidos, p. ej. "Peticion en espera de Antecedentes" (el SII espera algo ' +
|
|
11
|
+
'del contribuyente). Devuelve número, materia, estado actual y el historial; incluye ' +
|
|
12
|
+
'el mensaje textual del SII cuando existe (qué falta / por qué). Body-RUT: usa rut ' +
|
|
13
|
+
'para una empresa representada. Expone datos personales/tributarios del contribuyente.',
|
|
14
|
+
inputSchema: {
|
|
15
|
+
rut: z.string().optional(),
|
|
16
|
+
},
|
|
17
|
+
annotations: { readOnlyHint: true },
|
|
18
|
+
}, ({ rut }) => toolText(async () => JSON.stringify(await peticionesList(runtime, rutOpt(rut)), null, 2)));
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=peticiones.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"peticiones.js","sourceRoot":"","sources":["../../src/tools/peticiones.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,cAAc,EAAgB,MAAM,4BAA4B,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,MAAM,MAAM,GAAG,CAAC,GAAY,EAAoB,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAExE,MAAM,UAAU,uBAAuB,CAAC,MAAiB,EAAE,OAAgB;IACzE,MAAM,CAAC,YAAY,CACjB,iBAAiB,EACjB;QACE,KAAK,EAAE,4BAA4B;QACnC,WAAW,EACT,qFAAqF;YACrF,iFAAiF;YACjF,sFAAsF;YACtF,sFAAsF;YACtF,oFAAoF;YACpF,uFAAuF;QACzF,WAAW,EAAE;YACX,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;SAC3B;QACD,WAAW,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE;KACpC,EACD,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CACV,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAC5F,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rcv.d.ts","sourceRoot":"","sources":["../../src/tools/rcv.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEzE,OAAO,EAAqC,KAAK,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAO7F,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAiD1E"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { rcvList, rcvSummary } from '@albertomarturelo/sii-core';
|
|
3
|
+
import { toolText } from '../tool-helpers.js';
|
|
4
|
+
const sideOf = (venta) => (venta ? 'VENTA' : 'COMPRA');
|
|
5
|
+
// exactOptionalPropertyTypes: only carry `rut` when the override was passed.
|
|
6
|
+
const rutOpt = (rut) => (rut ? { rut } : {});
|
|
7
|
+
export function registerRcvTools(server, runtime) {
|
|
8
|
+
server.registerTool('rcv_summary', {
|
|
9
|
+
title: 'RCV resumen',
|
|
10
|
+
description: 'Resumen del Registro de Compras y Ventas por tipo de documento, para un período (YYYYMM/YYYY-MM). ' +
|
|
11
|
+
'COMPRAS por defecto; venta=true para VENTAS. Body-RUT: usa rut para una empresa representada.',
|
|
12
|
+
inputSchema: {
|
|
13
|
+
periodo: z.string(),
|
|
14
|
+
venta: z.boolean().optional(),
|
|
15
|
+
rut: z.string().optional(),
|
|
16
|
+
},
|
|
17
|
+
annotations: { readOnlyHint: true },
|
|
18
|
+
}, ({ periodo, venta, rut }) => toolText(async () => JSON.stringify(await rcvSummary(runtime, { periodo, side: sideOf(venta), ...rutOpt(rut) }), null, 2)));
|
|
19
|
+
server.registerTool('rcv_list', {
|
|
20
|
+
title: 'RCV detalle',
|
|
21
|
+
description: 'Detalle de documentos de un tipo (codigoTipoDoc, ej. "33") del RCV para un período. ' +
|
|
22
|
+
'COMPRAS por defecto; venta=true para VENTAS. Body-RUT: usa rut para una empresa representada.',
|
|
23
|
+
inputSchema: {
|
|
24
|
+
periodo: z.string(),
|
|
25
|
+
codigoTipoDoc: z.string(),
|
|
26
|
+
venta: z.boolean().optional(),
|
|
27
|
+
rut: z.string().optional(),
|
|
28
|
+
},
|
|
29
|
+
annotations: { readOnlyHint: true },
|
|
30
|
+
}, ({ periodo, codigoTipoDoc, venta, rut }) => toolText(async () => JSON.stringify(await rcvList(runtime, { periodo, side: sideOf(venta), codigoTipoDoc, ...rutOpt(rut) }), null, 2)));
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=rcv.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rcv.js","sourceRoot":"","sources":["../../src/tools/rcv.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,UAAU,EAA8B,MAAM,4BAA4B,CAAC;AAC7F,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,MAAM,MAAM,GAAG,CAAC,KAAe,EAAW,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;AAC1E,6EAA6E;AAC7E,MAAM,MAAM,GAAG,CAAC,GAAY,EAAoB,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC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,CACzC,QAAQ,CAAC,KAAK,IAAI,EAAE,CAClB,IAAI,CAAC,SAAS,CACZ,MAAM,OAAO,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,aAAa,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,EACvF,IAAI,EACJ,CAAC,CACF,CACF,CACJ,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"whoami.d.ts","sourceRoot":"","sources":["../../src/tools/whoami.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EAAU,KAAK,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAGlE,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAe7E"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { whoami } from '@albertomarturelo/sii-core';
|
|
2
|
+
import { toolText } from '../tool-helpers.js';
|
|
3
|
+
export function registerWhoamiTools(server, runtime) {
|
|
4
|
+
server.registerTool('whoami', {
|
|
5
|
+
title: 'Cuenta autenticada (whoami)',
|
|
6
|
+
description: 'Muestra la cuenta con la que estás autenticado en el SII: RUT, tipo (persona/empresa), ' +
|
|
7
|
+
'razón social o nombre, y email. Útil para saber con qué cuenta se está trabajando. ' +
|
|
8
|
+
'EXPONE PII PROPIA del usuario (nombre/razón social + email) al modelo. Lectura en vivo ' +
|
|
9
|
+
'del principal de la sesión (ignora el puntero operate). No recibe argumentos.',
|
|
10
|
+
// readOnly, but it DOES touch SII (a live session restore + portal read), like auth_logout.
|
|
11
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
12
|
+
}, () => toolText(async () => JSON.stringify(await whoami(runtime), null, 2)));
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=whoami.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"whoami.js","sourceRoot":"","sources":["../../src/tools/whoami.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,MAAM,EAAgB,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,MAAM,UAAU,mBAAmB,CAAC,MAAiB,EAAE,OAAgB;IACrE,MAAM,CAAC,YAAY,CACjB,QAAQ,EACR;QACE,KAAK,EAAE,6BAA6B;QACpC,WAAW,EACT,yFAAyF;YACzF,qFAAqF;YACrF,yFAAyF;YACzF,+EAA+E;QACjF,4FAA4F;QAC5F,WAAW,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE;KACzD,EACD,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,MAAM,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAC3E,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@albertomarturelo/sii-mcp",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "MCP (stdio) server for Chile's SII (tax authority): exposes authenticated reads — RCV, F29, F22, boletas de honorarios, DTE-authorized, peticiones administrativas — as tools/resources for Claude Desktop and Claude Code. Each tool is a thin call into @albertomarturelo/sii-core tasks (ADR-003).",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"sii",
|
|
8
|
+
"chile",
|
|
9
|
+
"impuestos",
|
|
10
|
+
"sii-cl",
|
|
11
|
+
"tax",
|
|
12
|
+
"mcp",
|
|
13
|
+
"model-context-protocol",
|
|
14
|
+
"claude",
|
|
15
|
+
"rcv",
|
|
16
|
+
"f29"
|
|
17
|
+
],
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"homepage": "https://github.com/albertomarturelo/sii#readme",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/albertomarturelo/sii.git",
|
|
23
|
+
"directory": "packages/mcp"
|
|
24
|
+
},
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/albertomarturelo/sii/issues"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"registry": "https://registry.npmjs.org",
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"bin": {
|
|
33
|
+
"sii-mcp": "./dist/main.js"
|
|
34
|
+
},
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=20"
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist",
|
|
40
|
+
"README.md",
|
|
41
|
+
"LICENSE"
|
|
42
|
+
],
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
45
|
+
"playwright": "^1.49.0",
|
|
46
|
+
"zod": "^4.4.3",
|
|
47
|
+
"@albertomarturelo/sii-core": "^0.5.0"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsc -b"
|
|
51
|
+
}
|
|
52
|
+
}
|