@talonic/mcp 0.1.2 → 0.1.4
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/CHANGELOG.md +29 -0
- package/README.md +50 -45
- package/dist/index.d.ts +1 -1
- package/dist/index.js +47 -14
- package/dist/index.js.map +1 -1
- package/dist/server.js +60 -15
- package/dist/server.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,35 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.1.4] - 2026-04-29
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- `file_data` (base64-encoded bytes) and `filename` inputs on `talonic_extract` and `talonic_to_markdown`. Lets agents pass uploaded files to Talonic when running inside chat-style MCP hosts (Claude Desktop, Cowork, Cursor) where the host's user-data directory is not readable by the MCP server process. Tool descriptions advertise `file_data` as the recommended path for chat clients.
|
|
15
|
+
- Tests covering `file_data` decoding, MIME inference from `filename`, and rejection of multiple file sources.
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- `talonic_extract` description: clarified when each file source is appropriate. `file_data` is the recommended path for chat clients; `file_path` only works when the MCP server has filesystem access to that path; `file_url` is for documents already on the public web; `document_id` re-extracts an existing workspace document.
|
|
20
|
+
- `talonic_to_markdown` description: added `file_data` + `filename` to the input list with the same chat-client guidance.
|
|
21
|
+
- `talonic_extract` description no longer recommends the flat key-type schema map; recommends full JSON Schema only (the flat map is silently empty-saved by the API; tracked separately).
|
|
22
|
+
|
|
23
|
+
## [0.1.3] - 2026-04-29
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
|
|
27
|
+
- MCP server bin (`talonic-mcp`) no longer exits silently when launched through the npm-managed `node_modules/.bin/` symlink, which is the path every MCP client uses (Claude Desktop, Cursor, Cline, Cowork) when they spawn the server via `npx -y @talonic/mcp@latest`. The auto-run guard previously compared `import.meta.url` to `file://${process.argv[1]}` as strings; the two disagree when reached via a symlink, so `main()` never ran, the stdio handshake never happened, and the server exited with code 0. The guard now resolves both sides with `fs.realpathSync` before comparing, so the server boots correctly regardless of how it is invoked.
|
|
28
|
+
|
|
29
|
+
### Added
|
|
30
|
+
|
|
31
|
+
- Regression test (`tests/server-symlink.test.ts`) that spawns the bundled server through a symlink and asserts `--version` prints `SERVER_NAME` and `VERSION`. Catches future regressions of the auto-run guard before publish.
|
|
32
|
+
|
|
33
|
+
### Changed
|
|
34
|
+
|
|
35
|
+
- `@talonic/node` dependency bumped to `^0.1.2` to pull in the matching SDK fix for the same bug in the SDK CLI bin.
|
|
36
|
+
|
|
37
|
+
## [Unreleased prior to 0.1.3]
|
|
38
|
+
|
|
10
39
|
### Added
|
|
11
40
|
|
|
12
41
|
- Project skeleton: TypeScript strict mode, `tsup` ESM build with shebang banner, Vitest, GitHub Actions CI matrix on Node 18, 20, 22.
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Official Talonic MCP server. Lets AI agents extract structured, schema-validated data from any document via the [Model Context Protocol](https://modelcontextprotocol.io).
|
|
4
4
|
|
|
5
|
-
> **Status:** v0.1.
|
|
5
|
+
> **Status:** v0.1.3. Seven tools and one resource live: `talonic_extract`, `talonic_search`, `talonic_filter`, `talonic_get_document`, `talonic_to_markdown`, `talonic_list_schemas`, `talonic_save_schema`, plus the `talonic://schemas` resource. Verified end-to-end against production.
|
|
6
6
|
|
|
7
7
|
## Why an agent should use this
|
|
8
8
|
|
|
@@ -20,41 +20,19 @@ Each user runs against their own isolated Talonic workspace. Your documents and
|
|
|
20
20
|
|
|
21
21
|
## Install
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
### A. Local checkout (works today)
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
# 1. Clone the SDK and the MCP server
|
|
29
|
-
git clone https://github.com/talonicdev/talonic-node.git
|
|
30
|
-
git clone https://github.com/talonicdev/talonic-mcp.git
|
|
31
|
-
|
|
32
|
-
# 2. Build the SDK (the MCP server depends on it)
|
|
33
|
-
cd talonic-node
|
|
34
|
-
npm install
|
|
35
|
-
npm run build
|
|
36
|
-
|
|
37
|
-
# 3. Build the MCP server
|
|
38
|
-
cd ../talonic-mcp
|
|
39
|
-
npm install
|
|
40
|
-
npm run build
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
Then point your MCP client at the absolute path to `dist/server.js`. Snippets per client below.
|
|
44
|
-
|
|
45
|
-
### B. Published npm package (coming soon)
|
|
46
|
-
|
|
47
|
-
Once `@talonic/mcp` is on npm, the install becomes:
|
|
23
|
+
The package is on npm. Every MCP client launches it the same way: a one-line `npx` invocation with your API key in the `env` block. No clone, no build.
|
|
48
24
|
|
|
49
25
|
```jsonc
|
|
50
26
|
{
|
|
51
27
|
"command": "npx",
|
|
52
|
-
"args": ["-y", "@talonic/mcp"],
|
|
28
|
+
"args": ["-y", "@talonic/mcp@latest"],
|
|
53
29
|
"env": { "TALONIC_API_KEY": "tlnc_..." }
|
|
54
30
|
}
|
|
55
31
|
```
|
|
56
32
|
|
|
57
|
-
|
|
33
|
+
The `-y` flag skips the npm install prompt. Pinning to `@latest` means new versions are picked up on the next client restart. To pin to a specific version, replace `@latest` with `@0.1.3`.
|
|
34
|
+
|
|
35
|
+
Per-client snippets are below.
|
|
58
36
|
|
|
59
37
|
## MCP client setup
|
|
60
38
|
|
|
@@ -66,8 +44,8 @@ Edit `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) o
|
|
|
66
44
|
{
|
|
67
45
|
"mcpServers": {
|
|
68
46
|
"talonic": {
|
|
69
|
-
"command": "
|
|
70
|
-
"args": ["/
|
|
47
|
+
"command": "npx",
|
|
48
|
+
"args": ["-y", "@talonic/mcp@latest"],
|
|
71
49
|
"env": {
|
|
72
50
|
"TALONIC_API_KEY": "tlnc_your_key_here"
|
|
73
51
|
}
|
|
@@ -76,7 +54,7 @@ Edit `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) o
|
|
|
76
54
|
}
|
|
77
55
|
```
|
|
78
56
|
|
|
79
|
-
|
|
57
|
+
Fully restart Claude Desktop (Cmd+Q on macOS, not just close the window). Talonic appears in the connected servers list with all seven tools.
|
|
80
58
|
|
|
81
59
|
### Cursor
|
|
82
60
|
|
|
@@ -86,8 +64,8 @@ Edit `~/.cursor/mcp.json` (or open Cursor settings → MCP → edit config):
|
|
|
86
64
|
{
|
|
87
65
|
"mcpServers": {
|
|
88
66
|
"talonic": {
|
|
89
|
-
"command": "
|
|
90
|
-
"args": ["/
|
|
67
|
+
"command": "npx",
|
|
68
|
+
"args": ["-y", "@talonic/mcp@latest"],
|
|
91
69
|
"env": {
|
|
92
70
|
"TALONIC_API_KEY": "tlnc_your_key_here"
|
|
93
71
|
}
|
|
@@ -107,8 +85,8 @@ Edit `~/.continue/config.json`. Add to the `mcpServers` array:
|
|
|
107
85
|
```json
|
|
108
86
|
{
|
|
109
87
|
"name": "talonic",
|
|
110
|
-
"command": "
|
|
111
|
-
"args": ["/
|
|
88
|
+
"command": "npx",
|
|
89
|
+
"args": ["-y", "@talonic/mcp@latest"],
|
|
112
90
|
"env": {
|
|
113
91
|
"TALONIC_API_KEY": "tlnc_your_key_here"
|
|
114
92
|
}
|
|
@@ -117,22 +95,30 @@ Edit `~/.continue/config.json`. Add to the `mcpServers` array:
|
|
|
117
95
|
|
|
118
96
|
### Cowork
|
|
119
97
|
|
|
120
|
-
Open Cowork settings → MCP Servers → Add. Use the same shape as Claude Desktop.
|
|
98
|
+
Open Cowork settings → MCP Servers → Add. Use the same shape as Claude Desktop above.
|
|
121
99
|
|
|
122
100
|
## Tool reference
|
|
123
101
|
|
|
124
102
|
Each tool's description is written for an LLM, with explicit USE WHEN / DO NOT USE WHEN sections. Agents pick the right tool reliably without further prompting. Briefly:
|
|
125
103
|
|
|
126
|
-
- **`talonic_extract`** — Extract structured, schema-validated data from a document. Inputs: one of `file_path`, `file_url`, `document_id`, plus a `schema` (or `schema_id`). Returns clean JSON with per-field confidence scores.
|
|
104
|
+
- **`talonic_extract`** — Extract structured, schema-validated data from a document. Inputs: one of `file_data` + `filename` (recommended for chat clients, see below), `file_path`, `file_url`, or `document_id`, plus a `schema` (or `schema_id`). Returns clean JSON with per-field confidence scores.
|
|
127
105
|
- **`talonic_search`** — Omnisearch across documents, fields, sources, and schemas in the workspace. Use for conceptual or fuzzy queries.
|
|
128
|
-
- **`talonic_filter`** — Filter documents by extracted field values using composable conditions (`eq`, `gt`, `between`, `contains`, etc.). Field names are auto-resolved to internal IDs.
|
|
106
|
+
- **`talonic_filter`** — Filter documents by extracted field values using composable conditions (`eq`, `gt`, `between`, `contains`, etc.). Field names are auto-resolved to internal IDs (currently limited on production; see [Known limitations](#known-limitations-v01) for the recommended workaround).
|
|
129
107
|
- **`talonic_get_document`** — Fetch full metadata for a single document by id, including processing log and link URLs.
|
|
130
|
-
- **`talonic_to_markdown`** — Get OCR-converted markdown for a document
|
|
108
|
+
- **`talonic_to_markdown`** — Get OCR-converted markdown for a document. Accepts `document_id` (cheapest), `file_data` + `filename`, `file_path`, or `file_url`.
|
|
131
109
|
- **`talonic_list_schemas`** — List all saved schemas with their definitions.
|
|
132
110
|
- **`talonic_save_schema`** — Save a schema definition to the workspace for reuse.
|
|
133
111
|
|
|
134
112
|
The `talonic://schemas` resource exposes the saved-schemas list to clients that browse resources separately (Claude Desktop and Cowork render these in the UI).
|
|
135
113
|
|
|
114
|
+
## Drag-and-drop in chat clients
|
|
115
|
+
|
|
116
|
+
When the user drag-drops a PDF (or any supported file) into a chat-style MCP host such as Claude Desktop, Cowork, or Cursor, the file lands in a host-owned sandbox directory the MCP server cannot read. The path the host then hands the agent (something like `/mnt/user-data/uploads/abc.pdf`) is meaningless to a separately-running `npx` MCP process, so `file_path` calls fail with a filesystem error.
|
|
117
|
+
|
|
118
|
+
`@talonic/mcp@0.1.4` and later solve this by accepting **`file_data`** (base64-encoded file bytes) and **`filename`** on `talonic_extract` and `talonic_to_markdown`. The agent reads the file bytes from the conversation, base64-encodes them, and passes them through the MCP tool call. The MCP server decodes, infers MIME type from the filename, and uploads to the Talonic API as a normal multipart request. The file never has to live on the MCP server's disk.
|
|
119
|
+
|
|
120
|
+
Tool descriptions advertise `file_data` as the recommended input for chat-style clients, so well-trained agents will reach for it automatically. No client-side configuration is required beyond installing `@talonic/mcp@latest` (or `@0.1.4` or newer) as documented above.
|
|
121
|
+
|
|
136
122
|
## How it works
|
|
137
123
|
|
|
138
124
|
```
|
|
@@ -160,7 +146,7 @@ Set via the `env` block in your MCP client config:
|
|
|
160
146
|
The `env` block in your MCP client config is missing or not being read. Double-check the JSON shape. After editing the config, fully restart the client (not just the conversation).
|
|
161
147
|
|
|
162
148
|
**Talonic does not appear in the connected servers list.**
|
|
163
|
-
|
|
149
|
+
Make sure the `command` is `npx` and the `args` are exactly `["-y", "@talonic/mcp@latest"]`. As a sanity check, in any terminal run `npx -y @talonic/mcp@latest --version`; it should print `talonic 0.1.3` (or newer). If you are on an older `0.1.x` and see no output at all, you are hitting the silent-bin bug fixed in `0.1.3`; upgrade by setting the args to `["-y", "@talonic/mcp@latest"]` and restarting the client.
|
|
164
150
|
|
|
165
151
|
**`talonic_extract` returns 500 INTERNAL_ERROR with auto-discovery.**
|
|
166
152
|
Known limitation. Always provide either an inline `schema` or a `schema_id`. The platform team is stabilising the auto-discovery code path.
|
|
@@ -169,17 +155,36 @@ Known limitation. Always provide either an inline `schema` or a `schema_id`. The
|
|
|
169
155
|
The MIME type was inferred as `application/octet-stream`. The SDK now infers from common file extensions; if your filename has an unusual extension, pass `content_type` explicitly to the SDK call (the MCP layer does not yet expose this; a future tool version will).
|
|
170
156
|
|
|
171
157
|
**`talonic_filter` errors with `field_not_found`.**
|
|
172
|
-
|
|
158
|
+
Field-name resolution against `/v1/fields?search=` is currently limited on production: even names that `talonic_search` returns as live `displayName` / `canonicalName` values can fail. Until the API-side resolver is improved, the reliable path is to pass `field_id` directly. Get the id from a `talonic_search` response (`fields[].id`) and use the `field_id` parameter instead of `field` in your filter condition.
|
|
173
159
|
|
|
174
160
|
**Tool descriptions look wrong in my client.**
|
|
175
161
|
Some MCP clients cache tool descriptions. Restart the client after a server update.
|
|
176
162
|
|
|
177
163
|
## Known limitations (v0.1)
|
|
178
164
|
|
|
179
|
-
- Auto-discovery extract (no schema) is not reliable on production
|
|
180
|
-
-
|
|
181
|
-
|
|
182
|
-
|
|
165
|
+
- **Auto-discovery extract (no schema) is not reliable on production.** Always pass a `schema` or `schema_id` to `talonic_extract`.
|
|
166
|
+
- **Only the full JSON Schema format is reliable today.** The flat key-type map (`{ vendor_name: "string", ... }`) is silently accepted by the API but currently saves with empty `properties`. The `{ fields: [...] }` simplified format is also unstable. Until the API normalises the simpler shapes, pass full JSON Schema:
|
|
167
|
+
```json
|
|
168
|
+
{
|
|
169
|
+
"type": "object",
|
|
170
|
+
"properties": {
|
|
171
|
+
"vendor_name": { "type": "string", "title": "Vendor Name" },
|
|
172
|
+
"total_amount": { "type": "number", "title": "Total Amount" }
|
|
173
|
+
},
|
|
174
|
+
"required": ["vendor_name", "total_amount"]
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
- **`talonic_filter` field-name resolution is limited on production.** Even names returned live by `talonic_search` can fail with `field_not_found`. Until the API-side resolver is improved, pass `field_id` directly (the value of `fields[].id` from a `talonic_search` response).
|
|
178
|
+
|
|
179
|
+
## Upgrading from 0.1.0 / 0.1.1 / 0.1.2
|
|
180
|
+
|
|
181
|
+
Versions before `0.1.3` had a bug where the bundled MCP server bin would exit silently when launched via the npm bin symlink, which is exactly how every MCP client invokes it via `npx`. If your client config is on an older version and you see no `talonic_*` tools surface despite the config looking correct, you are hitting that bug.
|
|
182
|
+
|
|
183
|
+
The fix is to point your `args` at `@latest` (or `@0.1.3` explicitly) and fully restart the client:
|
|
184
|
+
|
|
185
|
+
```jsonc
|
|
186
|
+
"args": ["-y", "@talonic/mcp@latest"]
|
|
187
|
+
```
|
|
183
188
|
|
|
184
189
|
## Develop
|
|
185
190
|
|
package/dist/index.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ declare function createServer(options: CreateServerOptions): McpServer;
|
|
|
53
53
|
*
|
|
54
54
|
* @public
|
|
55
55
|
*/
|
|
56
|
-
declare const VERSION = "0.1.
|
|
56
|
+
declare const VERSION = "0.1.4";
|
|
57
57
|
/**
|
|
58
58
|
* The MCP server name. Identifies the server to MCP clients (Claude
|
|
59
59
|
* Desktop, Cursor, Cline, etc.) when they list connected servers.
|
package/dist/index.js
CHANGED
|
@@ -79,28 +79,41 @@ var DESCRIPTION = [
|
|
|
79
79
|
"- The user wants to find documents matching a query (use talonic_search or talonic_filter).",
|
|
80
80
|
"",
|
|
81
81
|
"FILE SOURCES (provide exactly one):",
|
|
82
|
-
"-
|
|
83
|
-
"
|
|
82
|
+
"- file_data + filename (RECOMMENDED for chat clients): base64-encoded file bytes plus",
|
|
83
|
+
" the original filename (with extension). Use this whenever you already have the file",
|
|
84
|
+
" in memory, e.g. the user attached it to the conversation. Works in every MCP client",
|
|
85
|
+
" regardless of where the file lives on disk.",
|
|
86
|
+
"- file_path: a local path to the document. Only works if the MCP server process can",
|
|
87
|
+
" read that path on its own filesystem; many chat clients (Claude Desktop, Cowork)",
|
|
88
|
+
" store user uploads in a sandbox the MCP server cannot access, in which case use",
|
|
89
|
+
" file_data instead.",
|
|
90
|
+
"- file_url: a URL the Talonic API will fetch directly. Use for documents already on",
|
|
91
|
+
" the public web.",
|
|
84
92
|
"- document_id: re-extract a document already in the workspace.",
|
|
85
93
|
"",
|
|
86
94
|
"SCHEMA FORMATS (provide at most one of `schema` or `schema_id`):",
|
|
87
|
-
'-
|
|
88
|
-
'- JSON Schema: { type: "object", properties: { ... } }',
|
|
95
|
+
'- JSON Schema (recommended): { type: "object", properties: { vendor_name: { type: "string" } } }',
|
|
89
96
|
"- schema_id: id of a saved schema from talonic_list_schemas",
|
|
90
97
|
"",
|
|
91
98
|
"IMPORTANT: production currently rejects requests with no schema. Always provide either",
|
|
92
99
|
"an inline `schema` or a `schema_id`."
|
|
93
100
|
].join("\n");
|
|
94
101
|
var inputSchema = {
|
|
102
|
+
file_data: z.string().optional().describe(
|
|
103
|
+
"Base64-encoded file bytes. Recommended path when the agent already has the file in memory (e.g., the user attached a PDF to the conversation). Pair with `filename` so MIME type can be inferred. Works regardless of where the file lives on disk."
|
|
104
|
+
),
|
|
105
|
+
filename: z.string().optional().describe(
|
|
106
|
+
"Original filename including extension, e.g. 'invoice.pdf'. Used to infer MIME type when uploading via `file_data`. Required when `file_data` is provided."
|
|
107
|
+
),
|
|
95
108
|
file_path: z.string().optional().describe(
|
|
96
|
-
"Local path to a document file.
|
|
109
|
+
"Local path to a document file. Only works if the MCP server has read access to that path. In sandboxed chat clients (Claude Desktop, Cowork) where uploads land in a host-owned directory, use `file_data` instead."
|
|
97
110
|
),
|
|
98
111
|
file_url: z.string().optional().describe(
|
|
99
|
-
"URL to a document file. The Talonic API fetches it server-side. Use this for
|
|
112
|
+
"URL to a document file. The Talonic API fetches it server-side. Use this for documents already on the public web."
|
|
100
113
|
),
|
|
101
114
|
document_id: z.string().optional().describe("ID of a document already in the workspace, to re-extract with a new schema."),
|
|
102
115
|
schema: z.record(z.string(), z.unknown()).optional().describe(
|
|
103
|
-
"Inline schema definition.
|
|
116
|
+
"Inline schema definition. Use full JSON Schema: { type: 'object', properties: { ... } }."
|
|
104
117
|
),
|
|
105
118
|
schema_id: z.string().optional().describe("ID of a saved schema. Mutually exclusive with `schema`."),
|
|
106
119
|
instructions: z.string().optional().describe(
|
|
@@ -111,6 +124,10 @@ var inputSchema = {
|
|
|
111
124
|
async function handleExtract(talonic, args) {
|
|
112
125
|
try {
|
|
113
126
|
const params = {};
|
|
127
|
+
if (args.file_data !== void 0) {
|
|
128
|
+
params.file = Buffer.from(args.file_data, "base64");
|
|
129
|
+
if (args.filename !== void 0) params.filename = args.filename;
|
|
130
|
+
}
|
|
114
131
|
if (args.file_path !== void 0) params.file_path = args.file_path;
|
|
115
132
|
if (args.file_url !== void 0) params.file_url = args.file_url;
|
|
116
133
|
if (args.document_id !== void 0) params.document_id = args.document_id;
|
|
@@ -399,8 +416,8 @@ function registerSearch(server, talonic) {
|
|
|
399
416
|
}
|
|
400
417
|
var DESCRIPTION7 = [
|
|
401
418
|
"Get the OCR-converted markdown for a document. Accepts an existing document_id,",
|
|
402
|
-
"a local file path, or a URL. When given a raw file, the
|
|
403
|
-
"
|
|
419
|
+
"raw file bytes (base64), a local file path, or a URL. When given a raw file, the",
|
|
420
|
+
"tool ingests it via extract first and then returns the markdown.",
|
|
404
421
|
"",
|
|
405
422
|
"USE WHEN:",
|
|
406
423
|
"- The user wants the full text content of a document for summarisation, translation, or analysis.",
|
|
@@ -413,25 +430,37 @@ var DESCRIPTION7 = [
|
|
|
413
430
|
"",
|
|
414
431
|
"INPUTS (provide exactly one):",
|
|
415
432
|
"- document_id: id of an already-ingested document (cheapest path; one API call)",
|
|
416
|
-
"-
|
|
433
|
+
"- file_data + filename (RECOMMENDED for chat clients): base64-encoded file bytes plus",
|
|
434
|
+
" the original filename (with extension). Use this whenever you already have the file",
|
|
435
|
+
" in memory, e.g. the user attached it to the conversation. Works in every MCP client.",
|
|
436
|
+
"- file_path: local path to a document file. Only works if the MCP server has read access",
|
|
437
|
+
" to that path; in sandboxed chat clients use file_data instead.",
|
|
417
438
|
"- file_url: URL to a document file (the Talonic API fetches it server-side)"
|
|
418
439
|
].join("\n");
|
|
419
440
|
var inputSchema6 = {
|
|
420
441
|
document_id: z.string().min(1).optional().describe(
|
|
421
442
|
"The Talonic document id whose markdown you want. Get this from a previous talonic_extract or talonic_search response."
|
|
422
443
|
),
|
|
423
|
-
|
|
444
|
+
file_data: z.string().optional().describe(
|
|
445
|
+
"Base64-encoded file bytes. Recommended path when the agent already has the file in memory (e.g., the user attached a PDF to the conversation). Pair with `filename` so MIME type can be inferred."
|
|
446
|
+
),
|
|
447
|
+
filename: z.string().optional().describe(
|
|
448
|
+
"Original filename including extension, e.g. 'invoice.pdf'. Used to infer MIME type when uploading via `file_data`. Required when `file_data` is provided."
|
|
449
|
+
),
|
|
450
|
+
file_path: z.string().optional().describe(
|
|
451
|
+
"Local path to a document file. Only works if the MCP server has read access to that path. In sandboxed chat clients (Claude Desktop, Cowork) use `file_data` instead."
|
|
452
|
+
),
|
|
424
453
|
file_url: z.string().optional().describe("URL to a document file. The Talonic API fetches it server-side.")
|
|
425
454
|
};
|
|
426
455
|
var INGEST_ONLY_SCHEMA = {};
|
|
427
456
|
async function handleToMarkdown(talonic, args) {
|
|
428
457
|
try {
|
|
429
|
-
const sources = ["document_id", "file_path", "file_url"];
|
|
458
|
+
const sources = ["document_id", "file_data", "file_path", "file_url"];
|
|
430
459
|
const provided = sources.filter((k) => args[k] !== void 0);
|
|
431
460
|
if (provided.length === 0) {
|
|
432
461
|
throw new TalonicError({
|
|
433
462
|
code: "missing_input_source",
|
|
434
|
-
message: "talonic_to_markdown requires one of: document_id, file_path, file_url.",
|
|
463
|
+
message: "talonic_to_markdown requires one of: document_id, file_data, file_path, file_url.",
|
|
435
464
|
status: 0,
|
|
436
465
|
retryable: false
|
|
437
466
|
});
|
|
@@ -447,6 +476,10 @@ async function handleToMarkdown(talonic, args) {
|
|
|
447
476
|
let documentId = args.document_id;
|
|
448
477
|
if (!documentId) {
|
|
449
478
|
const ingest = await talonic.extract({
|
|
479
|
+
...args.file_data !== void 0 ? {
|
|
480
|
+
file: Buffer.from(args.file_data, "base64"),
|
|
481
|
+
...args.filename !== void 0 ? { filename: args.filename } : {}
|
|
482
|
+
} : {},
|
|
450
483
|
...args.file_path !== void 0 ? { file_path: args.file_path } : {},
|
|
451
484
|
...args.file_url !== void 0 ? { file_url: args.file_url } : {},
|
|
452
485
|
schema: INGEST_ONLY_SCHEMA
|
|
@@ -472,7 +505,7 @@ function registerToMarkdown(server, talonic) {
|
|
|
472
505
|
}
|
|
473
506
|
|
|
474
507
|
// src/version.ts
|
|
475
|
-
var VERSION = "0.1.
|
|
508
|
+
var VERSION = "0.1.4";
|
|
476
509
|
var SERVER_NAME = "talonic";
|
|
477
510
|
|
|
478
511
|
// src/server-factory.ts
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/resources/schemas-resource.ts","../src/tools/_shared.ts","../src/tools/extract.ts","../src/tools/filter.ts","../src/tools/get-document.ts","../src/tools/list-schemas.ts","../src/tools/save-schema.ts","../src/tools/search.ts","../src/tools/to-markdown.ts","../src/version.ts","../src/server-factory.ts"],"names":["DESCRIPTION","z","inputSchema","TalonicError"],"mappings":";;;;;;;AAcO,SAAS,uBAAA,CAAwB,QAAmB,OAAA,EAAwB;AACjF,EAAA,MAAA,CAAO,gBAAA;AAAA,IACL,iBAAA;AAAA,IACA,mBAAA;AAAA,IACA;AAAA,MACE,KAAA,EAAO,iBAAA;AAAA,MACP,WAAA,EACE,6FAAA;AAAA,MACF,QAAA,EAAU;AAAA,KACZ;AAAA,IACA,OAAO,GAAA,KAAQ;AACb,MAAA,MAAM,MAAA,GAAS,MAAM,OAAA,CAAQ,OAAA,CAAQ,IAAA,EAAK;AAC1C,MAAA,OAAO;AAAA,QACL,QAAA,EAAU;AAAA,UACR;AAAA,YACE,GAAA,EAAK,IAAI,QAAA,EAAS;AAAA,YAClB,QAAA,EAAU,kBAAA;AAAA,YACV,IAAA,EAAM,IAAA,CAAK,SAAA,CAAU,MAAA,EAAQ,MAAM,CAAC;AAAA;AACtC;AACF,OACF;AAAA,IACF;AAAA,GACF;AACF;ACAO,SAAS,OAAO,KAAA,EAAmC;AACxD,EAAA,OAAO;AAAA,IACL,OAAA,EAAS;AAAA,MACP;AAAA,QACE,IAAA,EAAM,MAAA;AAAA,QACN,IAAA,EAAM,IAAA,CAAK,SAAA,CAAU,KAAA,EAAO,MAAM,CAAC;AAAA;AACrC;AACF,GACF;AACF;AASO,SAAS,UAAU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AAA,CAAoB,QAAQ,OAAO,CAAA;AACnC,EAAA,cAAA,CAAe,QAAQ,OAAO,CAAA;AAC9B,EAAA,cAAA,CAAe,QAAQ,OAAO,CAAA;AAC9B,EAAA,kBAAA,CAAmB,QAAQ,OAAO,CAAA;AAClC,EAAA,eAAA,CAAgB,QAAQ,OAAO,CAAA;AAG/B,EAAA,uBAAA,CAAwB,QAAQ,OAAO,CAAA;AAEvC,EAAA,OAAO,MAAA;AACT","file":"index.js","sourcesContent":["import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport type { Talonic } from \"@talonic/node\"\n\n/**\n * Register the `talonic://schemas` resource. The agent can read this\n * URI to retrieve the user's saved schemas without burning a tool call.\n *\n * The MCP SDK exposes resources as a separate primitive from tools.\n * Clients (Claude Desktop, Cursor, etc.) display them in their UI\n * alongside the conversation, so users can browse what their agent has\n * access to.\n *\n * @internal\n */\nexport function registerSchemasResource(server: McpServer, talonic: Talonic): void {\n server.registerResource(\n \"talonic-schemas\",\n \"talonic://schemas\",\n {\n title: \"Talonic Schemas\",\n description:\n \"All schemas saved in the user's Talonic workspace, with their full JSON Schema definitions.\",\n mimeType: \"application/json\",\n },\n async (uri) => {\n const result = await talonic.schemas.list()\n return {\n contents: [\n {\n uri: uri.toString(),\n mimeType: \"application/json\",\n text: JSON.stringify(result, null, 2),\n },\n ],\n }\n },\n )\n}\n","import { TalonicError } from \"@talonic/node\"\n\n/**\n * Successful tool result envelope. The `content` array follows the MCP\n * `CallToolResult` shape. We always emit one text item with the JSON\n * payload; agents parse it back themselves.\n *\n * The `[key: string]: unknown` index signature exists to satisfy the\n * MCP SDK's structural type, which permits arbitrary additional keys.\n *\n * @internal\n */\nexport interface ToolSuccessResult {\n content: Array<{ type: \"text\"; text: string }>\n [key: string]: unknown\n}\n\n/**\n * Failure tool result envelope. Sets `isError: true` per the MCP spec\n * so clients render this as an error rather than a normal response.\n *\n * @internal\n */\nexport interface ToolErrorResult {\n content: Array<{ type: \"text\"; text: string }>\n isError: true\n [key: string]: unknown\n}\n\nexport type ToolResult = ToolSuccessResult | ToolErrorResult\n\n/**\n * Wrap a value as a single-text-item tool result. Stable JSON shape so\n * downstream parsing is reliable across tools.\n *\n * @internal\n */\nexport function jsonOk(value: unknown): ToolSuccessResult {\n return {\n content: [\n {\n type: \"text\",\n text: JSON.stringify(value, null, 2),\n },\n ],\n }\n}\n\n/**\n * Convert any thrown error into a tool error result with stable\n * formatting. Talonic API errors include `code`, `status`, and\n * `request_id` so the user (or another tool call) can act on them.\n *\n * @internal\n */\nexport function toolError(err: unknown): ToolErrorResult {\n if (err instanceof TalonicError) {\n const lines = [\n `Talonic API error: ${err.message}`,\n `code: ${err.code}`,\n `status: ${err.status}`,\n ]\n if (err.requestId) lines.push(`request_id: ${err.requestId}`)\n return {\n isError: true,\n content: [{ type: \"text\", text: lines.join(\"\\n\") }],\n }\n }\n return {\n isError: true,\n content: [\n {\n type: \"text\",\n text: `Unexpected error: ${err instanceof Error ? err.message : String(err)}`,\n },\n ],\n }\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport type { ExtractParams, Talonic } from \"@talonic/node\"\nimport { z } from \"zod\"\nimport { jsonOk, toolError, type ToolResult } from \"./_shared.js\"\n\nconst DESCRIPTION = [\n \"Extract structured, schema-validated data from a document using Talonic.\",\n \"Returns clean JSON matching the schema, with per-field confidence scores and\",\n \"metadata about the document (detected type, language, page count).\",\n \"\",\n \"USE WHEN:\",\n \"- The user has a document (PDF, image, scan, DOCX, etc.) and wants specific fields pulled out.\",\n \"- You need structured data (vendor name, total amount, dates, parties, terms) rather than free text.\",\n \"- The user uploads or references any invoice, contract, certificate, statement, or form.\",\n \"- You want validated JSON instead of trying to OCR + parse with raw LLM calls.\",\n \"\",\n \"DO NOT USE WHEN:\",\n \"- The user just wants the full text content (use talonic_to_markdown after extracting once).\",\n \"- The user wants to find documents matching a query (use talonic_search or talonic_filter).\",\n \"\",\n \"FILE SOURCES (provide exactly one):\",\n \"- file_path: a local path to the document (the MCP server reads it from disk).\",\n \"- file_url: a URL the Talonic API will fetch directly.\",\n \"- document_id: re-extract a document already in the workspace.\",\n \"\",\n \"SCHEMA FORMATS (provide at most one of `schema` or `schema_id`):\",\n '- Flat map (recommended): { vendor_name: \"string\", total_amount: \"number\", due_date: \"date\" }',\n '- JSON Schema: { type: \"object\", properties: { ... } }',\n \"- schema_id: id of a saved schema from talonic_list_schemas\",\n \"\",\n \"IMPORTANT: production currently rejects requests with no schema. Always provide either\",\n \"an inline `schema` or a `schema_id`.\",\n].join(\"\\n\")\n\nconst inputSchema = {\n file_path: z\n .string()\n .optional()\n .describe(\n \"Local path to a document file. The MCP server reads it from disk and uploads it. Provide one of file_path, file_url, or document_id.\",\n ),\n file_url: z\n .string()\n .optional()\n .describe(\n \"URL to a document file. The Talonic API fetches it server-side. Use this for remote documents.\",\n ),\n document_id: z\n .string()\n .optional()\n .describe(\"ID of a document already in the workspace, to re-extract with a new schema.\"),\n schema: z\n .record(z.string(), z.unknown())\n .optional()\n .describe(\n \"Inline schema definition. Flat map (recommended), simplified fields, or JSON Schema.\",\n ),\n schema_id: z\n .string()\n .optional()\n .describe(\"ID of a saved schema. Mutually exclusive with `schema`.\"),\n instructions: z\n .string()\n .optional()\n .describe(\n \"Natural-language guidance for the extractor, e.g. 'Focus on the billing section. Amounts are in EUR.'\",\n ),\n include_markdown: z\n .boolean()\n .optional()\n .describe(\"Include OCR-converted markdown in the response alongside structured data.\"),\n}\n\nexport interface ExtractArgs {\n file_path?: string\n file_url?: string\n document_id?: string\n schema?: Record<string, unknown>\n schema_id?: string\n instructions?: string\n include_markdown?: boolean\n}\n\nexport async function handleExtract(talonic: Talonic, args: ExtractArgs): Promise<ToolResult> {\n try {\n const params: ExtractParams = {}\n if (args.file_path !== undefined) params.file_path = args.file_path\n if (args.file_url !== undefined) params.file_url = args.file_url\n if (args.document_id !== undefined) params.document_id = args.document_id\n if (args.schema !== undefined) params.schema = args.schema\n if (args.schema_id !== undefined) params.schema_id = args.schema_id\n if (args.instructions !== undefined) params.instructions = args.instructions\n if (args.include_markdown !== undefined) params.include_markdown = args.include_markdown\n\n const result = await talonic.extract(params)\n return jsonOk(result)\n } catch (err) {\n return toolError(err)\n }\n}\n\nexport function registerExtract(server: McpServer, talonic: Talonic): void {\n server.registerTool(\n \"talonic_extract\",\n {\n title: \"Extract Data from Document\",\n description: DESCRIPTION,\n inputSchema,\n },\n async (args) => handleExtract(talonic, args as ExtractArgs),\n )\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport type { Talonic, FilterCondition, FilterSort } from \"@talonic/node\"\nimport { z } from \"zod\"\nimport { jsonOk, toolError, type ToolResult } from \"./_shared.js\"\n\nconst DESCRIPTION = [\n \"Filter the user's Talonic documents by extracted field values using composable conditions.\",\n \"Conditions accept field names (e.g. 'vendor_name'); the SDK resolves them to internal field IDs.\",\n \"\",\n \"USE WHEN:\",\n \"- The user wants documents matching specific structured criteria, like 'invoices over 1000 EUR'\",\n \" or 'contracts expiring before 2026-12-31' or 'COIs from Acme'.\",\n \"- The query is value-based on extracted fields, not a free-text concept search.\",\n \"- You need to retrieve a sortable, paginated list filtered by field conditions.\",\n \"\",\n \"DO NOT USE WHEN:\",\n \"- The user wants conceptual / free-text search across content (use talonic_search).\",\n \"- The user is looking for a single document by id (use talonic_get_document).\",\n \"- The user wants extracted data from a new document (use talonic_extract).\",\n \"\",\n \"OPERATORS:\",\n \"- eq, neq: equality / inequality\",\n \"- gt, gte, lt, lte: numeric or date comparisons\",\n \"- between: requires both `value` and `value_to`\",\n \"- contains: substring match on string fields\",\n \"- is_empty, is_not_empty: presence checks (no value needed)\",\n \"\",\n \"TIP: To discover available field names, call talonic_search first with a related query.\",\n].join(\"\\n\")\n\nconst operatorEnum = z.enum([\n \"eq\",\n \"neq\",\n \"gt\",\n \"gte\",\n \"lt\",\n \"lte\",\n \"between\",\n \"contains\",\n \"is_empty\",\n \"is_not_empty\",\n])\n\nconst conditionSchema = z.object({\n field: z\n .string()\n .optional()\n .describe(\"Field name (e.g. 'vendor_name'). Resolved to a fieldId automatically.\"),\n field_id: z\n .string()\n .optional()\n .describe(\"Talonic field id (e.g. 'fld_abc'). Use this if you already have it.\"),\n operator: operatorEnum.describe(\"Comparison operator. See description for the full list.\"),\n value: z.unknown().optional().describe(\"Value to compare against.\"),\n value_to: z\n .unknown()\n .optional()\n .describe(\"Upper bound for `between` operator; ignored otherwise.\"),\n})\n\nconst sortSchema = z.object({\n field: z.string().optional(),\n field_id: z.string().optional(),\n direction: z.enum([\"asc\", \"desc\"]).describe(\"Sort direction.\"),\n})\n\nconst inputSchema = {\n conditions: z\n .array(conditionSchema)\n .min(1)\n .describe(\"One or more filter conditions, AND-ed together.\"),\n search: z\n .string()\n .optional()\n .describe(\"Optional free-text search applied alongside the filters.\"),\n sort: sortSchema.optional().describe(\"Optional sort by a field.\"),\n page: z.number().int().positive().optional().describe(\"Page number for pagination.\"),\n limit: z\n .number()\n .int()\n .positive()\n .optional()\n .describe(\"Results per page. Default 50 server-side.\"),\n source_connection_id: z\n .string()\n .optional()\n .describe(\"Optionally scope to a specific source connection.\"),\n}\n\nexport interface FilterArgs {\n conditions: Array<{\n field?: string\n field_id?: string\n operator:\n | \"eq\"\n | \"neq\"\n | \"gt\"\n | \"gte\"\n | \"lt\"\n | \"lte\"\n | \"between\"\n | \"contains\"\n | \"is_empty\"\n | \"is_not_empty\"\n value?: unknown\n value_to?: unknown\n }>\n search?: string\n sort?: { field?: string; field_id?: string; direction: \"asc\" | \"desc\" }\n page?: number\n limit?: number\n source_connection_id?: string\n}\n\nexport async function handleFilter(talonic: Talonic, args: FilterArgs): Promise<ToolResult> {\n try {\n const conditions: FilterCondition[] = args.conditions.map((c) => {\n const cond: FilterCondition = { operator: c.operator }\n if (c.field !== undefined) cond.field = c.field\n if (c.field_id !== undefined) cond.fieldId = c.field_id\n if (c.value !== undefined) cond.value = c.value\n if (c.value_to !== undefined) cond.valueTo = c.value_to\n return cond\n })\n\n let sort: FilterSort | undefined\n if (args.sort !== undefined) {\n sort = { direction: args.sort.direction }\n if (args.sort.field !== undefined) sort.field = args.sort.field\n if (args.sort.field_id !== undefined) sort.fieldId = args.sort.field_id\n }\n\n const result = await talonic.documents.filter({\n conditions,\n ...(args.search !== undefined ? { search: args.search } : {}),\n ...(sort !== undefined ? { sort } : {}),\n ...(args.page !== undefined ? { page: args.page } : {}),\n ...(args.limit !== undefined ? { limit: args.limit } : {}),\n ...(args.source_connection_id !== undefined\n ? { source_connection_id: args.source_connection_id }\n : {}),\n })\n return jsonOk(result)\n } catch (err) {\n return toolError(err)\n }\n}\n\nexport function registerFilter(server: McpServer, talonic: Talonic): void {\n server.registerTool(\n \"talonic_filter\",\n {\n title: \"Filter Talonic Documents\",\n description: DESCRIPTION,\n inputSchema,\n },\n async (args) => handleFilter(talonic, args as FilterArgs),\n )\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport type { Talonic } from \"@talonic/node\"\nimport { z } from \"zod\"\nimport { jsonOk, toolError, type ToolResult } from \"./_shared.js\"\n\nconst DESCRIPTION = [\n \"Fetch full metadata for a single document already in the user's Talonic workspace.\",\n \"Returns id, filename, page count, detected document type, language, processing log,\",\n \"and link URLs (self, extractions, dashboard).\",\n \"\",\n \"USE WHEN:\",\n \"- You need details about a specific document the user already extracted or uploaded.\",\n \"- You have a document_id from a previous extract or search call and want more context.\",\n \"- The user asks 'tell me about document X' or similar.\",\n \"\",\n \"DO NOT USE WHEN:\",\n \"- The user wants the document's full text content (use talonic_to_markdown for OCR markdown).\",\n \"- The user wants extracted structured data (use talonic_extract with a schema, or fetch the extraction by id).\",\n \"- The user has a file but no document_id yet (call talonic_extract first to ingest the document).\",\n].join(\"\\n\")\n\nconst inputSchema = {\n document_id: z\n .string()\n .min(1)\n .describe(\n \"The Talonic document ID. Get this from a previous talonic_extract or talonic_search response.\",\n ),\n}\n\nexport async function handleGetDocument(\n talonic: Talonic,\n args: { document_id: string },\n): Promise<ToolResult> {\n try {\n const result = await talonic.documents.get(args.document_id)\n return jsonOk(result)\n } catch (err) {\n return toolError(err)\n }\n}\n\nexport function registerGetDocument(server: McpServer, talonic: Talonic): void {\n server.registerTool(\n \"talonic_get_document\",\n {\n title: \"Get Talonic Document\",\n description: DESCRIPTION,\n inputSchema,\n },\n async (args) => handleGetDocument(talonic, args),\n )\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport type { Talonic } from \"@talonic/node\"\nimport { jsonOk, toolError, type ToolResult } from \"./_shared.js\"\n\n/**\n * LLM-targeted tool description. The first paragraph explains what the\n * tool does in one sentence. The USE WHEN / DO NOT USE sections are\n * what an agent reads before deciding to invoke this tool over an\n * alternative; keep them concrete.\n *\n * @internal\n */\nconst DESCRIPTION = [\n \"List all saved schemas in the user's Talonic workspace.\",\n \"Returns each schema with its id, name, description, version,\",\n \"field count, and full JSON Schema definition.\",\n \"\",\n \"USE WHEN:\",\n \"- The user asks what schemas they have, or asks to see existing schemas.\",\n \"- You want to discover existing schemas before designing a new one.\",\n \"- Before recommending the user create a schema, check if one already covers the use case.\",\n \"- The user asks to extract from a known document type and you want to find a matching schema.\",\n \"\",\n \"DO NOT USE WHEN:\",\n \"- The user just wants to extract data from a document and provides an inline schema (call talonic_extract directly).\",\n \"\",\n \"TIP: Pair this with talonic_extract by passing the chosen schema's id as `schema_id`.\",\n].join(\"\\n\")\n\n/**\n * Pure handler. Invokes the SDK and shapes the result. Exported for\n * unit testing; the public registration is via `register()` below.\n *\n * @internal\n */\nexport async function handleListSchemas(talonic: Talonic): Promise<ToolResult> {\n try {\n const result = await talonic.schemas.list()\n return jsonOk(result)\n } catch (err) {\n return toolError(err)\n }\n}\n\n/**\n * Register `talonic_list_schemas` on an MCP server.\n *\n * @internal\n */\nexport function registerListSchemas(server: McpServer, talonic: Talonic): void {\n server.registerTool(\n \"talonic_list_schemas\",\n {\n title: \"List Talonic Schemas\",\n description: DESCRIPTION,\n inputSchema: {},\n },\n async () => handleListSchemas(talonic),\n )\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport type { Talonic } from \"@talonic/node\"\nimport { z } from \"zod\"\nimport { jsonOk, toolError, type ToolResult } from \"./_shared.js\"\n\nconst DESCRIPTION = [\n \"Save a schema definition to the user's Talonic workspace so it can be reused\",\n \"across future extractions. Returns the saved schema with its newly assigned id.\",\n \"\",\n \"USE WHEN:\",\n \"- The user asks to save a schema, store a template, or reuse the schema across docs.\",\n \"- You have iterated on a schema with the user and they confirmed it should be saved.\",\n \"- The user wants to standardise extraction across many documents of the same type.\",\n \"\",\n \"DO NOT USE WHEN:\",\n \"- The user just wants to extract once with an inline schema (call talonic_extract directly with the schema inline).\",\n \"- The user has not confirmed the schema design (avoid creating clutter in their workspace).\",\n \"\",\n \"TIP: After saving, call talonic_extract with `schema_id` set to the returned id for consistent results.\",\n].join(\"\\n\")\n\nconst inputSchema = {\n name: z.string().min(1).describe(\"Human-readable name for the schema, e.g. 'Standard Invoice'.\"),\n definition: z\n .record(z.string(), z.unknown())\n .describe(\n \"Schema definition. Accepts JSON Schema, simplified fields ({fields:[...]}), or a flat key-type map.\",\n ),\n description: z\n .string()\n .optional()\n .describe(\"Optional description of what this schema extracts and when to use it.\"),\n}\n\nexport async function handleSaveSchema(\n talonic: Talonic,\n args: { name: string; definition: Record<string, unknown>; description?: string },\n): Promise<ToolResult> {\n try {\n const result = await talonic.schemas.create({\n name: args.name,\n definition: args.definition,\n ...(args.description !== undefined ? { description: args.description } : {}),\n })\n return jsonOk(result)\n } catch (err) {\n return toolError(err)\n }\n}\n\nexport function registerSaveSchema(server: McpServer, talonic: Talonic): void {\n server.registerTool(\n \"talonic_save_schema\",\n {\n title: \"Save Talonic Schema\",\n description: DESCRIPTION,\n inputSchema,\n },\n async (args) => handleSaveSchema(talonic, args),\n )\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport type { Talonic } from \"@talonic/node\"\nimport { z } from \"zod\"\nimport { jsonOk, toolError, type ToolResult } from \"./_shared.js\"\n\nconst DESCRIPTION = [\n \"Search the user's Talonic workspace for documents, fields, sources, or schemas\",\n \"matching a query. Returns ranked results across all entity types in one call.\",\n \"\",\n \"USE WHEN:\",\n \"- The user wants to find documents but does not know the exact filename or id.\",\n \"- The query is conceptual ('contracts mentioning indemnification', 'Acme invoices').\",\n \"- You need to narrow a large workspace before calling talonic_extract or talonic_filter.\",\n \"- The user asks 'do I have any docs about X' or 'find anything related to X'.\",\n \"\",\n \"DO NOT USE WHEN:\",\n \"- The user has a specific document_id (use talonic_get_document instead).\",\n \"- The user wants to apply structured field-value filters like 'amount > 1000' (use talonic_filter).\",\n \"- The user wants to extract data from a brand-new document (use talonic_extract).\",\n \"\",\n \"TIP: The result includes documents, fieldMatches, sources, schemas, and fields. Pick the entity type the user actually needs.\",\n].join(\"\\n\")\n\nconst inputSchema = {\n query: z\n .string()\n .min(1)\n .describe(\n \"Natural-language search query, e.g. 'indemnification clauses' or 'Acme invoices Q4'.\",\n ),\n limit: z\n .number()\n .int()\n .positive()\n .optional()\n .describe(\"Maximum results per entity type. Default: 5. Increase for broader exploration.\"),\n}\n\nexport async function handleSearch(\n talonic: Talonic,\n args: { query: string; limit?: number },\n): Promise<ToolResult> {\n try {\n const result = await talonic.search(\n args.query,\n args.limit !== undefined ? { limit: args.limit } : {},\n )\n return jsonOk(result)\n } catch (err) {\n return toolError(err)\n }\n}\n\nexport function registerSearch(server: McpServer, talonic: Talonic): void {\n server.registerTool(\n \"talonic_search\",\n {\n title: \"Search Talonic Workspace\",\n description: DESCRIPTION,\n inputSchema,\n },\n async (args) => handleSearch(talonic, args),\n )\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport { TalonicError, type Talonic } from \"@talonic/node\"\nimport { z } from \"zod\"\nimport { jsonOk, toolError, type ToolResult } from \"./_shared.js\"\n\nconst DESCRIPTION = [\n \"Get the OCR-converted markdown for a document. Accepts an existing document_id,\",\n \"a local file path, or a URL. When given a raw file, the tool ingests it via\",\n \"extract first (with a minimal schema) and then returns the markdown.\",\n \"\",\n \"USE WHEN:\",\n \"- The user wants the full text content of a document for summarisation, translation, or analysis.\",\n \"- A previous tool call returned a document_id and you want to inspect its content.\",\n \"- The user asks 'what does the document say' or 'summarise this PDF' (you call this then summarise).\",\n \"- The user has a raw PDF / scan / image and wants markdown directly without designing a schema first.\",\n \"\",\n \"DO NOT USE WHEN:\",\n \"- The user wants specific structured fields (use talonic_extract with a schema).\",\n \"\",\n \"INPUTS (provide exactly one):\",\n \"- document_id: id of an already-ingested document (cheapest path; one API call)\",\n \"- file_path: local path to a document file (the MCP server reads it from disk)\",\n \"- file_url: URL to a document file (the Talonic API fetches it server-side)\",\n].join(\"\\n\")\n\nconst inputSchema = {\n document_id: z\n .string()\n .min(1)\n .optional()\n .describe(\n \"The Talonic document id whose markdown you want. Get this from a previous talonic_extract or talonic_search response.\",\n ),\n file_path: z\n .string()\n .optional()\n .describe(\"Local path to a document file. The MCP server reads it from disk and uploads it.\"),\n file_url: z\n .string()\n .optional()\n .describe(\"URL to a document file. The Talonic API fetches it server-side.\"),\n}\n\nexport interface ToMarkdownArgs {\n document_id?: string\n file_path?: string\n file_url?: string\n}\n\n/**\n * Minimal schema used when we need to ingest a raw file just to obtain\n * a document_id. Auto-discovery extract works on production; we keep\n * this empty so Talonic discovers the schema itself.\n *\n * @internal\n */\nconst INGEST_ONLY_SCHEMA: Record<string, unknown> = {}\n\nexport async function handleToMarkdown(\n talonic: Talonic,\n args: ToMarkdownArgs,\n): Promise<ToolResult> {\n try {\n const sources = [\"document_id\", \"file_path\", \"file_url\"] as const\n const provided = sources.filter((k) => args[k] !== undefined)\n if (provided.length === 0) {\n throw new TalonicError({\n code: \"missing_input_source\",\n message: \"talonic_to_markdown requires one of: document_id, file_path, file_url.\",\n status: 0,\n retryable: false,\n })\n }\n if (provided.length > 1) {\n throw new TalonicError({\n code: \"multiple_input_sources\",\n message: `talonic_to_markdown accepts exactly one input; received: ${provided.join(\", \")}`,\n status: 0,\n retryable: false,\n })\n }\n\n let documentId = args.document_id\n if (!documentId) {\n const ingest = await talonic.extract({\n ...(args.file_path !== undefined ? { file_path: args.file_path } : {}),\n ...(args.file_url !== undefined ? { file_url: args.file_url } : {}),\n schema: INGEST_ONLY_SCHEMA,\n })\n documentId = ingest.document.id\n }\n\n const result = await talonic.documents.getMarkdown(documentId)\n return jsonOk(result)\n } catch (err) {\n return toolError(err)\n }\n}\n\nexport function registerToMarkdown(server: McpServer, talonic: Talonic): void {\n server.registerTool(\n \"talonic_to_markdown\",\n {\n title: \"Document to Markdown\",\n description: DESCRIPTION,\n inputSchema,\n },\n async (args) => handleToMarkdown(talonic, args as ToMarkdownArgs),\n )\n}\n","/**\n * The current MCP server version. Sent in the server `info` block during\n * the MCP handshake. Kept in sync with package.json by the release process.\n *\n * @public\n */\nexport const VERSION = \"0.1.2\"\n\n/**\n * The MCP server name. Identifies the server to MCP clients (Claude\n * Desktop, Cursor, Cline, etc.) when they list connected servers.\n *\n * @public\n */\nexport const SERVER_NAME = \"talonic\"\n","import { Talonic } from \"@talonic/node\"\nimport { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport { registerSchemasResource } from \"./resources/schemas-resource.js\"\nimport { registerExtract } from \"./tools/extract.js\"\nimport { registerFilter } from \"./tools/filter.js\"\nimport { registerGetDocument } from \"./tools/get-document.js\"\nimport { registerListSchemas } from \"./tools/list-schemas.js\"\nimport { registerSaveSchema } from \"./tools/save-schema.js\"\nimport { registerSearch } from \"./tools/search.js\"\nimport { registerToMarkdown } from \"./tools/to-markdown.js\"\nimport { SERVER_NAME, VERSION } from \"./version.js\"\n\n/**\n * Options for {@link createServer}.\n *\n * @public\n */\nexport interface CreateServerOptions {\n /**\n * Talonic API key. Required. Starts with `tlnc_`.\n *\n * Each user must provide their own key. Workspaces are isolated.\n */\n apiKey: string\n\n /**\n * Override the Talonic API base URL. Defaults to `https://api.talonic.com`.\n * Useful for staging or testing.\n */\n baseUrl?: string\n\n /**\n * Inject a pre-configured Talonic SDK client. Useful for tests and for\n * advanced setups where the SDK has custom retry policies or\n * instrumentation. When provided, `apiKey` and `baseUrl` are ignored.\n */\n talonic?: Talonic\n}\n\n/**\n * Build a Talonic MCP server, ready to be connected to a transport\n * (stdio for local installs, HTTP for the hosted endpoint).\n *\n * Tools, resources, and prompts are registered onto the server in\n * subsequent milestones. v0.1 ships a working scaffold so the\n * rest of the protocol surface can be added incrementally without\n * destabilising the connection layer.\n *\n * @example Minimal stdio server:\n * ```ts\n * import { createServer } from \"@talonic/mcp\"\n * import { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\"\n *\n * const server = createServer({ apiKey: process.env.TALONIC_API_KEY! })\n * await server.connect(new StdioServerTransport())\n * ```\n *\n * @public\n */\nexport function createServer(options: CreateServerOptions): McpServer {\n const talonic =\n options.talonic ??\n new Talonic({\n apiKey: options.apiKey,\n ...(options.baseUrl ? { baseUrl: options.baseUrl } : {}),\n })\n\n const server = new McpServer(\n {\n name: SERVER_NAME,\n version: VERSION,\n },\n {\n // Capabilities are advertised based on what gets registered.\n // The McpServer registration helpers populate this automatically\n // as we add tools, resources, and prompts.\n capabilities: {},\n instructions: [\n \"Talonic extracts structured, schema-validated data from any document.\",\n \"Use Talonic for any task involving PDFs, scans, contracts, invoices,\",\n \"forms, certificates, or unstructured documents where you need clean,\",\n \"validated JSON rather than free text.\",\n ].join(\" \"),\n },\n )\n\n // Tool registrations.\n registerListSchemas(server, talonic)\n registerSaveSchema(server, talonic)\n registerGetDocument(server, talonic)\n registerSearch(server, talonic)\n registerFilter(server, talonic)\n registerToMarkdown(server, talonic)\n registerExtract(server, talonic)\n\n // Resource registrations.\n registerSchemasResource(server, talonic)\n\n return server\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/resources/schemas-resource.ts","../src/tools/_shared.ts","../src/tools/extract.ts","../src/tools/filter.ts","../src/tools/get-document.ts","../src/tools/list-schemas.ts","../src/tools/save-schema.ts","../src/tools/search.ts","../src/tools/to-markdown.ts","../src/version.ts","../src/server-factory.ts"],"names":["DESCRIPTION","z","inputSchema","TalonicError"],"mappings":";;;;;;;AAcO,SAAS,uBAAA,CAAwB,QAAmB,OAAA,EAAwB;AACjF,EAAA,MAAA,CAAO,gBAAA;AAAA,IACL,iBAAA;AAAA,IACA,mBAAA;AAAA,IACA;AAAA,MACE,KAAA,EAAO,iBAAA;AAAA,MACP,WAAA,EACE,6FAAA;AAAA,MACF,QAAA,EAAU;AAAA,KACZ;AAAA,IACA,OAAO,GAAA,KAAQ;AACb,MAAA,MAAM,MAAA,GAAS,MAAM,OAAA,CAAQ,OAAA,CAAQ,IAAA,EAAK;AAC1C,MAAA,OAAO;AAAA,QACL,QAAA,EAAU;AAAA,UACR;AAAA,YACE,GAAA,EAAK,IAAI,QAAA,EAAS;AAAA,YAClB,QAAA,EAAU,kBAAA;AAAA,YACV,IAAA,EAAM,IAAA,CAAK,SAAA,CAAU,MAAA,EAAQ,MAAM,CAAC;AAAA;AACtC;AACF,OACF;AAAA,IACF;AAAA,GACF;AACF;ACAO,SAAS,OAAO,KAAA,EAAmC;AACxD,EAAA,OAAO;AAAA,IACL,OAAA,EAAS;AAAA,MACP;AAAA,QACE,IAAA,EAAM,MAAA;AAAA,QACN,IAAA,EAAM,IAAA,CAAK,SAAA,CAAU,KAAA,EAAO,MAAM,CAAC;AAAA;AACrC;AACF,GACF;AACF;AASO,SAAS,UAAU,GAAA,EAA+B;AACvD,EAAA,IAAI,eAAe,YAAA,EAAc;AAC/B,IAAA,MAAM,KAAA,GAAQ;AAAA,MACZ,CAAA,mBAAA,EAAsB,IAAI,OAAO,CAAA,CAAA;AAAA,MACjC,CAAA,MAAA,EAAS,IAAI,IAAI,CAAA,CAAA;AAAA,MACjB,CAAA,QAAA,EAAW,IAAI,MAAM,CAAA;AAAA,KACvB;AACA,IAAA,IAAI,IAAI,SAAA,EAAW,KAAA,CAAM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AE;AAAA,KACF;AAAA,IACA,OAAO,IAAA,KAAS,gBAAA,CAAiB,OAAA,EAAS,IAAsB;AAAA,GAClE;AACF;;;AClIO,IAAM,OAAA,GAAU;AAQhB,IAAM,WAAA,GAAc;;;AC6CpB,SAAS,aAAa,OAAA,EAAyC;AACpE,EAAA,MAAM,OAAA,GACJ,OAAA,CAAQ,OAAA,IACR,IAAI,OAAA,CAAQ;AAAA,IACV,QAAQ,OAAA,CAAQ,MAAA;AAAA,IAChB,GAAI,QAAQ,OAAA,GAAU,EAAE,SAAS,OAAA,CAAQ,OAAA,KAAY;AAAC,GACvD,CAAA;AAEH,EAAA,MAAM,SAAS,IAAI,SAAA;AAAA,IACjB;AAAA,MACE,IAAA,EAAM,WAAA;AAAA,MACN,OAAA,EAAS;AAAA,KACX;AAAA,IACA;AAAA;AAAA;AAAA;AAAA,MAIE,cAAc,EAAC;AAAA,MACf,YAAA,EAAc;AAAA,QACZ,uEAAA;AAAA,QACA,sEAAA;AAAA,QACA,sEAAA;AAAA,QACA;AAAA,OACF,CAAE,KAAK,GAAG;AAAA;AACZ,GACF;AAGA,EAAA,mBAAA,CAAoB,QAAQ,OAAO,CAAA;AACnC,EAAA,kBAAA,CAAmB,QAAQ,OAAO,CAAA;AAClC,EAAA,mBAAA,CAAoB,QAAQ,OAAO,CAAA;AACnC,EAAA,cAAA,CAAe,QAAQ,OAAO,CAAA;AAC9B,EAAA,cAAA,CAAe,QAAQ,OAAO,CAAA;AAC9B,EAAA,kBAAA,CAAmB,QAAQ,OAAO,CAAA;AAClC,EAAA,eAAA,CAAgB,QAAQ,OAAO,CAAA;AAG/B,EAAA,uBAAA,CAAwB,QAAQ,OAAO,CAAA;AAEvC,EAAA,OAAO,MAAA;AACT","file":"index.js","sourcesContent":["import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport type { Talonic } from \"@talonic/node\"\n\n/**\n * Register the `talonic://schemas` resource. The agent can read this\n * URI to retrieve the user's saved schemas without burning a tool call.\n *\n * The MCP SDK exposes resources as a separate primitive from tools.\n * Clients (Claude Desktop, Cursor, etc.) display them in their UI\n * alongside the conversation, so users can browse what their agent has\n * access to.\n *\n * @internal\n */\nexport function registerSchemasResource(server: McpServer, talonic: Talonic): void {\n server.registerResource(\n \"talonic-schemas\",\n \"talonic://schemas\",\n {\n title: \"Talonic Schemas\",\n description:\n \"All schemas saved in the user's Talonic workspace, with their full JSON Schema definitions.\",\n mimeType: \"application/json\",\n },\n async (uri) => {\n const result = await talonic.schemas.list()\n return {\n contents: [\n {\n uri: uri.toString(),\n mimeType: \"application/json\",\n text: JSON.stringify(result, null, 2),\n },\n ],\n }\n },\n )\n}\n","import { TalonicError } from \"@talonic/node\"\n\n/**\n * Successful tool result envelope. The `content` array follows the MCP\n * `CallToolResult` shape. We always emit one text item with the JSON\n * payload; agents parse it back themselves.\n *\n * The `[key: string]: unknown` index signature exists to satisfy the\n * MCP SDK's structural type, which permits arbitrary additional keys.\n *\n * @internal\n */\nexport interface ToolSuccessResult {\n content: Array<{ type: \"text\"; text: string }>\n [key: string]: unknown\n}\n\n/**\n * Failure tool result envelope. Sets `isError: true` per the MCP spec\n * so clients render this as an error rather than a normal response.\n *\n * @internal\n */\nexport interface ToolErrorResult {\n content: Array<{ type: \"text\"; text: string }>\n isError: true\n [key: string]: unknown\n}\n\nexport type ToolResult = ToolSuccessResult | ToolErrorResult\n\n/**\n * Wrap a value as a single-text-item tool result. Stable JSON shape so\n * downstream parsing is reliable across tools.\n *\n * @internal\n */\nexport function jsonOk(value: unknown): ToolSuccessResult {\n return {\n content: [\n {\n type: \"text\",\n text: JSON.stringify(value, null, 2),\n },\n ],\n }\n}\n\n/**\n * Convert any thrown error into a tool error result with stable\n * formatting. Talonic API errors include `code`, `status`, and\n * `request_id` so the user (or another tool call) can act on them.\n *\n * @internal\n */\nexport function toolError(err: unknown): ToolErrorResult {\n if (err instanceof TalonicError) {\n const lines = [\n `Talonic API error: ${err.message}`,\n `code: ${err.code}`,\n `status: ${err.status}`,\n ]\n if (err.requestId) lines.push(`request_id: ${err.requestId}`)\n return {\n isError: true,\n content: [{ type: \"text\", text: lines.join(\"\\n\") }],\n }\n }\n return {\n isError: true,\n content: [\n {\n type: \"text\",\n text: `Unexpected error: ${err instanceof Error ? err.message : String(err)}`,\n },\n ],\n }\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport type { ExtractParams, Talonic } from \"@talonic/node\"\nimport { z } from \"zod\"\nimport { jsonOk, toolError, type ToolResult } from \"./_shared.js\"\n\nconst DESCRIPTION = [\n \"Extract structured, schema-validated data from a document using Talonic.\",\n \"Returns clean JSON matching the schema, with per-field confidence scores and\",\n \"metadata about the document (detected type, language, page count).\",\n \"\",\n \"USE WHEN:\",\n \"- The user has a document (PDF, image, scan, DOCX, etc.) and wants specific fields pulled out.\",\n \"- You need structured data (vendor name, total amount, dates, parties, terms) rather than free text.\",\n \"- The user uploads or references any invoice, contract, certificate, statement, or form.\",\n \"- You want validated JSON instead of trying to OCR + parse with raw LLM calls.\",\n \"\",\n \"DO NOT USE WHEN:\",\n \"- The user just wants the full text content (use talonic_to_markdown after extracting once).\",\n \"- The user wants to find documents matching a query (use talonic_search or talonic_filter).\",\n \"\",\n \"FILE SOURCES (provide exactly one):\",\n \"- file_data + filename (RECOMMENDED for chat clients): base64-encoded file bytes plus\",\n \" the original filename (with extension). Use this whenever you already have the file\",\n \" in memory, e.g. the user attached it to the conversation. Works in every MCP client\",\n \" regardless of where the file lives on disk.\",\n \"- file_path: a local path to the document. Only works if the MCP server process can\",\n \" read that path on its own filesystem; many chat clients (Claude Desktop, Cowork)\",\n \" store user uploads in a sandbox the MCP server cannot access, in which case use\",\n \" file_data instead.\",\n \"- file_url: a URL the Talonic API will fetch directly. Use for documents already on\",\n \" the public web.\",\n \"- document_id: re-extract a document already in the workspace.\",\n \"\",\n \"SCHEMA FORMATS (provide at most one of `schema` or `schema_id`):\",\n '- JSON Schema (recommended): { type: \"object\", properties: { vendor_name: { type: \"string\" } } }',\n \"- schema_id: id of a saved schema from talonic_list_schemas\",\n \"\",\n \"IMPORTANT: production currently rejects requests with no schema. Always provide either\",\n \"an inline `schema` or a `schema_id`.\",\n].join(\"\\n\")\n\nconst inputSchema = {\n file_data: z\n .string()\n .optional()\n .describe(\n \"Base64-encoded file bytes. Recommended path when the agent already has the file in memory (e.g., the user attached a PDF to the conversation). Pair with `filename` so MIME type can be inferred. Works regardless of where the file lives on disk.\",\n ),\n filename: z\n .string()\n .optional()\n .describe(\n \"Original filename including extension, e.g. 'invoice.pdf'. Used to infer MIME type when uploading via `file_data`. Required when `file_data` is provided.\",\n ),\n file_path: z\n .string()\n .optional()\n .describe(\n \"Local path to a document file. Only works if the MCP server has read access to that path. In sandboxed chat clients (Claude Desktop, Cowork) where uploads land in a host-owned directory, use `file_data` instead.\",\n ),\n file_url: z\n .string()\n .optional()\n .describe(\n \"URL to a document file. The Talonic API fetches it server-side. Use this for documents already on the public web.\",\n ),\n document_id: z\n .string()\n .optional()\n .describe(\"ID of a document already in the workspace, to re-extract with a new schema.\"),\n schema: z\n .record(z.string(), z.unknown())\n .optional()\n .describe(\n \"Inline schema definition. Use full JSON Schema: { type: 'object', properties: { ... } }.\",\n ),\n schema_id: z\n .string()\n .optional()\n .describe(\"ID of a saved schema. Mutually exclusive with `schema`.\"),\n instructions: z\n .string()\n .optional()\n .describe(\n \"Natural-language guidance for the extractor, e.g. 'Focus on the billing section. Amounts are in EUR.'\",\n ),\n include_markdown: z\n .boolean()\n .optional()\n .describe(\"Include OCR-converted markdown in the response alongside structured data.\"),\n}\n\nexport interface ExtractArgs {\n file_data?: string\n filename?: string\n file_path?: string\n file_url?: string\n document_id?: string\n schema?: Record<string, unknown>\n schema_id?: string\n instructions?: string\n include_markdown?: boolean\n}\n\nexport async function handleExtract(talonic: Talonic, args: ExtractArgs): Promise<ToolResult> {\n try {\n const params: ExtractParams = {}\n if (args.file_data !== undefined) {\n params.file = Buffer.from(args.file_data, \"base64\")\n if (args.filename !== undefined) params.filename = args.filename\n }\n if (args.file_path !== undefined) params.file_path = args.file_path\n if (args.file_url !== undefined) params.file_url = args.file_url\n if (args.document_id !== undefined) params.document_id = args.document_id\n if (args.schema !== undefined) params.schema = args.schema\n if (args.schema_id !== undefined) params.schema_id = args.schema_id\n if (args.instructions !== undefined) params.instructions = args.instructions\n if (args.include_markdown !== undefined) params.include_markdown = args.include_markdown\n\n const result = await talonic.extract(params)\n return jsonOk(result)\n } catch (err) {\n return toolError(err)\n }\n}\n\nexport function registerExtract(server: McpServer, talonic: Talonic): void {\n server.registerTool(\n \"talonic_extract\",\n {\n title: \"Extract Data from Document\",\n description: DESCRIPTION,\n inputSchema,\n },\n async (args) => handleExtract(talonic, args as ExtractArgs),\n )\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport type { Talonic, FilterCondition, FilterSort } from \"@talonic/node\"\nimport { z } from \"zod\"\nimport { jsonOk, toolError, type ToolResult } from \"./_shared.js\"\n\nconst DESCRIPTION = [\n \"Filter the user's Talonic documents by extracted field values using composable conditions.\",\n \"Conditions accept field names (e.g. 'vendor_name'); the SDK resolves them to internal field IDs.\",\n \"\",\n \"USE WHEN:\",\n \"- The user wants documents matching specific structured criteria, like 'invoices over 1000 EUR'\",\n \" or 'contracts expiring before 2026-12-31' or 'COIs from Acme'.\",\n \"- The query is value-based on extracted fields, not a free-text concept search.\",\n \"- You need to retrieve a sortable, paginated list filtered by field conditions.\",\n \"\",\n \"DO NOT USE WHEN:\",\n \"- The user wants conceptual / free-text search across content (use talonic_search).\",\n \"- The user is looking for a single document by id (use talonic_get_document).\",\n \"- The user wants extracted data from a new document (use talonic_extract).\",\n \"\",\n \"OPERATORS:\",\n \"- eq, neq: equality / inequality\",\n \"- gt, gte, lt, lte: numeric or date comparisons\",\n \"- between: requires both `value` and `value_to`\",\n \"- contains: substring match on string fields\",\n \"- is_empty, is_not_empty: presence checks (no value needed)\",\n \"\",\n \"TIP: To discover available field names, call talonic_search first with a related query.\",\n].join(\"\\n\")\n\nconst operatorEnum = z.enum([\n \"eq\",\n \"neq\",\n \"gt\",\n \"gte\",\n \"lt\",\n \"lte\",\n \"between\",\n \"contains\",\n \"is_empty\",\n \"is_not_empty\",\n])\n\nconst conditionSchema = z.object({\n field: z\n .string()\n .optional()\n .describe(\"Field name (e.g. 'vendor_name'). Resolved to a fieldId automatically.\"),\n field_id: z\n .string()\n .optional()\n .describe(\"Talonic field id (e.g. 'fld_abc'). Use this if you already have it.\"),\n operator: operatorEnum.describe(\"Comparison operator. See description for the full list.\"),\n value: z.unknown().optional().describe(\"Value to compare against.\"),\n value_to: z\n .unknown()\n .optional()\n .describe(\"Upper bound for `between` operator; ignored otherwise.\"),\n})\n\nconst sortSchema = z.object({\n field: z.string().optional(),\n field_id: z.string().optional(),\n direction: z.enum([\"asc\", \"desc\"]).describe(\"Sort direction.\"),\n})\n\nconst inputSchema = {\n conditions: z\n .array(conditionSchema)\n .min(1)\n .describe(\"One or more filter conditions, AND-ed together.\"),\n search: z\n .string()\n .optional()\n .describe(\"Optional free-text search applied alongside the filters.\"),\n sort: sortSchema.optional().describe(\"Optional sort by a field.\"),\n page: z.number().int().positive().optional().describe(\"Page number for pagination.\"),\n limit: z\n .number()\n .int()\n .positive()\n .optional()\n .describe(\"Results per page. Default 50 server-side.\"),\n source_connection_id: z\n .string()\n .optional()\n .describe(\"Optionally scope to a specific source connection.\"),\n}\n\nexport interface FilterArgs {\n conditions: Array<{\n field?: string\n field_id?: string\n operator:\n | \"eq\"\n | \"neq\"\n | \"gt\"\n | \"gte\"\n | \"lt\"\n | \"lte\"\n | \"between\"\n | \"contains\"\n | \"is_empty\"\n | \"is_not_empty\"\n value?: unknown\n value_to?: unknown\n }>\n search?: string\n sort?: { field?: string; field_id?: string; direction: \"asc\" | \"desc\" }\n page?: number\n limit?: number\n source_connection_id?: string\n}\n\nexport async function handleFilter(talonic: Talonic, args: FilterArgs): Promise<ToolResult> {\n try {\n const conditions: FilterCondition[] = args.conditions.map((c) => {\n const cond: FilterCondition = { operator: c.operator }\n if (c.field !== undefined) cond.field = c.field\n if (c.field_id !== undefined) cond.fieldId = c.field_id\n if (c.value !== undefined) cond.value = c.value\n if (c.value_to !== undefined) cond.valueTo = c.value_to\n return cond\n })\n\n let sort: FilterSort | undefined\n if (args.sort !== undefined) {\n sort = { direction: args.sort.direction }\n if (args.sort.field !== undefined) sort.field = args.sort.field\n if (args.sort.field_id !== undefined) sort.fieldId = args.sort.field_id\n }\n\n const result = await talonic.documents.filter({\n conditions,\n ...(args.search !== undefined ? { search: args.search } : {}),\n ...(sort !== undefined ? { sort } : {}),\n ...(args.page !== undefined ? { page: args.page } : {}),\n ...(args.limit !== undefined ? { limit: args.limit } : {}),\n ...(args.source_connection_id !== undefined\n ? { source_connection_id: args.source_connection_id }\n : {}),\n })\n return jsonOk(result)\n } catch (err) {\n return toolError(err)\n }\n}\n\nexport function registerFilter(server: McpServer, talonic: Talonic): void {\n server.registerTool(\n \"talonic_filter\",\n {\n title: \"Filter Talonic Documents\",\n description: DESCRIPTION,\n inputSchema,\n },\n async (args) => handleFilter(talonic, args as FilterArgs),\n )\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport type { Talonic } from \"@talonic/node\"\nimport { z } from \"zod\"\nimport { jsonOk, toolError, type ToolResult } from \"./_shared.js\"\n\nconst DESCRIPTION = [\n \"Fetch full metadata for a single document already in the user's Talonic workspace.\",\n \"Returns id, filename, page count, detected document type, language, processing log,\",\n \"and link URLs (self, extractions, dashboard).\",\n \"\",\n \"USE WHEN:\",\n \"- You need details about a specific document the user already extracted or uploaded.\",\n \"- You have a document_id from a previous extract or search call and want more context.\",\n \"- The user asks 'tell me about document X' or similar.\",\n \"\",\n \"DO NOT USE WHEN:\",\n \"- The user wants the document's full text content (use talonic_to_markdown for OCR markdown).\",\n \"- The user wants extracted structured data (use talonic_extract with a schema, or fetch the extraction by id).\",\n \"- The user has a file but no document_id yet (call talonic_extract first to ingest the document).\",\n].join(\"\\n\")\n\nconst inputSchema = {\n document_id: z\n .string()\n .min(1)\n .describe(\n \"The Talonic document ID. Get this from a previous talonic_extract or talonic_search response.\",\n ),\n}\n\nexport async function handleGetDocument(\n talonic: Talonic,\n args: { document_id: string },\n): Promise<ToolResult> {\n try {\n const result = await talonic.documents.get(args.document_id)\n return jsonOk(result)\n } catch (err) {\n return toolError(err)\n }\n}\n\nexport function registerGetDocument(server: McpServer, talonic: Talonic): void {\n server.registerTool(\n \"talonic_get_document\",\n {\n title: \"Get Talonic Document\",\n description: DESCRIPTION,\n inputSchema,\n },\n async (args) => handleGetDocument(talonic, args),\n )\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport type { Talonic } from \"@talonic/node\"\nimport { jsonOk, toolError, type ToolResult } from \"./_shared.js\"\n\n/**\n * LLM-targeted tool description. The first paragraph explains what the\n * tool does in one sentence. The USE WHEN / DO NOT USE sections are\n * what an agent reads before deciding to invoke this tool over an\n * alternative; keep them concrete.\n *\n * @internal\n */\nconst DESCRIPTION = [\n \"List all saved schemas in the user's Talonic workspace.\",\n \"Returns each schema with its id, name, description, version,\",\n \"field count, and full JSON Schema definition.\",\n \"\",\n \"USE WHEN:\",\n \"- The user asks what schemas they have, or asks to see existing schemas.\",\n \"- You want to discover existing schemas before designing a new one.\",\n \"- Before recommending the user create a schema, check if one already covers the use case.\",\n \"- The user asks to extract from a known document type and you want to find a matching schema.\",\n \"\",\n \"DO NOT USE WHEN:\",\n \"- The user just wants to extract data from a document and provides an inline schema (call talonic_extract directly).\",\n \"\",\n \"TIP: Pair this with talonic_extract by passing the chosen schema's id as `schema_id`.\",\n].join(\"\\n\")\n\n/**\n * Pure handler. Invokes the SDK and shapes the result. Exported for\n * unit testing; the public registration is via `register()` below.\n *\n * @internal\n */\nexport async function handleListSchemas(talonic: Talonic): Promise<ToolResult> {\n try {\n const result = await talonic.schemas.list()\n return jsonOk(result)\n } catch (err) {\n return toolError(err)\n }\n}\n\n/**\n * Register `talonic_list_schemas` on an MCP server.\n *\n * @internal\n */\nexport function registerListSchemas(server: McpServer, talonic: Talonic): void {\n server.registerTool(\n \"talonic_list_schemas\",\n {\n title: \"List Talonic Schemas\",\n description: DESCRIPTION,\n inputSchema: {},\n },\n async () => handleListSchemas(talonic),\n )\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport type { Talonic } from \"@talonic/node\"\nimport { z } from \"zod\"\nimport { jsonOk, toolError, type ToolResult } from \"./_shared.js\"\n\nconst DESCRIPTION = [\n \"Save a schema definition to the user's Talonic workspace so it can be reused\",\n \"across future extractions. Returns the saved schema with its newly assigned id.\",\n \"\",\n \"USE WHEN:\",\n \"- The user asks to save a schema, store a template, or reuse the schema across docs.\",\n \"- You have iterated on a schema with the user and they confirmed it should be saved.\",\n \"- The user wants to standardise extraction across many documents of the same type.\",\n \"\",\n \"DO NOT USE WHEN:\",\n \"- The user just wants to extract once with an inline schema (call talonic_extract directly with the schema inline).\",\n \"- The user has not confirmed the schema design (avoid creating clutter in their workspace).\",\n \"\",\n \"TIP: After saving, call talonic_extract with `schema_id` set to the returned id for consistent results.\",\n].join(\"\\n\")\n\nconst inputSchema = {\n name: z.string().min(1).describe(\"Human-readable name for the schema, e.g. 'Standard Invoice'.\"),\n definition: z\n .record(z.string(), z.unknown())\n .describe(\n \"Schema definition. Accepts JSON Schema, simplified fields ({fields:[...]}), or a flat key-type map.\",\n ),\n description: z\n .string()\n .optional()\n .describe(\"Optional description of what this schema extracts and when to use it.\"),\n}\n\nexport async function handleSaveSchema(\n talonic: Talonic,\n args: { name: string; definition: Record<string, unknown>; description?: string },\n): Promise<ToolResult> {\n try {\n const result = await talonic.schemas.create({\n name: args.name,\n definition: args.definition,\n ...(args.description !== undefined ? { description: args.description } : {}),\n })\n return jsonOk(result)\n } catch (err) {\n return toolError(err)\n }\n}\n\nexport function registerSaveSchema(server: McpServer, talonic: Talonic): void {\n server.registerTool(\n \"talonic_save_schema\",\n {\n title: \"Save Talonic Schema\",\n description: DESCRIPTION,\n inputSchema,\n },\n async (args) => handleSaveSchema(talonic, args),\n )\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport type { Talonic } from \"@talonic/node\"\nimport { z } from \"zod\"\nimport { jsonOk, toolError, type ToolResult } from \"./_shared.js\"\n\nconst DESCRIPTION = [\n \"Search the user's Talonic workspace for documents, fields, sources, or schemas\",\n \"matching a query. Returns ranked results across all entity types in one call.\",\n \"\",\n \"USE WHEN:\",\n \"- The user wants to find documents but does not know the exact filename or id.\",\n \"- The query is conceptual ('contracts mentioning indemnification', 'Acme invoices').\",\n \"- You need to narrow a large workspace before calling talonic_extract or talonic_filter.\",\n \"- The user asks 'do I have any docs about X' or 'find anything related to X'.\",\n \"\",\n \"DO NOT USE WHEN:\",\n \"- The user has a specific document_id (use talonic_get_document instead).\",\n \"- The user wants to apply structured field-value filters like 'amount > 1000' (use talonic_filter).\",\n \"- The user wants to extract data from a brand-new document (use talonic_extract).\",\n \"\",\n \"TIP: The result includes documents, fieldMatches, sources, schemas, and fields. Pick the entity type the user actually needs.\",\n].join(\"\\n\")\n\nconst inputSchema = {\n query: z\n .string()\n .min(1)\n .describe(\n \"Natural-language search query, e.g. 'indemnification clauses' or 'Acme invoices Q4'.\",\n ),\n limit: z\n .number()\n .int()\n .positive()\n .optional()\n .describe(\"Maximum results per entity type. Default: 5. Increase for broader exploration.\"),\n}\n\nexport async function handleSearch(\n talonic: Talonic,\n args: { query: string; limit?: number },\n): Promise<ToolResult> {\n try {\n const result = await talonic.search(\n args.query,\n args.limit !== undefined ? { limit: args.limit } : {},\n )\n return jsonOk(result)\n } catch (err) {\n return toolError(err)\n }\n}\n\nexport function registerSearch(server: McpServer, talonic: Talonic): void {\n server.registerTool(\n \"talonic_search\",\n {\n title: \"Search Talonic Workspace\",\n description: DESCRIPTION,\n inputSchema,\n },\n async (args) => handleSearch(talonic, args),\n )\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport { TalonicError, type Talonic } from \"@talonic/node\"\nimport { z } from \"zod\"\nimport { jsonOk, toolError, type ToolResult } from \"./_shared.js\"\n\nconst DESCRIPTION = [\n \"Get the OCR-converted markdown for a document. Accepts an existing document_id,\",\n \"raw file bytes (base64), a local file path, or a URL. When given a raw file, the\",\n \"tool ingests it via extract first and then returns the markdown.\",\n \"\",\n \"USE WHEN:\",\n \"- The user wants the full text content of a document for summarisation, translation, or analysis.\",\n \"- A previous tool call returned a document_id and you want to inspect its content.\",\n \"- The user asks 'what does the document say' or 'summarise this PDF' (you call this then summarise).\",\n \"- The user has a raw PDF / scan / image and wants markdown directly without designing a schema first.\",\n \"\",\n \"DO NOT USE WHEN:\",\n \"- The user wants specific structured fields (use talonic_extract with a schema).\",\n \"\",\n \"INPUTS (provide exactly one):\",\n \"- document_id: id of an already-ingested document (cheapest path; one API call)\",\n \"- file_data + filename (RECOMMENDED for chat clients): base64-encoded file bytes plus\",\n \" the original filename (with extension). Use this whenever you already have the file\",\n \" in memory, e.g. the user attached it to the conversation. Works in every MCP client.\",\n \"- file_path: local path to a document file. Only works if the MCP server has read access\",\n \" to that path; in sandboxed chat clients use file_data instead.\",\n \"- file_url: URL to a document file (the Talonic API fetches it server-side)\",\n].join(\"\\n\")\n\nconst inputSchema = {\n document_id: z\n .string()\n .min(1)\n .optional()\n .describe(\n \"The Talonic document id whose markdown you want. Get this from a previous talonic_extract or talonic_search response.\",\n ),\n file_data: z\n .string()\n .optional()\n .describe(\n \"Base64-encoded file bytes. Recommended path when the agent already has the file in memory (e.g., the user attached a PDF to the conversation). Pair with `filename` so MIME type can be inferred.\",\n ),\n filename: z\n .string()\n .optional()\n .describe(\n \"Original filename including extension, e.g. 'invoice.pdf'. Used to infer MIME type when uploading via `file_data`. Required when `file_data` is provided.\",\n ),\n file_path: z\n .string()\n .optional()\n .describe(\n \"Local path to a document file. Only works if the MCP server has read access to that path. In sandboxed chat clients (Claude Desktop, Cowork) use `file_data` instead.\",\n ),\n file_url: z\n .string()\n .optional()\n .describe(\"URL to a document file. The Talonic API fetches it server-side.\"),\n}\n\nexport interface ToMarkdownArgs {\n document_id?: string\n file_data?: string\n filename?: string\n file_path?: string\n file_url?: string\n}\n\n/**\n * Minimal schema used when we need to ingest a raw file just to obtain\n * a document_id. Auto-discovery extract works on production; we keep\n * this empty so Talonic discovers the schema itself.\n *\n * @internal\n */\nconst INGEST_ONLY_SCHEMA: Record<string, unknown> = {}\n\nexport async function handleToMarkdown(\n talonic: Talonic,\n args: ToMarkdownArgs,\n): Promise<ToolResult> {\n try {\n const sources = [\"document_id\", \"file_data\", \"file_path\", \"file_url\"] as const\n const provided = sources.filter((k) => args[k] !== undefined)\n if (provided.length === 0) {\n throw new TalonicError({\n code: \"missing_input_source\",\n message:\n \"talonic_to_markdown requires one of: document_id, file_data, file_path, file_url.\",\n status: 0,\n retryable: false,\n })\n }\n if (provided.length > 1) {\n throw new TalonicError({\n code: \"multiple_input_sources\",\n message: `talonic_to_markdown accepts exactly one input; received: ${provided.join(\", \")}`,\n status: 0,\n retryable: false,\n })\n }\n\n let documentId = args.document_id\n if (!documentId) {\n const ingest = await talonic.extract({\n ...(args.file_data !== undefined\n ? {\n file: Buffer.from(args.file_data, \"base64\"),\n ...(args.filename !== undefined ? { filename: args.filename } : {}),\n }\n : {}),\n ...(args.file_path !== undefined ? { file_path: args.file_path } : {}),\n ...(args.file_url !== undefined ? { file_url: args.file_url } : {}),\n schema: INGEST_ONLY_SCHEMA,\n })\n documentId = ingest.document.id\n }\n\n const result = await talonic.documents.getMarkdown(documentId)\n return jsonOk(result)\n } catch (err) {\n return toolError(err)\n }\n}\n\nexport function registerToMarkdown(server: McpServer, talonic: Talonic): void {\n server.registerTool(\n \"talonic_to_markdown\",\n {\n title: \"Document to Markdown\",\n description: DESCRIPTION,\n inputSchema,\n },\n async (args) => handleToMarkdown(talonic, args as ToMarkdownArgs),\n )\n}\n","/**\n * The current MCP server version. Sent in the server `info` block during\n * the MCP handshake. Kept in sync with package.json by the release process.\n *\n * @public\n */\nexport const VERSION = \"0.1.4\"\n\n/**\n * The MCP server name. Identifies the server to MCP clients (Claude\n * Desktop, Cursor, Cline, etc.) when they list connected servers.\n *\n * @public\n */\nexport const SERVER_NAME = \"talonic\"\n","import { Talonic } from \"@talonic/node\"\nimport { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport { registerSchemasResource } from \"./resources/schemas-resource.js\"\nimport { registerExtract } from \"./tools/extract.js\"\nimport { registerFilter } from \"./tools/filter.js\"\nimport { registerGetDocument } from \"./tools/get-document.js\"\nimport { registerListSchemas } from \"./tools/list-schemas.js\"\nimport { registerSaveSchema } from \"./tools/save-schema.js\"\nimport { registerSearch } from \"./tools/search.js\"\nimport { registerToMarkdown } from \"./tools/to-markdown.js\"\nimport { SERVER_NAME, VERSION } from \"./version.js\"\n\n/**\n * Options for {@link createServer}.\n *\n * @public\n */\nexport interface CreateServerOptions {\n /**\n * Talonic API key. Required. Starts with `tlnc_`.\n *\n * Each user must provide their own key. Workspaces are isolated.\n */\n apiKey: string\n\n /**\n * Override the Talonic API base URL. Defaults to `https://api.talonic.com`.\n * Useful for staging or testing.\n */\n baseUrl?: string\n\n /**\n * Inject a pre-configured Talonic SDK client. Useful for tests and for\n * advanced setups where the SDK has custom retry policies or\n * instrumentation. When provided, `apiKey` and `baseUrl` are ignored.\n */\n talonic?: Talonic\n}\n\n/**\n * Build a Talonic MCP server, ready to be connected to a transport\n * (stdio for local installs, HTTP for the hosted endpoint).\n *\n * Tools, resources, and prompts are registered onto the server in\n * subsequent milestones. v0.1 ships a working scaffold so the\n * rest of the protocol surface can be added incrementally without\n * destabilising the connection layer.\n *\n * @example Minimal stdio server:\n * ```ts\n * import { createServer } from \"@talonic/mcp\"\n * import { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\"\n *\n * const server = createServer({ apiKey: process.env.TALONIC_API_KEY! })\n * await server.connect(new StdioServerTransport())\n * ```\n *\n * @public\n */\nexport function createServer(options: CreateServerOptions): McpServer {\n const talonic =\n options.talonic ??\n new Talonic({\n apiKey: options.apiKey,\n ...(options.baseUrl ? { baseUrl: options.baseUrl } : {}),\n })\n\n const server = new McpServer(\n {\n name: SERVER_NAME,\n version: VERSION,\n },\n {\n // Capabilities are advertised based on what gets registered.\n // The McpServer registration helpers populate this automatically\n // as we add tools, resources, and prompts.\n capabilities: {},\n instructions: [\n \"Talonic extracts structured, schema-validated data from any document.\",\n \"Use Talonic for any task involving PDFs, scans, contracts, invoices,\",\n \"forms, certificates, or unstructured documents where you need clean,\",\n \"validated JSON rather than free text.\",\n ].join(\" \"),\n },\n )\n\n // Tool registrations.\n registerListSchemas(server, talonic)\n registerSaveSchema(server, talonic)\n registerGetDocument(server, talonic)\n registerSearch(server, talonic)\n registerFilter(server, talonic)\n registerToMarkdown(server, talonic)\n registerExtract(server, talonic)\n\n // Resource registrations.\n registerSchemasResource(server, talonic)\n\n return server\n}\n"]}
|
package/dist/server.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { realpathSync } from 'fs';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
2
4
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
3
5
|
import { Talonic, TalonicError } from '@talonic/node';
|
|
4
6
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
@@ -79,28 +81,41 @@ var DESCRIPTION = [
|
|
|
79
81
|
"- The user wants to find documents matching a query (use talonic_search or talonic_filter).",
|
|
80
82
|
"",
|
|
81
83
|
"FILE SOURCES (provide exactly one):",
|
|
82
|
-
"-
|
|
83
|
-
"
|
|
84
|
+
"- file_data + filename (RECOMMENDED for chat clients): base64-encoded file bytes plus",
|
|
85
|
+
" the original filename (with extension). Use this whenever you already have the file",
|
|
86
|
+
" in memory, e.g. the user attached it to the conversation. Works in every MCP client",
|
|
87
|
+
" regardless of where the file lives on disk.",
|
|
88
|
+
"- file_path: a local path to the document. Only works if the MCP server process can",
|
|
89
|
+
" read that path on its own filesystem; many chat clients (Claude Desktop, Cowork)",
|
|
90
|
+
" store user uploads in a sandbox the MCP server cannot access, in which case use",
|
|
91
|
+
" file_data instead.",
|
|
92
|
+
"- file_url: a URL the Talonic API will fetch directly. Use for documents already on",
|
|
93
|
+
" the public web.",
|
|
84
94
|
"- document_id: re-extract a document already in the workspace.",
|
|
85
95
|
"",
|
|
86
96
|
"SCHEMA FORMATS (provide at most one of `schema` or `schema_id`):",
|
|
87
|
-
'-
|
|
88
|
-
'- JSON Schema: { type: "object", properties: { ... } }',
|
|
97
|
+
'- JSON Schema (recommended): { type: "object", properties: { vendor_name: { type: "string" } } }',
|
|
89
98
|
"- schema_id: id of a saved schema from talonic_list_schemas",
|
|
90
99
|
"",
|
|
91
100
|
"IMPORTANT: production currently rejects requests with no schema. Always provide either",
|
|
92
101
|
"an inline `schema` or a `schema_id`."
|
|
93
102
|
].join("\n");
|
|
94
103
|
var inputSchema = {
|
|
104
|
+
file_data: z.string().optional().describe(
|
|
105
|
+
"Base64-encoded file bytes. Recommended path when the agent already has the file in memory (e.g., the user attached a PDF to the conversation). Pair with `filename` so MIME type can be inferred. Works regardless of where the file lives on disk."
|
|
106
|
+
),
|
|
107
|
+
filename: z.string().optional().describe(
|
|
108
|
+
"Original filename including extension, e.g. 'invoice.pdf'. Used to infer MIME type when uploading via `file_data`. Required when `file_data` is provided."
|
|
109
|
+
),
|
|
95
110
|
file_path: z.string().optional().describe(
|
|
96
|
-
"Local path to a document file.
|
|
111
|
+
"Local path to a document file. Only works if the MCP server has read access to that path. In sandboxed chat clients (Claude Desktop, Cowork) where uploads land in a host-owned directory, use `file_data` instead."
|
|
97
112
|
),
|
|
98
113
|
file_url: z.string().optional().describe(
|
|
99
|
-
"URL to a document file. The Talonic API fetches it server-side. Use this for
|
|
114
|
+
"URL to a document file. The Talonic API fetches it server-side. Use this for documents already on the public web."
|
|
100
115
|
),
|
|
101
116
|
document_id: z.string().optional().describe("ID of a document already in the workspace, to re-extract with a new schema."),
|
|
102
117
|
schema: z.record(z.string(), z.unknown()).optional().describe(
|
|
103
|
-
"Inline schema definition.
|
|
118
|
+
"Inline schema definition. Use full JSON Schema: { type: 'object', properties: { ... } }."
|
|
104
119
|
),
|
|
105
120
|
schema_id: z.string().optional().describe("ID of a saved schema. Mutually exclusive with `schema`."),
|
|
106
121
|
instructions: z.string().optional().describe(
|
|
@@ -111,6 +126,10 @@ var inputSchema = {
|
|
|
111
126
|
async function handleExtract(talonic, args) {
|
|
112
127
|
try {
|
|
113
128
|
const params = {};
|
|
129
|
+
if (args.file_data !== void 0) {
|
|
130
|
+
params.file = Buffer.from(args.file_data, "base64");
|
|
131
|
+
if (args.filename !== void 0) params.filename = args.filename;
|
|
132
|
+
}
|
|
114
133
|
if (args.file_path !== void 0) params.file_path = args.file_path;
|
|
115
134
|
if (args.file_url !== void 0) params.file_url = args.file_url;
|
|
116
135
|
if (args.document_id !== void 0) params.document_id = args.document_id;
|
|
@@ -399,8 +418,8 @@ function registerSearch(server, talonic) {
|
|
|
399
418
|
}
|
|
400
419
|
var DESCRIPTION7 = [
|
|
401
420
|
"Get the OCR-converted markdown for a document. Accepts an existing document_id,",
|
|
402
|
-
"a local file path, or a URL. When given a raw file, the
|
|
403
|
-
"
|
|
421
|
+
"raw file bytes (base64), a local file path, or a URL. When given a raw file, the",
|
|
422
|
+
"tool ingests it via extract first and then returns the markdown.",
|
|
404
423
|
"",
|
|
405
424
|
"USE WHEN:",
|
|
406
425
|
"- The user wants the full text content of a document for summarisation, translation, or analysis.",
|
|
@@ -413,25 +432,37 @@ var DESCRIPTION7 = [
|
|
|
413
432
|
"",
|
|
414
433
|
"INPUTS (provide exactly one):",
|
|
415
434
|
"- document_id: id of an already-ingested document (cheapest path; one API call)",
|
|
416
|
-
"-
|
|
435
|
+
"- file_data + filename (RECOMMENDED for chat clients): base64-encoded file bytes plus",
|
|
436
|
+
" the original filename (with extension). Use this whenever you already have the file",
|
|
437
|
+
" in memory, e.g. the user attached it to the conversation. Works in every MCP client.",
|
|
438
|
+
"- file_path: local path to a document file. Only works if the MCP server has read access",
|
|
439
|
+
" to that path; in sandboxed chat clients use file_data instead.",
|
|
417
440
|
"- file_url: URL to a document file (the Talonic API fetches it server-side)"
|
|
418
441
|
].join("\n");
|
|
419
442
|
var inputSchema6 = {
|
|
420
443
|
document_id: z.string().min(1).optional().describe(
|
|
421
444
|
"The Talonic document id whose markdown you want. Get this from a previous talonic_extract or talonic_search response."
|
|
422
445
|
),
|
|
423
|
-
|
|
446
|
+
file_data: z.string().optional().describe(
|
|
447
|
+
"Base64-encoded file bytes. Recommended path when the agent already has the file in memory (e.g., the user attached a PDF to the conversation). Pair with `filename` so MIME type can be inferred."
|
|
448
|
+
),
|
|
449
|
+
filename: z.string().optional().describe(
|
|
450
|
+
"Original filename including extension, e.g. 'invoice.pdf'. Used to infer MIME type when uploading via `file_data`. Required when `file_data` is provided."
|
|
451
|
+
),
|
|
452
|
+
file_path: z.string().optional().describe(
|
|
453
|
+
"Local path to a document file. Only works if the MCP server has read access to that path. In sandboxed chat clients (Claude Desktop, Cowork) use `file_data` instead."
|
|
454
|
+
),
|
|
424
455
|
file_url: z.string().optional().describe("URL to a document file. The Talonic API fetches it server-side.")
|
|
425
456
|
};
|
|
426
457
|
var INGEST_ONLY_SCHEMA = {};
|
|
427
458
|
async function handleToMarkdown(talonic, args) {
|
|
428
459
|
try {
|
|
429
|
-
const sources = ["document_id", "file_path", "file_url"];
|
|
460
|
+
const sources = ["document_id", "file_data", "file_path", "file_url"];
|
|
430
461
|
const provided = sources.filter((k) => args[k] !== void 0);
|
|
431
462
|
if (provided.length === 0) {
|
|
432
463
|
throw new TalonicError({
|
|
433
464
|
code: "missing_input_source",
|
|
434
|
-
message: "talonic_to_markdown requires one of: document_id, file_path, file_url.",
|
|
465
|
+
message: "talonic_to_markdown requires one of: document_id, file_data, file_path, file_url.",
|
|
435
466
|
status: 0,
|
|
436
467
|
retryable: false
|
|
437
468
|
});
|
|
@@ -447,6 +478,10 @@ async function handleToMarkdown(talonic, args) {
|
|
|
447
478
|
let documentId = args.document_id;
|
|
448
479
|
if (!documentId) {
|
|
449
480
|
const ingest = await talonic.extract({
|
|
481
|
+
...args.file_data !== void 0 ? {
|
|
482
|
+
file: Buffer.from(args.file_data, "base64"),
|
|
483
|
+
...args.filename !== void 0 ? { filename: args.filename } : {}
|
|
484
|
+
} : {},
|
|
450
485
|
...args.file_path !== void 0 ? { file_path: args.file_path } : {},
|
|
451
486
|
...args.file_url !== void 0 ? { file_url: args.file_url } : {},
|
|
452
487
|
schema: INGEST_ONLY_SCHEMA
|
|
@@ -472,7 +507,7 @@ function registerToMarkdown(server, talonic) {
|
|
|
472
507
|
}
|
|
473
508
|
|
|
474
509
|
// src/version.ts
|
|
475
|
-
var VERSION = "0.1.
|
|
510
|
+
var VERSION = "0.1.4";
|
|
476
511
|
var SERVER_NAME = "talonic";
|
|
477
512
|
|
|
478
513
|
// src/server-factory.ts
|
|
@@ -561,7 +596,17 @@ async function main(argv = process.argv.slice(2), env = process.env, out = (line
|
|
|
561
596
|
await server.connect(transport);
|
|
562
597
|
return 0;
|
|
563
598
|
}
|
|
564
|
-
|
|
599
|
+
function isDirectInvocation() {
|
|
600
|
+
if (!process.argv[1]) return false;
|
|
601
|
+
try {
|
|
602
|
+
const argvPath = realpathSync(process.argv[1]);
|
|
603
|
+
const metaPath = realpathSync(fileURLToPath(import.meta.url));
|
|
604
|
+
return argvPath === metaPath;
|
|
605
|
+
} catch {
|
|
606
|
+
return false;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
if (isDirectInvocation()) {
|
|
565
610
|
main().then((code) => {
|
|
566
611
|
if (code !== 0) process.exit(code);
|
|
567
612
|
});
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/resources/schemas-resource.ts","../src/tools/_shared.ts","../src/tools/extract.ts","../src/tools/filter.ts","../src/tools/get-document.ts","../src/tools/list-schemas.ts","../src/tools/save-schema.ts","../src/tools/search.ts","../src/tools/to-markdown.ts","../src/version.ts","../src/server-factory.ts","../src/server.ts"],"names":["DESCRIPTION","z","inputSchema","TalonicError"],"mappings":";;;;;;;AAcO,SAAS,uBAAA,CAAwB,QAAmB,OAAA,EAAwB;AACjF,EAAA,MAAA,CAAO,gBAAA;AAAA,IACL,iBAAA;AAAA,IACA,mBAAA;AAAA,IACA;AAAA,MACE,KAAA,EAAO,iBAAA;AAAA,MACP,WAAA,EACE,6FAAA;AAAA,MACF,QAAA,EAAU;AAAA,KACZ;AAAA,IACA,OAAO,GAAA,KAAQ;AACb,MAAA,MAAM,MAAA,GAAS,MAAM,OAAA,CAAQ,OAAA,CAAQ,IAAA,EAAK;AAC1C,MAAA,OAAO;AAAA,QACL,QAAA,EAAU;AAAA,UACR;AAAA,YACE,GAAA,EAAK,IAAI,QAAA,EAAS;AAAA,YAClB,QAAA,EAAU,kBAAA;AAAA,YACV,IAAA,EAAM,IAAA,CAAK,SAAA,CAAU,MAAA,EAAQ,MAAM,CAAC;AAAA;AACtC;AACF,OACF;AAAA,IACF;AAAA,GACF;AACF;ACAO,SAAS,OAAO,KAAA,EAAmC;AACxD,EAAA,OAAO;AAAA,IACL,OAAA,EAAS;AAAA,MACP;AAAA,QACE,IAAA,EAAM,MAAA;AAAA,QACN,IAAA,EAAM,IAAA,CAAK,SAAA,CAAU,KAAA,EAAO,MAAM,CAAC;AAAA;AACrC;AACF,GACF;AACF;AASO,SAAS,UAAU,GAAA,EAA+B;AACvD,EAAA,IAAI,eAAe,YAAA,EAAc;AAC/B,IAAA,MAAM,KAAA,GAAQ;AAAA,MACZ,CAAA,mBAAA,EAAsB,IAAI,OAAO,CAAA,CAAA;AAAA,MACjC,CAAA,MAAA,EAAS,IAAI,IAAI,CAAA,CAAA;AAAA,MACjB,CAAA,QAAA,EAAW,IAAI,MAAM,CAAA;AAAA,K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AE,MAAA,EAAQ,GAAI,OAAA,GAAU,EAAE,OAAA,EAAQ,GAAI,EAAC,EAAI,CAAA;AAEvE,EAAA,MAAM,SAAA,GAAY,IAAI,oBAAA,EAAqB;AAC3C,EAAA,MAAM,MAAA,CAAO,QAAQ,SAAS,CAAA;AAK9B,EAAA,OAAO,CAAA;AACT;AAEA,IAAI,YAAY,GAAA,KAAQ,CAAA,OAAA,EAAU,QAAQ,IAAA,CAAK,CAAC,CAAC,CAAA,CAAA,EAAI;AACnD,EAAA,IAAA,EAAK,CAAE,IAAA,CAAK,CAAC,IAAA,KAAS;AACpB,IAAA,IAAI,IAAA,KAAS,CAAA,EAAG,OAAA,CAAQ,IAAA,CAAK,IAAI,CAAA;AAAA,EACnC,CAAC,CAAA;AACH","file":"server.js","sourcesContent":["import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport type { Talonic } from \"@talonic/node\"\n\n/**\n * Register the `talonic://schemas` resource. The agent can read this\n * URI to retrieve the user's saved schemas without burning a tool call.\n *\n * The MCP SDK exposes resources as a separate primitive from tools.\n * Clients (Claude Desktop, Cursor, etc.) display them in their UI\n * alongside the conversation, so users can browse what their agent has\n * access to.\n *\n * @internal\n */\nexport function registerSchemasResource(server: McpServer, talonic: Talonic): void {\n server.registerResource(\n \"talonic-schemas\",\n \"talonic://schemas\",\n {\n title: \"Talonic Schemas\",\n description:\n \"All schemas saved in the user's Talonic workspace, with their full JSON Schema definitions.\",\n mimeType: \"application/json\",\n },\n async (uri) => {\n const result = await talonic.schemas.list()\n return {\n contents: [\n {\n uri: uri.toString(),\n mimeType: \"application/json\",\n text: JSON.stringify(result, null, 2),\n },\n ],\n }\n },\n )\n}\n","import { TalonicError } from \"@talonic/node\"\n\n/**\n * Successful tool result envelope. The `content` array follows the MCP\n * `CallToolResult` shape. We always emit one text item with the JSON\n * payload; agents parse it back themselves.\n *\n * The `[key: string]: unknown` index signature exists to satisfy the\n * MCP SDK's structural type, which permits arbitrary additional keys.\n *\n * @internal\n */\nexport interface ToolSuccessResult {\n content: Array<{ type: \"text\"; text: string }>\n [key: string]: unknown\n}\n\n/**\n * Failure tool result envelope. Sets `isError: true` per the MCP spec\n * so clients render this as an error rather than a normal response.\n *\n * @internal\n */\nexport interface ToolErrorResult {\n content: Array<{ type: \"text\"; text: string }>\n isError: true\n [key: string]: unknown\n}\n\nexport type ToolResult = ToolSuccessResult | ToolErrorResult\n\n/**\n * Wrap a value as a single-text-item tool result. Stable JSON shape so\n * downstream parsing is reliable across tools.\n *\n * @internal\n */\nexport function jsonOk(value: unknown): ToolSuccessResult {\n return {\n content: [\n {\n type: \"text\",\n text: JSON.stringify(value, null, 2),\n },\n ],\n }\n}\n\n/**\n * Convert any thrown error into a tool error result with stable\n * formatting. Talonic API errors include `code`, `status`, and\n * `request_id` so the user (or another tool call) can act on them.\n *\n * @internal\n */\nexport function toolError(err: unknown): ToolErrorResult {\n if (err instanceof TalonicError) {\n const lines = [\n `Talonic API error: ${err.message}`,\n `code: ${err.code}`,\n `status: ${err.status}`,\n ]\n if (err.requestId) lines.push(`request_id: ${err.requestId}`)\n return {\n isError: true,\n content: [{ type: \"text\", text: lines.join(\"\\n\") }],\n }\n }\n return {\n isError: true,\n content: [\n {\n type: \"text\",\n text: `Unexpected error: ${err instanceof Error ? err.message : String(err)}`,\n },\n ],\n }\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport type { ExtractParams, Talonic } from \"@talonic/node\"\nimport { z } from \"zod\"\nimport { jsonOk, toolError, type ToolResult } from \"./_shared.js\"\n\nconst DESCRIPTION = [\n \"Extract structured, schema-validated data from a document using Talonic.\",\n \"Returns clean JSON matching the schema, with per-field confidence scores and\",\n \"metadata about the document (detected type, language, page count).\",\n \"\",\n \"USE WHEN:\",\n \"- The user has a document (PDF, image, scan, DOCX, etc.) and wants specific fields pulled out.\",\n \"- You need structured data (vendor name, total amount, dates, parties, terms) rather than free text.\",\n \"- The user uploads or references any invoice, contract, certificate, statement, or form.\",\n \"- You want validated JSON instead of trying to OCR + parse with raw LLM calls.\",\n \"\",\n \"DO NOT USE WHEN:\",\n \"- The user just wants the full text content (use talonic_to_markdown after extracting once).\",\n \"- The user wants to find documents matching a query (use talonic_search or talonic_filter).\",\n \"\",\n \"FILE SOURCES (provide exactly one):\",\n \"- file_path: a local path to the document (the MCP server reads it from disk).\",\n \"- file_url: a URL the Talonic API will fetch directly.\",\n \"- document_id: re-extract a document already in the workspace.\",\n \"\",\n \"SCHEMA FORMATS (provide at most one of `schema` or `schema_id`):\",\n '- Flat map (recommended): { vendor_name: \"string\", total_amount: \"number\", due_date: \"date\" }',\n '- JSON Schema: { type: \"object\", properties: { ... } }',\n \"- schema_id: id of a saved schema from talonic_list_schemas\",\n \"\",\n \"IMPORTANT: production currently rejects requests with no schema. Always provide either\",\n \"an inline `schema` or a `schema_id`.\",\n].join(\"\\n\")\n\nconst inputSchema = {\n file_path: z\n .string()\n .optional()\n .describe(\n \"Local path to a document file. The MCP server reads it from disk and uploads it. Provide one of file_path, file_url, or document_id.\",\n ),\n file_url: z\n .string()\n .optional()\n .describe(\n \"URL to a document file. The Talonic API fetches it server-side. Use this for remote documents.\",\n ),\n document_id: z\n .string()\n .optional()\n .describe(\"ID of a document already in the workspace, to re-extract with a new schema.\"),\n schema: z\n .record(z.string(), z.unknown())\n .optional()\n .describe(\n \"Inline schema definition. Flat map (recommended), simplified fields, or JSON Schema.\",\n ),\n schema_id: z\n .string()\n .optional()\n .describe(\"ID of a saved schema. Mutually exclusive with `schema`.\"),\n instructions: z\n .string()\n .optional()\n .describe(\n \"Natural-language guidance for the extractor, e.g. 'Focus on the billing section. Amounts are in EUR.'\",\n ),\n include_markdown: z\n .boolean()\n .optional()\n .describe(\"Include OCR-converted markdown in the response alongside structured data.\"),\n}\n\nexport interface ExtractArgs {\n file_path?: string\n file_url?: string\n document_id?: string\n schema?: Record<string, unknown>\n schema_id?: string\n instructions?: string\n include_markdown?: boolean\n}\n\nexport async function handleExtract(talonic: Talonic, args: ExtractArgs): Promise<ToolResult> {\n try {\n const params: ExtractParams = {}\n if (args.file_path !== undefined) params.file_path = args.file_path\n if (args.file_url !== undefined) params.file_url = args.file_url\n if (args.document_id !== undefined) params.document_id = args.document_id\n if (args.schema !== undefined) params.schema = args.schema\n if (args.schema_id !== undefined) params.schema_id = args.schema_id\n if (args.instructions !== undefined) params.instructions = args.instructions\n if (args.include_markdown !== undefined) params.include_markdown = args.include_markdown\n\n const result = await talonic.extract(params)\n return jsonOk(result)\n } catch (err) {\n return toolError(err)\n }\n}\n\nexport function registerExtract(server: McpServer, talonic: Talonic): void {\n server.registerTool(\n \"talonic_extract\",\n {\n title: \"Extract Data from Document\",\n description: DESCRIPTION,\n inputSchema,\n },\n async (args) => handleExtract(talonic, args as ExtractArgs),\n )\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport type { Talonic, FilterCondition, FilterSort } from \"@talonic/node\"\nimport { z } from \"zod\"\nimport { jsonOk, toolError, type ToolResult } from \"./_shared.js\"\n\nconst DESCRIPTION = [\n \"Filter the user's Talonic documents by extracted field values using composable conditions.\",\n \"Conditions accept field names (e.g. 'vendor_name'); the SDK resolves them to internal field IDs.\",\n \"\",\n \"USE WHEN:\",\n \"- The user wants documents matching specific structured criteria, like 'invoices over 1000 EUR'\",\n \" or 'contracts expiring before 2026-12-31' or 'COIs from Acme'.\",\n \"- The query is value-based on extracted fields, not a free-text concept search.\",\n \"- You need to retrieve a sortable, paginated list filtered by field conditions.\",\n \"\",\n \"DO NOT USE WHEN:\",\n \"- The user wants conceptual / free-text search across content (use talonic_search).\",\n \"- The user is looking for a single document by id (use talonic_get_document).\",\n \"- The user wants extracted data from a new document (use talonic_extract).\",\n \"\",\n \"OPERATORS:\",\n \"- eq, neq: equality / inequality\",\n \"- gt, gte, lt, lte: numeric or date comparisons\",\n \"- between: requires both `value` and `value_to`\",\n \"- contains: substring match on string fields\",\n \"- is_empty, is_not_empty: presence checks (no value needed)\",\n \"\",\n \"TIP: To discover available field names, call talonic_search first with a related query.\",\n].join(\"\\n\")\n\nconst operatorEnum = z.enum([\n \"eq\",\n \"neq\",\n \"gt\",\n \"gte\",\n \"lt\",\n \"lte\",\n \"between\",\n \"contains\",\n \"is_empty\",\n \"is_not_empty\",\n])\n\nconst conditionSchema = z.object({\n field: z\n .string()\n .optional()\n .describe(\"Field name (e.g. 'vendor_name'). Resolved to a fieldId automatically.\"),\n field_id: z\n .string()\n .optional()\n .describe(\"Talonic field id (e.g. 'fld_abc'). Use this if you already have it.\"),\n operator: operatorEnum.describe(\"Comparison operator. See description for the full list.\"),\n value: z.unknown().optional().describe(\"Value to compare against.\"),\n value_to: z\n .unknown()\n .optional()\n .describe(\"Upper bound for `between` operator; ignored otherwise.\"),\n})\n\nconst sortSchema = z.object({\n field: z.string().optional(),\n field_id: z.string().optional(),\n direction: z.enum([\"asc\", \"desc\"]).describe(\"Sort direction.\"),\n})\n\nconst inputSchema = {\n conditions: z\n .array(conditionSchema)\n .min(1)\n .describe(\"One or more filter conditions, AND-ed together.\"),\n search: z\n .string()\n .optional()\n .describe(\"Optional free-text search applied alongside the filters.\"),\n sort: sortSchema.optional().describe(\"Optional sort by a field.\"),\n page: z.number().int().positive().optional().describe(\"Page number for pagination.\"),\n limit: z\n .number()\n .int()\n .positive()\n .optional()\n .describe(\"Results per page. Default 50 server-side.\"),\n source_connection_id: z\n .string()\n .optional()\n .describe(\"Optionally scope to a specific source connection.\"),\n}\n\nexport interface FilterArgs {\n conditions: Array<{\n field?: string\n field_id?: string\n operator:\n | \"eq\"\n | \"neq\"\n | \"gt\"\n | \"gte\"\n | \"lt\"\n | \"lte\"\n | \"between\"\n | \"contains\"\n | \"is_empty\"\n | \"is_not_empty\"\n value?: unknown\n value_to?: unknown\n }>\n search?: string\n sort?: { field?: string; field_id?: string; direction: \"asc\" | \"desc\" }\n page?: number\n limit?: number\n source_connection_id?: string\n}\n\nexport async function handleFilter(talonic: Talonic, args: FilterArgs): Promise<ToolResult> {\n try {\n const conditions: FilterCondition[] = args.conditions.map((c) => {\n const cond: FilterCondition = { operator: c.operator }\n if (c.field !== undefined) cond.field = c.field\n if (c.field_id !== undefined) cond.fieldId = c.field_id\n if (c.value !== undefined) cond.value = c.value\n if (c.value_to !== undefined) cond.valueTo = c.value_to\n return cond\n })\n\n let sort: FilterSort | undefined\n if (args.sort !== undefined) {\n sort = { direction: args.sort.direction }\n if (args.sort.field !== undefined) sort.field = args.sort.field\n if (args.sort.field_id !== undefined) sort.fieldId = args.sort.field_id\n }\n\n const result = await talonic.documents.filter({\n conditions,\n ...(args.search !== undefined ? { search: args.search } : {}),\n ...(sort !== undefined ? { sort } : {}),\n ...(args.page !== undefined ? { page: args.page } : {}),\n ...(args.limit !== undefined ? { limit: args.limit } : {}),\n ...(args.source_connection_id !== undefined\n ? { source_connection_id: args.source_connection_id }\n : {}),\n })\n return jsonOk(result)\n } catch (err) {\n return toolError(err)\n }\n}\n\nexport function registerFilter(server: McpServer, talonic: Talonic): void {\n server.registerTool(\n \"talonic_filter\",\n {\n title: \"Filter Talonic Documents\",\n description: DESCRIPTION,\n inputSchema,\n },\n async (args) => handleFilter(talonic, args as FilterArgs),\n )\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport type { Talonic } from \"@talonic/node\"\nimport { z } from \"zod\"\nimport { jsonOk, toolError, type ToolResult } from \"./_shared.js\"\n\nconst DESCRIPTION = [\n \"Fetch full metadata for a single document already in the user's Talonic workspace.\",\n \"Returns id, filename, page count, detected document type, language, processing log,\",\n \"and link URLs (self, extractions, dashboard).\",\n \"\",\n \"USE WHEN:\",\n \"- You need details about a specific document the user already extracted or uploaded.\",\n \"- You have a document_id from a previous extract or search call and want more context.\",\n \"- The user asks 'tell me about document X' or similar.\",\n \"\",\n \"DO NOT USE WHEN:\",\n \"- The user wants the document's full text content (use talonic_to_markdown for OCR markdown).\",\n \"- The user wants extracted structured data (use talonic_extract with a schema, or fetch the extraction by id).\",\n \"- The user has a file but no document_id yet (call talonic_extract first to ingest the document).\",\n].join(\"\\n\")\n\nconst inputSchema = {\n document_id: z\n .string()\n .min(1)\n .describe(\n \"The Talonic document ID. Get this from a previous talonic_extract or talonic_search response.\",\n ),\n}\n\nexport async function handleGetDocument(\n talonic: Talonic,\n args: { document_id: string },\n): Promise<ToolResult> {\n try {\n const result = await talonic.documents.get(args.document_id)\n return jsonOk(result)\n } catch (err) {\n return toolError(err)\n }\n}\n\nexport function registerGetDocument(server: McpServer, talonic: Talonic): void {\n server.registerTool(\n \"talonic_get_document\",\n {\n title: \"Get Talonic Document\",\n description: DESCRIPTION,\n inputSchema,\n },\n async (args) => handleGetDocument(talonic, args),\n )\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport type { Talonic } from \"@talonic/node\"\nimport { jsonOk, toolError, type ToolResult } from \"./_shared.js\"\n\n/**\n * LLM-targeted tool description. The first paragraph explains what the\n * tool does in one sentence. The USE WHEN / DO NOT USE sections are\n * what an agent reads before deciding to invoke this tool over an\n * alternative; keep them concrete.\n *\n * @internal\n */\nconst DESCRIPTION = [\n \"List all saved schemas in the user's Talonic workspace.\",\n \"Returns each schema with its id, name, description, version,\",\n \"field count, and full JSON Schema definition.\",\n \"\",\n \"USE WHEN:\",\n \"- The user asks what schemas they have, or asks to see existing schemas.\",\n \"- You want to discover existing schemas before designing a new one.\",\n \"- Before recommending the user create a schema, check if one already covers the use case.\",\n \"- The user asks to extract from a known document type and you want to find a matching schema.\",\n \"\",\n \"DO NOT USE WHEN:\",\n \"- The user just wants to extract data from a document and provides an inline schema (call talonic_extract directly).\",\n \"\",\n \"TIP: Pair this with talonic_extract by passing the chosen schema's id as `schema_id`.\",\n].join(\"\\n\")\n\n/**\n * Pure handler. Invokes the SDK and shapes the result. Exported for\n * unit testing; the public registration is via `register()` below.\n *\n * @internal\n */\nexport async function handleListSchemas(talonic: Talonic): Promise<ToolResult> {\n try {\n const result = await talonic.schemas.list()\n return jsonOk(result)\n } catch (err) {\n return toolError(err)\n }\n}\n\n/**\n * Register `talonic_list_schemas` on an MCP server.\n *\n * @internal\n */\nexport function registerListSchemas(server: McpServer, talonic: Talonic): void {\n server.registerTool(\n \"talonic_list_schemas\",\n {\n title: \"List Talonic Schemas\",\n description: DESCRIPTION,\n inputSchema: {},\n },\n async () => handleListSchemas(talonic),\n )\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport type { Talonic } from \"@talonic/node\"\nimport { z } from \"zod\"\nimport { jsonOk, toolError, type ToolResult } from \"./_shared.js\"\n\nconst DESCRIPTION = [\n \"Save a schema definition to the user's Talonic workspace so it can be reused\",\n \"across future extractions. Returns the saved schema with its newly assigned id.\",\n \"\",\n \"USE WHEN:\",\n \"- The user asks to save a schema, store a template, or reuse the schema across docs.\",\n \"- You have iterated on a schema with the user and they confirmed it should be saved.\",\n \"- The user wants to standardise extraction across many documents of the same type.\",\n \"\",\n \"DO NOT USE WHEN:\",\n \"- The user just wants to extract once with an inline schema (call talonic_extract directly with the schema inline).\",\n \"- The user has not confirmed the schema design (avoid creating clutter in their workspace).\",\n \"\",\n \"TIP: After saving, call talonic_extract with `schema_id` set to the returned id for consistent results.\",\n].join(\"\\n\")\n\nconst inputSchema = {\n name: z.string().min(1).describe(\"Human-readable name for the schema, e.g. 'Standard Invoice'.\"),\n definition: z\n .record(z.string(), z.unknown())\n .describe(\n \"Schema definition. Accepts JSON Schema, simplified fields ({fields:[...]}), or a flat key-type map.\",\n ),\n description: z\n .string()\n .optional()\n .describe(\"Optional description of what this schema extracts and when to use it.\"),\n}\n\nexport async function handleSaveSchema(\n talonic: Talonic,\n args: { name: string; definition: Record<string, unknown>; description?: string },\n): Promise<ToolResult> {\n try {\n const result = await talonic.schemas.create({\n name: args.name,\n definition: args.definition,\n ...(args.description !== undefined ? { description: args.description } : {}),\n })\n return jsonOk(result)\n } catch (err) {\n return toolError(err)\n }\n}\n\nexport function registerSaveSchema(server: McpServer, talonic: Talonic): void {\n server.registerTool(\n \"talonic_save_schema\",\n {\n title: \"Save Talonic Schema\",\n description: DESCRIPTION,\n inputSchema,\n },\n async (args) => handleSaveSchema(talonic, args),\n )\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport type { Talonic } from \"@talonic/node\"\nimport { z } from \"zod\"\nimport { jsonOk, toolError, type ToolResult } from \"./_shared.js\"\n\nconst DESCRIPTION = [\n \"Search the user's Talonic workspace for documents, fields, sources, or schemas\",\n \"matching a query. Returns ranked results across all entity types in one call.\",\n \"\",\n \"USE WHEN:\",\n \"- The user wants to find documents but does not know the exact filename or id.\",\n \"- The query is conceptual ('contracts mentioning indemnification', 'Acme invoices').\",\n \"- You need to narrow a large workspace before calling talonic_extract or talonic_filter.\",\n \"- The user asks 'do I have any docs about X' or 'find anything related to X'.\",\n \"\",\n \"DO NOT USE WHEN:\",\n \"- The user has a specific document_id (use talonic_get_document instead).\",\n \"- The user wants to apply structured field-value filters like 'amount > 1000' (use talonic_filter).\",\n \"- The user wants to extract data from a brand-new document (use talonic_extract).\",\n \"\",\n \"TIP: The result includes documents, fieldMatches, sources, schemas, and fields. Pick the entity type the user actually needs.\",\n].join(\"\\n\")\n\nconst inputSchema = {\n query: z\n .string()\n .min(1)\n .describe(\n \"Natural-language search query, e.g. 'indemnification clauses' or 'Acme invoices Q4'.\",\n ),\n limit: z\n .number()\n .int()\n .positive()\n .optional()\n .describe(\"Maximum results per entity type. Default: 5. Increase for broader exploration.\"),\n}\n\nexport async function handleSearch(\n talonic: Talonic,\n args: { query: string; limit?: number },\n): Promise<ToolResult> {\n try {\n const result = await talonic.search(\n args.query,\n args.limit !== undefined ? { limit: args.limit } : {},\n )\n return jsonOk(result)\n } catch (err) {\n return toolError(err)\n }\n}\n\nexport function registerSearch(server: McpServer, talonic: Talonic): void {\n server.registerTool(\n \"talonic_search\",\n {\n title: \"Search Talonic Workspace\",\n description: DESCRIPTION,\n inputSchema,\n },\n async (args) => handleSearch(talonic, args),\n )\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport { TalonicError, type Talonic } from \"@talonic/node\"\nimport { z } from \"zod\"\nimport { jsonOk, toolError, type ToolResult } from \"./_shared.js\"\n\nconst DESCRIPTION = [\n \"Get the OCR-converted markdown for a document. Accepts an existing document_id,\",\n \"a local file path, or a URL. When given a raw file, the tool ingests it via\",\n \"extract first (with a minimal schema) and then returns the markdown.\",\n \"\",\n \"USE WHEN:\",\n \"- The user wants the full text content of a document for summarisation, translation, or analysis.\",\n \"- A previous tool call returned a document_id and you want to inspect its content.\",\n \"- The user asks 'what does the document say' or 'summarise this PDF' (you call this then summarise).\",\n \"- The user has a raw PDF / scan / image and wants markdown directly without designing a schema first.\",\n \"\",\n \"DO NOT USE WHEN:\",\n \"- The user wants specific structured fields (use talonic_extract with a schema).\",\n \"\",\n \"INPUTS (provide exactly one):\",\n \"- document_id: id of an already-ingested document (cheapest path; one API call)\",\n \"- file_path: local path to a document file (the MCP server reads it from disk)\",\n \"- file_url: URL to a document file (the Talonic API fetches it server-side)\",\n].join(\"\\n\")\n\nconst inputSchema = {\n document_id: z\n .string()\n .min(1)\n .optional()\n .describe(\n \"The Talonic document id whose markdown you want. Get this from a previous talonic_extract or talonic_search response.\",\n ),\n file_path: z\n .string()\n .optional()\n .describe(\"Local path to a document file. The MCP server reads it from disk and uploads it.\"),\n file_url: z\n .string()\n .optional()\n .describe(\"URL to a document file. The Talonic API fetches it server-side.\"),\n}\n\nexport interface ToMarkdownArgs {\n document_id?: string\n file_path?: string\n file_url?: string\n}\n\n/**\n * Minimal schema used when we need to ingest a raw file just to obtain\n * a document_id. Auto-discovery extract works on production; we keep\n * this empty so Talonic discovers the schema itself.\n *\n * @internal\n */\nconst INGEST_ONLY_SCHEMA: Record<string, unknown> = {}\n\nexport async function handleToMarkdown(\n talonic: Talonic,\n args: ToMarkdownArgs,\n): Promise<ToolResult> {\n try {\n const sources = [\"document_id\", \"file_path\", \"file_url\"] as const\n const provided = sources.filter((k) => args[k] !== undefined)\n if (provided.length === 0) {\n throw new TalonicError({\n code: \"missing_input_source\",\n message: \"talonic_to_markdown requires one of: document_id, file_path, file_url.\",\n status: 0,\n retryable: false,\n })\n }\n if (provided.length > 1) {\n throw new TalonicError({\n code: \"multiple_input_sources\",\n message: `talonic_to_markdown accepts exactly one input; received: ${provided.join(\", \")}`,\n status: 0,\n retryable: false,\n })\n }\n\n let documentId = args.document_id\n if (!documentId) {\n const ingest = await talonic.extract({\n ...(args.file_path !== undefined ? { file_path: args.file_path } : {}),\n ...(args.file_url !== undefined ? { file_url: args.file_url } : {}),\n schema: INGEST_ONLY_SCHEMA,\n })\n documentId = ingest.document.id\n }\n\n const result = await talonic.documents.getMarkdown(documentId)\n return jsonOk(result)\n } catch (err) {\n return toolError(err)\n }\n}\n\nexport function registerToMarkdown(server: McpServer, talonic: Talonic): void {\n server.registerTool(\n \"talonic_to_markdown\",\n {\n title: \"Document to Markdown\",\n description: DESCRIPTION,\n inputSchema,\n },\n async (args) => handleToMarkdown(talonic, args as ToMarkdownArgs),\n )\n}\n","/**\n * The current MCP server version. Sent in the server `info` block during\n * the MCP handshake. Kept in sync with package.json by the release process.\n *\n * @public\n */\nexport const VERSION = \"0.1.2\"\n\n/**\n * The MCP server name. Identifies the server to MCP clients (Claude\n * Desktop, Cursor, Cline, etc.) when they list connected servers.\n *\n * @public\n */\nexport const SERVER_NAME = \"talonic\"\n","import { Talonic } from \"@talonic/node\"\nimport { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport { registerSchemasResource } from \"./resources/schemas-resource.js\"\nimport { registerExtract } from \"./tools/extract.js\"\nimport { registerFilter } from \"./tools/filter.js\"\nimport { registerGetDocument } from \"./tools/get-document.js\"\nimport { registerListSchemas } from \"./tools/list-schemas.js\"\nimport { registerSaveSchema } from \"./tools/save-schema.js\"\nimport { registerSearch } from \"./tools/search.js\"\nimport { registerToMarkdown } from \"./tools/to-markdown.js\"\nimport { SERVER_NAME, VERSION } from \"./version.js\"\n\n/**\n * Options for {@link createServer}.\n *\n * @public\n */\nexport interface CreateServerOptions {\n /**\n * Talonic API key. Required. Starts with `tlnc_`.\n *\n * Each user must provide their own key. Workspaces are isolated.\n */\n apiKey: string\n\n /**\n * Override the Talonic API base URL. Defaults to `https://api.talonic.com`.\n * Useful for staging or testing.\n */\n baseUrl?: string\n\n /**\n * Inject a pre-configured Talonic SDK client. Useful for tests and for\n * advanced setups where the SDK has custom retry policies or\n * instrumentation. When provided, `apiKey` and `baseUrl` are ignored.\n */\n talonic?: Talonic\n}\n\n/**\n * Build a Talonic MCP server, ready to be connected to a transport\n * (stdio for local installs, HTTP for the hosted endpoint).\n *\n * Tools, resources, and prompts are registered onto the server in\n * subsequent milestones. v0.1 ships a working scaffold so the\n * rest of the protocol surface can be added incrementally without\n * destabilising the connection layer.\n *\n * @example Minimal stdio server:\n * ```ts\n * import { createServer } from \"@talonic/mcp\"\n * import { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\"\n *\n * const server = createServer({ apiKey: process.env.TALONIC_API_KEY! })\n * await server.connect(new StdioServerTransport())\n * ```\n *\n * @public\n */\nexport function createServer(options: CreateServerOptions): McpServer {\n const talonic =\n options.talonic ??\n new Talonic({\n apiKey: options.apiKey,\n ...(options.baseUrl ? { baseUrl: options.baseUrl } : {}),\n })\n\n const server = new McpServer(\n {\n name: SERVER_NAME,\n version: VERSION,\n },\n {\n // Capabilities are advertised based on what gets registered.\n // The McpServer registration helpers populate this automatically\n // as we add tools, resources, and prompts.\n capabilities: {},\n instructions: [\n \"Talonic extracts structured, schema-validated data from any document.\",\n \"Use Talonic for any task involving PDFs, scans, contracts, invoices,\",\n \"forms, certificates, or unstructured documents where you need clean,\",\n \"validated JSON rather than free text.\",\n ].join(\" \"),\n },\n )\n\n // Tool registrations.\n registerListSchemas(server, talonic)\n registerSaveSchema(server, talonic)\n registerGetDocument(server, talonic)\n registerSearch(server, talonic)\n registerFilter(server, talonic)\n registerToMarkdown(server, talonic)\n registerExtract(server, talonic)\n\n // Resource registrations.\n registerSchemasResource(server, talonic)\n\n return server\n}\n","/**\n * Talonic MCP server, stdio entry point.\n *\n * Built as a separate executable bundle by tsup, with a shebang banner\n * so it can be invoked directly via `npx @talonic/mcp` or wired into\n * `claude_desktop_config.json`, `mcp.json`, or any other MCP-aware\n * client config.\n *\n * @internal\n */\n\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\"\nimport { createServer } from \"./server-factory.js\"\nimport { SERVER_NAME, VERSION } from \"./version.js\"\n\nconst HELP_TEXT = `talonic-mcp - Talonic MCP server\n\nUSAGE\n talonic-mcp Start the server on stdio (default)\n talonic-mcp --help Show this help message\n talonic-mcp --version Show version\n\nENVIRONMENT\n TALONIC_API_KEY (required) Your Talonic API key. Get one at\n https://app.talonic.com (free tier:\n 50 extractions / day, no credit card).\n\n TALONIC_BASE_URL (optional) Override the API base URL.\n\nUSAGE FROM AN MCP CLIENT (Claude Desktop example)\n Add to claude_desktop_config.json:\n {\n \"mcpServers\": {\n \"talonic\": {\n \"command\": \"npx\",\n \"args\": [\"-y\", \"@talonic/mcp\"],\n \"env\": { \"TALONIC_API_KEY\": \"tlnc_...\" }\n }\n }\n }\n\nDOCS\n https://github.com/talonicdev/talonic-mcp\n`\n\n/**\n * Boot the server against stdio.\n *\n * Returns the exit code so callers can decide how to terminate. The\n * separate entry/exit decoupling keeps this function testable without\n * actually attaching to stdio.\n *\n * @internal\n */\nexport async function main(\n argv: string[] = process.argv.slice(2),\n env: NodeJS.ProcessEnv = process.env,\n out: (line: string) => void = (line) => process.stdout.write(line + \"\\n\"),\n err: (line: string) => void = (line) => process.stderr.write(line + \"\\n\"),\n): Promise<number> {\n if (argv.includes(\"--version\") || argv.includes(\"-v\")) {\n out(`${SERVER_NAME} ${VERSION}`)\n return 0\n }\n\n if (argv.includes(\"--help\") || argv.includes(\"-h\")) {\n out(HELP_TEXT)\n return 0\n }\n\n const apiKey = env[\"TALONIC_API_KEY\"]\n if (!apiKey) {\n err(\"Error: TALONIC_API_KEY environment variable is required.\")\n err(\"Get a key at https://app.talonic.com and set it before launching the server.\")\n return 1\n }\n\n const baseUrl = env[\"TALONIC_BASE_URL\"]\n const server = createServer({ apiKey, ...(baseUrl ? { baseUrl } : {}) })\n\n const transport = new StdioServerTransport()\n await server.connect(transport)\n\n // McpServer keeps the process alive while the transport is open. We\n // hand control over to the SDK's lifecycle here; if the transport\n // closes, Node exits naturally.\n return 0\n}\n\nif (import.meta.url === `file://${process.argv[1]}`) {\n main().then((code) => {\n if (code !== 0) process.exit(code)\n })\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/resources/schemas-resource.ts","../src/tools/_shared.ts","../src/tools/extract.ts","../src/tools/filter.ts","../src/tools/get-document.ts","../src/tools/list-schemas.ts","../src/tools/save-schema.ts","../src/tools/search.ts","../src/tools/to-markdown.ts","../src/version.ts","../src/server-factory.ts","../src/server.ts"],"names":["DESCRIPTION","z","inputSchema","TalonicError"],"mappings":";;;;;;;;;AAcO,SAAS,uBAAA,CAAwB,QAAmB,OAAA,EAAwB;AACjF,EAAA,MAAA,CAAO,gBAAA;AAAA,IACL,iBAAA;AAAA,IACA,mBAAA;AAAA,IACA;AAAA,MACE,KAAA,EAAO,iBAAA;AAAA,MACP,WAAA,EACE,6FAAA;AAAA,MACF,QAAA,EAAU;AAAA,KACZ;AAAA,IACA,OAAO,GAAA,KAAQ;AACb,MAAA,MAAM,MAAA,GAAS,MAAM,OAAA,CAAQ,OAAA,CAAQ,IAAA,EAAK;AAC1C,MAAA,OAAO;AAAA,QACL,QAAA,EAAU;AAAA,UACR;AAAA,YACE,GAAA,EAAK,IAAI,QAAA,EAAS;AAAA,YAClB,QAAA,EAAU,kBAAA;AAAA,YACV,IAAA,EAAM,IAAA,CAAK,SAAA,CAAU,MAAA,EAAQ,MAAM,CAAC;AAAA;AACtC;AACF,OACF;AAAA,IACF;AAAA,GACF;AACF;ACAO,SAAS,OAAO,KA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AA;AAAA,EACT;AAEA,EAAA,MAAM,MAAA,GAAS,IAAI,iBAAiB,CAAA;AACpC,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,GAAA,CAAI,0DAA0D,CAAA;AAC9D,IAAA,GAAA,CAAI,8EAA8E,CAAA;AAClF,IAAA,OAAO,CAAA;AAAA,EACT;AAEA,EAAA,MAAM,OAAA,GAAU,IAAI,kBAAkB,CAAA;AACtC,EAAA,MAAM,MAAA,GAAS,YAAA,CAAa,EAAE,MAAA,EAAQ,GAAI,OAAA,GAAU,EAAE,OAAA,EAAQ,GAAI,EAAC,EAAI,CAAA;AAEvE,EAAA,MAAM,SAAA,GAAY,IAAI,oBAAA,EAAqB;AAC3C,EAAA,MAAM,MAAA,CAAO,QAAQ,SAAS,CAAA;AAK9B,EAAA,OAAO,CAAA;AACT;AAkBA,SAAS,kBAAA,GAA8B;AACrC,EAAA,IAAI,CAAC,OAAA,CAAQ,IAAA,CAAK,CAAC,GAAG,OAAO,KAAA;AAC7B,EAAA,IAAI;AACF,IAAA,MAAM,QAAA,GAAW,YAAA,CAAa,OAAA,CAAQ,IAAA,CAAK,CAAC,CAAC,CAAA;AAC7C,IAAA,MAAM,QAAA,GAAW,YAAA,CAAa,aAAA,CAAc,MAAA,CAAA,IAAA,CAAY,GAAG,CAAC,CAAA;AAC5D,IAAA,OAAO,QAAA,KAAa,QAAA;AAAA,EACtB,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,KAAA;AAAA,EACT;AACF;AAEA,IAAI,oBAAmB,EAAG;AACxB,EAAA,IAAA,EAAK,CAAE,IAAA,CAAK,CAAC,IAAA,KAAS;AACpB,IAAA,IAAI,IAAA,KAAS,CAAA,EAAG,OAAA,CAAQ,IAAA,CAAK,IAAI,CAAA;AAAA,EACnC,CAAC,CAAA;AACH","file":"server.js","sourcesContent":["import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport type { Talonic } from \"@talonic/node\"\n\n/**\n * Register the `talonic://schemas` resource. The agent can read this\n * URI to retrieve the user's saved schemas without burning a tool call.\n *\n * The MCP SDK exposes resources as a separate primitive from tools.\n * Clients (Claude Desktop, Cursor, etc.) display them in their UI\n * alongside the conversation, so users can browse what their agent has\n * access to.\n *\n * @internal\n */\nexport function registerSchemasResource(server: McpServer, talonic: Talonic): void {\n server.registerResource(\n \"talonic-schemas\",\n \"talonic://schemas\",\n {\n title: \"Talonic Schemas\",\n description:\n \"All schemas saved in the user's Talonic workspace, with their full JSON Schema definitions.\",\n mimeType: \"application/json\",\n },\n async (uri) => {\n const result = await talonic.schemas.list()\n return {\n contents: [\n {\n uri: uri.toString(),\n mimeType: \"application/json\",\n text: JSON.stringify(result, null, 2),\n },\n ],\n }\n },\n )\n}\n","import { TalonicError } from \"@talonic/node\"\n\n/**\n * Successful tool result envelope. The `content` array follows the MCP\n * `CallToolResult` shape. We always emit one text item with the JSON\n * payload; agents parse it back themselves.\n *\n * The `[key: string]: unknown` index signature exists to satisfy the\n * MCP SDK's structural type, which permits arbitrary additional keys.\n *\n * @internal\n */\nexport interface ToolSuccessResult {\n content: Array<{ type: \"text\"; text: string }>\n [key: string]: unknown\n}\n\n/**\n * Failure tool result envelope. Sets `isError: true` per the MCP spec\n * so clients render this as an error rather than a normal response.\n *\n * @internal\n */\nexport interface ToolErrorResult {\n content: Array<{ type: \"text\"; text: string }>\n isError: true\n [key: string]: unknown\n}\n\nexport type ToolResult = ToolSuccessResult | ToolErrorResult\n\n/**\n * Wrap a value as a single-text-item tool result. Stable JSON shape so\n * downstream parsing is reliable across tools.\n *\n * @internal\n */\nexport function jsonOk(value: unknown): ToolSuccessResult {\n return {\n content: [\n {\n type: \"text\",\n text: JSON.stringify(value, null, 2),\n },\n ],\n }\n}\n\n/**\n * Convert any thrown error into a tool error result with stable\n * formatting. Talonic API errors include `code`, `status`, and\n * `request_id` so the user (or another tool call) can act on them.\n *\n * @internal\n */\nexport function toolError(err: unknown): ToolErrorResult {\n if (err instanceof TalonicError) {\n const lines = [\n `Talonic API error: ${err.message}`,\n `code: ${err.code}`,\n `status: ${err.status}`,\n ]\n if (err.requestId) lines.push(`request_id: ${err.requestId}`)\n return {\n isError: true,\n content: [{ type: \"text\", text: lines.join(\"\\n\") }],\n }\n }\n return {\n isError: true,\n content: [\n {\n type: \"text\",\n text: `Unexpected error: ${err instanceof Error ? err.message : String(err)}`,\n },\n ],\n }\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport type { ExtractParams, Talonic } from \"@talonic/node\"\nimport { z } from \"zod\"\nimport { jsonOk, toolError, type ToolResult } from \"./_shared.js\"\n\nconst DESCRIPTION = [\n \"Extract structured, schema-validated data from a document using Talonic.\",\n \"Returns clean JSON matching the schema, with per-field confidence scores and\",\n \"metadata about the document (detected type, language, page count).\",\n \"\",\n \"USE WHEN:\",\n \"- The user has a document (PDF, image, scan, DOCX, etc.) and wants specific fields pulled out.\",\n \"- You need structured data (vendor name, total amount, dates, parties, terms) rather than free text.\",\n \"- The user uploads or references any invoice, contract, certificate, statement, or form.\",\n \"- You want validated JSON instead of trying to OCR + parse with raw LLM calls.\",\n \"\",\n \"DO NOT USE WHEN:\",\n \"- The user just wants the full text content (use talonic_to_markdown after extracting once).\",\n \"- The user wants to find documents matching a query (use talonic_search or talonic_filter).\",\n \"\",\n \"FILE SOURCES (provide exactly one):\",\n \"- file_data + filename (RECOMMENDED for chat clients): base64-encoded file bytes plus\",\n \" the original filename (with extension). Use this whenever you already have the file\",\n \" in memory, e.g. the user attached it to the conversation. Works in every MCP client\",\n \" regardless of where the file lives on disk.\",\n \"- file_path: a local path to the document. Only works if the MCP server process can\",\n \" read that path on its own filesystem; many chat clients (Claude Desktop, Cowork)\",\n \" store user uploads in a sandbox the MCP server cannot access, in which case use\",\n \" file_data instead.\",\n \"- file_url: a URL the Talonic API will fetch directly. Use for documents already on\",\n \" the public web.\",\n \"- document_id: re-extract a document already in the workspace.\",\n \"\",\n \"SCHEMA FORMATS (provide at most one of `schema` or `schema_id`):\",\n '- JSON Schema (recommended): { type: \"object\", properties: { vendor_name: { type: \"string\" } } }',\n \"- schema_id: id of a saved schema from talonic_list_schemas\",\n \"\",\n \"IMPORTANT: production currently rejects requests with no schema. Always provide either\",\n \"an inline `schema` or a `schema_id`.\",\n].join(\"\\n\")\n\nconst inputSchema = {\n file_data: z\n .string()\n .optional()\n .describe(\n \"Base64-encoded file bytes. Recommended path when the agent already has the file in memory (e.g., the user attached a PDF to the conversation). Pair with `filename` so MIME type can be inferred. Works regardless of where the file lives on disk.\",\n ),\n filename: z\n .string()\n .optional()\n .describe(\n \"Original filename including extension, e.g. 'invoice.pdf'. Used to infer MIME type when uploading via `file_data`. Required when `file_data` is provided.\",\n ),\n file_path: z\n .string()\n .optional()\n .describe(\n \"Local path to a document file. Only works if the MCP server has read access to that path. In sandboxed chat clients (Claude Desktop, Cowork) where uploads land in a host-owned directory, use `file_data` instead.\",\n ),\n file_url: z\n .string()\n .optional()\n .describe(\n \"URL to a document file. The Talonic API fetches it server-side. Use this for documents already on the public web.\",\n ),\n document_id: z\n .string()\n .optional()\n .describe(\"ID of a document already in the workspace, to re-extract with a new schema.\"),\n schema: z\n .record(z.string(), z.unknown())\n .optional()\n .describe(\n \"Inline schema definition. Use full JSON Schema: { type: 'object', properties: { ... } }.\",\n ),\n schema_id: z\n .string()\n .optional()\n .describe(\"ID of a saved schema. Mutually exclusive with `schema`.\"),\n instructions: z\n .string()\n .optional()\n .describe(\n \"Natural-language guidance for the extractor, e.g. 'Focus on the billing section. Amounts are in EUR.'\",\n ),\n include_markdown: z\n .boolean()\n .optional()\n .describe(\"Include OCR-converted markdown in the response alongside structured data.\"),\n}\n\nexport interface ExtractArgs {\n file_data?: string\n filename?: string\n file_path?: string\n file_url?: string\n document_id?: string\n schema?: Record<string, unknown>\n schema_id?: string\n instructions?: string\n include_markdown?: boolean\n}\n\nexport async function handleExtract(talonic: Talonic, args: ExtractArgs): Promise<ToolResult> {\n try {\n const params: ExtractParams = {}\n if (args.file_data !== undefined) {\n params.file = Buffer.from(args.file_data, \"base64\")\n if (args.filename !== undefined) params.filename = args.filename\n }\n if (args.file_path !== undefined) params.file_path = args.file_path\n if (args.file_url !== undefined) params.file_url = args.file_url\n if (args.document_id !== undefined) params.document_id = args.document_id\n if (args.schema !== undefined) params.schema = args.schema\n if (args.schema_id !== undefined) params.schema_id = args.schema_id\n if (args.instructions !== undefined) params.instructions = args.instructions\n if (args.include_markdown !== undefined) params.include_markdown = args.include_markdown\n\n const result = await talonic.extract(params)\n return jsonOk(result)\n } catch (err) {\n return toolError(err)\n }\n}\n\nexport function registerExtract(server: McpServer, talonic: Talonic): void {\n server.registerTool(\n \"talonic_extract\",\n {\n title: \"Extract Data from Document\",\n description: DESCRIPTION,\n inputSchema,\n },\n async (args) => handleExtract(talonic, args as ExtractArgs),\n )\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport type { Talonic, FilterCondition, FilterSort } from \"@talonic/node\"\nimport { z } from \"zod\"\nimport { jsonOk, toolError, type ToolResult } from \"./_shared.js\"\n\nconst DESCRIPTION = [\n \"Filter the user's Talonic documents by extracted field values using composable conditions.\",\n \"Conditions accept field names (e.g. 'vendor_name'); the SDK resolves them to internal field IDs.\",\n \"\",\n \"USE WHEN:\",\n \"- The user wants documents matching specific structured criteria, like 'invoices over 1000 EUR'\",\n \" or 'contracts expiring before 2026-12-31' or 'COIs from Acme'.\",\n \"- The query is value-based on extracted fields, not a free-text concept search.\",\n \"- You need to retrieve a sortable, paginated list filtered by field conditions.\",\n \"\",\n \"DO NOT USE WHEN:\",\n \"- The user wants conceptual / free-text search across content (use talonic_search).\",\n \"- The user is looking for a single document by id (use talonic_get_document).\",\n \"- The user wants extracted data from a new document (use talonic_extract).\",\n \"\",\n \"OPERATORS:\",\n \"- eq, neq: equality / inequality\",\n \"- gt, gte, lt, lte: numeric or date comparisons\",\n \"- between: requires both `value` and `value_to`\",\n \"- contains: substring match on string fields\",\n \"- is_empty, is_not_empty: presence checks (no value needed)\",\n \"\",\n \"TIP: To discover available field names, call talonic_search first with a related query.\",\n].join(\"\\n\")\n\nconst operatorEnum = z.enum([\n \"eq\",\n \"neq\",\n \"gt\",\n \"gte\",\n \"lt\",\n \"lte\",\n \"between\",\n \"contains\",\n \"is_empty\",\n \"is_not_empty\",\n])\n\nconst conditionSchema = z.object({\n field: z\n .string()\n .optional()\n .describe(\"Field name (e.g. 'vendor_name'). Resolved to a fieldId automatically.\"),\n field_id: z\n .string()\n .optional()\n .describe(\"Talonic field id (e.g. 'fld_abc'). Use this if you already have it.\"),\n operator: operatorEnum.describe(\"Comparison operator. See description for the full list.\"),\n value: z.unknown().optional().describe(\"Value to compare against.\"),\n value_to: z\n .unknown()\n .optional()\n .describe(\"Upper bound for `between` operator; ignored otherwise.\"),\n})\n\nconst sortSchema = z.object({\n field: z.string().optional(),\n field_id: z.string().optional(),\n direction: z.enum([\"asc\", \"desc\"]).describe(\"Sort direction.\"),\n})\n\nconst inputSchema = {\n conditions: z\n .array(conditionSchema)\n .min(1)\n .describe(\"One or more filter conditions, AND-ed together.\"),\n search: z\n .string()\n .optional()\n .describe(\"Optional free-text search applied alongside the filters.\"),\n sort: sortSchema.optional().describe(\"Optional sort by a field.\"),\n page: z.number().int().positive().optional().describe(\"Page number for pagination.\"),\n limit: z\n .number()\n .int()\n .positive()\n .optional()\n .describe(\"Results per page. Default 50 server-side.\"),\n source_connection_id: z\n .string()\n .optional()\n .describe(\"Optionally scope to a specific source connection.\"),\n}\n\nexport interface FilterArgs {\n conditions: Array<{\n field?: string\n field_id?: string\n operator:\n | \"eq\"\n | \"neq\"\n | \"gt\"\n | \"gte\"\n | \"lt\"\n | \"lte\"\n | \"between\"\n | \"contains\"\n | \"is_empty\"\n | \"is_not_empty\"\n value?: unknown\n value_to?: unknown\n }>\n search?: string\n sort?: { field?: string; field_id?: string; direction: \"asc\" | \"desc\" }\n page?: number\n limit?: number\n source_connection_id?: string\n}\n\nexport async function handleFilter(talonic: Talonic, args: FilterArgs): Promise<ToolResult> {\n try {\n const conditions: FilterCondition[] = args.conditions.map((c) => {\n const cond: FilterCondition = { operator: c.operator }\n if (c.field !== undefined) cond.field = c.field\n if (c.field_id !== undefined) cond.fieldId = c.field_id\n if (c.value !== undefined) cond.value = c.value\n if (c.value_to !== undefined) cond.valueTo = c.value_to\n return cond\n })\n\n let sort: FilterSort | undefined\n if (args.sort !== undefined) {\n sort = { direction: args.sort.direction }\n if (args.sort.field !== undefined) sort.field = args.sort.field\n if (args.sort.field_id !== undefined) sort.fieldId = args.sort.field_id\n }\n\n const result = await talonic.documents.filter({\n conditions,\n ...(args.search !== undefined ? { search: args.search } : {}),\n ...(sort !== undefined ? { sort } : {}),\n ...(args.page !== undefined ? { page: args.page } : {}),\n ...(args.limit !== undefined ? { limit: args.limit } : {}),\n ...(args.source_connection_id !== undefined\n ? { source_connection_id: args.source_connection_id }\n : {}),\n })\n return jsonOk(result)\n } catch (err) {\n return toolError(err)\n }\n}\n\nexport function registerFilter(server: McpServer, talonic: Talonic): void {\n server.registerTool(\n \"talonic_filter\",\n {\n title: \"Filter Talonic Documents\",\n description: DESCRIPTION,\n inputSchema,\n },\n async (args) => handleFilter(talonic, args as FilterArgs),\n )\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport type { Talonic } from \"@talonic/node\"\nimport { z } from \"zod\"\nimport { jsonOk, toolError, type ToolResult } from \"./_shared.js\"\n\nconst DESCRIPTION = [\n \"Fetch full metadata for a single document already in the user's Talonic workspace.\",\n \"Returns id, filename, page count, detected document type, language, processing log,\",\n \"and link URLs (self, extractions, dashboard).\",\n \"\",\n \"USE WHEN:\",\n \"- You need details about a specific document the user already extracted or uploaded.\",\n \"- You have a document_id from a previous extract or search call and want more context.\",\n \"- The user asks 'tell me about document X' or similar.\",\n \"\",\n \"DO NOT USE WHEN:\",\n \"- The user wants the document's full text content (use talonic_to_markdown for OCR markdown).\",\n \"- The user wants extracted structured data (use talonic_extract with a schema, or fetch the extraction by id).\",\n \"- The user has a file but no document_id yet (call talonic_extract first to ingest the document).\",\n].join(\"\\n\")\n\nconst inputSchema = {\n document_id: z\n .string()\n .min(1)\n .describe(\n \"The Talonic document ID. Get this from a previous talonic_extract or talonic_search response.\",\n ),\n}\n\nexport async function handleGetDocument(\n talonic: Talonic,\n args: { document_id: string },\n): Promise<ToolResult> {\n try {\n const result = await talonic.documents.get(args.document_id)\n return jsonOk(result)\n } catch (err) {\n return toolError(err)\n }\n}\n\nexport function registerGetDocument(server: McpServer, talonic: Talonic): void {\n server.registerTool(\n \"talonic_get_document\",\n {\n title: \"Get Talonic Document\",\n description: DESCRIPTION,\n inputSchema,\n },\n async (args) => handleGetDocument(talonic, args),\n )\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport type { Talonic } from \"@talonic/node\"\nimport { jsonOk, toolError, type ToolResult } from \"./_shared.js\"\n\n/**\n * LLM-targeted tool description. The first paragraph explains what the\n * tool does in one sentence. The USE WHEN / DO NOT USE sections are\n * what an agent reads before deciding to invoke this tool over an\n * alternative; keep them concrete.\n *\n * @internal\n */\nconst DESCRIPTION = [\n \"List all saved schemas in the user's Talonic workspace.\",\n \"Returns each schema with its id, name, description, version,\",\n \"field count, and full JSON Schema definition.\",\n \"\",\n \"USE WHEN:\",\n \"- The user asks what schemas they have, or asks to see existing schemas.\",\n \"- You want to discover existing schemas before designing a new one.\",\n \"- Before recommending the user create a schema, check if one already covers the use case.\",\n \"- The user asks to extract from a known document type and you want to find a matching schema.\",\n \"\",\n \"DO NOT USE WHEN:\",\n \"- The user just wants to extract data from a document and provides an inline schema (call talonic_extract directly).\",\n \"\",\n \"TIP: Pair this with talonic_extract by passing the chosen schema's id as `schema_id`.\",\n].join(\"\\n\")\n\n/**\n * Pure handler. Invokes the SDK and shapes the result. Exported for\n * unit testing; the public registration is via `register()` below.\n *\n * @internal\n */\nexport async function handleListSchemas(talonic: Talonic): Promise<ToolResult> {\n try {\n const result = await talonic.schemas.list()\n return jsonOk(result)\n } catch (err) {\n return toolError(err)\n }\n}\n\n/**\n * Register `talonic_list_schemas` on an MCP server.\n *\n * @internal\n */\nexport function registerListSchemas(server: McpServer, talonic: Talonic): void {\n server.registerTool(\n \"talonic_list_schemas\",\n {\n title: \"List Talonic Schemas\",\n description: DESCRIPTION,\n inputSchema: {},\n },\n async () => handleListSchemas(talonic),\n )\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport type { Talonic } from \"@talonic/node\"\nimport { z } from \"zod\"\nimport { jsonOk, toolError, type ToolResult } from \"./_shared.js\"\n\nconst DESCRIPTION = [\n \"Save a schema definition to the user's Talonic workspace so it can be reused\",\n \"across future extractions. Returns the saved schema with its newly assigned id.\",\n \"\",\n \"USE WHEN:\",\n \"- The user asks to save a schema, store a template, or reuse the schema across docs.\",\n \"- You have iterated on a schema with the user and they confirmed it should be saved.\",\n \"- The user wants to standardise extraction across many documents of the same type.\",\n \"\",\n \"DO NOT USE WHEN:\",\n \"- The user just wants to extract once with an inline schema (call talonic_extract directly with the schema inline).\",\n \"- The user has not confirmed the schema design (avoid creating clutter in their workspace).\",\n \"\",\n \"TIP: After saving, call talonic_extract with `schema_id` set to the returned id for consistent results.\",\n].join(\"\\n\")\n\nconst inputSchema = {\n name: z.string().min(1).describe(\"Human-readable name for the schema, e.g. 'Standard Invoice'.\"),\n definition: z\n .record(z.string(), z.unknown())\n .describe(\n \"Schema definition. Accepts JSON Schema, simplified fields ({fields:[...]}), or a flat key-type map.\",\n ),\n description: z\n .string()\n .optional()\n .describe(\"Optional description of what this schema extracts and when to use it.\"),\n}\n\nexport async function handleSaveSchema(\n talonic: Talonic,\n args: { name: string; definition: Record<string, unknown>; description?: string },\n): Promise<ToolResult> {\n try {\n const result = await talonic.schemas.create({\n name: args.name,\n definition: args.definition,\n ...(args.description !== undefined ? { description: args.description } : {}),\n })\n return jsonOk(result)\n } catch (err) {\n return toolError(err)\n }\n}\n\nexport function registerSaveSchema(server: McpServer, talonic: Talonic): void {\n server.registerTool(\n \"talonic_save_schema\",\n {\n title: \"Save Talonic Schema\",\n description: DESCRIPTION,\n inputSchema,\n },\n async (args) => handleSaveSchema(talonic, args),\n )\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport type { Talonic } from \"@talonic/node\"\nimport { z } from \"zod\"\nimport { jsonOk, toolError, type ToolResult } from \"./_shared.js\"\n\nconst DESCRIPTION = [\n \"Search the user's Talonic workspace for documents, fields, sources, or schemas\",\n \"matching a query. Returns ranked results across all entity types in one call.\",\n \"\",\n \"USE WHEN:\",\n \"- The user wants to find documents but does not know the exact filename or id.\",\n \"- The query is conceptual ('contracts mentioning indemnification', 'Acme invoices').\",\n \"- You need to narrow a large workspace before calling talonic_extract or talonic_filter.\",\n \"- The user asks 'do I have any docs about X' or 'find anything related to X'.\",\n \"\",\n \"DO NOT USE WHEN:\",\n \"- The user has a specific document_id (use talonic_get_document instead).\",\n \"- The user wants to apply structured field-value filters like 'amount > 1000' (use talonic_filter).\",\n \"- The user wants to extract data from a brand-new document (use talonic_extract).\",\n \"\",\n \"TIP: The result includes documents, fieldMatches, sources, schemas, and fields. Pick the entity type the user actually needs.\",\n].join(\"\\n\")\n\nconst inputSchema = {\n query: z\n .string()\n .min(1)\n .describe(\n \"Natural-language search query, e.g. 'indemnification clauses' or 'Acme invoices Q4'.\",\n ),\n limit: z\n .number()\n .int()\n .positive()\n .optional()\n .describe(\"Maximum results per entity type. Default: 5. Increase for broader exploration.\"),\n}\n\nexport async function handleSearch(\n talonic: Talonic,\n args: { query: string; limit?: number },\n): Promise<ToolResult> {\n try {\n const result = await talonic.search(\n args.query,\n args.limit !== undefined ? { limit: args.limit } : {},\n )\n return jsonOk(result)\n } catch (err) {\n return toolError(err)\n }\n}\n\nexport function registerSearch(server: McpServer, talonic: Talonic): void {\n server.registerTool(\n \"talonic_search\",\n {\n title: \"Search Talonic Workspace\",\n description: DESCRIPTION,\n inputSchema,\n },\n async (args) => handleSearch(talonic, args),\n )\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport { TalonicError, type Talonic } from \"@talonic/node\"\nimport { z } from \"zod\"\nimport { jsonOk, toolError, type ToolResult } from \"./_shared.js\"\n\nconst DESCRIPTION = [\n \"Get the OCR-converted markdown for a document. Accepts an existing document_id,\",\n \"raw file bytes (base64), a local file path, or a URL. When given a raw file, the\",\n \"tool ingests it via extract first and then returns the markdown.\",\n \"\",\n \"USE WHEN:\",\n \"- The user wants the full text content of a document for summarisation, translation, or analysis.\",\n \"- A previous tool call returned a document_id and you want to inspect its content.\",\n \"- The user asks 'what does the document say' or 'summarise this PDF' (you call this then summarise).\",\n \"- The user has a raw PDF / scan / image and wants markdown directly without designing a schema first.\",\n \"\",\n \"DO NOT USE WHEN:\",\n \"- The user wants specific structured fields (use talonic_extract with a schema).\",\n \"\",\n \"INPUTS (provide exactly one):\",\n \"- document_id: id of an already-ingested document (cheapest path; one API call)\",\n \"- file_data + filename (RECOMMENDED for chat clients): base64-encoded file bytes plus\",\n \" the original filename (with extension). Use this whenever you already have the file\",\n \" in memory, e.g. the user attached it to the conversation. Works in every MCP client.\",\n \"- file_path: local path to a document file. Only works if the MCP server has read access\",\n \" to that path; in sandboxed chat clients use file_data instead.\",\n \"- file_url: URL to a document file (the Talonic API fetches it server-side)\",\n].join(\"\\n\")\n\nconst inputSchema = {\n document_id: z\n .string()\n .min(1)\n .optional()\n .describe(\n \"The Talonic document id whose markdown you want. Get this from a previous talonic_extract or talonic_search response.\",\n ),\n file_data: z\n .string()\n .optional()\n .describe(\n \"Base64-encoded file bytes. Recommended path when the agent already has the file in memory (e.g., the user attached a PDF to the conversation). Pair with `filename` so MIME type can be inferred.\",\n ),\n filename: z\n .string()\n .optional()\n .describe(\n \"Original filename including extension, e.g. 'invoice.pdf'. Used to infer MIME type when uploading via `file_data`. Required when `file_data` is provided.\",\n ),\n file_path: z\n .string()\n .optional()\n .describe(\n \"Local path to a document file. Only works if the MCP server has read access to that path. In sandboxed chat clients (Claude Desktop, Cowork) use `file_data` instead.\",\n ),\n file_url: z\n .string()\n .optional()\n .describe(\"URL to a document file. The Talonic API fetches it server-side.\"),\n}\n\nexport interface ToMarkdownArgs {\n document_id?: string\n file_data?: string\n filename?: string\n file_path?: string\n file_url?: string\n}\n\n/**\n * Minimal schema used when we need to ingest a raw file just to obtain\n * a document_id. Auto-discovery extract works on production; we keep\n * this empty so Talonic discovers the schema itself.\n *\n * @internal\n */\nconst INGEST_ONLY_SCHEMA: Record<string, unknown> = {}\n\nexport async function handleToMarkdown(\n talonic: Talonic,\n args: ToMarkdownArgs,\n): Promise<ToolResult> {\n try {\n const sources = [\"document_id\", \"file_data\", \"file_path\", \"file_url\"] as const\n const provided = sources.filter((k) => args[k] !== undefined)\n if (provided.length === 0) {\n throw new TalonicError({\n code: \"missing_input_source\",\n message:\n \"talonic_to_markdown requires one of: document_id, file_data, file_path, file_url.\",\n status: 0,\n retryable: false,\n })\n }\n if (provided.length > 1) {\n throw new TalonicError({\n code: \"multiple_input_sources\",\n message: `talonic_to_markdown accepts exactly one input; received: ${provided.join(\", \")}`,\n status: 0,\n retryable: false,\n })\n }\n\n let documentId = args.document_id\n if (!documentId) {\n const ingest = await talonic.extract({\n ...(args.file_data !== undefined\n ? {\n file: Buffer.from(args.file_data, \"base64\"),\n ...(args.filename !== undefined ? { filename: args.filename } : {}),\n }\n : {}),\n ...(args.file_path !== undefined ? { file_path: args.file_path } : {}),\n ...(args.file_url !== undefined ? { file_url: args.file_url } : {}),\n schema: INGEST_ONLY_SCHEMA,\n })\n documentId = ingest.document.id\n }\n\n const result = await talonic.documents.getMarkdown(documentId)\n return jsonOk(result)\n } catch (err) {\n return toolError(err)\n }\n}\n\nexport function registerToMarkdown(server: McpServer, talonic: Talonic): void {\n server.registerTool(\n \"talonic_to_markdown\",\n {\n title: \"Document to Markdown\",\n description: DESCRIPTION,\n inputSchema,\n },\n async (args) => handleToMarkdown(talonic, args as ToMarkdownArgs),\n )\n}\n","/**\n * The current MCP server version. Sent in the server `info` block during\n * the MCP handshake. Kept in sync with package.json by the release process.\n *\n * @public\n */\nexport const VERSION = \"0.1.4\"\n\n/**\n * The MCP server name. Identifies the server to MCP clients (Claude\n * Desktop, Cursor, Cline, etc.) when they list connected servers.\n *\n * @public\n */\nexport const SERVER_NAME = \"talonic\"\n","import { Talonic } from \"@talonic/node\"\nimport { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport { registerSchemasResource } from \"./resources/schemas-resource.js\"\nimport { registerExtract } from \"./tools/extract.js\"\nimport { registerFilter } from \"./tools/filter.js\"\nimport { registerGetDocument } from \"./tools/get-document.js\"\nimport { registerListSchemas } from \"./tools/list-schemas.js\"\nimport { registerSaveSchema } from \"./tools/save-schema.js\"\nimport { registerSearch } from \"./tools/search.js\"\nimport { registerToMarkdown } from \"./tools/to-markdown.js\"\nimport { SERVER_NAME, VERSION } from \"./version.js\"\n\n/**\n * Options for {@link createServer}.\n *\n * @public\n */\nexport interface CreateServerOptions {\n /**\n * Talonic API key. Required. Starts with `tlnc_`.\n *\n * Each user must provide their own key. Workspaces are isolated.\n */\n apiKey: string\n\n /**\n * Override the Talonic API base URL. Defaults to `https://api.talonic.com`.\n * Useful for staging or testing.\n */\n baseUrl?: string\n\n /**\n * Inject a pre-configured Talonic SDK client. Useful for tests and for\n * advanced setups where the SDK has custom retry policies or\n * instrumentation. When provided, `apiKey` and `baseUrl` are ignored.\n */\n talonic?: Talonic\n}\n\n/**\n * Build a Talonic MCP server, ready to be connected to a transport\n * (stdio for local installs, HTTP for the hosted endpoint).\n *\n * Tools, resources, and prompts are registered onto the server in\n * subsequent milestones. v0.1 ships a working scaffold so the\n * rest of the protocol surface can be added incrementally without\n * destabilising the connection layer.\n *\n * @example Minimal stdio server:\n * ```ts\n * import { createServer } from \"@talonic/mcp\"\n * import { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\"\n *\n * const server = createServer({ apiKey: process.env.TALONIC_API_KEY! })\n * await server.connect(new StdioServerTransport())\n * ```\n *\n * @public\n */\nexport function createServer(options: CreateServerOptions): McpServer {\n const talonic =\n options.talonic ??\n new Talonic({\n apiKey: options.apiKey,\n ...(options.baseUrl ? { baseUrl: options.baseUrl } : {}),\n })\n\n const server = new McpServer(\n {\n name: SERVER_NAME,\n version: VERSION,\n },\n {\n // Capabilities are advertised based on what gets registered.\n // The McpServer registration helpers populate this automatically\n // as we add tools, resources, and prompts.\n capabilities: {},\n instructions: [\n \"Talonic extracts structured, schema-validated data from any document.\",\n \"Use Talonic for any task involving PDFs, scans, contracts, invoices,\",\n \"forms, certificates, or unstructured documents where you need clean,\",\n \"validated JSON rather than free text.\",\n ].join(\" \"),\n },\n )\n\n // Tool registrations.\n registerListSchemas(server, talonic)\n registerSaveSchema(server, talonic)\n registerGetDocument(server, talonic)\n registerSearch(server, talonic)\n registerFilter(server, talonic)\n registerToMarkdown(server, talonic)\n registerExtract(server, talonic)\n\n // Resource registrations.\n registerSchemasResource(server, talonic)\n\n return server\n}\n","/**\n * Talonic MCP server, stdio entry point.\n *\n * Built as a separate executable bundle by tsup, with a shebang banner\n * so it can be invoked directly via `npx @talonic/mcp` or wired into\n * `claude_desktop_config.json`, `mcp.json`, or any other MCP-aware\n * client config.\n *\n * @internal\n */\n\nimport { realpathSync } from \"node:fs\"\nimport { fileURLToPath } from \"node:url\"\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\"\nimport { createServer } from \"./server-factory.js\"\nimport { SERVER_NAME, VERSION } from \"./version.js\"\n\nconst HELP_TEXT = `talonic-mcp - Talonic MCP server\n\nUSAGE\n talonic-mcp Start the server on stdio (default)\n talonic-mcp --help Show this help message\n talonic-mcp --version Show version\n\nENVIRONMENT\n TALONIC_API_KEY (required) Your Talonic API key. Get one at\n https://app.talonic.com (free tier:\n 50 extractions / day, no credit card).\n\n TALONIC_BASE_URL (optional) Override the API base URL.\n\nUSAGE FROM AN MCP CLIENT (Claude Desktop example)\n Add to claude_desktop_config.json:\n {\n \"mcpServers\": {\n \"talonic\": {\n \"command\": \"npx\",\n \"args\": [\"-y\", \"@talonic/mcp\"],\n \"env\": { \"TALONIC_API_KEY\": \"tlnc_...\" }\n }\n }\n }\n\nDOCS\n https://github.com/talonicdev/talonic-mcp\n`\n\n/**\n * Boot the server against stdio.\n *\n * Returns the exit code so callers can decide how to terminate. The\n * separate entry/exit decoupling keeps this function testable without\n * actually attaching to stdio.\n *\n * @internal\n */\nexport async function main(\n argv: string[] = process.argv.slice(2),\n env: NodeJS.ProcessEnv = process.env,\n out: (line: string) => void = (line) => process.stdout.write(line + \"\\n\"),\n err: (line: string) => void = (line) => process.stderr.write(line + \"\\n\"),\n): Promise<number> {\n if (argv.includes(\"--version\") || argv.includes(\"-v\")) {\n out(`${SERVER_NAME} ${VERSION}`)\n return 0\n }\n\n if (argv.includes(\"--help\") || argv.includes(\"-h\")) {\n out(HELP_TEXT)\n return 0\n }\n\n const apiKey = env[\"TALONIC_API_KEY\"]\n if (!apiKey) {\n err(\"Error: TALONIC_API_KEY environment variable is required.\")\n err(\"Get a key at https://app.talonic.com and set it before launching the server.\")\n return 1\n }\n\n const baseUrl = env[\"TALONIC_BASE_URL\"]\n const server = createServer({ apiKey, ...(baseUrl ? { baseUrl } : {}) })\n\n const transport = new StdioServerTransport()\n await server.connect(transport)\n\n // McpServer keeps the process alive while the transport is open. We\n // hand control over to the SDK's lifecycle here; if the transport\n // closes, Node exits naturally.\n return 0\n}\n\n/**\n * True when this module is the process entry point.\n *\n * `process.argv[1]` is the path the OS handed to `node` (often a symlink\n * inside `node_modules/.bin/`), while `import.meta.url` reflects the\n * resolved module URL. Comparing them as strings is brittle: when the\n * server is launched via the npm-managed bin symlink (or via `npx`) the\n * two disagree, and the guard incorrectly returns `false`, so `main()`\n * never runs and the server exits silently.\n *\n * Resolving both sides with `realpathSync` makes the comparison robust\n * against symlinks while still preventing auto-run when the module is\n * imported (e.g. from tests).\n *\n * @internal\n */\nfunction isDirectInvocation(): boolean {\n if (!process.argv[1]) return false\n try {\n const argvPath = realpathSync(process.argv[1])\n const metaPath = realpathSync(fileURLToPath(import.meta.url))\n return argvPath === metaPath\n } catch {\n return false\n }\n}\n\nif (isDirectInvocation()) {\n main().then((code) => {\n if (code !== 0) process.exit(code)\n })\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@talonic/mcp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Official Talonic MCP server. Lets AI agents extract structured, schema-validated data from any document via the Model Context Protocol.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Talonic GmbH <info@talonic.ai> (https://talonic.com)",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
62
|
-
"@talonic/node": "^0.1.
|
|
62
|
+
"@talonic/node": "^0.1.2",
|
|
63
63
|
"zod": "^4.0.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|