@abbit/abbit-mcp 0.2.0 → 0.3.0
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 +38 -8
- package/dist/{personal-key.js → api-key.js} +18 -18
- package/dist/attachment-transfer.js +104 -0
- package/dist/auth.js +20 -13
- package/dist/cli.js +28 -11
- package/dist/model.js +13 -5
- package/dist/proxy.js +2 -2
- package/dist/token-manager.js +33 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @abbit/abbit-mcp
|
|
2
2
|
|
|
3
|
-
Preview CLI that connects an MCP client to Abbit's remote MCP over local stdio. It supports browser or
|
|
3
|
+
Preview CLI that connects an MCP client to Abbit's remote MCP over local stdio. It supports browser, personal-key or service-key login, private local credentials, and serialized OAuth token refresh. Requires Node.js `>=24.15.0 <25` and an Abbit account with access to a workspace.
|
|
4
4
|
|
|
5
5
|
## Supported platforms
|
|
6
6
|
|
|
@@ -16,13 +16,13 @@ abbit-mcp login
|
|
|
16
16
|
abbit-mcp status
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
Login opens or prints a browser authorization URL. Select your workspace and approve access. Browser login requires reaching the same machine's loopback callback. Use an existing personal key for SSH/headless login.
|
|
19
|
+
Login opens or prints a browser authorization URL. Select your workspace and approve access. Browser login requires reaching the same machine's loopback callback. Use an existing personal or service key for SSH/headless login.
|
|
20
20
|
|
|
21
21
|
Login requests Tracker access and Wiki listing, creation, reading, search rebuilding, and editing. IAM grants only your approved, permitted scope. Existing sessions keep their original permissions during refresh. After updating from a version without Wiki listing or creation scopes, run `abbit-mcp login` again and approve the needed Wiki access.
|
|
22
22
|
|
|
23
|
-
##
|
|
23
|
+
## API-key login
|
|
24
24
|
|
|
25
|
-
Use an existing Abbit personal API key with the permissions needed by your tools:
|
|
25
|
+
Use an existing Abbit personal (`abbit_pk_v1`) or service (`abbit_sk_v1`) API key with the permissions needed by your tools:
|
|
26
26
|
|
|
27
27
|
```sh
|
|
28
28
|
abbit-mcp login --key
|
|
@@ -31,16 +31,28 @@ abbit-mcp login --key
|
|
|
31
31
|
Paste the key into the hidden prompt and press Enter. For headless use, redirect a protected file or pipe a secret manager's output into the same command:
|
|
32
32
|
|
|
33
33
|
```sh
|
|
34
|
-
abbit-mcp login --key < /secure/path/
|
|
34
|
+
abbit-mcp login --key < /secure/path/api-key
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
For the local adapter, supply the key only through hidden input or stdin; never as a command argument. Login validates the key with Abbit MCP before replacing your local login. Key issuance and permission management remain in IAM.
|
|
38
38
|
|
|
39
|
-
`serve`
|
|
39
|
+
`serve` sends the saved key as `Authorization: Bearer <key>`. IAM checks its current permissions, expiry and revocation on every request. Keys do not refresh; replace a rejected key by running `login --key` again. Failed authentication never falls back to another login. `status` reports the locally saved key's class and namespace without displaying the key; it does not check current server validity.
|
|
40
40
|
|
|
41
41
|
A successful login selects its authentication method: key login disables previous browser sessions locally and attempts to revoke them; browser login removes the local key. Failed OAuth revocation stays pending for a later `logout` retry. `logout` removes the saved key **only from this machine**; revoke it separately in IAM to invalidate other copies.
|
|
42
42
|
|
|
43
|
-
Both methods use the locked, atomic `~/.abbit/credentials.json` store (directory mode 0700, file mode 0600). Key login
|
|
43
|
+
Both methods use the locked, atomic `~/.abbit/credentials.json` store (directory mode 0700, file mode 0600). Key login stores exactly one optional `personalKey` or `serviceKey` field in the version-1 document. Existing OAuth and personal-key documents remain readable. Clients before 0.3.0 reject service-key documents safely; use this version to log out or return to browser login before downgrading.
|
|
44
|
+
|
|
45
|
+
## Direct HTTP MCP in Codex
|
|
46
|
+
|
|
47
|
+
Both key classes can also authenticate directly to the remote MCP endpoint. Codex supports an environment-sourced bearer in `~/.codex/config.toml`:
|
|
48
|
+
|
|
49
|
+
```toml
|
|
50
|
+
[mcp_servers.abbit]
|
|
51
|
+
url = "https://api.abusybit.com/v1/mcp"
|
|
52
|
+
bearer_token_env_var = "ABBIT_API_KEY"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Set `ABBIT_API_KEY` in the environment of the Codex process. Its value is the complete key without the `Bearer ` prefix. This connection does not use the local adapter or its credential store. Codex also accepts a literal header via `http_headers = { Authorization = "Bearer <key>" }`; that stores the secret in the configuration file. Use only one credential source. See the [official Codex configuration reference](https://learn.chatgpt.com/docs/config-file/config-reference#configtoml).
|
|
44
56
|
|
|
45
57
|
## MCP client configuration
|
|
46
58
|
|
|
@@ -164,3 +176,21 @@ abbit-mcp logout
|
|
|
164
176
|
This package provides the `abbit-mcp` command, not an importable JavaScript library. It contains compiled runtime modules and this README; npm installs its declared runtime dependencies. The preview channel starts at `0.1.0` and carries no stable API guarantee. Abbit code remains `UNLICENSED`; public registry access does not grant an open-source license. Dependencies retain their respective licenses.
|
|
165
177
|
|
|
166
178
|
Maintainers: see the [publication policy](https://github.com/abbitco/abbit-platfrom/blob/main/wiki/mcp/npm-publication.md) and [runtime contract](https://github.com/abbitco/abbit-platfrom/blob/main/wiki/mcp/local-stdio-adapter.md).
|
|
179
|
+
|
|
180
|
+
## Tracker attachment bytes
|
|
181
|
+
|
|
182
|
+
Initiate an upload using `tracker_initiate_attachment_upload`, then stream its exact file locally:
|
|
183
|
+
|
|
184
|
+
```sh
|
|
185
|
+
abbit-mcp attachment-upload TRACKER_ID ITEM_ID UPLOAD_ID ./proof.png
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Complete it with `tracker_complete_attachment_upload`, then call `tracker_add_comment_with_attachments` (optional caption) or `tracker_publish_attachments`. Reuse each metadata command's idempotency key after an uncertain response. A transfer failure should be followed by upload inspection before retrying. Files are capped at 25 MiB; tool arguments never contain bytes/base64, URLs, or server-side local paths.
|
|
189
|
+
|
|
190
|
+
List associations with `tracker_list_attachments`, then retrieve an original to a new destination:
|
|
191
|
+
|
|
192
|
+
```sh
|
|
193
|
+
abbit-mcp attachment-download TRACKER_ID ITEM_ID ATTACHMENT_ID ./downloaded-proof.png
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
The helper verifies size/SHA-256 before publishing the local file and never overwrites an existing destination. Both byte helpers use the selected local credential, fixed gateway origin and exact Tracker routes. Credentials are absent from arguments, output and filenames. These commands require the attachment-capable gateway deployment.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
2
2
|
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
3
3
|
import { iamRequestTimeoutMs, mcpAudience } from './constants.js';
|
|
4
|
-
import {
|
|
5
|
-
export const
|
|
4
|
+
import { parseApiKey } from './model.js';
|
|
5
|
+
export const readApiKey = (input = process.stdin, output = process.stderr) => new Promise((resolve, reject) => {
|
|
6
6
|
const interactive = input.isTTY === true;
|
|
7
7
|
const wasRaw = input.isRaw === true;
|
|
8
8
|
let value = '';
|
|
@@ -26,15 +26,15 @@ export const readPersonalKey = (input = process.stdin, output = process.stderr)
|
|
|
26
26
|
value = '';
|
|
27
27
|
if (error !== undefined)
|
|
28
28
|
reject(error);
|
|
29
|
-
else if (
|
|
30
|
-
reject(new Error('Enter a valid Abbit
|
|
29
|
+
else if (parseApiKey(key) === undefined)
|
|
30
|
+
reject(new Error('Enter a valid Abbit API key.'));
|
|
31
31
|
else
|
|
32
32
|
resolve(key);
|
|
33
33
|
};
|
|
34
|
-
const onError = () => finish(new Error('Could not read the
|
|
34
|
+
const onError = () => finish(new Error('Could not read the API key.'));
|
|
35
35
|
const onEnd = () => finish();
|
|
36
|
-
const onClose = () => finish(new Error('
|
|
37
|
-
const onTerminate = () => finish(new Error('
|
|
36
|
+
const onClose = () => finish(new Error('API-key input closed.'));
|
|
37
|
+
const onTerminate = () => finish(new Error('API-key login canceled.'));
|
|
38
38
|
const onData = (chunk) => {
|
|
39
39
|
for (const char of chunk.toString()) {
|
|
40
40
|
if (interactive && (char === '\u0003' || char === '\u0004'))
|
|
@@ -46,24 +46,24 @@ export const readPersonalKey = (input = process.stdin, output = process.stderr)
|
|
|
46
46
|
else
|
|
47
47
|
value += char;
|
|
48
48
|
if (value.length > 2_048)
|
|
49
|
-
return finish(new Error('
|
|
49
|
+
return finish(new Error('API-key input is too long.'));
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
52
|
if (interactive) {
|
|
53
53
|
if (input.setRawMode === undefined)
|
|
54
54
|
return reject(new Error('Hidden input is unavailable. Redirect the key through stdin.'));
|
|
55
55
|
input.setRawMode(true);
|
|
56
|
-
output.write('
|
|
56
|
+
output.write('API key (hidden): ');
|
|
57
57
|
}
|
|
58
58
|
input.on('data', onData).once('end', onEnd).once('error', onError).once('close', onClose);
|
|
59
59
|
process.once('SIGTERM', onTerminate);
|
|
60
60
|
process.once('SIGINT', onTerminate);
|
|
61
61
|
input.resume();
|
|
62
62
|
});
|
|
63
|
-
export const
|
|
63
|
+
export const fetchWithApiKey = async (key, input, init = {}, fetchImpl = fetch) => {
|
|
64
64
|
const url = input instanceof Request ? input.url : String(input);
|
|
65
65
|
if (url !== mcpAudience)
|
|
66
|
-
throw new Error('
|
|
66
|
+
throw new Error('API keys may only be sent to the Abbit MCP endpoint.');
|
|
67
67
|
const headers = new Headers(init.headers);
|
|
68
68
|
headers.set('authorization', `Bearer ${key}`);
|
|
69
69
|
try {
|
|
@@ -77,16 +77,16 @@ export const fetchWithPersonalKey = async (key, input, init = {}, fetchImpl = fe
|
|
|
77
77
|
throw new Error('Abbit MCP request failed.');
|
|
78
78
|
}
|
|
79
79
|
};
|
|
80
|
-
export const
|
|
81
|
-
if (
|
|
82
|
-
throw new Error('Enter a valid Abbit
|
|
83
|
-
const client = new Client({ name: 'abbit-mcp-r0', version: '0.
|
|
80
|
+
export const validateApiKey = async (key, fetchImpl = fetch) => {
|
|
81
|
+
if (parseApiKey(key) === undefined)
|
|
82
|
+
throw new Error('Enter a valid Abbit API key.');
|
|
83
|
+
const client = new Client({ name: 'abbit-mcp-r0', version: '0.3.0' }, { capabilities: {} });
|
|
84
84
|
const transport = new StreamableHTTPClientTransport(new URL(mcpAudience), {
|
|
85
85
|
fetch: async (input, init) => {
|
|
86
|
-
const response = await
|
|
86
|
+
const response = await fetchWithApiKey(key, input, { ...init, signal: AbortSignal.timeout(iamRequestTimeoutMs) }, fetchImpl);
|
|
87
87
|
if (!response.ok && response.status !== 405) {
|
|
88
88
|
await response.body?.cancel();
|
|
89
|
-
throw new Error('
|
|
89
|
+
throw new Error('API-key authentication failed.');
|
|
90
90
|
}
|
|
91
91
|
return response;
|
|
92
92
|
},
|
|
@@ -95,7 +95,7 @@ export const validatePersonalKey = async (key, fetchImpl = fetch) => {
|
|
|
95
95
|
await client.connect(transport, { timeout: iamRequestTimeoutMs });
|
|
96
96
|
}
|
|
97
97
|
catch {
|
|
98
|
-
throw new Error('Could not authenticate the
|
|
98
|
+
throw new Error('Could not authenticate the API key with Abbit MCP. Check the key and connection.');
|
|
99
99
|
}
|
|
100
100
|
finally {
|
|
101
101
|
await client.close().catch(() => undefined);
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { link, open, unlink } from 'node:fs/promises';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
import { Readable } from 'node:stream';
|
|
5
|
+
const encode = (value) => {
|
|
6
|
+
if (!value || [...value].length > 128 || value === '.' || value === '..' || value.includes('\0') || /[\uD800-\uDFFF]/u.test(value))
|
|
7
|
+
throw new Error('Invalid attachment identifier.');
|
|
8
|
+
return encodeURIComponent(value);
|
|
9
|
+
};
|
|
10
|
+
const target = (trackerId, itemId, suffix) => new URL(`https://api.abusybit.com/v2/trackers/${encode(trackerId)}/items/${encode(itemId)}/attachments/${suffix}`);
|
|
11
|
+
export async function uploadAttachment(manager, trackerId, itemId, uploadId, path) {
|
|
12
|
+
const file = await open(path, 'r');
|
|
13
|
+
try {
|
|
14
|
+
const stat = await file.stat();
|
|
15
|
+
if (!stat.isFile() || stat.size > 26214400)
|
|
16
|
+
throw new Error('Choose a regular file no larger than 25 MiB.');
|
|
17
|
+
const key = `stream-${randomUUID()}`;
|
|
18
|
+
const response = await manager.attachmentFetch(target(trackerId, itemId, `uploads/${encode(uploadId)}/content`), () => ({
|
|
19
|
+
method: 'PUT',
|
|
20
|
+
headers: { 'Content-Type': 'application/octet-stream', 'Idempotency-Key': key },
|
|
21
|
+
body: Readable.toWeb(file.createReadStream({ autoClose: false, start: 0 })),
|
|
22
|
+
duplex: 'half',
|
|
23
|
+
signal: AbortSignal.timeout(125000),
|
|
24
|
+
}));
|
|
25
|
+
if (response.status !== 200) {
|
|
26
|
+
await response.body?.cancel();
|
|
27
|
+
throw new Error(`Attachment upload was not confirmed (HTTP ${response.status}). Inspect the upload before retrying.`);
|
|
28
|
+
}
|
|
29
|
+
await response.body?.cancel();
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
if (error instanceof Error && /^(Choose|Attachment upload was not confirmed)/.test(error.message))
|
|
33
|
+
throw error;
|
|
34
|
+
throw new Error('Attachment upload could not be confirmed. Inspect the upload before retrying.');
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
await file.close();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export async function downloadAttachment(manager, trackerId, itemId, attachmentId, path) {
|
|
41
|
+
const temporary = join(dirname(path), `.abbit-attachment-${randomUUID()}`);
|
|
42
|
+
let created = false;
|
|
43
|
+
try {
|
|
44
|
+
const response = await manager.attachmentFetch(target(trackerId, itemId, `${encode(attachmentId)}/content`), () => ({
|
|
45
|
+
method: 'GET',
|
|
46
|
+
signal: AbortSignal.timeout(125000),
|
|
47
|
+
}));
|
|
48
|
+
if (response.status !== 200) {
|
|
49
|
+
await response.body?.cancel();
|
|
50
|
+
throw new Error(`Attachment download failed (HTTP ${response.status}).`);
|
|
51
|
+
}
|
|
52
|
+
const raw = response.headers.get('content-length'), sha = response.headers.get('x-attachment-sha256');
|
|
53
|
+
if (!raw ||
|
|
54
|
+
!/^\d{1,8}$/.test(raw) ||
|
|
55
|
+
Number(raw) > 26214400 ||
|
|
56
|
+
!sha ||
|
|
57
|
+
!/^[a-f0-9]{64}$/.test(sha) ||
|
|
58
|
+
response.headers.get('content-type') !== 'application/octet-stream') {
|
|
59
|
+
await response.body?.cancel();
|
|
60
|
+
throw new Error('Attachment response could not be verified.');
|
|
61
|
+
}
|
|
62
|
+
const file = await open(temporary, 'wx', 0o600);
|
|
63
|
+
created = true;
|
|
64
|
+
const hash = createHash('sha256');
|
|
65
|
+
let count = 0;
|
|
66
|
+
const reader = response.body?.getReader();
|
|
67
|
+
try {
|
|
68
|
+
if (reader)
|
|
69
|
+
while (true) {
|
|
70
|
+
const part = await reader.read();
|
|
71
|
+
if (part.done)
|
|
72
|
+
break;
|
|
73
|
+
count += part.value.length;
|
|
74
|
+
if (count > Number(raw))
|
|
75
|
+
throw new Error('Attachment response could not be verified.');
|
|
76
|
+
hash.update(part.value);
|
|
77
|
+
let offset = 0;
|
|
78
|
+
while (offset < part.value.length) {
|
|
79
|
+
const written = await file.write(part.value.subarray(offset));
|
|
80
|
+
offset += written.bytesWritten;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (count !== Number(raw) || hash.digest('hex') !== sha)
|
|
84
|
+
throw new Error('Attachment response could not be verified.');
|
|
85
|
+
await file.sync();
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
await reader?.cancel().catch(() => undefined);
|
|
89
|
+
reader?.releaseLock();
|
|
90
|
+
await file.close();
|
|
91
|
+
}
|
|
92
|
+
// Atomic no-overwrite publication: an existing destination is never replaced.
|
|
93
|
+
await link(temporary, path);
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
if (error instanceof Error && /^Attachment (download failed|response could not)/.test(error.message))
|
|
97
|
+
throw error;
|
|
98
|
+
throw new Error('Attachment download failed. Choose a new writable destination; existing files are never replaced.');
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
if (created)
|
|
102
|
+
await unlink(temporary).catch(() => undefined);
|
|
103
|
+
}
|
|
104
|
+
}
|
package/dist/auth.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { createHash, randomBytes } from 'node:crypto';
|
|
3
3
|
import { createServer } from 'node:http';
|
|
4
|
+
import { validateApiKey } from './api-key.js';
|
|
4
5
|
import { authorizationTimeoutMs, iamOrigin, isMcpClientId, isMcpScopeSet, mcpAudience, mcpScope, parseMcpScope, refreshHardLifetimeMs, refreshIdleLifetimeMs, } from './constants.js';
|
|
5
|
-
import { createAccessTokenEntry,
|
|
6
|
-
import { validatePersonalKey } from './personal-key.js';
|
|
6
|
+
import { createAccessTokenEntry, parseApiKey } from './model.js';
|
|
7
7
|
const matchesMcpIdentity = (record) => record.origin === iamOrigin && isMcpClientId(record.clientId) && record.audience === mcpAudience;
|
|
8
8
|
const matchesMcp = (record) => matchesMcpIdentity(record) && isMcpScopeSet(record.approvedScopes);
|
|
9
9
|
const matchesLegacyMcp = (record) => matchesMcpIdentity(record) && record.approvedScopes.length === 1 && record.approvedScopes[0] === 'mcp:access';
|
|
@@ -215,6 +215,7 @@ export class McpAuthService {
|
|
|
215
215
|
};
|
|
216
216
|
const predecessors = await this.store.withLock(async (document) => {
|
|
217
217
|
delete document.personalKey;
|
|
218
|
+
delete document.serviceKey;
|
|
218
219
|
const pending = [];
|
|
219
220
|
for (const previous of Object.values(document.credentials)) {
|
|
220
221
|
if (!matchesAnyMcp(previous) || previous.credentialId === record.credentialId)
|
|
@@ -246,16 +247,21 @@ export class McpAuthService {
|
|
|
246
247
|
}
|
|
247
248
|
}
|
|
248
249
|
async loginWithKey(key, fetchImpl = fetch) {
|
|
249
|
-
const
|
|
250
|
-
if (
|
|
251
|
-
throw new Error('Enter a valid Abbit
|
|
252
|
-
await
|
|
250
|
+
const parsed = parseApiKey(key);
|
|
251
|
+
if (parsed === undefined)
|
|
252
|
+
throw new Error('Enter a valid Abbit API key.');
|
|
253
|
+
await validateApiKey(key, fetchImpl);
|
|
253
254
|
const pending = await this.store.withLock(async (document) => {
|
|
254
255
|
for (const record of Object.values(document.credentials).filter(matchesAnyMcp)) {
|
|
255
256
|
record.state = 'pendingRevocation';
|
|
256
257
|
record.accessTokens = [];
|
|
257
258
|
}
|
|
258
|
-
document.personalKey
|
|
259
|
+
delete document.personalKey;
|
|
260
|
+
delete document.serviceKey;
|
|
261
|
+
if (parsed.kind === 'personal')
|
|
262
|
+
document.personalKey = key;
|
|
263
|
+
else
|
|
264
|
+
document.serviceKey = key;
|
|
259
265
|
return {
|
|
260
266
|
result: Object.values(document.credentials)
|
|
261
267
|
.filter(matchesAnyMcp)
|
|
@@ -264,11 +270,11 @@ export class McpAuthService {
|
|
|
264
270
|
};
|
|
265
271
|
});
|
|
266
272
|
await this.revokePending(pending);
|
|
267
|
-
return
|
|
273
|
+
return parsed;
|
|
268
274
|
}
|
|
269
275
|
async status(currentTime = new Date()) {
|
|
270
276
|
const document = await this.store.read();
|
|
271
|
-
const
|
|
277
|
+
const key = parseApiKey(document.personalKey ?? document.serviceKey);
|
|
272
278
|
const records = Object.values(document.credentials).filter(matchesAnyMcp);
|
|
273
279
|
const stateFor = (record) => {
|
|
274
280
|
if (record.state === 'pendingRevocation')
|
|
@@ -281,10 +287,10 @@ export class McpAuthService {
|
|
|
281
287
|
: 'active';
|
|
282
288
|
};
|
|
283
289
|
const namespaces = records.map((record) => ({ namespaceId: record.namespaceId, state: stateFor(record) }));
|
|
284
|
-
if (
|
|
285
|
-
namespaces.unshift({ namespaceId:
|
|
290
|
+
if (key !== undefined)
|
|
291
|
+
namespaces.unshift({ namespaceId: key.namespaceId, state: 'active' });
|
|
286
292
|
return {
|
|
287
|
-
...(
|
|
293
|
+
...(key === undefined ? {} : { apiKey: key }),
|
|
288
294
|
authenticated: namespaces.some(({ state }) => state === 'active'),
|
|
289
295
|
pendingRevocation: namespaces.some(({ state }) => state === 'pendingRevocation'),
|
|
290
296
|
reauthenticationRequired: namespaces.some(({ state }) => state === 'reauthenticationRequired'),
|
|
@@ -294,8 +300,9 @@ export class McpAuthService {
|
|
|
294
300
|
async logout() {
|
|
295
301
|
let forgotten = 0;
|
|
296
302
|
const pending = await this.store.withLock(async (document) => {
|
|
297
|
-
forgotten = document.personalKey === undefined ? 0 : 1;
|
|
303
|
+
forgotten = document.personalKey === undefined && document.serviceKey === undefined ? 0 : 1;
|
|
298
304
|
delete document.personalKey;
|
|
305
|
+
delete document.serviceKey;
|
|
299
306
|
const selected = Object.values(document.credentials).filter(matchesAnyMcp);
|
|
300
307
|
for (const record of selected) {
|
|
301
308
|
record.state = 'pendingRevocation';
|
package/dist/cli.js
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command } from 'commander';
|
|
3
|
+
import { readApiKey } from './api-key.js';
|
|
4
|
+
import { downloadAttachment, uploadAttachment } from './attachment-transfer.js';
|
|
3
5
|
import { McpAuthService } from './auth.js';
|
|
4
6
|
import { CredentialStore } from './credentials.js';
|
|
5
7
|
import { createMcpIamClient, refreshMcpToken } from './iam-client.js';
|
|
6
|
-
import { readPersonalKey } from './personal-key.js';
|
|
7
8
|
import { serveLocalMcp } from './proxy.js';
|
|
8
9
|
import { McpTokenManager } from './token-manager.js';
|
|
9
10
|
const store = new CredentialStore();
|
|
10
11
|
const iam = createMcpIamClient();
|
|
11
12
|
const auth = new McpAuthService(store, iam);
|
|
12
|
-
const program = new Command().name('abbit-mcp').description('Abbit local stdio MCP adapter').version('0.
|
|
13
|
+
const program = new Command().name('abbit-mcp').description('Abbit local stdio MCP adapter').version('0.3.0').showHelpAfterError();
|
|
13
14
|
program.configureOutput({
|
|
14
|
-
outputError: (_message, write) => write('Invalid command. Use --help. Supply
|
|
15
|
+
outputError: (_message, write) => write('Invalid command. Use --help. Supply API keys through hidden input or stdin, never arguments.\n'),
|
|
15
16
|
});
|
|
16
17
|
program
|
|
17
18
|
.command('login')
|
|
18
|
-
.description('Authorize Abbit MCP in your browser or with a personal key')
|
|
19
|
-
.option('--key', 'Read an existing personal API key from hidden input or stdin')
|
|
19
|
+
.description('Authorize Abbit MCP in your browser or with a personal or service key')
|
|
20
|
+
.option('--key', 'Read an existing personal or service API key from hidden input or stdin')
|
|
20
21
|
.allowExcessArguments(false)
|
|
21
22
|
.action(async (options) => {
|
|
22
23
|
if (options.key) {
|
|
23
|
-
const record = await auth.loginWithKey(await
|
|
24
|
-
process.stdout.write(`Authenticated Abbit MCP with a
|
|
24
|
+
const record = await auth.loginWithKey(await readApiKey());
|
|
25
|
+
process.stdout.write(`Authenticated Abbit MCP with a ${record.kind} key for namespace ${JSON.stringify(record.namespaceId)}.\n`);
|
|
25
26
|
return;
|
|
26
27
|
}
|
|
27
28
|
const record = await auth.login({ output: (line) => process.stdout.write(`${line}\n`) });
|
|
@@ -32,8 +33,8 @@ program
|
|
|
32
33
|
.description('Show local Abbit MCP authentication status')
|
|
33
34
|
.action(async () => {
|
|
34
35
|
const status = await auth.status();
|
|
35
|
-
if (status.
|
|
36
|
-
process.stdout.write(
|
|
36
|
+
if (status.apiKey !== undefined) {
|
|
37
|
+
process.stdout.write(`${status.apiKey.kind === 'personal' ? 'Personal' : 'Service'} key saved for namespace ${JSON.stringify(status.apiKey.namespaceId)} (server checks validity on use).\n`);
|
|
37
38
|
}
|
|
38
39
|
else if (status.authenticated) {
|
|
39
40
|
for (const record of status.namespaces.filter(({ state }) => state === 'active')) {
|
|
@@ -50,11 +51,11 @@ program
|
|
|
50
51
|
});
|
|
51
52
|
program
|
|
52
53
|
.command('logout')
|
|
53
|
-
.description('Forget
|
|
54
|
+
.description('Forget an API key locally and revoke browser OAuth credentials')
|
|
54
55
|
.action(async () => {
|
|
55
56
|
const result = await auth.logout();
|
|
56
57
|
if (result.forgotten > 0)
|
|
57
|
-
process.stdout.write('
|
|
58
|
+
process.stdout.write('API key removed locally. The key remains valid until revoked in IAM.\n');
|
|
58
59
|
if (result.pending > 0) {
|
|
59
60
|
process.stdout.write('Local access disabled; remote revocation is pending.\n');
|
|
60
61
|
process.exitCode = 1;
|
|
@@ -77,6 +78,22 @@ program
|
|
|
77
78
|
});
|
|
78
79
|
}
|
|
79
80
|
});
|
|
81
|
+
program
|
|
82
|
+
.command('attachment-upload <trackerId> <itemId> <uploadId> <file>')
|
|
83
|
+
.description('Stream a local file to an initiated Tracker upload; complete and publish through MCP')
|
|
84
|
+
.allowExcessArguments(false)
|
|
85
|
+
.action(async (trackerId, itemId, uploadId, file) => {
|
|
86
|
+
await uploadAttachment(new McpTokenManager(store, refreshMcpToken()), trackerId, itemId, uploadId, file);
|
|
87
|
+
process.stdout.write('Bytes staged. Complete the upload and publish its attachment through MCP.\n');
|
|
88
|
+
});
|
|
89
|
+
program
|
|
90
|
+
.command('attachment-download <trackerId> <itemId> <attachmentId> <destination>')
|
|
91
|
+
.description('Download an original Tracker attachment to a new local file, verifying its SHA-256')
|
|
92
|
+
.allowExcessArguments(false)
|
|
93
|
+
.action(async (trackerId, itemId, attachmentId, destination) => {
|
|
94
|
+
await downloadAttachment(new McpTokenManager(store, refreshMcpToken()), trackerId, itemId, attachmentId, destination);
|
|
95
|
+
process.stdout.write('Original attachment downloaded and verified.\n');
|
|
96
|
+
});
|
|
80
97
|
program.parseAsync().catch((error) => {
|
|
81
98
|
const message = error instanceof Error ? error.message : 'Abbit MCP failed.';
|
|
82
99
|
process.stderr.write(`${message}\n`);
|
package/dist/model.js
CHANGED
|
@@ -56,11 +56,11 @@ export const isMcpRefreshToken = (value, expectedNamespaceId) => {
|
|
|
56
56
|
const namespaceId = decodeNamespaceLocator(locator);
|
|
57
57
|
return namespaceId !== undefined && (expectedNamespaceId === undefined || namespaceId === expectedNamespaceId);
|
|
58
58
|
};
|
|
59
|
-
export const
|
|
59
|
+
export const parseApiKey = (value) => {
|
|
60
60
|
if (typeof value !== 'string' || value.length > 2_048)
|
|
61
61
|
return undefined;
|
|
62
62
|
const [prefix, locator, lookup, secret, extra] = value.split('.');
|
|
63
|
-
if (prefix !== 'abbit_pk_v1' ||
|
|
63
|
+
if ((prefix !== 'abbit_pk_v1' && prefix !== 'abbit_sk_v1') ||
|
|
64
64
|
locator === undefined ||
|
|
65
65
|
lookup === undefined ||
|
|
66
66
|
secret === undefined ||
|
|
@@ -68,7 +68,8 @@ export const personalKeyNamespace = (value) => {
|
|
|
68
68
|
!/^[A-Za-z0-9_-]{21}[AQgw]$/u.test(lookup) ||
|
|
69
69
|
!/^[A-Za-z0-9_-]{42}[AEIMQUYcgkosw048]$/u.test(secret))
|
|
70
70
|
return undefined;
|
|
71
|
-
|
|
71
|
+
const namespaceId = decodeNamespaceLocator(locator);
|
|
72
|
+
return namespaceId === undefined ? undefined : { kind: prefix === 'abbit_pk_v1' ? 'personal' : 'service', namespaceId };
|
|
72
73
|
};
|
|
73
74
|
const isAccessToken = (value) => isRecord(value) &&
|
|
74
75
|
hasExactKeys(value, ['accessToken', 'audience', 'scopes', 'issuedAt', 'expiresAt']) &&
|
|
@@ -128,10 +129,17 @@ const isCredential = (value) => {
|
|
|
128
129
|
export const emptyCredentialDocument = () => ({ version: 1, credentials: {} });
|
|
129
130
|
export const parseCredentialDocument = (value) => {
|
|
130
131
|
if (!isRecord(value) ||
|
|
131
|
-
!hasExactKeys(value,
|
|
132
|
+
!hasExactKeys(value, [
|
|
133
|
+
'version',
|
|
134
|
+
'credentials',
|
|
135
|
+
...('personalKey' in value ? ['personalKey'] : []),
|
|
136
|
+
...('serviceKey' in value ? ['serviceKey'] : []),
|
|
137
|
+
]) ||
|
|
132
138
|
value.version !== 1 ||
|
|
133
139
|
!isRecord(value.credentials) ||
|
|
134
|
-
('personalKey' in value &&
|
|
140
|
+
('personalKey' in value && parseApiKey(value.personalKey)?.kind !== 'personal') ||
|
|
141
|
+
('serviceKey' in value && parseApiKey(value.serviceKey)?.kind !== 'service') ||
|
|
142
|
+
('personalKey' in value && 'serviceKey' in value)) {
|
|
135
143
|
throw new TypeError('credential document validation failed');
|
|
136
144
|
}
|
|
137
145
|
for (const [key, credential] of Object.entries(value.credentials)) {
|
package/dist/proxy.js
CHANGED
|
@@ -5,13 +5,13 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
|
5
5
|
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
6
6
|
import { mcpAudience } from './constants.js';
|
|
7
7
|
export const createLocalMcpProxyServer = (upstream) => {
|
|
8
|
-
const server = new Server({ name: 'abbit-mcp-r0', version: '0.
|
|
8
|
+
const server = new Server({ name: 'abbit-mcp-r0', version: '0.3.0' }, { capabilities: { tools: {} } });
|
|
9
9
|
server.setRequestHandler(ListToolsRequestSchema, (request) => upstream.listTools(request.params));
|
|
10
10
|
server.setRequestHandler(CallToolRequestSchema, (request) => upstream.callTool(request.params));
|
|
11
11
|
return server;
|
|
12
12
|
};
|
|
13
13
|
export const serveLocalMcp = async (options) => {
|
|
14
|
-
const upstream = new Client({ name: 'abbit-mcp-r0', version: '0.
|
|
14
|
+
const upstream = new Client({ name: 'abbit-mcp-r0', version: '0.3.0' }, { capabilities: {} });
|
|
15
15
|
const fetchImpl = options.fetch ?? fetch;
|
|
16
16
|
const upstreamTransport = new StreamableHTTPClientTransport(new URL(mcpAudience), {
|
|
17
17
|
fetch: (input, init) => options.tokenManager.authenticatedFetch(input, init, fetchImpl),
|
package/dist/token-manager.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { fetchWithApiKey } from './api-key.js';
|
|
2
3
|
import { accessTokenSafetyWindowMs, iamOrigin, isMcpClientId, isMcpScopeSet, mcpAudience, parseMcpScope, refreshIdleLifetimeMs, } from './constants.js';
|
|
3
4
|
import { createAccessTokenEntry } from './model.js';
|
|
4
|
-
import { fetchWithPersonalKey } from './personal-key.js';
|
|
5
5
|
export class McpReauthenticationRequiredError extends Error {
|
|
6
6
|
constructor() {
|
|
7
7
|
super('Abbit MCP authentication is required. Run `abbit-mcp login`.');
|
|
@@ -36,10 +36,11 @@ export class McpTokenManager {
|
|
|
36
36
|
async getAccessContext(options = {}) {
|
|
37
37
|
const initialNow = this.now();
|
|
38
38
|
const initialDocument = await this.store.read();
|
|
39
|
-
|
|
39
|
+
const key = initialDocument.personalKey ?? initialDocument.serviceKey;
|
|
40
|
+
if (key !== undefined) {
|
|
40
41
|
if (options.credentialId !== undefined || options.rejectedToken !== undefined)
|
|
41
42
|
throw new McpReauthenticationRequiredError();
|
|
42
|
-
return { accessToken:
|
|
43
|
+
return { accessToken: key, credentialId: 'api-key', apiKey: true };
|
|
43
44
|
}
|
|
44
45
|
const initial = options.credentialId === undefined
|
|
45
46
|
? selectCredential(Object.values(initialDocument.credentials))
|
|
@@ -56,7 +57,7 @@ export class McpTokenManager {
|
|
|
56
57
|
return { accessToken: cached.accessToken, credentialId };
|
|
57
58
|
return this.store.withLock(async (document, commit) => {
|
|
58
59
|
const completedAt = this.now();
|
|
59
|
-
if (document.personalKey !== undefined)
|
|
60
|
+
if (document.personalKey !== undefined || document.serviceKey !== undefined)
|
|
60
61
|
throw new McpReauthenticationRequiredError();
|
|
61
62
|
const credential = document.credentials[credentialId];
|
|
62
63
|
if (credential === undefined || credential.state !== 'active' || !matchesMcpProfile(credential)) {
|
|
@@ -96,8 +97,8 @@ export class McpTokenManager {
|
|
|
96
97
|
}
|
|
97
98
|
async authenticatedFetch(input, init = {}, fetchImpl = fetch) {
|
|
98
99
|
const initial = await this.getAccessContext();
|
|
99
|
-
if (initial.
|
|
100
|
-
return
|
|
100
|
+
if (initial.apiKey)
|
|
101
|
+
return fetchWithApiKey(initial.accessToken, input, init, fetchImpl);
|
|
101
102
|
const first = await fetchImpl(input, this.withBearer(init, initial.accessToken));
|
|
102
103
|
if (first.status !== 401)
|
|
103
104
|
return first;
|
|
@@ -105,6 +106,32 @@ export class McpTokenManager {
|
|
|
105
106
|
const successor = await this.getAccessContext({ credentialId: initial.credentialId, rejectedToken: initial.accessToken });
|
|
106
107
|
return fetchImpl(input, this.withBearer(init, successor.accessToken));
|
|
107
108
|
}
|
|
109
|
+
async attachmentFetch(url, init, fetchImpl = fetch) {
|
|
110
|
+
if (url.origin !== 'https://api.abusybit.com' ||
|
|
111
|
+
url.search ||
|
|
112
|
+
url.hash ||
|
|
113
|
+
url.username ||
|
|
114
|
+
url.password ||
|
|
115
|
+
!/^\/v2\/trackers\/[^/]+\/items\/[^/]+\/attachments\/(?:uploads\/[^/]+\/content|[^/]+\/content)$/.test(url.pathname))
|
|
116
|
+
throw new Error('Invalid Tracker attachment transfer route.');
|
|
117
|
+
const initial = await this.getAccessContext();
|
|
118
|
+
const send = (accessToken) => {
|
|
119
|
+
const options = init();
|
|
120
|
+
const upload = url.pathname.includes('/attachments/uploads/');
|
|
121
|
+
if (options.method !== (upload ? 'PUT' : 'GET'))
|
|
122
|
+
throw new Error('Invalid attachment transfer method.');
|
|
123
|
+
const headers = new Headers(options.headers);
|
|
124
|
+
headers.set('authorization', `Bearer ${accessToken}`);
|
|
125
|
+
headers.set('x-abbit-credential-profile', 'mcp');
|
|
126
|
+
return fetchImpl(url, { ...options, headers, redirect: 'error' });
|
|
127
|
+
};
|
|
128
|
+
const first = await send(initial.accessToken);
|
|
129
|
+
if (first.status !== 401 || initial.apiKey)
|
|
130
|
+
return first;
|
|
131
|
+
await first.body?.cancel();
|
|
132
|
+
const successor = await this.getAccessContext({ credentialId: initial.credentialId, rejectedToken: initial.accessToken });
|
|
133
|
+
return send(successor.accessToken);
|
|
134
|
+
}
|
|
108
135
|
withBearer(init, token) {
|
|
109
136
|
const headers = new Headers(init.headers);
|
|
110
137
|
headers.set('authorization', `Bearer ${token}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abbit/abbit-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Abbit-owned local stdio MCP adapter.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"build": "tsc -p tsconfig.build.json",
|
|
30
30
|
"verify:package": "node scripts/verify-package.ts",
|
|
31
31
|
"typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.test.json --noEmit",
|
|
32
|
-
"test": "npm run build && tsc -p tsconfig.test.json && node --test test-dist/test/*.test.js",
|
|
32
|
+
"test": "npm run build && tsc -p tsconfig.test.json && node --test test-dist/test/*.test.js test-dist/test/unit/*.unit.spec.js",
|
|
33
33
|
"test:e2e": "npm run build && tsc -p tsconfig.test.json && node --test test-dist/test/proxy.test.js test-dist/test/token-manager.test.js"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|