@lornatang/dsh-atlassian 0.1.14 → 0.1.15
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 +5 -0
- package/README.md +1 -1
- package/README.zh.md +1 -1
- package/lib/board.js +39 -44
- package/lib/bridge.js +50 -62
- package/lib/index.js +2 -1
- package/lib/jira-resource.js +29 -0
- package/lib/server-bridge.js +5 -3
- package/lib/types/board.d.ts +3 -6
- package/lib/types/bridge.d.ts +3 -6
- package/lib/types/jira-resource.d.ts +10 -0
- package/lib/types/server-bridge.d.ts +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.15 - 2026-11-19
|
|
4
|
+
|
|
5
|
+
- Serialize connection replacement and refresh the Jira site cache when the connection changes.
|
|
6
|
+
- Apply connection settings only after saving them and use the same Jira resource parser during connection and board loading.
|
|
7
|
+
|
|
3
8
|
## 0.1.14 - 2026-11-19
|
|
4
9
|
|
|
5
10
|
- Reuse the site resolved while connecting for the first Jira board render, removing a duplicate accessibleatlassianresources MCP round-trip; the board still falls back to its own lookup when the cached site is stale.
|
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ dsh plugin --profile <name> add @lornatang/dsh-atlassian
|
|
|
34
34
|
dsh plugin --profile <name> remove @lornatang/dsh-atlassian
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
The same release is also attached as an archive on GitHub: `dsh plugin --profile <name> add https://github.com/Lornatang/dsh-atlassian/releases/download/v0.1.
|
|
37
|
+
The same release is also attached as an archive on GitHub: `dsh plugin --profile <name> add https://github.com/Lornatang/dsh-atlassian/releases/download/v0.1.15/lornatang-dsh-atlassian-0.1.15.tgz`.
|
|
38
38
|
|
|
39
39
|
`add` composes the layer into the profile: the profile's `cordis.patch.yml` gains an insert entry with row id `atlassian`, package `@lornatang/dsh-atlassian`, and the five values the shipped patch carries — `mode: cloud`, `serverName: atlassian`, `url: https://mcp.atlassian.com/v1/mcp`, `redirectPort: 3334` and `autoOpenBrowser: true`. The manifest declares `dsh.bundle.patch: ./cordis.patch.yml`, which is the declaration the reconcile step reads; `remove` deletes the entry again. Restart DSH after either command, because the profile composes its rows and its client half only at startup, then open Settings → Atlassian. Releases before 0.1.5 published this package as `@lornatang/dsh-atlassian-bridge`; add the scoped name, remove the old package from the same profile and restart once — the row, its settings and the stored credentials survive.
|
|
40
40
|
|
package/README.zh.md
CHANGED
|
@@ -34,7 +34,7 @@ dsh plugin --profile <name> add @lornatang/dsh-atlassian
|
|
|
34
34
|
dsh plugin --profile <name> remove @lornatang/dsh-atlassian
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
也可以从 GitHub release 附带的压缩包安装同一版本:`dsh plugin --profile <name> add https://github.com/Lornatang/dsh-atlassian/releases/download/v0.1.
|
|
37
|
+
也可以从 GitHub release 附带的压缩包安装同一版本:`dsh plugin --profile <name> add https://github.com/Lornatang/dsh-atlassian/releases/download/v0.1.15/lornatang-dsh-atlassian-0.1.15.tgz`。
|
|
38
38
|
|
|
39
39
|
`add` 会把本层组合进 profile:profile 的 `cordis.patch.yml` 会增加一条 insert 记录,行 id 为 `atlassian`,包名为 `@lornatang/dsh-atlassian`,并带上随包提供的补丁中的五个值——`mode: cloud`、`serverName: atlassian`、`url: https://mcp.atlassian.com/v1/mcp`、`redirectPort: 3334` 与 `autoOpenBrowser: true`。包的 manifest 声明了 `dsh.bundle.patch: ./cordis.patch.yml`,reconcile 步骤读取的正是这条声明;`remove` 会再次删除该记录。两条命令执行后都要重启 DSH,因为 profile 只在启动时组合自己的行与客户端部分,随后打开 Settings → Atlassian。0.1.5 之前的版本以 `@lornatang/dsh-atlassian-bridge` 发布;添加带作用域的新名称、从同一 profile 删除旧包、重启一次即可——行、其设置与已保存的凭据都会保留。
|
|
40
40
|
|
package/lib/board.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { decodeToolJson, selectJiraResource } from './jira-resource.js';
|
|
1
2
|
export class BoardError extends Error {
|
|
2
3
|
code;
|
|
3
4
|
constructor(code, message) {
|
|
@@ -31,8 +32,15 @@ export class JiraBoard {
|
|
|
31
32
|
#resource;
|
|
32
33
|
#pending;
|
|
33
34
|
constructor(bridge) { this.#bridge = bridge; }
|
|
34
|
-
get site() { return this.#resource?.epoch ===
|
|
35
|
-
|
|
35
|
+
get site() { return this.#resource?.epoch === this.#epoch() ? this.#resource.site : undefined; }
|
|
36
|
+
#epoch() { return this.#bridge.epoch?.() ?? 0; }
|
|
37
|
+
#checkEpoch(epoch) {
|
|
38
|
+
if (this.#epoch() !== epoch)
|
|
39
|
+
throw new BoardError('not-connected', 'Atlassian connection changed; retry the request');
|
|
40
|
+
}
|
|
41
|
+
async #call(pattern, args, timeoutMs, epoch) {
|
|
42
|
+
if (epoch !== undefined)
|
|
43
|
+
this.#checkEpoch(epoch);
|
|
36
44
|
const name = this.#bridge.rawNameMatching(pattern);
|
|
37
45
|
if (!name) {
|
|
38
46
|
const state = this.#bridge.snapshot?.();
|
|
@@ -47,25 +55,26 @@ export class JiraBoard {
|
|
|
47
55
|
catch (error) {
|
|
48
56
|
throw new BoardError('tool-failed', error instanceof Error ? error.message : String(error));
|
|
49
57
|
}
|
|
50
|
-
const raw = blocks.map((entry) => val(obj(entry)['text']) ?? '').join('\n').trim().replace(/^```[a-z]*\s*/i, '').replace(/```\s*$/, '');
|
|
51
58
|
try {
|
|
52
|
-
return
|
|
59
|
+
return decodeToolJson(blocks);
|
|
53
60
|
}
|
|
54
61
|
catch {
|
|
55
62
|
throw new BoardError('unparsable', 'Jira response is not valid JSON');
|
|
56
63
|
}
|
|
57
64
|
}
|
|
58
65
|
async cloudId() {
|
|
59
|
-
const
|
|
66
|
+
const resource = await this.#getResource();
|
|
67
|
+
this.#checkEpoch(resource.epoch);
|
|
68
|
+
return resource.id;
|
|
69
|
+
}
|
|
70
|
+
async #getResource() {
|
|
71
|
+
const epoch = this.#epoch();
|
|
60
72
|
if (this.#resource?.epoch === epoch)
|
|
61
|
-
return this.#resource
|
|
62
|
-
// The bridge
|
|
63
|
-
// instead of paying a second MCP round-trip on the first board render.
|
|
73
|
+
return this.#resource;
|
|
74
|
+
// The bridge may already have resolved the site while connecting.
|
|
64
75
|
const shared = this.#bridge.resource?.();
|
|
65
|
-
if (shared
|
|
66
|
-
this.#resource =
|
|
67
|
-
return shared.id;
|
|
68
|
-
}
|
|
76
|
+
if (shared?.epoch === epoch)
|
|
77
|
+
return this.#resource = shared;
|
|
69
78
|
if (this.#pending?.epoch === epoch)
|
|
70
79
|
return this.#pending.promise;
|
|
71
80
|
const promise = this.#resolveSite(epoch);
|
|
@@ -80,37 +89,21 @@ export class JiraBoard {
|
|
|
80
89
|
}
|
|
81
90
|
async #resolveSite(epoch) {
|
|
82
91
|
const data = await this.#call(/accessibleatlassianresources/i, {}, 20000);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (!id || !url)
|
|
89
|
-
continue;
|
|
90
|
-
try {
|
|
91
|
-
const parsed = new URL(url);
|
|
92
|
-
if (!['http:', 'https:'].includes(parsed.protocol) || parsed.username || parsed.password)
|
|
93
|
-
continue;
|
|
94
|
-
// A reconnect may have invalidated this resolution while it was in flight.
|
|
95
|
-
if ((this.#bridge.epoch?.() ?? 0) === epoch)
|
|
96
|
-
this.#resource = { epoch, id, base: `${parsed.origin}${parsed.pathname.replace(/\/$/, '')}`, site: parsed.host };
|
|
97
|
-
return id;
|
|
98
|
-
}
|
|
99
|
-
catch {
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
throw new BoardError('no-site', 'No accessible Jira site was found');
|
|
92
|
+
this.#checkEpoch(epoch);
|
|
93
|
+
const resource = selectJiraResource(data, (url) => this.#bridge.allowsHttpResource?.(url) ?? false);
|
|
94
|
+
if (!resource)
|
|
95
|
+
throw new BoardError('no-site', 'No accessible Jira site was found');
|
|
96
|
+
return this.#resource = { epoch, ...resource };
|
|
104
97
|
}
|
|
105
98
|
async load(query) {
|
|
106
|
-
const id = await this
|
|
99
|
+
const { id, base, site, epoch } = await this.#getResource();
|
|
107
100
|
const fallback = 'updated >= -180d ORDER BY updated DESC';
|
|
108
101
|
let jql = query.jql?.trim() || fallback;
|
|
109
102
|
let retried = false;
|
|
110
103
|
let result;
|
|
111
104
|
for (;;) {
|
|
112
105
|
try {
|
|
113
|
-
result = obj(await this.#call(/searchJiraIssuesUsingJql/i, { cloudId: id, jql, maxResults: query.limit, fields: ['summary', 'status', 'issuetype', 'priority', 'assignee', 'reporter', 'updated', 'project'] }, query.timeoutMs));
|
|
106
|
+
result = obj(await this.#call(/searchJiraIssuesUsingJql/i, { cloudId: id, jql, maxResults: query.limit, fields: ['summary', 'status', 'issuetype', 'priority', 'assignee', 'reporter', 'updated', 'project'] }, query.timeoutMs, epoch));
|
|
114
107
|
break;
|
|
115
108
|
}
|
|
116
109
|
catch (error) {
|
|
@@ -123,21 +116,21 @@ export class JiraBoard {
|
|
|
123
116
|
}
|
|
124
117
|
}
|
|
125
118
|
const rows = Array.isArray(result['issues']) ? result['issues'] : [];
|
|
126
|
-
const issues = rows.map((value) => issue(value,
|
|
127
|
-
return { issues, constrained: retried, jql, site
|
|
119
|
+
const issues = rows.map((value) => issue(value, base)).filter((value) => !!value);
|
|
120
|
+
return { issues, constrained: retried, jql, site, cloudId: id, truncated: result['isLast'] === false, limit: query.limit };
|
|
128
121
|
}
|
|
129
122
|
async detail(key, timeoutMs) {
|
|
130
|
-
const id = await this
|
|
131
|
-
const data = obj(await this.#call(/^getJiraIssue$/i, { cloudId: id, issueIdOrKey: key, responseContentFormat: 'markdown' }, timeoutMs));
|
|
123
|
+
const { id, base, epoch } = await this.#getResource();
|
|
124
|
+
const data = obj(await this.#call(/^getJiraIssue$/i, { cloudId: id, issueIdOrKey: key, responseContentFormat: 'markdown' }, timeoutMs, epoch));
|
|
132
125
|
const row = Array.isArray(data['issues']) ? data['issues'][0] : data;
|
|
133
|
-
const found = issue(row,
|
|
126
|
+
const found = issue(row, base);
|
|
134
127
|
if (!found)
|
|
135
128
|
throw new BoardError('not-found', `Issue ${key} was not found`);
|
|
136
129
|
return { issue: found, description: val(obj(obj(row)['fields'])['description']) ?? '' };
|
|
137
130
|
}
|
|
138
131
|
async transitions(key, timeoutMs) {
|
|
139
|
-
const id = await this
|
|
140
|
-
const data = obj(await this.#call(/getTransitionsForJiraIssue/i, { cloudId: id, issueIdOrKey: key }, timeoutMs));
|
|
132
|
+
const { id, epoch } = await this.#getResource();
|
|
133
|
+
const data = obj(await this.#call(/getTransitionsForJiraIssue/i, { cloudId: id, issueIdOrKey: key }, timeoutMs, epoch));
|
|
141
134
|
const rows = Array.isArray(data['transitions']) ? data['transitions'] : [];
|
|
142
135
|
return rows.map((raw) => {
|
|
143
136
|
const row = obj(raw);
|
|
@@ -147,10 +140,12 @@ export class JiraBoard {
|
|
|
147
140
|
}).filter((row) => row.id && row.name);
|
|
148
141
|
}
|
|
149
142
|
async transition(key, transitionId, timeoutMs) {
|
|
150
|
-
|
|
143
|
+
const { id, epoch } = await this.#getResource();
|
|
144
|
+
await this.#call(/^transitionJiraIssue$/i, { cloudId: id, issueIdOrKey: key, transition: { id: transitionId } }, timeoutMs, epoch);
|
|
151
145
|
}
|
|
152
146
|
async projects(timeoutMs) {
|
|
153
|
-
const
|
|
147
|
+
const { id, epoch } = await this.#getResource();
|
|
148
|
+
const data = await this.#call(/getVisibleJiraProjects/i, { cloudId: id }, timeoutMs, epoch);
|
|
154
149
|
const rows = Array.isArray(data) ? data : Array.isArray(obj(data)['values']) ? obj(data)['values'] : [];
|
|
155
150
|
return rows.map((raw) => { const row = obj(raw); return { key: val(row['key']) ?? '', name: val(row['name']) ?? val(row['key']) ?? '' }; }).filter((row) => row.key).sort((a, b) => a.key.localeCompare(b.key));
|
|
156
151
|
}
|
package/lib/bridge.js
CHANGED
|
@@ -3,8 +3,9 @@ import { AsyncLocalStorage } from 'node:async_hooks';
|
|
|
3
3
|
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
4
4
|
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
5
5
|
import { UnauthorizedError, auth } from '@modelcontextprotocol/sdk/client/auth.js';
|
|
6
|
-
import { AtlassianOAuthProvider, CallbackServer, RedirectRegistrationChanged, createCloudFetch, secureUrl } from './oauth.js';
|
|
6
|
+
import { AtlassianOAuthProvider, CallbackServer, RedirectRegistrationChanged, createCloudFetch, isLoopbackHost, secureUrl } from './oauth.js';
|
|
7
7
|
import { OAuthTokensSchema } from '@modelcontextprotocol/sdk/shared/auth.js';
|
|
8
|
+
import { decodeToolJson, selectJiraResource } from './jira-resource.js';
|
|
8
9
|
import { openInBrowser } from './open-url.js';
|
|
9
10
|
import { sameTokens } from './store.js';
|
|
10
11
|
async function waitForFlight(flight, signal) {
|
|
@@ -213,12 +214,19 @@ export class AtlassianBridge {
|
|
|
213
214
|
},
|
|
214
215
|
});
|
|
215
216
|
}
|
|
216
|
-
#
|
|
217
|
+
#advanceGeneration() {
|
|
218
|
+
this.#generation++;
|
|
219
|
+
this.#resource = undefined;
|
|
220
|
+
this.#controller.abort();
|
|
221
|
+
this.#controller = new AbortController();
|
|
222
|
+
return this.#generation;
|
|
223
|
+
}
|
|
217
224
|
epoch() { return this.#generation; }
|
|
218
225
|
/** Site resolved during connect, shared with the board to avoid a duplicate MCP call. */
|
|
219
226
|
resource() {
|
|
220
|
-
return this.#
|
|
227
|
+
return this.#status === 'ready' ? this.#resource : undefined;
|
|
221
228
|
}
|
|
229
|
+
allowsHttpResource(url) { return this.#allowLoopbackHttp && isLoopbackHost(url.hostname); }
|
|
222
230
|
#setStatus(status) { this.#status = status; this.#wake(); }
|
|
223
231
|
#setUrl(url) { this.#url = url; this.#wake(); }
|
|
224
232
|
#wake() { const waiters = [...this.#waiters]; this.#waiters.clear(); for (const wake of waiters)
|
|
@@ -241,7 +249,7 @@ export class AtlassianBridge {
|
|
|
241
249
|
});
|
|
242
250
|
}
|
|
243
251
|
snapshot() {
|
|
244
|
-
const site = this
|
|
252
|
+
const site = this.resource()?.site;
|
|
245
253
|
let mismatch = false;
|
|
246
254
|
if (site && this.#options.expectedSite.trim()) {
|
|
247
255
|
try {
|
|
@@ -261,7 +269,9 @@ export class AtlassianBridge {
|
|
|
261
269
|
async start() {
|
|
262
270
|
if (this.#boot)
|
|
263
271
|
return this.#boot;
|
|
264
|
-
|
|
272
|
+
if (this.#disposed || this.#work || this.#status === 'ready')
|
|
273
|
+
return;
|
|
274
|
+
const generation = this.#advanceGeneration();
|
|
265
275
|
const boot = (async () => {
|
|
266
276
|
this.#setStatus('connecting');
|
|
267
277
|
await this.#options.store.load(this.#controller.signal);
|
|
@@ -293,29 +303,39 @@ export class AtlassianBridge {
|
|
|
293
303
|
}
|
|
294
304
|
}
|
|
295
305
|
async authorize() {
|
|
296
|
-
|
|
306
|
+
if (this.#boot)
|
|
307
|
+
await this.#boot;
|
|
297
308
|
if (this.#disposed || this.#status === 'ready')
|
|
298
309
|
return this.snapshot();
|
|
299
|
-
if (!this.#callback.listening)
|
|
300
|
-
await this.#callback.listen(this.#options.redirectPort);
|
|
301
310
|
if (this.#status === 'authorizing' && this.#url) {
|
|
302
311
|
if (this.#options.autoOpenBrowser)
|
|
303
312
|
await openInBrowser(this.#url);
|
|
304
313
|
return this.snapshot();
|
|
305
314
|
}
|
|
306
|
-
if (!this.#work)
|
|
307
|
-
|
|
308
|
-
this.#clearTools();
|
|
309
|
-
this.#setUrl(undefined);
|
|
310
|
-
this.#launch(true, this.#generation);
|
|
311
|
-
}
|
|
315
|
+
if (!this.#work)
|
|
316
|
+
this.#launch(true, this.#advanceGeneration());
|
|
312
317
|
// Wait for a settled state: the authorization URL is published just before
|
|
313
318
|
// the status leaves 'connecting', and callers act on the returned status.
|
|
314
319
|
await this.#waitFor(20000, () => this.#status !== 'connecting');
|
|
315
320
|
return this.snapshot();
|
|
316
321
|
}
|
|
317
322
|
#launch(open, generation) {
|
|
318
|
-
|
|
323
|
+
this.#setStatus('connecting');
|
|
324
|
+
this.#error = undefined;
|
|
325
|
+
const signal = this.#controller.signal;
|
|
326
|
+
const work = Promise.resolve().then(async () => {
|
|
327
|
+
// Assign the flight before the old client closes or a listener starts.
|
|
328
|
+
if (signal.aborted)
|
|
329
|
+
return;
|
|
330
|
+
await this.#closeClient();
|
|
331
|
+
if (signal.aborted)
|
|
332
|
+
return;
|
|
333
|
+
this.#clearTools();
|
|
334
|
+
this.#setUrl(undefined);
|
|
335
|
+
if (!this.#callback.listening)
|
|
336
|
+
await this.#callback.listen(this.#options.redirectPort);
|
|
337
|
+
await this.#connect(open, generation, signal);
|
|
338
|
+
}).catch((error) => {
|
|
319
339
|
if (!this.#disposed && generation === this.#generation) {
|
|
320
340
|
this.#setStatus('error');
|
|
321
341
|
this.#error = error instanceof Error ? error.message : String(error);
|
|
@@ -326,14 +346,13 @@ export class AtlassianBridge {
|
|
|
326
346
|
void work.finally(() => { if (this.#work === work)
|
|
327
347
|
this.#work = undefined; });
|
|
328
348
|
}
|
|
329
|
-
async #connect(open, generation) {
|
|
330
|
-
const check = () => { if (
|
|
349
|
+
async #connect(open, generation, signal) {
|
|
350
|
+
const check = () => { if (signal.aborted)
|
|
331
351
|
throw new Error('connection cancelled'); };
|
|
332
352
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
333
353
|
check();
|
|
334
354
|
this.#setStatus('connecting');
|
|
335
|
-
|
|
336
|
-
const client = new Client({ name: 'dsh-atlassian', version: '0.1.14' });
|
|
355
|
+
const client = new Client({ name: 'dsh-atlassian', version: '0.1.15' });
|
|
337
356
|
// Releasing the session lease here would race the SDK's saveTokens; an
|
|
338
357
|
// exchange that is still in flight is released by its own finally block.
|
|
339
358
|
client.onerror = () => { const operation = this.#operation.getStore(); if (operation?.exchangePending)
|
|
@@ -341,7 +360,7 @@ export class AtlassianBridge {
|
|
|
341
360
|
const transport = new StreamableHTTPClientTransport(new URL(this.#options.url), { authProvider: this.#provider, fetch: this.#fetch });
|
|
342
361
|
const send = transport.send.bind(transport);
|
|
343
362
|
transport.send = (message, options) => {
|
|
344
|
-
const operation =
|
|
363
|
+
const operation = { generation, signal };
|
|
345
364
|
return this.#operation.run(operation, async () => {
|
|
346
365
|
try {
|
|
347
366
|
return await send(message, options);
|
|
@@ -378,9 +397,9 @@ export class AtlassianBridge {
|
|
|
378
397
|
try {
|
|
379
398
|
const callback = await waiting;
|
|
380
399
|
check();
|
|
381
|
-
await this.#operation.run(
|
|
400
|
+
await this.#operation.run({ generation, signal }, () => auth(this.#provider, { serverUrl: this.#options.url, authorizationCode: callback.code, fetchFn: this.#fetch }));
|
|
382
401
|
check();
|
|
383
|
-
await this.#options.store.clearCredentialsIf(() => !this.#disposed && generation === this.#generation, undefined, undefined,
|
|
402
|
+
await this.#options.store.clearCredentialsIf(() => !this.#disposed && generation === this.#generation, undefined, undefined, signal, false, 'codeVerifier');
|
|
384
403
|
}
|
|
385
404
|
finally {
|
|
386
405
|
this.#waiting = false;
|
|
@@ -390,7 +409,7 @@ export class AtlassianBridge {
|
|
|
390
409
|
this.#client = client;
|
|
391
410
|
await this.#registerTools(client);
|
|
392
411
|
check();
|
|
393
|
-
await this.#readSite(client, generation,
|
|
412
|
+
await this.#readSite(client, generation, signal);
|
|
394
413
|
check();
|
|
395
414
|
this.#setUrl(undefined);
|
|
396
415
|
this.#setStatus('ready');
|
|
@@ -453,41 +472,13 @@ export class AtlassianBridge {
|
|
|
453
472
|
return;
|
|
454
473
|
try {
|
|
455
474
|
const result = await client.callTool({ name, arguments: {} }, undefined, { timeout: 20000, signal });
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
const reported = new URL(first['url']);
|
|
464
|
-
secureUrl(reported, this.#allowLoopbackHttp);
|
|
465
|
-
await this.#options.store.patch({ site: reported.host }, () => !this.#disposed && generation === this.#generation && !signal.aborted, undefined, undefined, signal);
|
|
466
|
-
}
|
|
467
|
-
catch { /* The status label is optional; the board still validates URLs itself. */ }
|
|
468
|
-
}
|
|
469
|
-
for (const item of list) {
|
|
470
|
-
if (!item || typeof item !== 'object')
|
|
471
|
-
continue;
|
|
472
|
-
const entry = item;
|
|
473
|
-
const id = entry['id'];
|
|
474
|
-
const url = entry['url'];
|
|
475
|
-
if (typeof id !== 'string' || !id || typeof url !== 'string' || !url)
|
|
476
|
-
continue;
|
|
477
|
-
let parsed;
|
|
478
|
-
try {
|
|
479
|
-
parsed = new URL(url);
|
|
480
|
-
if (!['http:', 'https:'].includes(parsed.protocol) || parsed.username || parsed.password)
|
|
481
|
-
continue;
|
|
482
|
-
}
|
|
483
|
-
catch {
|
|
484
|
-
continue;
|
|
485
|
-
}
|
|
486
|
-
if (!this.#disposed && generation === this.#generation && !signal.aborted) {
|
|
487
|
-
this.#resource = { epoch: generation, id, base: `${parsed.origin}${parsed.pathname.replace(/\/$/, '')}`, site: parsed.host };
|
|
488
|
-
}
|
|
489
|
-
break;
|
|
490
|
-
}
|
|
475
|
+
if (result.isError || signal.aborted)
|
|
476
|
+
return;
|
|
477
|
+
const site = selectJiraResource(decodeToolJson(result.content), (url) => this.allowsHttpResource(url));
|
|
478
|
+
if (!site)
|
|
479
|
+
return;
|
|
480
|
+
this.#resource = { epoch: generation, ...site };
|
|
481
|
+
await this.#options.store.patch({ site: site.site }, () => !signal.aborted, undefined, undefined, signal);
|
|
491
482
|
}
|
|
492
483
|
catch { /* The connection can work without a site label. */ }
|
|
493
484
|
}
|
|
@@ -500,10 +491,7 @@ export class AtlassianBridge {
|
|
|
500
491
|
return Array.isArray(result.content) ? result.content : [];
|
|
501
492
|
}
|
|
502
493
|
async disconnect() {
|
|
503
|
-
this.#
|
|
504
|
-
this.#resource = undefined;
|
|
505
|
-
this.#controller.abort();
|
|
506
|
-
this.#controller = new AbortController();
|
|
494
|
+
this.#advanceGeneration();
|
|
507
495
|
this.#setStatus('idle');
|
|
508
496
|
this.#callback.cancelWait();
|
|
509
497
|
await this.#boot?.catch(() => undefined);
|
package/lib/index.js
CHANGED
|
@@ -22,12 +22,13 @@ export function apply(ctx, config) {
|
|
|
22
22
|
const connection = {
|
|
23
23
|
snapshot: () => ({ ...config.server }),
|
|
24
24
|
update: async (input) => {
|
|
25
|
-
const next =
|
|
25
|
+
const next = configureEndpoints(config, input);
|
|
26
26
|
const editor = scope.get('configEditor');
|
|
27
27
|
const entry = editor?.entries().find((candidate) => candidate.options.id === 'atlassian');
|
|
28
28
|
if (!editor || !entry)
|
|
29
29
|
throw new Error('DSH configuration editor is unavailable');
|
|
30
30
|
await editor.edit(entry, (current) => configureEndpoints(Config(current), input));
|
|
31
|
+
Object.assign(config, next);
|
|
31
32
|
if (identityFor(next) !== identity) {
|
|
32
33
|
// The profile now points at a different endpoint; leave no credentials behind for the old one.
|
|
33
34
|
void store.destroy().catch((error) => ctx.logger.warn(`atlassian: ${String(error)}`));
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export function decodeToolJson(content) {
|
|
2
|
+
const blocks = Array.isArray(content) ? content : [];
|
|
3
|
+
const raw = blocks.map((entry) => {
|
|
4
|
+
const text = entry && typeof entry === 'object' ? entry['text'] : undefined;
|
|
5
|
+
return typeof text === 'string' ? text : '';
|
|
6
|
+
}).join('\n').trim().replace(/^```[a-z]*\s*/i, '').replace(/```\s*$/, '');
|
|
7
|
+
return JSON.parse(raw);
|
|
8
|
+
}
|
|
9
|
+
export function selectJiraResource(data, allowsHttp) {
|
|
10
|
+
for (const item of Array.isArray(data) ? data : [data]) {
|
|
11
|
+
if (!item || typeof item !== 'object')
|
|
12
|
+
continue;
|
|
13
|
+
const { id, url } = item;
|
|
14
|
+
if (typeof id !== 'string' || !id.trim() || typeof url !== 'string' || !url.trim())
|
|
15
|
+
continue;
|
|
16
|
+
let parsed;
|
|
17
|
+
try {
|
|
18
|
+
parsed = new URL(url);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (parsed.username || parsed.password)
|
|
24
|
+
continue;
|
|
25
|
+
if (parsed.protocol !== 'https:' && !(parsed.protocol === 'http:' && allowsHttp?.(parsed)))
|
|
26
|
+
continue;
|
|
27
|
+
return { id, base: `${parsed.origin}${parsed.pathname.replace(/\/$/, '')}`, site: parsed.host };
|
|
28
|
+
}
|
|
29
|
+
}
|
package/lib/server-bridge.js
CHANGED
|
@@ -78,6 +78,7 @@ export class ServerBridge {
|
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
80
|
epoch() { return this.#generation; }
|
|
81
|
+
allowsHttpResource() { return this.#config.allowInsecureHttp; }
|
|
81
82
|
rawNames() { return [...this.#operations.keys()]; }
|
|
82
83
|
rawNameMatching(pattern) { return this.rawNames().find((name) => pattern.test(name)); }
|
|
83
84
|
async start() {
|
|
@@ -90,7 +91,7 @@ export class ServerBridge {
|
|
|
90
91
|
return;
|
|
91
92
|
this.#credentials = this.#store.current.serverCredentials ?? {};
|
|
92
93
|
if (this.#credentials.jira || this.#credentials.confluence)
|
|
93
|
-
await this.#begin({}
|
|
94
|
+
await this.#begin({});
|
|
94
95
|
})();
|
|
95
96
|
try {
|
|
96
97
|
await this.#starting;
|
|
@@ -104,12 +105,13 @@ export class ServerBridge {
|
|
|
104
105
|
if (this.#disposed)
|
|
105
106
|
return this.snapshot();
|
|
106
107
|
if (!this.#running)
|
|
107
|
-
await this.#begin(input
|
|
108
|
+
await this.#begin(input);
|
|
108
109
|
else
|
|
109
110
|
await this.#running;
|
|
110
111
|
return this.snapshot();
|
|
111
112
|
}
|
|
112
|
-
async #begin(input
|
|
113
|
+
async #begin(input) {
|
|
114
|
+
const generation = ++this.#generation;
|
|
113
115
|
this.#status = 'connecting';
|
|
114
116
|
this.#error = undefined;
|
|
115
117
|
const run = this.#connect(input, generation).catch((error) => {
|
package/lib/types/board.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ConnectionResource } from './jira-resource.js';
|
|
1
2
|
export interface ToolBridge {
|
|
2
3
|
rawNameMatching(pattern: RegExp): string | undefined;
|
|
3
4
|
callTool(name: string, args: Record<string, unknown>, timeoutMs?: number): Promise<readonly unknown[]>;
|
|
@@ -8,12 +9,8 @@ export interface ToolBridge {
|
|
|
8
9
|
/** Changes whenever the connection is replaced, so cached site data can be invalidated. */
|
|
9
10
|
epoch?(): number;
|
|
10
11
|
/** Site resolved while connecting, so the first board render need not repeat that MCP call. */
|
|
11
|
-
resource?():
|
|
12
|
-
|
|
13
|
-
id: string;
|
|
14
|
-
base: string;
|
|
15
|
-
site: string;
|
|
16
|
-
} | undefined;
|
|
12
|
+
resource?(): ConnectionResource | undefined;
|
|
13
|
+
allowsHttpResource?(url: URL): boolean;
|
|
17
14
|
}
|
|
18
15
|
export interface BoardStatus {
|
|
19
16
|
name: string;
|
package/lib/types/bridge.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ToolDefinition } from '@deepseek-ai/dsh-tools';
|
|
2
2
|
import { type Logger } from './oauth.js';
|
|
3
|
+
import { type ConnectionResource } from './jira-resource.js';
|
|
3
4
|
import { type SessionStore } from './store.js';
|
|
4
5
|
export interface BridgeHost {
|
|
5
6
|
register(definition: ToolDefinition): () => void;
|
|
@@ -38,12 +39,8 @@ export declare class AtlassianBridge {
|
|
|
38
39
|
constructor(host: BridgeHost, options: BridgeOptions);
|
|
39
40
|
epoch(): number;
|
|
40
41
|
/** Site resolved during connect, shared with the board to avoid a duplicate MCP call. */
|
|
41
|
-
resource():
|
|
42
|
-
|
|
43
|
-
id: string;
|
|
44
|
-
base: string;
|
|
45
|
-
site: string;
|
|
46
|
-
} | undefined;
|
|
42
|
+
resource(): ConnectionResource | undefined;
|
|
43
|
+
allowsHttpResource(url: URL): boolean;
|
|
47
44
|
snapshot(): BridgeSnapshot;
|
|
48
45
|
rawNames(): readonly string[];
|
|
49
46
|
rawNameMatching(pattern: RegExp): string | undefined;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface JiraResource {
|
|
2
|
+
readonly id: string;
|
|
3
|
+
readonly base: string;
|
|
4
|
+
readonly site: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ConnectionResource extends JiraResource {
|
|
7
|
+
readonly epoch: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function decodeToolJson(content: unknown): unknown;
|
|
10
|
+
export declare function selectJiraResource(data: unknown, allowsHttp?: (url: URL) => boolean): JiraResource | undefined;
|
package/package.json
CHANGED