tunc-mcp 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 TUNC LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -45,6 +45,45 @@ npm install tunc-mcp
45
45
  Node 18 or newer. No dependencies. Get an API key at
46
46
  <https://tunchub.com/account/keys/new> — you can scope it read-only.
47
47
 
48
+ ## Options
49
+
50
+ Every helper takes an object. Only the key is required, and it falls back to `TUNC_API_KEY`.
51
+
52
+ ```js
53
+ import { orb, art, doc, connect, SERVERS } from 'tunc-mcp';
54
+
55
+ const memory = orb({
56
+ apiKey: process.env.TUNC_API_KEY,
57
+ endpoint: 'https://mcp.tuncorb.com/mcp', // override: staging, a proxy, or a local mock
58
+ });
59
+ ```
60
+
61
+ - `apiKey` — defaults to `TUNC_API_KEY`. It is checked when the client is constructed, so a missing key fails immediately rather than on the first call.
62
+ - `endpoint` — replaces the built-in URL for that service. This is what you use to point the client at a test server.
63
+ - `service` — `"orb"`, `"art"` or `"doc"`, if you construct `TuncMcpClient` directly instead of using `orb()` / `art()` / `doc()`.
64
+
65
+ `SERVERS` is the map of default endpoints. `connect(key)` returns all three clients at once.
66
+
67
+ ## What comes back
68
+
69
+ `callTool()` returns the server's MCP result unchanged:
70
+
71
+ ```js
72
+ { content: [{ type: "text", text: "<json string>" }], structuredContent: { /* … */ }, isError: false }
73
+ ```
74
+
75
+ Confusingly, the same payload often appears twice — as `structuredContent` and again serialised into `content[0].text`. Use `structuredContent` when it is there. When you only want the text, `callText()` unwraps it for you:
76
+
77
+ ```js
78
+ const text = await memory.callText('data_read', { name: 'contacts/ada' });
79
+ ```
80
+
81
+ Tool names come from the server, not from this package. Call `listTools()` to see what a service actually offers before writing against it — the list is not hard-coded here and changes as the servers change.
82
+
83
+ ## ESM only
84
+
85
+ This package is ESM. In a CommonJS project, either set `"type": "module"` in `package.json` or import it from an `.mjs` file. Otherwise Node fails with `SyntaxError: Cannot use import statement outside a module`.
86
+
48
87
  ## Use
49
88
 
50
89
  ```js
@@ -52,13 +91,43 @@ import { orb, art, doc } from 'tunc-mcp';
52
91
 
53
92
  const memory = orb(); // reads TUNC_API_KEY
54
93
 
94
+ // Every tool takes an `operation` that picks what it does. Ask for a shape the
95
+ // server does not have and you get invalid_arguments back, so call listTools()
96
+ // once and read the real schemas rather than trusting an example.
97
+ //
98
+ // data_write operation: create | append
99
+ // data_read operation: shelves | list | get | log | search | status
100
+ // data_update operation: replace | patch (needs if_revision)
101
+ // data_delete operation: record | entries | log (needs if_revision)
102
+
55
103
  // Agent memory: durable records, revision-guarded
56
104
  await memory.callTool('data_write', {
105
+ operation: 'create',
57
106
  name: 'contacts/ada',
58
107
  about: 'Primary contact, Example Ltd',
59
108
  value: { email: 'ada@example.com', timezone: 'Europe/London' },
60
109
  });
61
110
 
111
+ const record = await memory.callTool('data_read', {
112
+ operation: 'get',
113
+ name: 'contacts/ada',
114
+ });
115
+ const revision = JSON.parse(record.content[0].text).revision;
116
+
117
+ // Change it only if nobody else has, and delete it the same way
118
+ await memory.callTool('data_update', {
119
+ operation: 'patch',
120
+ name: 'contacts/ada',
121
+ if_revision: revision,
122
+ patch: [{ op: 'replace', path: '/timezone', value: 'Europe/Paris' }],
123
+ });
124
+
125
+ await memory.callTool('data_delete', {
126
+ operation: 'record',
127
+ name: 'contacts/ada',
128
+ if_revision: revision,
129
+ });
130
+
62
131
  // Artifacts: store a file, get a private link
63
132
  const files = art();
64
133
  await files.callTool('art_write', {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tunc-mcp",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "MCP client for Tunc Orb (agent memory database), Tunc Art (artifact storage and private file sharing) and Tunc Doc (documents, spreadsheets, decks).",
5
5
  "keywords": [
6
6
  "mcp",
package/src/client.js CHANGED
@@ -99,16 +99,21 @@ export class TuncMcpClient {
99
99
  if (session) this.#sessionId = session;
100
100
 
101
101
  const text = await response.text();
102
+ const body = parseBody(response.headers.get('content-type'), text);
102
103
 
103
104
  if (response.status === 401) {
105
+ // The server knows why it refused: missing key, revoked, or wrong scope.
106
+ // Keep its words and add ours, rather than replacing a specific answer
107
+ // with a generic one.
108
+ const server = body?.error?.message;
104
109
  throw new TuncMcpError(
105
- 'Unauthorized. The API key is missing, revoked, or not scoped for this service.',
106
- { status: 401, body: text },
110
+ server
111
+ ? `${server} (the API key is missing, revoked, or not scoped for this service)`
112
+ : 'Unauthorized. The API key is missing, revoked, or not scoped for this service.',
113
+ { status: 401, code: body?.error?.code, body },
107
114
  );
108
115
  }
109
116
 
110
- const body = parseBody(response.headers.get('content-type'), text);
111
-
112
117
  if (!response.ok) {
113
118
  throw new TuncMcpError(body?.error?.message ?? `HTTP ${response.status}`, {
114
119
  status: response.status,