@talonic/mcp 0.1.3 → 0.1.5

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 CHANGED
@@ -7,6 +7,56 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.1.5] - 2026-04-30
11
+
12
+ ### Changed
13
+
14
+ - `@talonic/node` dependency bumped to `^0.1.3`. Picks up the SDK refactor that drops local field-name pre-resolution; canonical names like `vendor.name` are now passed straight through to the API for server-side resolution.
15
+ - `talonic_filter` description: documents that the API now resolves canonical field names server-side, and flags that `is_not_empty` currently underreports.
16
+ - `talonic_extract` description: re-introduces the flat key-type map as an accepted schema format with a fallback note (the API documents it; if normalisation fails, the agent should retry with full JSON Schema).
17
+ - `talonic_save_schema` description: same treatment as `talonic_extract`, plus mention that responses include `short_id` (e.g. `SCH-XXXXXXXX`) alongside the UUID.
18
+
19
+ ### Fixed in upstream API (no MCP change required)
20
+
21
+ - `file_data` multipart uploads to `/v1/extract` no longer return `422 No document text available`.
22
+ - Error responses from `/v1/extract`, `/v1/schemas`, and `/v1/documents/filter` now include `request_id` and a useful `message`.
23
+ - `/v1/schemas/:id` accepts both UUIDs and `SCH-XXXXXXXX` short ids; responses include the `short_id` field.
24
+
25
+ ### Known issues (still open at upstream)
26
+
27
+ - Schema flat-map normalisation rejects valid flat-map definitions with "Schema definition produced no fields" despite advertising the format. Workaround: send full JSON Schema.
28
+ - `is_not_empty` filter operator returns empty results for fields known to be populated.
29
+ - `/v1/extract` `schema_id` does not accept the SCH- short form yet; UUID required.
30
+
31
+ ## [0.1.4] - 2026-04-29
32
+
33
+ ### Added
34
+
35
+ - `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.
36
+ - Tests covering `file_data` decoding, MIME inference from `filename`, and rejection of multiple file sources.
37
+
38
+ ### Changed
39
+
40
+ - `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.
41
+ - `talonic_to_markdown` description: added `file_data` + `filename` to the input list with the same chat-client guidance.
42
+ - `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).
43
+
44
+ ## [0.1.3] - 2026-04-29
45
+
46
+ ### Fixed
47
+
48
+ - 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.
49
+
50
+ ### Added
51
+
52
+ - 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.
53
+
54
+ ### Changed
55
+
56
+ - `@talonic/node` dependency bumped to `^0.1.2` to pull in the matching SDK fix for the same bug in the SDK CLI bin.
57
+
58
+ ## [Unreleased prior to 0.1.3]
59
+
10
60
  ### Added
11
61
 
12
62
  - 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.0 with 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.
5
+ > **Status:** v0.1.5. 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
- There are two paths today: a local-checkout path that works right now, and a one-line `npx` path that becomes available once we publish to npm.
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
- No clone, no build. The `-y` flag skips the install prompt.
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": "node",
70
- "args": ["/absolute/path/to/talonic-mcp/dist/server.js"],
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
- Restart Claude Desktop. Talonic appears in the connected servers list with all seven tools.
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": "node",
90
- "args": ["/absolute/path/to/talonic-mcp/dist/server.js"],
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": "node",
111
- "args": ["/absolute/path/to/talonic-mcp/dist/server.js"],
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.). Accepts canonical field names (e.g. `vendor.name`, `policy.0_coverage_type`) which the Talonic API resolves to ids server-side, or UUIDs directly. The `is_not_empty` operator currently underreports; see [Known limitations](#known-limitations-v01).
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 already in the workspace.
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
- Check the absolute path in `args` is correct and that `dist/server.js` exists. Try running it directly: `node /absolute/path/to/talonic-mcp/dist/server.js --version`. It should print `talonic 0.1.0`.
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.5` (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.
@@ -168,18 +154,41 @@ Known limitation. Always provide either an inline `schema` or a `schema_id`. The
168
154
  **`talonic_extract` rejects with `unsupported_file_type`.**
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
- **`talonic_filter` errors with `field_not_found`.**
172
- The field name does not exist in your workspace yet. Run `talonic_search` or `talonic_list_schemas` first to discover available field names.
157
+ **`talonic_filter` errors with `VALIDATION_ERROR` / "No field matches name".**
158
+ You passed a `field` value the API does not know. Field names must be canonical names from the field registry (e.g. `vendor.name`, `policy.0_term_end`). Call `talonic_search` first; the canonical names appear in `fields[].canonicalName` of the response. You can also pass a UUID via `field_id` if you have one.
159
+
160
+ **`talonic_filter` returns no results when you expect data.**
161
+ The `is_not_empty` operator currently underreports. Use a more specific operator (`eq`, `gt`, `gte`, `lt`, `lte`, `between`, `contains`) against a known value when possible.
173
162
 
174
163
  **Tool descriptions look wrong in my client.**
175
164
  Some MCP clients cache tool descriptions. Restart the client after a server update.
176
165
 
177
166
  ## Known limitations (v0.1)
178
167
 
179
- - Auto-discovery extract (no schema) is not reliable on production. Always pass a schema.
180
- - The simplified-fields schema format `{ fields: [...] }` is unstable on production. Use flat-map (`{ vendor_name: "string", ... }`) or full JSON Schema.
181
- - `talonic_to_markdown` requires an existing `document_id`. To convert a fresh file, call `talonic_extract` first with a minimal schema, then `talonic_to_markdown` with the resulting `document.id`.
182
- - The `@talonic/node` SDK is not yet on npm; install via local checkout for now.
168
+ - **Auto-discovery extract (no schema) is not reliable on production.** Always pass a `schema` or `schema_id` to `talonic_extract`.
169
+ - **Schema definition: prefer full JSON Schema for now.** The flat key-type map (`{ vendor_name: "string", ... }`) is documented as supported and the API's own error message lists it as accepted, but as of writing the server-side normaliser does not actually translate it. If a flat-map save returns a "no fields" error, fall back to:
170
+ ```json
171
+ {
172
+ "type": "object",
173
+ "properties": {
174
+ "vendor_name": { "type": "string", "title": "Vendor Name" },
175
+ "total_amount": { "type": "number", "title": "Total Amount" }
176
+ },
177
+ "required": ["vendor_name", "total_amount"]
178
+ }
179
+ ```
180
+ - **`is_not_empty` filter currently underreports.** A condition with `operator: "is_not_empty"` may return zero documents even when fields are populated. Use specific operators (`eq`, `gt`, `gte`, `lt`, `lte`, `between`, `contains`) against known values instead.
181
+ - **`schema_id` on `talonic_extract` requires the UUID form.** Other endpoints accept either UUID or `SCH-XXXXXXXX`, but `/v1/extract` currently only accepts UUIDs there. Pass the UUID from `talonic_list_schemas`.
182
+
183
+ ## Upgrading from 0.1.0 / 0.1.1 / 0.1.2
184
+
185
+ 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.
186
+
187
+ The fix is to point your `args` at `@latest` (or `@0.1.3` explicitly) and fully restart the client:
188
+
189
+ ```jsonc
190
+ "args": ["-y", "@talonic/mcp@latest"]
191
+ ```
183
192
 
184
193
  ## Develop
185
194
 
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.3";
56
+ declare const VERSION = "0.1.5";
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,30 +79,46 @@ 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
- "- file_path: a local path to the document (the MCP server reads it from disk).",
83
- "- file_url: a URL the Talonic API will fetch directly.",
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
- '- Flat map (recommended): { vendor_name: "string", total_amount: "number", due_date: "date" }',
88
- '- JSON Schema: { type: "object", properties: { ... } }',
89
- "- schema_id: id of a saved schema from talonic_list_schemas",
95
+ '- JSON Schema (most reliable): { type: "object", properties: { vendor_name: { type: "string" } } }',
96
+ '- Flat key-type map: { vendor_name: "string", invoice_total: "number" } -- API normalises server-side. If you get a "no fields" error, fall back to JSON Schema.',
97
+ "- schema_id: id of a saved schema from talonic_list_schemas. Accepts the UUID or the SCH-XXXXXXXX short id.",
90
98
  "",
91
99
  "IMPORTANT: production currently rejects requests with no schema. Always provide either",
92
100
  "an inline `schema` or a `schema_id`."
93
101
  ].join("\n");
94
102
  var inputSchema = {
103
+ file_data: z.string().optional().describe(
104
+ "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."
105
+ ),
106
+ filename: z.string().optional().describe(
107
+ "Original filename including extension, e.g. 'invoice.pdf'. Used to infer MIME type when uploading via `file_data`. Required when `file_data` is provided."
108
+ ),
95
109
  file_path: z.string().optional().describe(
96
- "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."
110
+ "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
111
  ),
98
112
  file_url: z.string().optional().describe(
99
- "URL to a document file. The Talonic API fetches it server-side. Use this for remote documents."
113
+ "URL to a document file. The Talonic API fetches it server-side. Use this for documents already on the public web."
100
114
  ),
101
115
  document_id: z.string().optional().describe("ID of a document already in the workspace, to re-extract with a new schema."),
102
116
  schema: z.record(z.string(), z.unknown()).optional().describe(
103
- "Inline schema definition. Flat map (recommended), simplified fields, or JSON Schema."
117
+ "Inline schema definition. Most reliable: full JSON Schema {type:'object', properties:{...}}. Also accepted: a flat key-type map {field_name:'string', amount:'number'} which the API normalises. Mutually exclusive with `schema_id`."
118
+ ),
119
+ schema_id: z.string().optional().describe(
120
+ "ID of a saved schema. Accepts UUID or SCH-XXXXXXXX short id. Mutually exclusive with `schema`."
104
121
  ),
105
- schema_id: z.string().optional().describe("ID of a saved schema. Mutually exclusive with `schema`."),
106
122
  instructions: z.string().optional().describe(
107
123
  "Natural-language guidance for the extractor, e.g. 'Focus on the billing section. Amounts are in EUR.'"
108
124
  ),
@@ -111,6 +127,10 @@ var inputSchema = {
111
127
  async function handleExtract(talonic, args) {
112
128
  try {
113
129
  const params = {};
130
+ if (args.file_data !== void 0) {
131
+ params.file = Buffer.from(args.file_data, "base64");
132
+ if (args.filename !== void 0) params.filename = args.filename;
133
+ }
114
134
  if (args.file_path !== void 0) params.file_path = args.file_path;
115
135
  if (args.file_url !== void 0) params.file_url = args.file_url;
116
136
  if (args.document_id !== void 0) params.document_id = args.document_id;
@@ -137,7 +157,8 @@ function registerExtract(server, talonic) {
137
157
  }
138
158
  var DESCRIPTION2 = [
139
159
  "Filter the user's Talonic documents by extracted field values using composable conditions.",
140
- "Conditions accept field names (e.g. 'vendor_name'); the SDK resolves them to internal field IDs.",
160
+ "Conditions accept either a canonical field name (e.g. 'vendor.name', 'policy.0_coverage_type')",
161
+ "or a field UUID. The Talonic API resolves names to ids server-side.",
141
162
  "",
142
163
  "USE WHEN:",
143
164
  "- The user wants documents matching specific structured criteria, like 'invoices over 1000 EUR'",
@@ -155,9 +176,14 @@ var DESCRIPTION2 = [
155
176
  "- gt, gte, lt, lte: numeric or date comparisons",
156
177
  "- between: requires both `value` and `value_to`",
157
178
  "- contains: substring match on string fields",
158
- "- is_empty, is_not_empty: presence checks (no value needed)",
179
+ "- is_empty: presence check (no value needed)",
180
+ "- is_not_empty: presence check (no value needed). Note: currently underreports;",
181
+ " use `eq` / `gt` / `contains` etc. against a known value when possible.",
159
182
  "",
160
- "TIP: To discover available field names, call talonic_search first with a related query."
183
+ "TIPS:",
184
+ "- To discover available field names, call talonic_search first with a related query.",
185
+ " fields[].canonicalName from the response is what to pass as `field` here.",
186
+ "- Both `field` (name) and `field_id` (UUID) reach the API as `fieldId`. Either is fine."
161
187
  ].join("\n");
162
188
  var operatorEnum = z.enum([
163
189
  "eq",
@@ -172,8 +198,10 @@ var operatorEnum = z.enum([
172
198
  "is_not_empty"
173
199
  ]);
174
200
  var conditionSchema = z.object({
175
- field: z.string().optional().describe("Field name (e.g. 'vendor_name'). Resolved to a fieldId automatically."),
176
- field_id: z.string().optional().describe("Talonic field id (e.g. 'fld_abc'). Use this if you already have it."),
201
+ field: z.string().optional().describe(
202
+ "Canonical field name (e.g. 'vendor.name', 'policy.0_coverage_type'). The Talonic API resolves names to ids server-side. Mutually exclusive with `field_id`."
203
+ ),
204
+ field_id: z.string().optional().describe("Talonic field UUID. Mutually exclusive with `field`."),
177
205
  operator: operatorEnum.describe("Comparison operator. See description for the full list."),
178
206
  value: z.unknown().optional().describe("Value to compare against."),
179
207
  value_to: z.unknown().optional().describe("Upper bound for `between` operator; ignored otherwise.")
@@ -309,7 +337,7 @@ function registerListSchemas(server, talonic) {
309
337
  }
310
338
  var DESCRIPTION5 = [
311
339
  "Save a schema definition to the user's Talonic workspace so it can be reused",
312
- "across future extractions. Returns the saved schema with its newly assigned id.",
340
+ "across future extractions. Returns the saved schema with its newly assigned id and short_id.",
313
341
  "",
314
342
  "USE WHEN:",
315
343
  "- The user asks to save a schema, store a template, or reuse the schema across docs.",
@@ -320,12 +348,16 @@ var DESCRIPTION5 = [
320
348
  "- The user just wants to extract once with an inline schema (call talonic_extract directly with the schema inline).",
321
349
  "- The user has not confirmed the schema design (avoid creating clutter in their workspace).",
322
350
  "",
323
- "TIP: After saving, call talonic_extract with `schema_id` set to the returned id for consistent results."
351
+ "DEFINITION FORMATS:",
352
+ '- JSON Schema (most reliable): { type: "object", properties: { vendor_name: { type: "string" } } }',
353
+ '- Flat key-type map: { vendor_name: "string", invoice_total: "number" } -- API normalises server-side. If you get a "no fields" error from the API, fall back to JSON Schema.',
354
+ "",
355
+ "TIP: After saving, call talonic_extract with `schema_id` set to the returned id (UUID or SCH- short id) for consistent results."
324
356
  ].join("\n");
325
357
  var inputSchema4 = {
326
358
  name: z.string().min(1).describe("Human-readable name for the schema, e.g. 'Standard Invoice'."),
327
359
  definition: z.record(z.string(), z.unknown()).describe(
328
- "Schema definition. Accepts JSON Schema, simplified fields ({fields:[...]}), or a flat key-type map."
360
+ "Schema definition. Most reliable: full JSON Schema {type:'object', properties:{...}}. Also accepted: a flat key-type map {field_name:'string', amount:'number'} which the API normalises."
329
361
  ),
330
362
  description: z.string().optional().describe("Optional description of what this schema extracts and when to use it.")
331
363
  };
@@ -399,8 +431,8 @@ function registerSearch(server, talonic) {
399
431
  }
400
432
  var DESCRIPTION7 = [
401
433
  "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 tool ingests it via",
403
- "extract first (with a minimal schema) and then returns the markdown.",
434
+ "raw file bytes (base64), a local file path, or a URL. When given a raw file, the",
435
+ "tool ingests it via extract first and then returns the markdown.",
404
436
  "",
405
437
  "USE WHEN:",
406
438
  "- The user wants the full text content of a document for summarisation, translation, or analysis.",
@@ -413,25 +445,37 @@ var DESCRIPTION7 = [
413
445
  "",
414
446
  "INPUTS (provide exactly one):",
415
447
  "- document_id: id of an already-ingested document (cheapest path; one API call)",
416
- "- file_path: local path to a document file (the MCP server reads it from disk)",
448
+ "- file_data + filename (RECOMMENDED for chat clients): base64-encoded file bytes plus",
449
+ " the original filename (with extension). Use this whenever you already have the file",
450
+ " in memory, e.g. the user attached it to the conversation. Works in every MCP client.",
451
+ "- file_path: local path to a document file. Only works if the MCP server has read access",
452
+ " to that path; in sandboxed chat clients use file_data instead.",
417
453
  "- file_url: URL to a document file (the Talonic API fetches it server-side)"
418
454
  ].join("\n");
419
455
  var inputSchema6 = {
420
456
  document_id: z.string().min(1).optional().describe(
421
457
  "The Talonic document id whose markdown you want. Get this from a previous talonic_extract or talonic_search response."
422
458
  ),
423
- file_path: z.string().optional().describe("Local path to a document file. The MCP server reads it from disk and uploads it."),
459
+ file_data: z.string().optional().describe(
460
+ "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."
461
+ ),
462
+ filename: z.string().optional().describe(
463
+ "Original filename including extension, e.g. 'invoice.pdf'. Used to infer MIME type when uploading via `file_data`. Required when `file_data` is provided."
464
+ ),
465
+ file_path: z.string().optional().describe(
466
+ "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."
467
+ ),
424
468
  file_url: z.string().optional().describe("URL to a document file. The Talonic API fetches it server-side.")
425
469
  };
426
470
  var INGEST_ONLY_SCHEMA = {};
427
471
  async function handleToMarkdown(talonic, args) {
428
472
  try {
429
- const sources = ["document_id", "file_path", "file_url"];
473
+ const sources = ["document_id", "file_data", "file_path", "file_url"];
430
474
  const provided = sources.filter((k) => args[k] !== void 0);
431
475
  if (provided.length === 0) {
432
476
  throw new TalonicError({
433
477
  code: "missing_input_source",
434
- message: "talonic_to_markdown requires one of: document_id, file_path, file_url.",
478
+ message: "talonic_to_markdown requires one of: document_id, file_data, file_path, file_url.",
435
479
  status: 0,
436
480
  retryable: false
437
481
  });
@@ -447,6 +491,10 @@ async function handleToMarkdown(talonic, args) {
447
491
  let documentId = args.document_id;
448
492
  if (!documentId) {
449
493
  const ingest = await talonic.extract({
494
+ ...args.file_data !== void 0 ? {
495
+ file: Buffer.from(args.file_data, "base64"),
496
+ ...args.filename !== void 0 ? { filename: args.filename } : {}
497
+ } : {},
450
498
  ...args.file_path !== void 0 ? { file_path: args.file_path } : {},
451
499
  ...args.file_url !== void 0 ? { file_url: args.file_url } : {},
452
500
  schema: INGEST_ONLY_SCHEMA
@@ -472,7 +520,7 @@ function registerToMarkdown(server, talonic) {
472
520
  }
473
521
 
474
522
  // src/version.ts
475
- var VERSION = "0.1.3";
523
+ var VERSION = "0.1.5";
476
524
  var SERVER_NAME = "talonic";
477
525
 
478
526
  // 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,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,CA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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.3\"\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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AAaH,YAAAA;AAAA,MACb,WAAA,EAAAE;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 (most reliable): { type: \"object\", properties: { vendor_name: { type: \"string\" } } }',\n '- Flat key-type map: { vendor_name: \"string\", invoice_total: \"number\" } -- API normalises server-side. If you get a \"no fields\" error, fall back to JSON Schema.',\n \"- schema_id: id of a saved schema from talonic_list_schemas. Accepts the UUID or the SCH-XXXXXXXX short id.\",\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. Most reliable: full JSON Schema {type:'object', properties:{...}}. Also accepted: a flat key-type map {field_name:'string', amount:'number'} which the API normalises. Mutually exclusive with `schema_id`.\",\n ),\n schema_id: z\n .string()\n .optional()\n .describe(\n \"ID of a saved schema. Accepts UUID or SCH-XXXXXXXX short id. Mutually exclusive with `schema`.\",\n ),\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 either a canonical field name (e.g. 'vendor.name', 'policy.0_coverage_type')\",\n \"or a field UUID. The Talonic API resolves names to ids server-side.\",\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: presence check (no value needed)\",\n \"- is_not_empty: presence check (no value needed). Note: currently underreports;\",\n \" use `eq` / `gt` / `contains` etc. against a known value when possible.\",\n \"\",\n \"TIPS:\",\n \"- To discover available field names, call talonic_search first with a related query.\",\n \" fields[].canonicalName from the response is what to pass as `field` here.\",\n \"- Both `field` (name) and `field_id` (UUID) reach the API as `fieldId`. Either is fine.\",\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(\n \"Canonical field name (e.g. 'vendor.name', 'policy.0_coverage_type'). The Talonic API resolves names to ids server-side. Mutually exclusive with `field_id`.\",\n ),\n field_id: z.string().optional().describe(\"Talonic field UUID. Mutually exclusive with `field`.\"),\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 and short_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 \"DEFINITION FORMATS:\",\n '- JSON Schema (most reliable): { type: \"object\", properties: { vendor_name: { type: \"string\" } } }',\n '- Flat key-type map: { vendor_name: \"string\", invoice_total: \"number\" } -- API normalises server-side. If you get a \"no fields\" error from the API, fall back to JSON Schema.',\n \"\",\n \"TIP: After saving, call talonic_extract with `schema_id` set to the returned id (UUID or SCH- short 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. Most reliable: full JSON Schema {type:'object', properties:{...}}. Also accepted: a flat key-type map {field_name:'string', amount:'number'} which the API normalises.\",\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.5\"\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
@@ -81,30 +81,46 @@ var DESCRIPTION = [
81
81
  "- The user wants to find documents matching a query (use talonic_search or talonic_filter).",
82
82
  "",
83
83
  "FILE SOURCES (provide exactly one):",
84
- "- file_path: a local path to the document (the MCP server reads it from disk).",
85
- "- file_url: a URL the Talonic API will fetch directly.",
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.",
86
94
  "- document_id: re-extract a document already in the workspace.",
87
95
  "",
88
96
  "SCHEMA FORMATS (provide at most one of `schema` or `schema_id`):",
89
- '- Flat map (recommended): { vendor_name: "string", total_amount: "number", due_date: "date" }',
90
- '- JSON Schema: { type: "object", properties: { ... } }',
91
- "- schema_id: id of a saved schema from talonic_list_schemas",
97
+ '- JSON Schema (most reliable): { type: "object", properties: { vendor_name: { type: "string" } } }',
98
+ '- Flat key-type map: { vendor_name: "string", invoice_total: "number" } -- API normalises server-side. If you get a "no fields" error, fall back to JSON Schema.',
99
+ "- schema_id: id of a saved schema from talonic_list_schemas. Accepts the UUID or the SCH-XXXXXXXX short id.",
92
100
  "",
93
101
  "IMPORTANT: production currently rejects requests with no schema. Always provide either",
94
102
  "an inline `schema` or a `schema_id`."
95
103
  ].join("\n");
96
104
  var inputSchema = {
105
+ file_data: z.string().optional().describe(
106
+ "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."
107
+ ),
108
+ filename: z.string().optional().describe(
109
+ "Original filename including extension, e.g. 'invoice.pdf'. Used to infer MIME type when uploading via `file_data`. Required when `file_data` is provided."
110
+ ),
97
111
  file_path: z.string().optional().describe(
98
- "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."
112
+ "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."
99
113
  ),
100
114
  file_url: z.string().optional().describe(
101
- "URL to a document file. The Talonic API fetches it server-side. Use this for remote documents."
115
+ "URL to a document file. The Talonic API fetches it server-side. Use this for documents already on the public web."
102
116
  ),
103
117
  document_id: z.string().optional().describe("ID of a document already in the workspace, to re-extract with a new schema."),
104
118
  schema: z.record(z.string(), z.unknown()).optional().describe(
105
- "Inline schema definition. Flat map (recommended), simplified fields, or JSON Schema."
119
+ "Inline schema definition. Most reliable: full JSON Schema {type:'object', properties:{...}}. Also accepted: a flat key-type map {field_name:'string', amount:'number'} which the API normalises. Mutually exclusive with `schema_id`."
120
+ ),
121
+ schema_id: z.string().optional().describe(
122
+ "ID of a saved schema. Accepts UUID or SCH-XXXXXXXX short id. Mutually exclusive with `schema`."
106
123
  ),
107
- schema_id: z.string().optional().describe("ID of a saved schema. Mutually exclusive with `schema`."),
108
124
  instructions: z.string().optional().describe(
109
125
  "Natural-language guidance for the extractor, e.g. 'Focus on the billing section. Amounts are in EUR.'"
110
126
  ),
@@ -113,6 +129,10 @@ var inputSchema = {
113
129
  async function handleExtract(talonic, args) {
114
130
  try {
115
131
  const params = {};
132
+ if (args.file_data !== void 0) {
133
+ params.file = Buffer.from(args.file_data, "base64");
134
+ if (args.filename !== void 0) params.filename = args.filename;
135
+ }
116
136
  if (args.file_path !== void 0) params.file_path = args.file_path;
117
137
  if (args.file_url !== void 0) params.file_url = args.file_url;
118
138
  if (args.document_id !== void 0) params.document_id = args.document_id;
@@ -139,7 +159,8 @@ function registerExtract(server, talonic) {
139
159
  }
140
160
  var DESCRIPTION2 = [
141
161
  "Filter the user's Talonic documents by extracted field values using composable conditions.",
142
- "Conditions accept field names (e.g. 'vendor_name'); the SDK resolves them to internal field IDs.",
162
+ "Conditions accept either a canonical field name (e.g. 'vendor.name', 'policy.0_coverage_type')",
163
+ "or a field UUID. The Talonic API resolves names to ids server-side.",
143
164
  "",
144
165
  "USE WHEN:",
145
166
  "- The user wants documents matching specific structured criteria, like 'invoices over 1000 EUR'",
@@ -157,9 +178,14 @@ var DESCRIPTION2 = [
157
178
  "- gt, gte, lt, lte: numeric or date comparisons",
158
179
  "- between: requires both `value` and `value_to`",
159
180
  "- contains: substring match on string fields",
160
- "- is_empty, is_not_empty: presence checks (no value needed)",
181
+ "- is_empty: presence check (no value needed)",
182
+ "- is_not_empty: presence check (no value needed). Note: currently underreports;",
183
+ " use `eq` / `gt` / `contains` etc. against a known value when possible.",
161
184
  "",
162
- "TIP: To discover available field names, call talonic_search first with a related query."
185
+ "TIPS:",
186
+ "- To discover available field names, call talonic_search first with a related query.",
187
+ " fields[].canonicalName from the response is what to pass as `field` here.",
188
+ "- Both `field` (name) and `field_id` (UUID) reach the API as `fieldId`. Either is fine."
163
189
  ].join("\n");
164
190
  var operatorEnum = z.enum([
165
191
  "eq",
@@ -174,8 +200,10 @@ var operatorEnum = z.enum([
174
200
  "is_not_empty"
175
201
  ]);
176
202
  var conditionSchema = z.object({
177
- field: z.string().optional().describe("Field name (e.g. 'vendor_name'). Resolved to a fieldId automatically."),
178
- field_id: z.string().optional().describe("Talonic field id (e.g. 'fld_abc'). Use this if you already have it."),
203
+ field: z.string().optional().describe(
204
+ "Canonical field name (e.g. 'vendor.name', 'policy.0_coverage_type'). The Talonic API resolves names to ids server-side. Mutually exclusive with `field_id`."
205
+ ),
206
+ field_id: z.string().optional().describe("Talonic field UUID. Mutually exclusive with `field`."),
179
207
  operator: operatorEnum.describe("Comparison operator. See description for the full list."),
180
208
  value: z.unknown().optional().describe("Value to compare against."),
181
209
  value_to: z.unknown().optional().describe("Upper bound for `between` operator; ignored otherwise.")
@@ -311,7 +339,7 @@ function registerListSchemas(server, talonic) {
311
339
  }
312
340
  var DESCRIPTION5 = [
313
341
  "Save a schema definition to the user's Talonic workspace so it can be reused",
314
- "across future extractions. Returns the saved schema with its newly assigned id.",
342
+ "across future extractions. Returns the saved schema with its newly assigned id and short_id.",
315
343
  "",
316
344
  "USE WHEN:",
317
345
  "- The user asks to save a schema, store a template, or reuse the schema across docs.",
@@ -322,12 +350,16 @@ var DESCRIPTION5 = [
322
350
  "- The user just wants to extract once with an inline schema (call talonic_extract directly with the schema inline).",
323
351
  "- The user has not confirmed the schema design (avoid creating clutter in their workspace).",
324
352
  "",
325
- "TIP: After saving, call talonic_extract with `schema_id` set to the returned id for consistent results."
353
+ "DEFINITION FORMATS:",
354
+ '- JSON Schema (most reliable): { type: "object", properties: { vendor_name: { type: "string" } } }',
355
+ '- Flat key-type map: { vendor_name: "string", invoice_total: "number" } -- API normalises server-side. If you get a "no fields" error from the API, fall back to JSON Schema.',
356
+ "",
357
+ "TIP: After saving, call talonic_extract with `schema_id` set to the returned id (UUID or SCH- short id) for consistent results."
326
358
  ].join("\n");
327
359
  var inputSchema4 = {
328
360
  name: z.string().min(1).describe("Human-readable name for the schema, e.g. 'Standard Invoice'."),
329
361
  definition: z.record(z.string(), z.unknown()).describe(
330
- "Schema definition. Accepts JSON Schema, simplified fields ({fields:[...]}), or a flat key-type map."
362
+ "Schema definition. Most reliable: full JSON Schema {type:'object', properties:{...}}. Also accepted: a flat key-type map {field_name:'string', amount:'number'} which the API normalises."
331
363
  ),
332
364
  description: z.string().optional().describe("Optional description of what this schema extracts and when to use it.")
333
365
  };
@@ -401,8 +433,8 @@ function registerSearch(server, talonic) {
401
433
  }
402
434
  var DESCRIPTION7 = [
403
435
  "Get the OCR-converted markdown for a document. Accepts an existing document_id,",
404
- "a local file path, or a URL. When given a raw file, the tool ingests it via",
405
- "extract first (with a minimal schema) and then returns the markdown.",
436
+ "raw file bytes (base64), a local file path, or a URL. When given a raw file, the",
437
+ "tool ingests it via extract first and then returns the markdown.",
406
438
  "",
407
439
  "USE WHEN:",
408
440
  "- The user wants the full text content of a document for summarisation, translation, or analysis.",
@@ -415,25 +447,37 @@ var DESCRIPTION7 = [
415
447
  "",
416
448
  "INPUTS (provide exactly one):",
417
449
  "- document_id: id of an already-ingested document (cheapest path; one API call)",
418
- "- file_path: local path to a document file (the MCP server reads it from disk)",
450
+ "- file_data + filename (RECOMMENDED for chat clients): base64-encoded file bytes plus",
451
+ " the original filename (with extension). Use this whenever you already have the file",
452
+ " in memory, e.g. the user attached it to the conversation. Works in every MCP client.",
453
+ "- file_path: local path to a document file. Only works if the MCP server has read access",
454
+ " to that path; in sandboxed chat clients use file_data instead.",
419
455
  "- file_url: URL to a document file (the Talonic API fetches it server-side)"
420
456
  ].join("\n");
421
457
  var inputSchema6 = {
422
458
  document_id: z.string().min(1).optional().describe(
423
459
  "The Talonic document id whose markdown you want. Get this from a previous talonic_extract or talonic_search response."
424
460
  ),
425
- file_path: z.string().optional().describe("Local path to a document file. The MCP server reads it from disk and uploads it."),
461
+ file_data: z.string().optional().describe(
462
+ "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."
463
+ ),
464
+ filename: z.string().optional().describe(
465
+ "Original filename including extension, e.g. 'invoice.pdf'. Used to infer MIME type when uploading via `file_data`. Required when `file_data` is provided."
466
+ ),
467
+ file_path: z.string().optional().describe(
468
+ "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."
469
+ ),
426
470
  file_url: z.string().optional().describe("URL to a document file. The Talonic API fetches it server-side.")
427
471
  };
428
472
  var INGEST_ONLY_SCHEMA = {};
429
473
  async function handleToMarkdown(talonic, args) {
430
474
  try {
431
- const sources = ["document_id", "file_path", "file_url"];
475
+ const sources = ["document_id", "file_data", "file_path", "file_url"];
432
476
  const provided = sources.filter((k) => args[k] !== void 0);
433
477
  if (provided.length === 0) {
434
478
  throw new TalonicError({
435
479
  code: "missing_input_source",
436
- message: "talonic_to_markdown requires one of: document_id, file_path, file_url.",
480
+ message: "talonic_to_markdown requires one of: document_id, file_data, file_path, file_url.",
437
481
  status: 0,
438
482
  retryable: false
439
483
  });
@@ -449,6 +493,10 @@ async function handleToMarkdown(talonic, args) {
449
493
  let documentId = args.document_id;
450
494
  if (!documentId) {
451
495
  const ingest = await talonic.extract({
496
+ ...args.file_data !== void 0 ? {
497
+ file: Buffer.from(args.file_data, "base64"),
498
+ ...args.filename !== void 0 ? { filename: args.filename } : {}
499
+ } : {},
452
500
  ...args.file_path !== void 0 ? { file_path: args.file_path } : {},
453
501
  ...args.file_url !== void 0 ? { file_url: args.file_url } : {},
454
502
  schema: INGEST_ONLY_SCHEMA
@@ -474,7 +522,7 @@ function registerToMarkdown(server, talonic) {
474
522
  }
475
523
 
476
524
  // src/version.ts
477
- var VERSION = "0.1.3";
525
+ var VERSION = "0.1.5";
478
526
  var SERVER_NAME = "talonic";
479
527
 
480
528
  // src/server-factory.ts
@@ -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,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,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_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.3\"\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"]}
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,EAA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C7B,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 (most reliable): { type: \"object\", properties: { vendor_name: { type: \"string\" } } }',\n '- Flat key-type map: { vendor_name: \"string\", invoice_total: \"number\" } -- API normalises server-side. If you get a \"no fields\" error, fall back to JSON Schema.',\n \"- schema_id: id of a saved schema from talonic_list_schemas. Accepts the UUID or the SCH-XXXXXXXX short id.\",\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. Most reliable: full JSON Schema {type:'object', properties:{...}}. Also accepted: a flat key-type map {field_name:'string', amount:'number'} which the API normalises. Mutually exclusive with `schema_id`.\",\n ),\n schema_id: z\n .string()\n .optional()\n .describe(\n \"ID of a saved schema. Accepts UUID or SCH-XXXXXXXX short id. Mutually exclusive with `schema`.\",\n ),\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 either a canonical field name (e.g. 'vendor.name', 'policy.0_coverage_type')\",\n \"or a field UUID. The Talonic API resolves names to ids server-side.\",\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: presence check (no value needed)\",\n \"- is_not_empty: presence check (no value needed). Note: currently underreports;\",\n \" use `eq` / `gt` / `contains` etc. against a known value when possible.\",\n \"\",\n \"TIPS:\",\n \"- To discover available field names, call talonic_search first with a related query.\",\n \" fields[].canonicalName from the response is what to pass as `field` here.\",\n \"- Both `field` (name) and `field_id` (UUID) reach the API as `fieldId`. Either is fine.\",\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(\n \"Canonical field name (e.g. 'vendor.name', 'policy.0_coverage_type'). The Talonic API resolves names to ids server-side. Mutually exclusive with `field_id`.\",\n ),\n field_id: z.string().optional().describe(\"Talonic field UUID. Mutually exclusive with `field`.\"),\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 and short_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 \"DEFINITION FORMATS:\",\n '- JSON Schema (most reliable): { type: \"object\", properties: { vendor_name: { type: \"string\" } } }',\n '- Flat key-type map: { vendor_name: \"string\", invoice_total: \"number\" } -- API normalises server-side. If you get a \"no fields\" error from the API, fall back to JSON Schema.',\n \"\",\n \"TIP: After saving, call talonic_extract with `schema_id` set to the returned id (UUID or SCH- short 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. Most reliable: full JSON Schema {type:'object', properties:{...}}. Also accepted: a flat key-type map {field_name:'string', amount:'number'} which the API normalises.\",\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.5\"\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",
3
+ "version": "0.1.5",
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.2",
62
+ "@talonic/node": "^0.1.3",
63
63
  "zod": "^4.0.0"
64
64
  },
65
65
  "devDependencies": {