@talonic/mcp 0.1.64 → 0.1.66
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/dist/http-server.js +98 -25
- package/dist/http-server.js.map +1 -1
- package/dist/index.js +27 -10
- package/dist/index.js.map +1 -1
- package/dist/server.js +27 -10
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
package/dist/http-server.js
CHANGED
|
@@ -613,6 +613,20 @@ var WIDGET_HTML9 = buildWidgetHtml({
|
|
|
613
613
|
});
|
|
614
614
|
|
|
615
615
|
// src/widgets/register.ts
|
|
616
|
+
function getWidgetTemplateHtml(uri) {
|
|
617
|
+
const map = {
|
|
618
|
+
[WIDGET_URIS.extract]: getExtractionResultWidgetHtml,
|
|
619
|
+
[WIDGET_URIS.search]: getSearchResultsWidgetHtml,
|
|
620
|
+
[WIDGET_URIS.filter]: getFilterResultsWidgetHtml,
|
|
621
|
+
[WIDGET_URIS.getDocument]: getDocumentMetaWidgetHtml,
|
|
622
|
+
[WIDGET_URIS.toMarkdown]: getMarkdownViewWidgetHtml,
|
|
623
|
+
[WIDGET_URIS.listSchemas]: getSchemaListWidgetHtml,
|
|
624
|
+
[WIDGET_URIS.saveSchema]: getSchemaSavedWidgetHtml,
|
|
625
|
+
[WIDGET_URIS.getBalance]: getBalanceWidgetHtml,
|
|
626
|
+
[WIDGET_URIS.requestUpload]: getUploadLinkWidgetHtml
|
|
627
|
+
};
|
|
628
|
+
return map[uri]?.();
|
|
629
|
+
}
|
|
616
630
|
function registerExtractionResultWidget(server) {
|
|
617
631
|
registerWidget(server, {
|
|
618
632
|
name: "extraction-result-widget",
|
|
@@ -876,6 +890,7 @@ var DESCRIPTION2 = [
|
|
|
876
890
|
"USE WHEN: value-based criteria on extracted fields \u2014 numeric/date/text comparisons or presence checks.",
|
|
877
891
|
"NOT FOR: free-text / concept search (use talonic_search) \xB7 a single document by id (use talonic_get_document).",
|
|
878
892
|
"ARGS: conditions[] (AND-ed). Each = EXACTLY ONE of `field` (canonical name) or `field_id` (UUID), an `operator`, and usually a `value`. Operators: eq, neq, gt, gte, lt, lte, between (needs `value` AND `value_to`), contains, is_empty / is_not_empty (no value). `value`/`value_to` are string|number|boolean matching the field type (ISO YYYY-MM-DD for dates).",
|
|
893
|
+
"TEXT FILTERS: for eq/contains/is_not_empty on a text field, just TRY a natural field name ('currency', 'vendor_name') \u2014 names resolve server-side and an unresolved field surfaces in warnings[] rather than erroring. Do NOT block on discovering the field first; search-first is only required for numeric operators.",
|
|
879
894
|
"NUMERIC GUARD: gt/gte/lt/lte/between only work when the field's dataType is 'number'. Call talonic_search first and check dataType; a numeric op on a string field returns zero matches. If the response has `warnings[]`, surface them to the user \u2014 do not silently retry.",
|
|
880
895
|
"RETURNS: data[] (matching documents with field values), total, warnings[]."
|
|
881
896
|
].join("\n");
|
|
@@ -1057,7 +1072,7 @@ var DESCRIPTION4 = [
|
|
|
1057
1072
|
"NOT FOR: full text (use talonic_to_markdown) \xB7 extracted fields (use talonic_extract).",
|
|
1058
1073
|
"BY NAME: if the user names a file, call talonic_search first to get its document_id, then call this.",
|
|
1059
1074
|
"ARGS: document_id.",
|
|
1060
|
-
"RETURNS: filename, pages, type_detected, language, and `status`. Status lifecycle: pending_upload -> queued -> extracting -> completed. Wait for `completed` before calling talonic_extract on a freshly uploaded doc."
|
|
1075
|
+
"RETURNS: filename, pages, type_detected, language, and `status`. Status lifecycle: pending_upload -> queued -> extracting -> completed. Wait for `completed` before calling talonic_extract on a freshly uploaded doc. To read the document's text, call talonic_to_markdown with this id."
|
|
1061
1076
|
].join("\n");
|
|
1062
1077
|
var inputSchema4 = {
|
|
1063
1078
|
document_id: z.string().min(1).describe(
|
|
@@ -1285,16 +1300,17 @@ function registerSaveSchema(server, getTalonic) {
|
|
|
1285
1300
|
);
|
|
1286
1301
|
}
|
|
1287
1302
|
var DESCRIPTION7 = [
|
|
1288
|
-
"Find documents, fields, schemas, or sources in the workspace
|
|
1303
|
+
"Find documents, fields, schemas, or sources in the workspace. One call returns ranked results across all types.",
|
|
1289
1304
|
"",
|
|
1290
|
-
"
|
|
1305
|
+
"MATCHING IS LITERAL KEYWORD, not semantic. Query with ONE short SINGULAR term or an exact filename: 'invoice', 'bank statement', 'sample-invoice.pdf'. Sentences ('documents related to invoices') and plurals ('invoices') return empty. If a search comes back empty, retry with a shorter singular keyword before concluding the workspace has nothing.",
|
|
1306
|
+
"USE WHEN: the user names or describes a document without an id, or you need a document_id or a filterable field name before extract / to_markdown / get_document / filter.",
|
|
1291
1307
|
"NOT FOR: structured field-value filters like 'amount > 1000' (use talonic_filter).",
|
|
1292
|
-
"ARGS: query (
|
|
1308
|
+
"ARGS: query (short literal keyword); optional limit.",
|
|
1293
1309
|
"RETURNS: documents[], fields[]/fieldMatches[] (only `filterable: true` entries work in talonic_filter), schemas[], sources[]. Use the id from documents[] to act on a named file."
|
|
1294
1310
|
].join("\n");
|
|
1295
1311
|
var inputSchema6 = {
|
|
1296
1312
|
query: z.string().min(1).describe(
|
|
1297
|
-
"
|
|
1313
|
+
"ONE short, SINGULAR keyword or an exact filename \u2014 'invoice', 'insurance certificate', 'sample-invoice.pdf'. Matching is literal: sentences and plurals return empty."
|
|
1298
1314
|
),
|
|
1299
1315
|
limit: z.number().int().positive().optional().describe("Maximum results per entity type. Default: 5. Increase for broader exploration.")
|
|
1300
1316
|
};
|
|
@@ -1338,6 +1354,9 @@ var outputSchema7 = {
|
|
|
1338
1354
|
})
|
|
1339
1355
|
).describe(
|
|
1340
1356
|
"Field-registry entries matching the query. filterable: true entries are usable with talonic_filter."
|
|
1357
|
+
),
|
|
1358
|
+
hint: z.string().optional().describe(
|
|
1359
|
+
"Present only when nothing matched: actionable guidance to retry with a shorter singular keyword."
|
|
1341
1360
|
)
|
|
1342
1361
|
};
|
|
1343
1362
|
async function handleSearch(talonic, args) {
|
|
@@ -1346,6 +1365,14 @@ async function handleSearch(talonic, args) {
|
|
|
1346
1365
|
args.query,
|
|
1347
1366
|
args.limit !== void 0 ? { limit: args.limit } : {}
|
|
1348
1367
|
);
|
|
1368
|
+
const r = result;
|
|
1369
|
+
const empty = (r["documents"]?.length ?? 0) === 0 && (r["fieldMatches"]?.length ?? 0) === 0 && (r["sources"]?.length ?? 0) === 0 && (r["schemas"]?.length ?? 0) === 0 && (r["fields"]?.length ?? 0) === 0;
|
|
1370
|
+
if (empty) {
|
|
1371
|
+
return jsonOk({
|
|
1372
|
+
...result,
|
|
1373
|
+
hint: "No matches. Matching is literal keyword search \u2014 retry with ONE short, SINGULAR term or an exact filename (e.g. 'invoice', not 'invoices' or a sentence) before concluding nothing exists."
|
|
1374
|
+
});
|
|
1375
|
+
}
|
|
1349
1376
|
return jsonOk(result);
|
|
1350
1377
|
} catch (err) {
|
|
1351
1378
|
return toolError(err);
|
|
@@ -1551,7 +1578,7 @@ function registerToMarkdown(server, getTalonic) {
|
|
|
1551
1578
|
|
|
1552
1579
|
// package.json
|
|
1553
1580
|
var package_default = {
|
|
1554
|
-
version: "0.1.
|
|
1581
|
+
version: "0.1.66"};
|
|
1555
1582
|
|
|
1556
1583
|
// src/version.ts
|
|
1557
1584
|
var VERSION = package_default.version;
|
|
@@ -1610,12 +1637,16 @@ function createServer(options) {
|
|
|
1610
1637
|
"Talonic turns any document (PDF, scan, image, DOCX, contract, invoice, form,",
|
|
1611
1638
|
"certificate, statement) into clean, schema-validated JSON, and answers questions",
|
|
1612
1639
|
"about the user's document workspace.",
|
|
1613
|
-
"
|
|
1614
|
-
"
|
|
1615
|
-
"
|
|
1640
|
+
"ALL NINE talonic_* tools are registered and callable on EVERY turn of this",
|
|
1641
|
+
"session. If you believe one is missing from your toolset, you are mistaken \u2014",
|
|
1642
|
+
"invoke it anyway. Never tell the user a Talonic tool is unavailable or not in",
|
|
1643
|
+
"your toolset, and never ask them to 'enable' anything.",
|
|
1616
1644
|
"If the user refers to a document by name (e.g. 'invoice.pdf'), first call",
|
|
1617
1645
|
"talonic_search to resolve the name to a document_id, then call the tool you need",
|
|
1618
|
-
"with that id \u2014 do not ask the user for an id.
|
|
1646
|
+
"with that id \u2014 do not ask the user for an id.",
|
|
1647
|
+
"talonic_search matches LITERAL keywords: query with one short singular term or an",
|
|
1648
|
+
"exact filename, never a sentence; on an empty result retry with a shorter keyword.",
|
|
1649
|
+
"Prefer acting over explaining."
|
|
1619
1650
|
].join(" ")
|
|
1620
1651
|
}
|
|
1621
1652
|
);
|
|
@@ -1648,9 +1679,11 @@ var ALLOWED_ORIGINS = /* @__PURE__ */ new Set([
|
|
|
1648
1679
|
"https://mcp.so",
|
|
1649
1680
|
"https://smithery.ai"
|
|
1650
1681
|
]);
|
|
1682
|
+
var SANDBOX_ORIGIN_SUFFIX = ".web-sandbox.oaiusercontent.com";
|
|
1651
1683
|
function isOriginAllowed(originHeader) {
|
|
1652
1684
|
if (!originHeader) return true;
|
|
1653
|
-
|
|
1685
|
+
if (ALLOWED_ORIGINS.has(originHeader)) return true;
|
|
1686
|
+
return originHeader.startsWith("https://") && originHeader.endsWith(SANDBOX_ORIGIN_SUFFIX);
|
|
1654
1687
|
}
|
|
1655
1688
|
|
|
1656
1689
|
// src/favicon.ts
|
|
@@ -1683,6 +1716,14 @@ function extractBearerToken(req) {
|
|
|
1683
1716
|
return void 0;
|
|
1684
1717
|
}
|
|
1685
1718
|
var WWW_AUTHENTICATE = `Bearer resource_metadata="${RESOURCE_URL}/.well-known/oauth-protected-resource"`;
|
|
1719
|
+
function asWidgetTemplateRead(parsed) {
|
|
1720
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return null;
|
|
1721
|
+
const msg = parsed;
|
|
1722
|
+
if (msg.method !== "resources/read") return null;
|
|
1723
|
+
const uri = msg.params?.uri;
|
|
1724
|
+
if (typeof uri !== "string" || !uri.startsWith("ui://widget/")) return null;
|
|
1725
|
+
return { uri, id: msg.id ?? null };
|
|
1726
|
+
}
|
|
1686
1727
|
function createRequestHandler() {
|
|
1687
1728
|
return async (req, res) => {
|
|
1688
1729
|
const url = new URL(req.url ?? "/", "http://localhost");
|
|
@@ -1780,20 +1821,6 @@ function createRequestHandler() {
|
|
|
1780
1821
|
);
|
|
1781
1822
|
return;
|
|
1782
1823
|
}
|
|
1783
|
-
const token = extractBearerToken(req);
|
|
1784
|
-
if (!token) {
|
|
1785
|
-
res.writeHead(401, {
|
|
1786
|
-
"Content-Type": "application/json",
|
|
1787
|
-
"WWW-Authenticate": WWW_AUTHENTICATE
|
|
1788
|
-
});
|
|
1789
|
-
res.end(
|
|
1790
|
-
JSON.stringify({
|
|
1791
|
-
error: "unauthorized",
|
|
1792
|
-
message: "Provide a Talonic API key (tlnc_...) or an OAuth 2.1 access token via Authorization: Bearer ... header. API keys may also be passed via ?apiKey=tlnc_... query param; never put OAuth tokens in URLs."
|
|
1793
|
-
})
|
|
1794
|
-
);
|
|
1795
|
-
return;
|
|
1796
|
-
}
|
|
1797
1824
|
if (req.method === "DELETE") {
|
|
1798
1825
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
1799
1826
|
res.end(JSON.stringify({ ok: true }));
|
|
@@ -1824,6 +1851,52 @@ function createRequestHandler() {
|
|
|
1824
1851
|
res.end(JSON.stringify({ error: "bad_request", message: "Invalid JSON body." }));
|
|
1825
1852
|
return;
|
|
1826
1853
|
}
|
|
1854
|
+
const widgetRead = asWidgetTemplateRead(parsed);
|
|
1855
|
+
if (widgetRead) {
|
|
1856
|
+
const html = getWidgetTemplateHtml(widgetRead.uri);
|
|
1857
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
1858
|
+
if (html === void 0) {
|
|
1859
|
+
res.end(
|
|
1860
|
+
JSON.stringify({
|
|
1861
|
+
jsonrpc: "2.0",
|
|
1862
|
+
id: widgetRead.id,
|
|
1863
|
+
error: { code: -32002, message: `Resource not found: ${widgetRead.uri}` }
|
|
1864
|
+
})
|
|
1865
|
+
);
|
|
1866
|
+
return;
|
|
1867
|
+
}
|
|
1868
|
+
res.end(
|
|
1869
|
+
JSON.stringify({
|
|
1870
|
+
jsonrpc: "2.0",
|
|
1871
|
+
id: widgetRead.id,
|
|
1872
|
+
result: {
|
|
1873
|
+
contents: [
|
|
1874
|
+
{
|
|
1875
|
+
uri: widgetRead.uri,
|
|
1876
|
+
mimeType: "text/html;profile=mcp-app",
|
|
1877
|
+
text: html,
|
|
1878
|
+
_meta: widgetMeta()
|
|
1879
|
+
}
|
|
1880
|
+
]
|
|
1881
|
+
}
|
|
1882
|
+
})
|
|
1883
|
+
);
|
|
1884
|
+
return;
|
|
1885
|
+
}
|
|
1886
|
+
const token = extractBearerToken(req);
|
|
1887
|
+
if (!token) {
|
|
1888
|
+
res.writeHead(401, {
|
|
1889
|
+
"Content-Type": "application/json",
|
|
1890
|
+
"WWW-Authenticate": WWW_AUTHENTICATE
|
|
1891
|
+
});
|
|
1892
|
+
res.end(
|
|
1893
|
+
JSON.stringify({
|
|
1894
|
+
error: "unauthorized",
|
|
1895
|
+
message: "Provide a Talonic API key (tlnc_...) or an OAuth 2.1 access token via Authorization: Bearer ... header. API keys may also be passed via ?apiKey=tlnc_... query param; never put OAuth tokens in URLs."
|
|
1896
|
+
})
|
|
1897
|
+
);
|
|
1898
|
+
return;
|
|
1899
|
+
}
|
|
1827
1900
|
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: void 0 });
|
|
1828
1901
|
const mcpServer = createServer({ tokenProvider: () => token });
|
|
1829
1902
|
res.on("close", () => {
|