slab-mcp 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -9
- package/dist/client.d.ts +3 -1
- package/dist/client.js +3 -1
- package/dist/client.js.map +1 -1
- package/dist/config.d.ts +3 -0
- package/dist/config.js +3 -5
- package/dist/config.js.map +1 -1
- package/dist/credentials.d.ts +33 -0
- package/dist/credentials.js +77 -0
- package/dist/credentials.js.map +1 -0
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/version.d.ts +13 -0
- package/dist/version.js +16 -0
- package/dist/version.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -65,12 +65,62 @@ key.
|
|
|
65
65
|
|
|
66
66
|
| Variable | Required | Default | Description |
|
|
67
67
|
|---|---|---|---|
|
|
68
|
-
| `SLAB_API_KEY` |
|
|
68
|
+
| `SLAB_API_KEY` | one of these two | — | Your slab API key, literally. |
|
|
69
|
+
| `SLAB_API_KEY_COMMAND` | one of these two | — | A command that *prints* the key. See [Handling the API key](#handling-the-api-key). |
|
|
69
70
|
| `SLAB_API_URL` | No | `https://api.slab.dev-jeb.com` | Override for local development. |
|
|
70
71
|
| `SLAB_COLLECTOR` | No | your account's default | Collector UUID to act as. |
|
|
71
72
|
| `SLAB_MCP_WRITE` | No | `0` | Set to `1` to register the write tools. |
|
|
72
73
|
| `SLAB_MCP_TIMEOUT_MS` | No | `30000` | Per-request HTTP timeout. |
|
|
73
74
|
|
|
75
|
+
### Handling the API key
|
|
76
|
+
|
|
77
|
+
Pasting the key straight into your MCP client config works, and for CI or a container it is the
|
|
78
|
+
right answer. On a workstation there is a better one, for a reason specific to agents.
|
|
79
|
+
|
|
80
|
+
The usual objection to a key in a config file is plaintext-at-rest — but `~/.claude.json` is already
|
|
81
|
+
`0600`, so the OS is not the weak point. The weak point is that **the agent can read its own
|
|
82
|
+
config**. Ask Claude Code to debug a flaky MCP server and a perfectly reasonable next step is to
|
|
83
|
+
read that file, at which point a live credential is in a transcript, in scrollback, and in whatever
|
|
84
|
+
that conversation gets pasted into. Nothing was breached; the key leaked sideways through ordinary
|
|
85
|
+
use.
|
|
86
|
+
|
|
87
|
+
So prefer `SLAB_API_KEY_COMMAND`, which holds an *instruction* instead of a credential:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
# store the key once, in the OS keychain
|
|
91
|
+
security add-generic-password -s slab-mcp -a "$USER" -w # macOS; prompts for the key
|
|
92
|
+
|
|
93
|
+
claude mcp add slab -s user \
|
|
94
|
+
-e SLAB_API_KEY_COMMAND='security find-generic-password -s slab-mcp -w' \
|
|
95
|
+
-- npx -y slab-mcp
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Now `~/.claude.json` contains a lookup command, and the secret lives behind the OS keychain. The
|
|
99
|
+
same seam works with anything that prints a secret to stdout:
|
|
100
|
+
|
|
101
|
+
| Backend | Command |
|
|
102
|
+
|---|---|
|
|
103
|
+
| macOS Keychain | `security find-generic-password -s slab-mcp -w` |
|
|
104
|
+
| 1Password | `op read "op://Private/slab/credential"` |
|
|
105
|
+
| pass | `pass show slab/api-key` |
|
|
106
|
+
| Vault | `vault kv get -field=key secret/slab` |
|
|
107
|
+
|
|
108
|
+
slab-mcp depends on none of them — it runs whatever you give it and reads stdout, so a backend it
|
|
109
|
+
has never heard of works too.
|
|
110
|
+
|
|
111
|
+
Two more things worth doing, both of which slab already supports:
|
|
112
|
+
|
|
113
|
+
- **Mint a dedicated key for the MCP** and name it (`slab` portal → Account → API Keys). Keys carry
|
|
114
|
+
a label and `last_used_dt` and revoke individually, so an agent-held key can be killed without
|
|
115
|
+
disturbing your CLI or scripts, and you can see when it was last used.
|
|
116
|
+
- **Leave writes off** unless you need them. A read-only key-holder cannot damage your collection
|
|
117
|
+
regardless of what the agent is talked into.
|
|
118
|
+
|
|
119
|
+
Notes: if both variables are set, `SLAB_API_KEY` wins — explicit beats indirect, and the startup log
|
|
120
|
+
names the source (never the value) so a forgotten shell export shadowing your keychain is visible
|
|
121
|
+
rather than a mystery 401. Don't inline a secret in the command itself; a failing command is echoed
|
|
122
|
+
back in the error so you can debug it.
|
|
123
|
+
|
|
74
124
|
### Enabling writes
|
|
75
125
|
|
|
76
126
|
```json
|
|
@@ -226,15 +276,28 @@ There is **no `NPM_TOKEN` anywhere in this repo** — the workflow mints a short
|
|
|
226
276
|
that npm exchanges for a credential good for one publish, and attaches a provenance attestation
|
|
227
277
|
linking the tarball to the exact commit that built it. Nothing long-lived exists to leak.
|
|
228
278
|
|
|
229
|
-
|
|
230
|
-
|
|
279
|
+
The trusted publisher is configured as:
|
|
280
|
+
|
|
281
|
+
```
|
|
282
|
+
dev-jeb/slab-community -> slab-mcp-publish.yml -> env npm-publish -> npm publish
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
**All four of those must agree**, and the workflow filename is load-bearing: npm matches on the
|
|
286
|
+
filename alone (no path, and it must live directly in `.github/workflows/`). Renaming or moving
|
|
287
|
+
`slab-mcp-publish.yml` breaks publishing with an auth error that never mentions the filename, so
|
|
288
|
+
change the npm side first. The `environment: npm-publish` line in the publish job is what puts the
|
|
289
|
+
environment claim in the OIDC token — remove it and npm rejects the publish.
|
|
290
|
+
|
|
291
|
+
One publish workflow per tool, matching this repo's one-directory-one-tool rule: a new publishable
|
|
292
|
+
tool gets its own `<tool>-publish.yml` and its own trusted publisher, and nothing here changes.
|
|
293
|
+
|
|
294
|
+
Two remaining one-time steps:
|
|
231
295
|
|
|
232
|
-
1.
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
required reviewer so every publish waits for a human click.
|
|
296
|
+
1. **OIDC cannot perform a package's first publish** — npm requires the package to exist before a
|
|
297
|
+
trusted publisher can be attached. Run `cd slab-mcp && npm publish` once by hand, logged in as
|
|
298
|
+
the package owner. Every release after that goes through CI.
|
|
299
|
+
2. GitHub → **Settings → Environments → `npm-publish`** → add yourself as a required reviewer, so
|
|
300
|
+
each release pauses for a human click and a mistaken tag cannot ship on its own.
|
|
238
301
|
|
|
239
302
|
After that, releasing is:
|
|
240
303
|
|
package/dist/client.d.ts
CHANGED
|
@@ -5,10 +5,12 @@
|
|
|
5
5
|
* nothing about cards. Endpoint knowledge lives in the tool modules, so adding
|
|
6
6
|
* an endpoint never means touching this file.
|
|
7
7
|
*
|
|
8
|
-
* The response types are declared structurally in `types.ts` rather
|
|
8
|
+
* The response types are declared structurally in `types.ts` rather thanß
|
|
9
9
|
* generated, because a generated client would have to be regenerated to stay
|
|
10
10
|
* honest. `GET /openapi.json` is the authoritative contract and is exposed to
|
|
11
11
|
* the model as a resource — see src/resources/index.ts.
|
|
12
|
+
*
|
|
13
|
+
* deploy
|
|
12
14
|
*/
|
|
13
15
|
import type { Config } from './config.js';
|
|
14
16
|
export interface RequestOptions {
|
package/dist/client.js
CHANGED
|
@@ -5,10 +5,12 @@
|
|
|
5
5
|
* nothing about cards. Endpoint knowledge lives in the tool modules, so adding
|
|
6
6
|
* an endpoint never means touching this file.
|
|
7
7
|
*
|
|
8
|
-
* The response types are declared structurally in `types.ts` rather
|
|
8
|
+
* The response types are declared structurally in `types.ts` rather thanß
|
|
9
9
|
* generated, because a generated client would have to be regenerated to stay
|
|
10
10
|
* honest. `GET /openapi.json` is the authoritative contract and is exposed to
|
|
11
11
|
* the model as a resource — see src/resources/index.ts.
|
|
12
|
+
*
|
|
13
|
+
* deploy
|
|
12
14
|
*/
|
|
13
15
|
import { ApiConnectionError, ApiError } from './errors.js';
|
|
14
16
|
/** Strip undefined values so we never send `{"brand": undefined}` -> `{"brand": null}`. */
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,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AC;YACb,IAAI,GAAG,YAAY,QAAQ;gBAAE,MAAM,GAAG,CAAC;YACvC,MAAM,IAAI,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QACrG,CAAC;IACH,CAAC;CACF"}
|
package/dist/config.d.ts
CHANGED
|
@@ -5,12 +5,15 @@
|
|
|
5
5
|
* never included in a tool result, so the model on the other end of the
|
|
6
6
|
* transport cannot read it, echo it, or be tricked into exfiltrating it.
|
|
7
7
|
*/
|
|
8
|
+
import { type KeySource } from './credentials.js';
|
|
8
9
|
export declare const DEFAULT_API_URL = "https://api.slab.dev-jeb.com";
|
|
9
10
|
export interface Config {
|
|
10
11
|
/** Base URL of the slab API, no trailing slash. */
|
|
11
12
|
apiUrl: string;
|
|
12
13
|
/** Value sent as the `x-api-key` header on every request. */
|
|
13
14
|
apiKey: string;
|
|
15
|
+
/** Which mechanism supplied the key. Logged at startup; never the key itself. */
|
|
16
|
+
keySource: KeySource;
|
|
14
17
|
/** Collector the key acts for. Undefined = resolve lazily from `GET /account`. */
|
|
15
18
|
collectorUuid: string | undefined;
|
|
16
19
|
/** Whether mutating tools are registered at all. Off unless SLAB_MCP_WRITE=1. */
|
package/dist/config.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* never included in a tool result, so the model on the other end of the
|
|
6
6
|
* transport cannot read it, echo it, or be tricked into exfiltrating it.
|
|
7
7
|
*/
|
|
8
|
+
import { resolveApiKey } from './credentials.js';
|
|
8
9
|
import { ConfigError } from './errors.js';
|
|
9
10
|
export const DEFAULT_API_URL = 'https://api.slab.dev-jeb.com';
|
|
10
11
|
function truthy(value) {
|
|
@@ -13,11 +14,7 @@ function truthy(value) {
|
|
|
13
14
|
return ['1', 'true', 'yes', 'on'].includes(value.trim().toLowerCase());
|
|
14
15
|
}
|
|
15
16
|
export function loadConfig(env = process.env) {
|
|
16
|
-
const apiKey = env
|
|
17
|
-
if (!apiKey) {
|
|
18
|
-
throw new ConfigError('SLAB_API_KEY is not set. Get a key at https://app.slab.dev-jeb.com -> Account -> API Keys, ' +
|
|
19
|
-
'then set it in the "env" block of your MCP client config (see this tool\'s README).');
|
|
20
|
-
}
|
|
17
|
+
const { key: apiKey, source: keySource } = resolveApiKey(env);
|
|
21
18
|
const timeoutRaw = env.SLAB_MCP_TIMEOUT_MS?.trim();
|
|
22
19
|
const timeoutMs = timeoutRaw ? Number(timeoutRaw) : 30_000;
|
|
23
20
|
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
@@ -26,6 +23,7 @@ export function loadConfig(env = process.env) {
|
|
|
26
23
|
return {
|
|
27
24
|
apiUrl: (env.SLAB_API_URL?.trim() || DEFAULT_API_URL).replace(/\/+$/, ''),
|
|
28
25
|
apiKey,
|
|
26
|
+
keySource,
|
|
29
27
|
collectorUuid: env.SLAB_COLLECTOR?.trim() || undefined,
|
|
30
28
|
writesEnabled: truthy(env.SLAB_MCP_WRITE),
|
|
31
29
|
timeoutMs,
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,CAAC,MAAM,eAAe,GAAG,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAkB,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,CAAC,MAAM,eAAe,GAAG,8BAA8B,CAAC;AAiB9D,SAAS,MAAM,CAAC,KAAyB;IACvC,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC;IACzB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;AACzE,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,MAAyB,OAAO,CAAC,GAAG;IAC7D,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;IAE9D,MAAM,UAAU,GAAG,GAAG,CAAC,mBAAmB,EAAE,IAAI,EAAE,CAAC;IACnD,MAAM,SAAS,GAAG,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAC3D,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,SAAS,IAAI,CAAC,EAAE,CAAC;QAClD,MAAM,IAAI,WAAW,CAAC,uEAAuE,UAAU,IAAI,CAAC,CAAC;IAC/G,CAAC;IAED,OAAO;QACL,MAAM,EAAE,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,EAAE,IAAI,eAAe,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;QACzE,MAAM;QACN,SAAS;QACT,aAAa,EAAE,GAAG,CAAC,cAAc,EAAE,IAAI,EAAE,IAAI,SAAS;QACtD,aAAa,EAAE,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC;QACzC,SAAS;KACV,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the API key comes from.
|
|
3
|
+
*
|
|
4
|
+
* The obvious option — pasting the key into the MCP client's config as an env
|
|
5
|
+
* value — has a problem specific to agents, and it is not the usual
|
|
6
|
+
* plaintext-at-rest one. `~/.claude.json` is already 0600, so the OS is not the
|
|
7
|
+
* weak point. The weak point is that **the agent can read its own config**. Ask
|
|
8
|
+
* Claude Code to debug a flaky MCP server and a perfectly reasonable next step
|
|
9
|
+
* is to cat that file — at which point a live credential is sitting in a
|
|
10
|
+
* transcript, in scrollback, and in whatever that conversation gets pasted
|
|
11
|
+
* into. Nothing has been breached; the key just leaked sideways through normal
|
|
12
|
+
* use.
|
|
13
|
+
*
|
|
14
|
+
* So this resolves a key from one of two places:
|
|
15
|
+
*
|
|
16
|
+
* SLAB_API_KEY the literal key. Simple, and the right answer for CI,
|
|
17
|
+
* containers, and anywhere a secret manager is absent.
|
|
18
|
+
* SLAB_API_KEY_COMMAND a command whose stdout is the key. The config then
|
|
19
|
+
* holds an instruction, not a credential.
|
|
20
|
+
*
|
|
21
|
+
* The command form deliberately knows nothing about any particular vault. One
|
|
22
|
+
* seam covers macOS Keychain, 1Password, pass, Vault, or a script someone
|
|
23
|
+
* writes tomorrow — the same shape as the seeder's `sources/` and the CLI's
|
|
24
|
+
* `platforms/`: name the capability, let each backend implement it, and depend
|
|
25
|
+
* on none of them.
|
|
26
|
+
*/
|
|
27
|
+
export type KeySource = 'SLAB_API_KEY' | 'SLAB_API_KEY_COMMAND';
|
|
28
|
+
export interface ResolvedKey {
|
|
29
|
+
key: string;
|
|
30
|
+
/** Which mechanism supplied it. Logged at startup so a wrong key is diagnosable. */
|
|
31
|
+
source: KeySource;
|
|
32
|
+
}
|
|
33
|
+
export declare function resolveApiKey(env?: NodeJS.ProcessEnv): ResolvedKey;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the API key comes from.
|
|
3
|
+
*
|
|
4
|
+
* The obvious option — pasting the key into the MCP client's config as an env
|
|
5
|
+
* value — has a problem specific to agents, and it is not the usual
|
|
6
|
+
* plaintext-at-rest one. `~/.claude.json` is already 0600, so the OS is not the
|
|
7
|
+
* weak point. The weak point is that **the agent can read its own config**. Ask
|
|
8
|
+
* Claude Code to debug a flaky MCP server and a perfectly reasonable next step
|
|
9
|
+
* is to cat that file — at which point a live credential is sitting in a
|
|
10
|
+
* transcript, in scrollback, and in whatever that conversation gets pasted
|
|
11
|
+
* into. Nothing has been breached; the key just leaked sideways through normal
|
|
12
|
+
* use.
|
|
13
|
+
*
|
|
14
|
+
* So this resolves a key from one of two places:
|
|
15
|
+
*
|
|
16
|
+
* SLAB_API_KEY the literal key. Simple, and the right answer for CI,
|
|
17
|
+
* containers, and anywhere a secret manager is absent.
|
|
18
|
+
* SLAB_API_KEY_COMMAND a command whose stdout is the key. The config then
|
|
19
|
+
* holds an instruction, not a credential.
|
|
20
|
+
*
|
|
21
|
+
* The command form deliberately knows nothing about any particular vault. One
|
|
22
|
+
* seam covers macOS Keychain, 1Password, pass, Vault, or a script someone
|
|
23
|
+
* writes tomorrow — the same shape as the seeder's `sources/` and the CLI's
|
|
24
|
+
* `platforms/`: name the capability, let each backend implement it, and depend
|
|
25
|
+
* on none of them.
|
|
26
|
+
*/
|
|
27
|
+
import { execSync } from 'node:child_process';
|
|
28
|
+
import { ConfigError } from './errors.js';
|
|
29
|
+
/** How long a credential command may take before we give up on it. */
|
|
30
|
+
const COMMAND_TIMEOUT_MS = 10_000;
|
|
31
|
+
const SETUP_HELP = 'Set one of:\n' +
|
|
32
|
+
' SLAB_API_KEY — the key itself\n' +
|
|
33
|
+
' SLAB_API_KEY_COMMAND — a command that prints the key, e.g.\n' +
|
|
34
|
+
' security find-generic-password -s slab-mcp -w (macOS Keychain)\n' +
|
|
35
|
+
' op read "op://Private/slab/credential" (1Password)\n' +
|
|
36
|
+
' pass show slab/api-key (pass)\n' +
|
|
37
|
+
'Get a key at https://app.slab.dev-jeb.com -> Account -> API Keys.';
|
|
38
|
+
export function resolveApiKey(env = process.env) {
|
|
39
|
+
const literal = env.SLAB_API_KEY?.trim();
|
|
40
|
+
const command = env.SLAB_API_KEY_COMMAND?.trim();
|
|
41
|
+
// The literal wins when both are set. Explicit beats indirect, matching how
|
|
42
|
+
// git and docker resolve credentials — and the startup log names the source,
|
|
43
|
+
// so a forgotten shell export shadowing a vault is visible rather than a
|
|
44
|
+
// mystery 401.
|
|
45
|
+
if (literal)
|
|
46
|
+
return { key: literal, source: 'SLAB_API_KEY' };
|
|
47
|
+
if (command) {
|
|
48
|
+
let output;
|
|
49
|
+
try {
|
|
50
|
+
output = execSync(command, {
|
|
51
|
+
encoding: 'utf8',
|
|
52
|
+
timeout: COMMAND_TIMEOUT_MS,
|
|
53
|
+
// stdin from /dev/null: a credential helper that tries to prompt should
|
|
54
|
+
// fail fast rather than hang forever holding up the handshake. stderr
|
|
55
|
+
// is passed through to our stderr so "keychain item not found" is
|
|
56
|
+
// visible to the user in the client's server log.
|
|
57
|
+
stdio: ['ignore', 'pipe', 'inherit'],
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
// Deliberately does NOT include the command's stdout — on a partial
|
|
62
|
+
// failure that could be the secret itself.
|
|
63
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
64
|
+
throw new ConfigError(`SLAB_API_KEY_COMMAND failed: ${reason}\n` +
|
|
65
|
+
`Command was: ${command}\n` +
|
|
66
|
+
'Run it yourself in a terminal — it must print the key to stdout and exit 0.');
|
|
67
|
+
}
|
|
68
|
+
const key = output.trim();
|
|
69
|
+
if (!key) {
|
|
70
|
+
throw new ConfigError(`SLAB_API_KEY_COMMAND produced no output.\nCommand was: ${command}\n` +
|
|
71
|
+
'It must print the key to stdout.');
|
|
72
|
+
}
|
|
73
|
+
return { key, source: 'SLAB_API_KEY_COMMAND' };
|
|
74
|
+
}
|
|
75
|
+
throw new ConfigError(`No slab API key configured.\n\n${SETUP_HELP}`);
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,QAAQ,EAA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G,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;QAC1B,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,MAAM,IAAI,WAAW,CACnB,0DAA0D,OAAO,IAAI;gBACnE,kCAAkC,CACrC,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,sBAAsB,EAAE,CAAC;IACjD,CAAC;IAED,MAAM,IAAI,WAAW,CAAC,kCAAkC,UAAU,EAAE,CAAC,CAAC;AACxE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -20,7 +20,7 @@ import { ConfigError } from './errors.js';
|
|
|
20
20
|
import { registerPrompts } from './prompts/index.js';
|
|
21
21
|
import { registerResources } from './resources/index.js';
|
|
22
22
|
import { registerTools } from './tools/index.js';
|
|
23
|
-
|
|
23
|
+
import { VERSION } from './version.js';
|
|
24
24
|
/** stderr only — see the note above. */
|
|
25
25
|
function log(message) {
|
|
26
26
|
process.stderr.write(`[slab-mcp] ${message}\n`);
|
|
@@ -43,8 +43,10 @@ function main() {
|
|
|
43
43
|
const active = registerTools(server, ctx);
|
|
44
44
|
registerResources(server, ctx);
|
|
45
45
|
registerPrompts(server);
|
|
46
|
+
// Names the credential SOURCE, never the credential. Enough to diagnose
|
|
47
|
+
// "which key is it actually using", which is the usual cause of a 401.
|
|
46
48
|
log(`serving ${active.length} tools against ${config.apiUrl} ` +
|
|
47
|
-
`(writes ${config.writesEnabled ? 'ENABLED' : 'disabled'})`);
|
|
49
|
+
`(key from ${config.keySource}, writes ${config.writesEnabled ? 'ENABLED' : 'disabled'})`);
|
|
48
50
|
return server;
|
|
49
51
|
}, { onerror: (error) => log(`transport error: ${error.message}`) });
|
|
50
52
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,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G,CAAC,OAAO,CAAC,CAAC;YACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC;IAED,MAAM,GAAG,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IAElC,UAAU,CACR,GAAG,EAAE;QACH,MAAM,MAAM,GAAG,IAAI,SAAS,CAC1B,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,EAClC,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,CAC5D,CAAC;QACF,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC1C,iBAAiB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC/B,eAAe,CAAC,MAAM,CAAC,CAAC;QACxB,wEAAwE;QACxE,uEAAuE;QACvE,GAAG,CACD,WAAW,MAAM,CAAC,MAAM,kBAAkB,MAAM,CAAC,MAAM,GAAG;YACxD,aAAa,MAAM,CAAC,SAAS,YAAY,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,GAAG,CAC5F,CAAC;QACF,OAAO,MAAM,CAAC;IAChB,CAAC,EACD,EAAE,OAAO,EAAE,CAAC,KAAY,EAAE,EAAE,CAAC,GAAG,CAAC,oBAAoB,KAAK,CAAC,OAAO,EAAE,CAAC,EAAE,CACxE,CAAC;AACJ,CAAC;AAED,IAAI,EAAE,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The server's version, read from package.json rather than restated.
|
|
3
|
+
*
|
|
4
|
+
* This is the version MCP clients see in the initialize handshake and show in
|
|
5
|
+
* their server list. It was hardcoded here once and immediately went stale —
|
|
6
|
+
* the published 0.1.2 introduced itself as 0.1.0 — which is the same
|
|
7
|
+
* hand-maintained-copy failure this codebase avoids everywhere else.
|
|
8
|
+
*
|
|
9
|
+
* `../package.json` resolves to the package root from both `src/` (dev, via
|
|
10
|
+
* tsx) and `dist/` (published), and npm always includes package.json in the
|
|
11
|
+
* tarball regardless of the `files` allowlist, so it is present at runtime.
|
|
12
|
+
*/
|
|
13
|
+
export declare const VERSION: string;
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The server's version, read from package.json rather than restated.
|
|
3
|
+
*
|
|
4
|
+
* This is the version MCP clients see in the initialize handshake and show in
|
|
5
|
+
* their server list. It was hardcoded here once and immediately went stale —
|
|
6
|
+
* the published 0.1.2 introduced itself as 0.1.0 — which is the same
|
|
7
|
+
* hand-maintained-copy failure this codebase avoids everywhere else.
|
|
8
|
+
*
|
|
9
|
+
* `../package.json` resolves to the package root from both `src/` (dev, via
|
|
10
|
+
* tsx) and `dist/` (published), and npm always includes package.json in the
|
|
11
|
+
* tarball regardless of the `files` allowlist, so it is present at runtime.
|
|
12
|
+
*/
|
|
13
|
+
import { createRequire } from 'node:module';
|
|
14
|
+
const require = createRequire(import.meta.url);
|
|
15
|
+
export const VERSION = require('../package.json').version;
|
|
16
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/C,MAAM,CAAC,MAAM,OAAO,GAAY,OAAO,CAAC,iBAAiB,CAAyB,CAAC,OAAO,CAAC"}
|
package/package.json
CHANGED