@talonic/mcp 0.1.9 → 0.1.11
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/README.md +7 -3
- package/dist/content.d.ts +9 -9
- package/dist/content.js +811 -111
- package/dist/content.js.map +1 -1
- package/dist/http-server.js +175 -24
- package/dist/http-server.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +142 -21
- package/dist/index.js.map +1 -1
- package/dist/server.js +142 -21
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
package/dist/http-server.js
CHANGED
|
@@ -32,6 +32,75 @@ function registerSchemasResource(server, talonic) {
|
|
|
32
32
|
}
|
|
33
33
|
);
|
|
34
34
|
}
|
|
35
|
+
|
|
36
|
+
// src/resources/webhooks-resource.ts
|
|
37
|
+
var WEBHOOK_INFO_ENDPOINTS = [
|
|
38
|
+
{ path: "/v1/webhooks/events", key: "events", description: "Available webhook event types" },
|
|
39
|
+
{
|
|
40
|
+
path: "/v1/webhooks/delivery",
|
|
41
|
+
key: "delivery",
|
|
42
|
+
description: "Delivery behavior and retry policy"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
path: "/v1/webhooks/signatures",
|
|
46
|
+
key: "signatures",
|
|
47
|
+
description: "Signature verification algorithms"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
path: "/v1/webhooks/retries",
|
|
51
|
+
key: "retries",
|
|
52
|
+
description: "Retry schedule and backoff policy"
|
|
53
|
+
}
|
|
54
|
+
];
|
|
55
|
+
function registerWebhooksResource(server, apiKey, baseUrl) {
|
|
56
|
+
const base = baseUrl ?? "https://api.talonic.com";
|
|
57
|
+
server.registerResource(
|
|
58
|
+
"talonic-webhooks-reference",
|
|
59
|
+
"talonic://webhooks/reference",
|
|
60
|
+
{
|
|
61
|
+
title: "Talonic Webhooks Reference",
|
|
62
|
+
description: "Webhook event types, delivery behavior, signature verification algorithms, and retry policies.",
|
|
63
|
+
mimeType: "application/json"
|
|
64
|
+
},
|
|
65
|
+
async (uri) => {
|
|
66
|
+
const results = {};
|
|
67
|
+
await Promise.all(
|
|
68
|
+
WEBHOOK_INFO_ENDPOINTS.map(async ({ path, key }) => {
|
|
69
|
+
try {
|
|
70
|
+
const res = await fetch(`${base}${path}`, {
|
|
71
|
+
headers: {
|
|
72
|
+
Authorization: `Bearer ${apiKey}`,
|
|
73
|
+
Accept: "application/json"
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
if (res.ok) {
|
|
77
|
+
results[key] = await res.json();
|
|
78
|
+
} else {
|
|
79
|
+
results[key] = {
|
|
80
|
+
error: `HTTP ${res.status}`,
|
|
81
|
+
message: await res.text().catch(() => "")
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
} catch (err) {
|
|
85
|
+
results[key] = {
|
|
86
|
+
error: "fetch_failed",
|
|
87
|
+
message: err instanceof Error ? err.message : String(err)
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
);
|
|
92
|
+
return {
|
|
93
|
+
contents: [
|
|
94
|
+
{
|
|
95
|
+
uri: uri.toString(),
|
|
96
|
+
mimeType: "application/json",
|
|
97
|
+
text: JSON.stringify(results, null, 2)
|
|
98
|
+
}
|
|
99
|
+
]
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
);
|
|
103
|
+
}
|
|
35
104
|
function jsonOk(value) {
|
|
36
105
|
return {
|
|
37
106
|
content: [
|
|
@@ -42,6 +111,12 @@ function jsonOk(value) {
|
|
|
42
111
|
]
|
|
43
112
|
};
|
|
44
113
|
}
|
|
114
|
+
function validationError(message) {
|
|
115
|
+
return {
|
|
116
|
+
isError: true,
|
|
117
|
+
content: [{ type: "text", text: `Validation error: ${message}` }]
|
|
118
|
+
};
|
|
119
|
+
}
|
|
45
120
|
function toolError(err) {
|
|
46
121
|
if (err instanceof TalonicError) {
|
|
47
122
|
const lines = [
|
|
@@ -68,6 +143,8 @@ function toolError(err) {
|
|
|
68
143
|
|
|
69
144
|
// src/tools/extract.ts
|
|
70
145
|
var DESCRIPTION = [
|
|
146
|
+
"STATUS: stable. Production-safe when called with a schema. Schema-less extraction is disabled at the MCP layer.",
|
|
147
|
+
"",
|
|
71
148
|
"Extract structured, schema-validated data from a document using Talonic.",
|
|
72
149
|
"Returns clean JSON matching the schema, with per-field confidence scores and",
|
|
73
150
|
"metadata about the document (detected type, language, page count).",
|
|
@@ -95,13 +172,24 @@ var DESCRIPTION = [
|
|
|
95
172
|
" the public web.",
|
|
96
173
|
"- document_id: re-extract a document already in the workspace.",
|
|
97
174
|
"",
|
|
98
|
-
"SCHEMA
|
|
99
|
-
'- JSON Schema (
|
|
100
|
-
'- Flat key-type map: { vendor_name: "string", invoice_total: "number" }
|
|
101
|
-
"- schema_id: id of a saved schema from talonic_list_schemas. Accepts
|
|
175
|
+
"SCHEMA (REQUIRED, provide exactly one of `schema` or `schema_id`):",
|
|
176
|
+
'- JSON Schema (RECOMMENDED): { type: "object", properties: { vendor_name: { type: "string" } } }.',
|
|
177
|
+
'- Flat key-type map: { vendor_name: "string", invoice_total: "number" }. Accepted, but if you get a "no fields" error, fall back to JSON Schema.',
|
|
178
|
+
"- schema_id: id of a saved schema from talonic_list_schemas. Accepts UUID or SCH-XXXXXXXX short id.",
|
|
179
|
+
"",
|
|
180
|
+
"Calls without `schema` or `schema_id` are rejected with a validation error before they hit the API,",
|
|
181
|
+
"to prevent unreliable schema-free extractions reaching production.",
|
|
102
182
|
"",
|
|
103
|
-
"
|
|
104
|
-
"
|
|
183
|
+
"RESPONSE SHAPE (key fields):",
|
|
184
|
+
"- data: the structured extracted JSON, shaped by your schema.",
|
|
185
|
+
"- confidence.overall: 0..1 confidence for the extraction as a whole.",
|
|
186
|
+
"- confidence.fields: per-field confidence map. Treat fields below ~0.7 as needing human review.",
|
|
187
|
+
"- document.id, document.filename, document.pages, document.type_detected, document.language_detected.",
|
|
188
|
+
"- extraction_id, request_id: stable identifiers for support and re-fetch.",
|
|
189
|
+
"- processing.duration_ms, processing.region: useful for debugging and capacity planning.",
|
|
190
|
+
"- markdown: present only when `include_markdown: true`.",
|
|
191
|
+
"Cost, EUR price, and remaining credit balance are not surfaced in v0.1 and may appear in a later version.",
|
|
192
|
+
"Per-field source provenance (page, bounding box) is not surfaced in v0.1."
|
|
105
193
|
].join("\n");
|
|
106
194
|
var inputSchema = {
|
|
107
195
|
file_data: z.string().optional().describe(
|
|
@@ -118,10 +206,10 @@ var inputSchema = {
|
|
|
118
206
|
),
|
|
119
207
|
document_id: z.string().optional().describe("ID of a document already in the workspace, to re-extract with a new schema."),
|
|
120
208
|
schema: z.record(z.string(), z.unknown()).optional().describe(
|
|
121
|
-
"Inline schema definition.
|
|
209
|
+
"Inline schema definition. REQUIRED unless `schema_id` is provided. Recommended: full JSON Schema {type:'object', properties:{...}}. Also accepted: flat key-type map {field_name:'string', amount:'number'}. Mutually exclusive with `schema_id`."
|
|
122
210
|
),
|
|
123
211
|
schema_id: z.string().optional().describe(
|
|
124
|
-
"ID of a saved schema. Accepts UUID or SCH-XXXXXXXX short id. Mutually exclusive with `schema`."
|
|
212
|
+
"ID of a saved schema. REQUIRED unless `schema` is provided. Accepts UUID or SCH-XXXXXXXX short id from talonic_list_schemas. Mutually exclusive with `schema`."
|
|
125
213
|
),
|
|
126
214
|
instructions: z.string().optional().describe(
|
|
127
215
|
"Natural-language guidance for the extractor, e.g. 'Focus on the billing section. Amounts are in EUR.'"
|
|
@@ -129,6 +217,14 @@ var inputSchema = {
|
|
|
129
217
|
include_markdown: z.boolean().optional().describe("Include OCR-converted markdown in the response alongside structured data.")
|
|
130
218
|
};
|
|
131
219
|
async function handleExtract(talonic, args) {
|
|
220
|
+
if (args.schema === void 0 && args.schema_id === void 0) {
|
|
221
|
+
return validationError(
|
|
222
|
+
"talonic_extract requires a schema. Provide either an inline `schema` (JSON Schema or flat key-type map) or a `schema_id` from talonic_list_schemas. Schema-less extraction is unreliable in v0.1 and is disabled at the MCP layer."
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
if (args.schema !== void 0 && args.schema_id !== void 0) {
|
|
226
|
+
return validationError("talonic_extract accepts `schema` OR `schema_id`, not both. Pick one.");
|
|
227
|
+
}
|
|
132
228
|
try {
|
|
133
229
|
const params = {};
|
|
134
230
|
if (args.file_data !== void 0) {
|
|
@@ -160,6 +256,8 @@ function registerExtract(server, talonic) {
|
|
|
160
256
|
);
|
|
161
257
|
}
|
|
162
258
|
var DESCRIPTION2 = [
|
|
259
|
+
"STATUS: stable. Field-name resolution is server-side. The `is_not_empty` operator is intentionally not exposed in v0.1; see workaround below.",
|
|
260
|
+
"",
|
|
163
261
|
"Filter the user's Talonic documents by extracted field values using composable conditions.",
|
|
164
262
|
"Conditions accept either a canonical field name (e.g. 'vendor.name', 'policy.0_coverage_type')",
|
|
165
263
|
"or a field UUID. The Talonic API resolves names to ids server-side.",
|
|
@@ -176,13 +274,14 @@ var DESCRIPTION2 = [
|
|
|
176
274
|
"- The user wants extracted data from a new document (use talonic_extract).",
|
|
177
275
|
"",
|
|
178
276
|
"OPERATORS:",
|
|
179
|
-
"- eq, neq: equality / inequality",
|
|
180
|
-
"- gt, gte, lt, lte: numeric or date comparisons",
|
|
181
|
-
"- between: requires both `value` and `value_to
|
|
182
|
-
"- contains: substring match on string fields",
|
|
183
|
-
"- is_empty: presence check
|
|
184
|
-
"
|
|
185
|
-
"
|
|
277
|
+
"- eq, neq: equality / inequality.",
|
|
278
|
+
"- gt, gte, lt, lte: numeric or date comparisons.",
|
|
279
|
+
"- between: requires both `value` and `value_to`.",
|
|
280
|
+
"- contains: substring match on string fields.",
|
|
281
|
+
"- is_empty: presence check, no value needed. Returns documents where the field is null or missing.",
|
|
282
|
+
"",
|
|
283
|
+
"NOT SUPPORTED IN v0.1:",
|
|
284
|
+
"- is_not_empty: underreports against fields known to be populated. Removed from the supported operator list to keep filter results trustworthy. Workaround: filter with `eq`/`gt`/`contains` against a known value, or use `is_empty` then invert the result client-side. Tracked for a later release.",
|
|
186
285
|
"",
|
|
187
286
|
"TIPS:",
|
|
188
287
|
"- To discover available field names, call talonic_search first with a related query.",
|
|
@@ -198,8 +297,9 @@ var operatorEnum = z.enum([
|
|
|
198
297
|
"lte",
|
|
199
298
|
"between",
|
|
200
299
|
"contains",
|
|
201
|
-
"is_empty"
|
|
202
|
-
|
|
300
|
+
"is_empty"
|
|
301
|
+
// is_not_empty intentionally omitted in v0.1: it underreports against
|
|
302
|
+
// fields known to be populated. See description for the workaround.
|
|
203
303
|
]);
|
|
204
304
|
var conditionSchema = z.object({
|
|
205
305
|
field: z.string().optional().describe(
|
|
@@ -264,6 +364,8 @@ function registerFilter(server, talonic) {
|
|
|
264
364
|
);
|
|
265
365
|
}
|
|
266
366
|
var DESCRIPTION3 = [
|
|
367
|
+
"STATUS: stable.",
|
|
368
|
+
"",
|
|
267
369
|
"Fetch full metadata for a single document already in the user's Talonic workspace.",
|
|
268
370
|
"Returns id, filename, page count, detected document type, language, processing log,",
|
|
269
371
|
"and link URLs (self, extractions, dashboard).",
|
|
@@ -305,9 +407,12 @@ function registerGetDocument(server, talonic) {
|
|
|
305
407
|
|
|
306
408
|
// src/tools/list-schemas.ts
|
|
307
409
|
var DESCRIPTION4 = [
|
|
410
|
+
"STATUS: stable.",
|
|
411
|
+
"",
|
|
308
412
|
"List all saved schemas in the user's Talonic workspace.",
|
|
309
|
-
"Returns each schema with its id, name, description,
|
|
310
|
-
"field count, and full JSON Schema definition.",
|
|
413
|
+
"Returns each schema with its id (UUID), short_id (SCH-XXXXXXXX), name, description,",
|
|
414
|
+
"version, field count, and full JSON Schema definition. Either id form is accepted by",
|
|
415
|
+
"talonic_extract's `schema_id` parameter.",
|
|
311
416
|
"",
|
|
312
417
|
"USE WHEN:",
|
|
313
418
|
"- The user asks what schemas they have, or asks to see existing schemas.",
|
|
@@ -340,6 +445,8 @@ function registerListSchemas(server, talonic) {
|
|
|
340
445
|
);
|
|
341
446
|
}
|
|
342
447
|
var DESCRIPTION5 = [
|
|
448
|
+
"STATUS: stable.",
|
|
449
|
+
"",
|
|
343
450
|
"Save a schema definition to the user's Talonic workspace so it can be reused",
|
|
344
451
|
"across future extractions. Returns the saved schema with its newly assigned id and short_id.",
|
|
345
452
|
"",
|
|
@@ -389,6 +496,8 @@ function registerSaveSchema(server, talonic) {
|
|
|
389
496
|
);
|
|
390
497
|
}
|
|
391
498
|
var DESCRIPTION6 = [
|
|
499
|
+
"STATUS: stable.",
|
|
500
|
+
"",
|
|
392
501
|
"Search the user's Talonic workspace for documents, fields, sources, or schemas",
|
|
393
502
|
"matching a query. Returns ranked results across all entity types in one call.",
|
|
394
503
|
"",
|
|
@@ -434,6 +543,8 @@ function registerSearch(server, talonic) {
|
|
|
434
543
|
);
|
|
435
544
|
}
|
|
436
545
|
var DESCRIPTION7 = [
|
|
546
|
+
"STATUS: stable.",
|
|
547
|
+
"",
|
|
437
548
|
"Get the OCR-converted markdown for a document. Accepts an existing document_id,",
|
|
438
549
|
"raw file bytes (base64), a local file path, or a URL. When given a raw file, the",
|
|
439
550
|
"tool ingests it via extract first and then returns the markdown.",
|
|
@@ -471,7 +582,12 @@ var inputSchema6 = {
|
|
|
471
582
|
),
|
|
472
583
|
file_url: z.string().optional().describe("URL to a document file. The Talonic API fetches it server-side.")
|
|
473
584
|
};
|
|
474
|
-
var INGEST_ONLY_SCHEMA = {
|
|
585
|
+
var INGEST_ONLY_SCHEMA = {
|
|
586
|
+
type: "object",
|
|
587
|
+
properties: {
|
|
588
|
+
document_title: { type: "string" }
|
|
589
|
+
}
|
|
590
|
+
};
|
|
475
591
|
async function handleToMarkdown(talonic, args) {
|
|
476
592
|
try {
|
|
477
593
|
const sources = ["document_id", "file_data", "file_path", "file_url"];
|
|
@@ -523,8 +639,12 @@ function registerToMarkdown(server, talonic) {
|
|
|
523
639
|
);
|
|
524
640
|
}
|
|
525
641
|
|
|
642
|
+
// package.json
|
|
643
|
+
var package_default = {
|
|
644
|
+
version: "0.1.11"};
|
|
645
|
+
|
|
526
646
|
// src/version.ts
|
|
527
|
-
var VERSION =
|
|
647
|
+
var VERSION = package_default.version;
|
|
528
648
|
var SERVER_NAME = "talonic";
|
|
529
649
|
|
|
530
650
|
// src/server-factory.ts
|
|
@@ -559,6 +679,7 @@ function createServer(options) {
|
|
|
559
679
|
registerToMarkdown(server, talonic);
|
|
560
680
|
registerExtract(server, talonic);
|
|
561
681
|
registerSchemasResource(server, talonic);
|
|
682
|
+
registerWebhooksResource(server, options.apiKey, options.baseUrl);
|
|
562
683
|
return server;
|
|
563
684
|
}
|
|
564
685
|
|
|
@@ -585,6 +706,21 @@ var httpServer = createServer$1(async (req, res) => {
|
|
|
585
706
|
res.end(JSON.stringify({ status: "ok", server: SERVER_NAME, version: VERSION }));
|
|
586
707
|
return;
|
|
587
708
|
}
|
|
709
|
+
if (path === "/") {
|
|
710
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
711
|
+
res.end(
|
|
712
|
+
JSON.stringify({
|
|
713
|
+
name: SERVER_NAME,
|
|
714
|
+
version: VERSION,
|
|
715
|
+
description: "Talonic MCP server \u2014 extract structured, schema-validated data from any document.",
|
|
716
|
+
mcp_endpoint: "/mcp",
|
|
717
|
+
health_endpoint: "/health",
|
|
718
|
+
auth: "Provide a Talonic API key via Authorization: Bearer tlnc_... header or ?apiKey=tlnc_... query param.",
|
|
719
|
+
docs: "https://docs.talonic.com"
|
|
720
|
+
})
|
|
721
|
+
);
|
|
722
|
+
return;
|
|
723
|
+
}
|
|
588
724
|
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
589
725
|
res.setHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, OPTIONS");
|
|
590
726
|
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization, Mcp-Session-Id");
|
|
@@ -596,7 +732,12 @@ var httpServer = createServer$1(async (req, res) => {
|
|
|
596
732
|
}
|
|
597
733
|
if (path !== "/mcp") {
|
|
598
734
|
res.writeHead(404, { "Content-Type": "application/json" });
|
|
599
|
-
res.end(
|
|
735
|
+
res.end(
|
|
736
|
+
JSON.stringify({
|
|
737
|
+
error: "not_found",
|
|
738
|
+
message: `No route for ${path}. Use /mcp for the MCP endpoint or /health for status.`
|
|
739
|
+
})
|
|
740
|
+
);
|
|
600
741
|
return;
|
|
601
742
|
}
|
|
602
743
|
if (req.method === "DELETE") {
|
|
@@ -613,7 +754,12 @@ var httpServer = createServer$1(async (req, res) => {
|
|
|
613
754
|
const apiKey = extractApiKey(req);
|
|
614
755
|
if (!apiKey) {
|
|
615
756
|
res.writeHead(401, { "Content-Type": "application/json" });
|
|
616
|
-
res.end(
|
|
757
|
+
res.end(
|
|
758
|
+
JSON.stringify({
|
|
759
|
+
error: "unauthorized",
|
|
760
|
+
message: "Provide a Talonic API key via Authorization: Bearer tlnc_... header or ?apiKey=tlnc_... query param."
|
|
761
|
+
})
|
|
762
|
+
);
|
|
617
763
|
return;
|
|
618
764
|
}
|
|
619
765
|
const sessionId = req.headers["mcp-session-id"];
|
|
@@ -639,7 +785,12 @@ var httpServer = createServer$1(async (req, res) => {
|
|
|
639
785
|
}
|
|
640
786
|
if (sessionId && !isInitializeRequest(parsed)) {
|
|
641
787
|
res.writeHead(404, { "Content-Type": "application/json" });
|
|
642
|
-
res.end(
|
|
788
|
+
res.end(
|
|
789
|
+
JSON.stringify({
|
|
790
|
+
error: "session_not_found",
|
|
791
|
+
message: "Unknown session. Re-initialize without the Mcp-Session-Id header."
|
|
792
|
+
})
|
|
793
|
+
);
|
|
643
794
|
return;
|
|
644
795
|
}
|
|
645
796
|
const transport = new StreamableHTTPServerTransport({
|