@lornatang/dsh-atlassian 0.1.14 → 0.1.16

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/lib/bridge.js CHANGED
@@ -3,10 +3,14 @@ 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';
10
+ import { deferredOutputValidation, validateOutput } from './output-validator.js';
9
11
  import { sameTokens } from './store.js';
12
+ const MAX_DISCOVERY_BYTES = 8 * 1024 * 1024;
13
+ const MAX_TOOL_BYTES = 512 * 1024;
10
14
  async function waitForFlight(flight, signal) {
11
15
  if (signal.aborted)
12
16
  throw new Error('atlassian: connection cancelled');
@@ -213,12 +217,19 @@ export class AtlassianBridge {
213
217
  },
214
218
  });
215
219
  }
216
- #newOperation() { return { generation: this.#generation, signal: this.#controller.signal }; }
220
+ #advanceGeneration() {
221
+ this.#generation++;
222
+ this.#resource = undefined;
223
+ this.#controller.abort();
224
+ this.#controller = new AbortController();
225
+ return this.#generation;
226
+ }
217
227
  epoch() { return this.#generation; }
218
228
  /** Site resolved during connect, shared with the board to avoid a duplicate MCP call. */
219
229
  resource() {
220
- return this.#resource?.epoch === this.#generation ? this.#resource : undefined;
230
+ return this.#status === 'ready' ? this.#resource : undefined;
221
231
  }
232
+ allowsHttpResource(url) { return this.#allowLoopbackHttp && isLoopbackHost(url.hostname); }
222
233
  #setStatus(status) { this.#status = status; this.#wake(); }
223
234
  #setUrl(url) { this.#url = url; this.#wake(); }
224
235
  #wake() { const waiters = [...this.#waiters]; this.#waiters.clear(); for (const wake of waiters)
@@ -241,7 +252,7 @@ export class AtlassianBridge {
241
252
  });
242
253
  }
243
254
  snapshot() {
244
- const site = this.#options.store.current.site;
255
+ const site = this.resource()?.site;
245
256
  let mismatch = false;
246
257
  if (site && this.#options.expectedSite.trim()) {
247
258
  try {
@@ -256,12 +267,14 @@ export class AtlassianBridge {
256
267
  // would reach an unbound callback listener and fail with an HTTP 400.
257
268
  return { status: this.#status, authorizationUrl: this.#waiting ? this.#url : undefined, site, siteMismatch: mismatch, toolCount: this.#tools.size, error: this.#error };
258
269
  }
259
- rawNames() { return [...this.#tools.values()].map((value) => value.raw); }
270
+ rawNames() { return [...this.#tools.keys()]; }
260
271
  rawNameMatching(pattern) { return this.rawNames().find((name) => pattern.test(name)); }
261
272
  async start() {
262
273
  if (this.#boot)
263
274
  return this.#boot;
264
- const generation = this.#generation;
275
+ if (this.#disposed || this.#work || this.#status === 'ready')
276
+ return;
277
+ const generation = this.#advanceGeneration();
265
278
  const boot = (async () => {
266
279
  this.#setStatus('connecting');
267
280
  await this.#options.store.load(this.#controller.signal);
@@ -293,29 +306,39 @@ export class AtlassianBridge {
293
306
  }
294
307
  }
295
308
  async authorize() {
296
- await this.#boot;
309
+ if (this.#boot)
310
+ await this.#boot;
297
311
  if (this.#disposed || this.#status === 'ready')
298
312
  return this.snapshot();
299
- if (!this.#callback.listening)
300
- await this.#callback.listen(this.#options.redirectPort);
301
313
  if (this.#status === 'authorizing' && this.#url) {
302
314
  if (this.#options.autoOpenBrowser)
303
315
  await openInBrowser(this.#url);
304
316
  return this.snapshot();
305
317
  }
306
- if (!this.#work) {
307
- await this.#closeClient();
308
- this.#clearTools();
309
- this.#setUrl(undefined);
310
- this.#launch(true, this.#generation);
311
- }
318
+ if (!this.#work)
319
+ this.#launch(true, this.#advanceGeneration());
312
320
  // Wait for a settled state: the authorization URL is published just before
313
321
  // the status leaves 'connecting', and callers act on the returned status.
314
322
  await this.#waitFor(20000, () => this.#status !== 'connecting');
315
323
  return this.snapshot();
316
324
  }
317
325
  #launch(open, generation) {
318
- const work = this.#connect(open, generation).catch((error) => {
326
+ this.#setStatus('connecting');
327
+ this.#error = undefined;
328
+ const signal = this.#controller.signal;
329
+ const work = Promise.resolve().then(async () => {
330
+ // Assign the flight before the old client closes or a listener starts.
331
+ if (signal.aborted)
332
+ return;
333
+ await this.#closeClient();
334
+ if (signal.aborted)
335
+ return;
336
+ this.#clearTools();
337
+ this.#setUrl(undefined);
338
+ if (!this.#callback.listening)
339
+ await this.#callback.listen(this.#options.redirectPort);
340
+ await this.#connect(open, generation, signal);
341
+ }).catch((error) => {
319
342
  if (!this.#disposed && generation === this.#generation) {
320
343
  this.#setStatus('error');
321
344
  this.#error = error instanceof Error ? error.message : String(error);
@@ -326,14 +349,13 @@ export class AtlassianBridge {
326
349
  void work.finally(() => { if (this.#work === work)
327
350
  this.#work = undefined; });
328
351
  }
329
- async #connect(open, generation) {
330
- const check = () => { if (this.#disposed || generation !== this.#generation)
352
+ async #connect(open, generation, signal) {
353
+ const check = () => { if (signal.aborted)
331
354
  throw new Error('connection cancelled'); };
332
355
  for (let attempt = 0; attempt < 2; attempt++) {
333
356
  check();
334
357
  this.#setStatus('connecting');
335
- this.#error = undefined;
336
- const client = new Client({ name: 'dsh-atlassian', version: '0.1.14' });
358
+ const client = new Client({ name: 'dsh-atlassian', version: '0.1.15' }, { jsonSchemaValidator: deferredOutputValidation });
337
359
  // Releasing the session lease here would race the SDK's saveTokens; an
338
360
  // exchange that is still in flight is released by its own finally block.
339
361
  client.onerror = () => { const operation = this.#operation.getStore(); if (operation?.exchangePending)
@@ -341,7 +363,7 @@ export class AtlassianBridge {
341
363
  const transport = new StreamableHTTPClientTransport(new URL(this.#options.url), { authProvider: this.#provider, fetch: this.#fetch });
342
364
  const send = transport.send.bind(transport);
343
365
  transport.send = (message, options) => {
344
- const operation = this.#newOperation();
366
+ const operation = { generation, signal };
345
367
  return this.#operation.run(operation, async () => {
346
368
  try {
347
369
  return await send(message, options);
@@ -378,9 +400,9 @@ export class AtlassianBridge {
378
400
  try {
379
401
  const callback = await waiting;
380
402
  check();
381
- await this.#operation.run(this.#newOperation(), () => auth(this.#provider, { serverUrl: this.#options.url, authorizationCode: callback.code, fetchFn: this.#fetch }));
403
+ await this.#operation.run({ generation, signal }, () => auth(this.#provider, { serverUrl: this.#options.url, authorizationCode: callback.code, fetchFn: this.#fetch }));
382
404
  check();
383
- await this.#options.store.clearCredentialsIf(() => !this.#disposed && generation === this.#generation, undefined, undefined, this.#controller.signal, false, 'codeVerifier');
405
+ await this.#options.store.clearCredentialsIf(() => !this.#disposed && generation === this.#generation, undefined, undefined, signal, false, 'codeVerifier');
384
406
  }
385
407
  finally {
386
408
  this.#waiting = false;
@@ -388,27 +410,42 @@ export class AtlassianBridge {
388
410
  continue;
389
411
  }
390
412
  this.#client = client;
391
- await this.#registerTools(client);
392
- check();
393
- await this.#readSite(client, generation, this.#controller.signal);
394
- check();
395
- this.#setUrl(undefined);
396
- this.#setStatus('ready');
413
+ try {
414
+ await this.#registerTools(client, signal);
415
+ check();
416
+ await this.#readSite(client, generation, signal);
417
+ check();
418
+ this.#setUrl(undefined);
419
+ this.#setStatus('ready');
420
+ }
421
+ catch (error) {
422
+ this.#clearTools();
423
+ await this.#closeClient();
424
+ throw error;
425
+ }
397
426
  return;
398
427
  }
399
428
  throw new Error('Atlassian authorization did not establish a connection');
400
429
  }
401
- async #registerTools(client) {
430
+ async #registerTools(client, signal) {
402
431
  const found = [];
403
432
  const seen = new Set();
404
433
  let cursor;
434
+ let bytes = 0;
405
435
  do {
406
436
  if (seen.size >= 100)
407
437
  throw new Error('MCP server returned too many tool pages');
408
- const page = await client.listTools(cursor ? { cursor } : {});
409
- found.push(...page.tools);
410
- if (found.length > 1000)
438
+ const page = await client.listTools(cursor ? { cursor } : {}, { signal, timeout: this.#options.toolCallTimeoutMs });
439
+ if (found.length + page.tools.length > 1000)
411
440
  throw new Error('MCP server returned too many tools');
441
+ bytes += Buffer.byteLength(JSON.stringify(page), 'utf8');
442
+ if (bytes > MAX_DISCOVERY_BYTES)
443
+ throw new Error('MCP tool discovery exceeds the total byte limit');
444
+ for (const tool of page.tools) {
445
+ if (Buffer.byteLength(JSON.stringify(tool), 'utf8') > MAX_TOOL_BYTES)
446
+ throw new Error('MCP tool definition exceeds the byte limit');
447
+ found.push(tool);
448
+ }
412
449
  cursor = page.nextCursor;
413
450
  if (cursor && seen.has(cursor))
414
451
  throw new Error('MCP server repeated a continuation cursor');
@@ -422,29 +459,21 @@ export class AtlassianBridge {
422
459
  throw new Error('MCP server returned duplicate tool names');
423
460
  names.add(name);
424
461
  }
425
- this.#clearTools();
426
- try {
427
- for (const tool of found) {
428
- const name = publicToolName(this.#options.serverName, tool.name);
429
- const definition = {
430
- name, description: tool.description ?? '', parameters: tool.inputSchema,
431
- output: {
432
- schema: { type: 'object', properties: { content: { type: 'array', items: {} } }, required: ['content'], additionalProperties: false },
433
- render: (_args, result) => [{ type: 'text', text: display(result?.content) }],
434
- },
435
- execute: async (args, context) => {
436
- const result = await client.callTool({ name: tool.name, arguments: (typeof args === 'object' && args !== null ? args : {}) }, undefined, { timeout: this.#options.toolCallTimeoutMs, signal: context.signal });
437
- if (result.isError)
438
- throw new Error(display(result.content));
439
- return { content: result.content };
440
- },
441
- };
442
- this.#tools.set(name, { raw: tool.name, dispose: this.#host.register(definition) });
443
- }
444
- }
445
- catch (error) {
446
- this.#clearTools();
447
- throw error;
462
+ for (const tool of found) {
463
+ const name = publicToolName(this.#options.serverName, tool.name);
464
+ const definition = {
465
+ name, description: tool.description ?? '', parameters: tool.inputSchema,
466
+ output: {
467
+ schema: { type: 'object', properties: { content: { type: 'array', items: {} } }, required: ['content'], additionalProperties: false },
468
+ render: (_args, result) => [{ type: 'text', text: display(result?.content) }],
469
+ },
470
+ execute: async (args, context) => {
471
+ const combined = context.signal ? AbortSignal.any([signal, context.signal]) : signal;
472
+ const input = (typeof args === 'object' && args !== null ? args : {});
473
+ return { content: await this.#callTool(client, tool.name, input, this.#options.toolCallTimeoutMs, combined) };
474
+ },
475
+ };
476
+ this.#tools.set(tool.name, { outputSchema: tool.outputSchema, dispose: this.#host.register(definition) });
448
477
  }
449
478
  }
450
479
  async #readSite(client, generation, signal) {
@@ -452,58 +481,40 @@ export class AtlassianBridge {
452
481
  if (!name)
453
482
  return;
454
483
  try {
455
- const result = await client.callTool({ name, arguments: {} }, undefined, { timeout: 20000, signal });
456
- const items = JSON.parse(display(result.content));
457
- const list = Array.isArray(items) ? items : [items];
458
- // Publish the first safe site label for the status snapshot. The board's
459
- // stricter URL policy decides which entry can act as its cloud resource.
460
- const first = list[0];
461
- if (first && typeof first === 'object' && typeof first['url'] === 'string') {
462
- try {
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
- }
484
+ const content = await this.#callTool(client, name, {}, 20_000, signal);
485
+ if (signal.aborted)
486
+ return;
487
+ const site = selectJiraResource(decodeToolJson(content), (url) => this.allowsHttpResource(url));
488
+ if (!site)
489
+ return;
490
+ this.#resource = { epoch: generation, ...site };
491
+ await this.#options.store.patch({ site: site.site }, () => !signal.aborted, undefined, undefined, signal);
491
492
  }
492
493
  catch { /* The connection can work without a site label. */ }
493
494
  }
494
495
  async callTool(rawName, args, timeoutMs) {
495
496
  if (!this.#client || this.#status !== 'ready')
496
497
  throw new Error('Atlassian is not connected');
497
- const result = await this.#client.callTool({ name: rawName, arguments: args }, undefined, { timeout: timeoutMs ?? this.#options.toolCallTimeoutMs });
498
+ return this.#callTool(this.#client, rawName, args, timeoutMs ?? this.#options.toolCallTimeoutMs, this.#controller.signal);
499
+ }
500
+ async #callTool(client, name, args, timeout, signal) {
501
+ signal.throwIfAborted();
502
+ const tool = this.#tools.get(name);
503
+ if (!tool)
504
+ throw new Error(`Atlassian MCP tool ${name} was not discovered`);
505
+ const result = await client.callTool({ name, arguments: args }, undefined, { timeout, signal });
498
506
  if (result.isError)
499
507
  throw new Error(display(result.content));
508
+ if (tool.outputSchema) {
509
+ if (result.structuredContent === undefined)
510
+ throw new Error(`Atlassian MCP tool ${name} did not return structured output`);
511
+ await validateOutput(tool.outputSchema, result.structuredContent, timeout, signal);
512
+ }
513
+ signal.throwIfAborted();
500
514
  return Array.isArray(result.content) ? result.content : [];
501
515
  }
502
516
  async disconnect() {
503
- this.#generation++;
504
- this.#resource = undefined;
505
- this.#controller.abort();
506
- this.#controller = new AbortController();
517
+ this.#advanceGeneration();
507
518
  this.#setStatus('idle');
508
519
  this.#callback.cancelWait();
509
520
  await this.#boot?.catch(() => undefined);
package/lib/client.js CHANGED
@@ -48,25 +48,25 @@ const Context = React.createContext({ slots: { inject: () => () => undefined, re
48
48
  if (typeof document !== 'undefined') {
49
49
  const style = document.createElement('style');
50
50
  style.setAttribute('data-plugin-css', '@lornatang/dsh-atlassian');
51
- style.textContent = `
52
- .dab-root{--dab-line:color-mix(in srgb,currentColor 14%,transparent);--dab-soft:color-mix(in srgb,currentColor 4%,transparent);--dab-softer:color-mix(in srgb,currentColor 2.5%,transparent);box-sizing:border-box;padding:24px 28px 36px;max-width:1120px;margin:0 auto;color:inherit;font-size:14px;line-height:1.5}
53
- .dab-root *{box-sizing:border-box}.dab-settings{max-width:900px}.dab-root h2,.dab-root h3,.dab-root p{margin:0}.dab-root button,.dab-root input,.dab-root select{font:inherit}
54
- .dab-hero{display:flex;align-items:flex-start;gap:15px;margin-bottom:24px}.dab-brand-icon,.dab-service-icon{display:grid;place-items:center;flex:none;border-radius:14px;background:rgba(79,125,244,.15);color:#7098ff}
55
- .dab-brand-icon{width:46px;height:46px}.dab-brand-icon svg{width:24px;height:24px}.dab-hero-copy{flex:1;min-width:0}.dab-eyebrow{font-size:10px;font-weight:700;letter-spacing:.13em;text-transform:uppercase;opacity:.58;margin-bottom:3px!important}
56
- .dab-title{font-size:23px;line-height:1.2;font-weight:700;letter-spacing:-.025em}.dab-subtitle{margin-top:6px!important;opacity:.68;font-size:13px;max-width:560px}.dab-mode{flex:none;padding:5px 9px;border:1px solid var(--dab-line);border-radius:999px;background:var(--dab-soft);font-size:10px;font-weight:700;letter-spacing:.035em;opacity:.8}
57
- .dab-section-label{display:flex;align-items:center;justify-content:space-between;gap:12px;margin:24px 0 10px;font-size:11px;font-weight:700;letter-spacing:.09em;text-transform:uppercase;opacity:.6}
58
- .dab-status{display:flex;align-items:center;gap:14px;padding:16px 18px;border:1px solid var(--dab-line);border-radius:13px;background:var(--dab-softer)}.dab-status-icon{display:grid;place-items:center;width:34px;height:34px;flex:none;border-radius:10px;color:#7296fa;background:rgba(100,137,255,.14)}
59
- .dab-status-icon.is-ready{color:#2dbb87;background:rgba(45,187,135,.14)}.dab-status-icon.is-error{color:#f47878;background:rgba(244,120,120,.14)}.dab-status-main{min-width:0;flex:1}.dab-status-title{font-weight:700;font-size:14px}.dab-status-note{opacity:.64;font-size:12px;margin-top:1px!important;overflow-wrap:anywhere}.dab-status-count{padding-left:18px;border-left:1px solid var(--dab-line);text-align:right;white-space:nowrap}.dab-status-count strong{display:block;font-size:17px;line-height:1.1}.dab-status-count span{font-size:10px;text-transform:uppercase;letter-spacing:.07em;opacity:.58}
60
- .dab-service{border:1px solid var(--dab-line);border-radius:14px;background:var(--dab-softer);padding:18px;margin-bottom:12px}.dab-service-head{display:flex;align-items:center;gap:11px;margin-bottom:16px}.dab-service-icon{width:37px;height:37px;border-radius:11px;font-size:15px;font-weight:800}.dab-service-icon.is-confluence{background:rgba(92,158,230,.15);color:#70b5f5}.dab-service-title{font-size:14px;font-weight:700;line-height:1.25}.dab-service-url{font-size:12px;opacity:.62;overflow-wrap:anywhere}.dab-service-copy{min-width:0;flex:1}.dab-service-tag{font-size:10px;font-weight:700;letter-spacing:.05em;opacity:.52;text-transform:uppercase}
61
- .dab-config-head{display:flex;justify-content:space-between;gap:12px;align-items:flex-start;margin-bottom:15px}.dab-config-head p{font-size:12px;opacity:.65;margin-top:3px!important}.dab-advanced{margin-top:14px;font-size:12px}.dab-advanced summary{cursor:pointer;font-weight:650;opacity:.75;list-style-position:inside}.dab-advanced-body{padding-top:12px}.dab-checkbox{display:flex;align-items:flex-start;gap:8px;margin-top:13px;line-height:1.4}.dab-checkbox input{accent-color:#5984f3;margin-top:2px}.dab-config-actions{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin-top:15px}.dab-config-hint{font-size:12px;opacity:.62}
62
- .dab-field-grid{display:grid;grid-template-columns:1fr 1fr;gap:14px}.dab-field{display:block;min-width:0;font-size:12px;font-weight:650}.dab-field span{display:block;margin-bottom:6px}.dab-input{width:100%;min-width:0;min-height:39px;padding:8px 11px;border:1px solid var(--dab-line);border-radius:9px;background:var(--dab-soft);color:inherit;outline:none;transition:border-color .15s,box-shadow .15s}.dab-input::placeholder{color:inherit;opacity:.42}.dab-input:focus{border-color:#7196ff;box-shadow:0 0 0 3px rgba(104,145,255,.17)}
63
- .dab-help{font-size:12px;opacity:.62;margin-top:11px!important}.dab-callout{display:flex;gap:9px;align-items:flex-start;padding:11px 12px;border-radius:9px;background:rgba(226,161,40,.11);color:color-mix(in srgb,currentColor 45%,#e8a82e);font-size:12px;margin-top:13px}.dab-callout svg{width:15px;height:15px;flex:none;margin-top:1px}
64
- .dab-alert{padding:11px 13px;border:1px solid rgba(230,89,89,.3);border-radius:10px;background:rgba(230,89,89,.09);color:color-mix(in srgb,currentColor 40%,#ed6969);white-space:pre-wrap;overflow-wrap:anywhere;font-size:13px;margin-top:14px!important}.dab-actions{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin-top:18px}.dab-action-note{font-size:12px;opacity:.58;margin-left:auto}.dab-button{display:inline-flex;align-items:center;justify-content:center;gap:7px;min-height:36px;padding:7px 13px;border:1px solid var(--dab-line);border-radius:9px;background:var(--dab-soft);color:inherit;font-weight:600;cursor:pointer;transition:background .15s,border-color .15s,transform .15s}.dab-button:hover:not(:disabled){background:color-mix(in srgb,currentColor 9%,transparent)}.dab-button:focus-visible{outline:2px solid #7196ff;outline-offset:2px}.dab-button:disabled{opacity:.4;cursor:not-allowed}.dab-button-primary{border-color:#4678ed;background:#4678ed;color:#fff}.dab-button-primary:hover:not(:disabled){background:#356be0;border-color:#356be0}.dab-button svg{width:15px;height:15px;flex:none}
65
- .dab-link{color:#779bff;text-decoration:none;font-weight:600}.dab-link:hover{text-decoration:underline}.dab-cloud-card{padding:18px;border:1px solid var(--dab-line);border-radius:14px;background:var(--dab-softer)}.dab-cloud-card strong{display:block;margin-bottom:5px}.dab-cloud-card p{font-size:13px;opacity:.68}
66
- .dab-board-head{display:flex;align-items:flex-start;justify-content:space-between;gap:12px;margin-bottom:20px}.dab-row{display:flex;gap:9px;align-items:center;flex-wrap:wrap;margin:10px 0}.dab-toolbar{display:flex;gap:9px;align-items:center;flex-wrap:wrap}.dab-search{flex:1;min-width:180px}.dab-project{width:auto;min-width:140px}.dab-query{display:flex;gap:9px;align-items:center;margin:10px 0 16px;padding:10px 12px;border:1px solid var(--dab-line);border-radius:10px;background:var(--dab-softer)}.dab-query label{font-size:11px;font-weight:800;letter-spacing:.06em;opacity:.65}.dab-query .dab-input{border:0;background:transparent;min-height:32px;padding:4px 6px;flex:1}.dab-query .dab-input:focus{box-shadow:none}.dab-selection{display:flex;align-items:center;gap:8px;flex-wrap:wrap;padding:10px 12px;margin:0 0 16px;border:1px solid rgba(105,145,255,.3);border-radius:10px;background:rgba(105,145,255,.08)}.dab-selection-count{font-size:12px;font-weight:700;margin-right:5px}
67
- .dab-columns{display:flex;align-items:flex-start;gap:12px;overflow-x:auto;padding-bottom:12px}.dab-column{min-width:230px;flex:1;border:1px solid var(--dab-line);border-radius:12px;background:var(--dab-softer);padding:10px}.dab-column-head{display:flex;justify-content:space-between;align-items:center;gap:8px;padding:3px 3px 9px;font-size:12px;font-weight:700}.dab-column-count{font-size:11px;font-weight:600;opacity:.6}.dab-issue{border:1px solid var(--dab-line);border-radius:10px;background:var(--dab-soft);padding:11px;margin:0 0 8px;cursor:pointer;transition:border-color .15s,transform .15s}.dab-issue:hover{border-color:rgba(105,145,255,.5);transform:translateY(-1px)}.dab-issue:focus-visible{outline:2px solid #7196ff;outline-offset:2px}.dab-issue-key{display:flex;align-items:center;gap:6px;font-size:11px;font-weight:700;color:#7a9cff}.dab-issue-key input{accent-color:#5984f3}.dab-issue-summary{font-weight:600;font-size:13px;line-height:1.4;margin-top:7px}.dab-issue-meta{display:block;margin-top:8px;font-size:11px;opacity:.6}.dab-empty{padding:36px 18px;text-align:center;border:1px dashed var(--dab-line);border-radius:12px;opacity:.65;font-size:13px}
68
- .dab-detail{position:fixed;right:0;top:0;bottom:0;width:min(520px,90vw);overflow:auto;background:var(--dab-detail-bg,Canvas);color:CanvasText;border-left:1px solid var(--dab-line);padding:22px;z-index:50;box-shadow:0 0 24px #0004}.dab-detail-head{display:flex;justify-content:space-between;align-items:center;gap:12px}.dab-detail pre{white-space:pre-wrap;overflow-wrap:anywhere;font:inherit;opacity:.85;margin:18px 0}.dab-message{font-size:13px;opacity:.8;margin:10px 0!important}.dab-root svg{display:block}
69
- @media(max-width:640px){.dab-root{padding:18px 16px 28px}.dab-hero{gap:11px}.dab-mode{display:none}.dab-field-grid{grid-template-columns:1fr}.dab-status-count{padding-left:10px}.dab-action-note{width:100%;margin-left:0}.dab-board-head{display:block}.dab-toolbar>*{min-width:0}.dab-project{flex:1}}
51
+ style.textContent = `
52
+ .dab-root{--dab-line:color-mix(in srgb,currentColor 14%,transparent);--dab-soft:color-mix(in srgb,currentColor 4%,transparent);--dab-softer:color-mix(in srgb,currentColor 2.5%,transparent);box-sizing:border-box;padding:24px 28px 36px;max-width:1120px;margin:0 auto;color:inherit;font-size:14px;line-height:1.5}
53
+ .dab-root *{box-sizing:border-box}.dab-settings{max-width:900px}.dab-root h2,.dab-root h3,.dab-root p{margin:0}.dab-root button,.dab-root input,.dab-root select{font:inherit}
54
+ .dab-hero{display:flex;align-items:flex-start;gap:15px;margin-bottom:24px}.dab-brand-icon,.dab-service-icon{display:grid;place-items:center;flex:none;border-radius:14px;background:rgba(79,125,244,.15);color:#7098ff}
55
+ .dab-brand-icon{width:46px;height:46px}.dab-brand-icon svg{width:24px;height:24px}.dab-hero-copy{flex:1;min-width:0}.dab-eyebrow{font-size:10px;font-weight:700;letter-spacing:.13em;text-transform:uppercase;opacity:.58;margin-bottom:3px!important}
56
+ .dab-title{font-size:23px;line-height:1.2;font-weight:700;letter-spacing:-.025em}.dab-subtitle{margin-top:6px!important;opacity:.68;font-size:13px;max-width:560px}.dab-mode{flex:none;padding:5px 9px;border:1px solid var(--dab-line);border-radius:999px;background:var(--dab-soft);font-size:10px;font-weight:700;letter-spacing:.035em;opacity:.8}
57
+ .dab-section-label{display:flex;align-items:center;justify-content:space-between;gap:12px;margin:24px 0 10px;font-size:11px;font-weight:700;letter-spacing:.09em;text-transform:uppercase;opacity:.6}
58
+ .dab-status{display:flex;align-items:center;gap:14px;padding:16px 18px;border:1px solid var(--dab-line);border-radius:13px;background:var(--dab-softer)}.dab-status-icon{display:grid;place-items:center;width:34px;height:34px;flex:none;border-radius:10px;color:#7296fa;background:rgba(100,137,255,.14)}
59
+ .dab-status-icon.is-ready{color:#2dbb87;background:rgba(45,187,135,.14)}.dab-status-icon.is-error{color:#f47878;background:rgba(244,120,120,.14)}.dab-status-main{min-width:0;flex:1}.dab-status-title{font-weight:700;font-size:14px}.dab-status-note{opacity:.64;font-size:12px;margin-top:1px!important;overflow-wrap:anywhere}.dab-status-count{padding-left:18px;border-left:1px solid var(--dab-line);text-align:right;white-space:nowrap}.dab-status-count strong{display:block;font-size:17px;line-height:1.1}.dab-status-count span{font-size:10px;text-transform:uppercase;letter-spacing:.07em;opacity:.58}
60
+ .dab-service{border:1px solid var(--dab-line);border-radius:14px;background:var(--dab-softer);padding:18px;margin-bottom:12px}.dab-service-head{display:flex;align-items:center;gap:11px;margin-bottom:16px}.dab-service-icon{width:37px;height:37px;border-radius:11px;font-size:15px;font-weight:800}.dab-service-icon.is-confluence{background:rgba(92,158,230,.15);color:#70b5f5}.dab-service-title{font-size:14px;font-weight:700;line-height:1.25}.dab-service-url{font-size:12px;opacity:.62;overflow-wrap:anywhere}.dab-service-copy{min-width:0;flex:1}.dab-service-tag{font-size:10px;font-weight:700;letter-spacing:.05em;opacity:.52;text-transform:uppercase}
61
+ .dab-config-head{display:flex;justify-content:space-between;gap:12px;align-items:flex-start;margin-bottom:15px}.dab-config-head p{font-size:12px;opacity:.65;margin-top:3px!important}.dab-advanced{margin-top:14px;font-size:12px}.dab-advanced summary{cursor:pointer;font-weight:650;opacity:.75;list-style-position:inside}.dab-advanced-body{padding-top:12px}.dab-checkbox{display:flex;align-items:flex-start;gap:8px;margin-top:13px;line-height:1.4}.dab-checkbox input{accent-color:#5984f3;margin-top:2px}.dab-config-actions{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin-top:15px}.dab-config-hint{font-size:12px;opacity:.62}
62
+ .dab-field-grid{display:grid;grid-template-columns:1fr 1fr;gap:14px}.dab-field{display:block;min-width:0;font-size:12px;font-weight:650}.dab-field span{display:block;margin-bottom:6px}.dab-input{width:100%;min-width:0;min-height:39px;padding:8px 11px;border:1px solid var(--dab-line);border-radius:9px;background:var(--dab-soft);color:inherit;outline:none;transition:border-color .15s,box-shadow .15s}.dab-input::placeholder{color:inherit;opacity:.42}.dab-input:focus{border-color:#7196ff;box-shadow:0 0 0 3px rgba(104,145,255,.17)}
63
+ .dab-help{font-size:12px;opacity:.62;margin-top:11px!important}.dab-callout{display:flex;gap:9px;align-items:flex-start;padding:11px 12px;border-radius:9px;background:rgba(226,161,40,.11);color:color-mix(in srgb,currentColor 45%,#e8a82e);font-size:12px;margin-top:13px}.dab-callout svg{width:15px;height:15px;flex:none;margin-top:1px}
64
+ .dab-alert{padding:11px 13px;border:1px solid rgba(230,89,89,.3);border-radius:10px;background:rgba(230,89,89,.09);color:color-mix(in srgb,currentColor 40%,#ed6969);white-space:pre-wrap;overflow-wrap:anywhere;font-size:13px;margin-top:14px!important}.dab-actions{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin-top:18px}.dab-action-note{font-size:12px;opacity:.58;margin-left:auto}.dab-button{display:inline-flex;align-items:center;justify-content:center;gap:7px;min-height:36px;padding:7px 13px;border:1px solid var(--dab-line);border-radius:9px;background:var(--dab-soft);color:inherit;font-weight:600;cursor:pointer;transition:background .15s,border-color .15s,transform .15s}.dab-button:hover:not(:disabled){background:color-mix(in srgb,currentColor 9%,transparent)}.dab-button:focus-visible{outline:2px solid #7196ff;outline-offset:2px}.dab-button:disabled{opacity:.4;cursor:not-allowed}.dab-button-primary{border-color:#4678ed;background:#4678ed;color:#fff}.dab-button-primary:hover:not(:disabled){background:#356be0;border-color:#356be0}.dab-button svg{width:15px;height:15px;flex:none}
65
+ .dab-link{color:#779bff;text-decoration:none;font-weight:600}.dab-link:hover{text-decoration:underline}.dab-cloud-card{padding:18px;border:1px solid var(--dab-line);border-radius:14px;background:var(--dab-softer)}.dab-cloud-card strong{display:block;margin-bottom:5px}.dab-cloud-card p{font-size:13px;opacity:.68}
66
+ .dab-board-head{display:flex;align-items:flex-start;justify-content:space-between;gap:12px;margin-bottom:20px}.dab-row{display:flex;gap:9px;align-items:center;flex-wrap:wrap;margin:10px 0}.dab-toolbar{display:flex;gap:9px;align-items:center;flex-wrap:wrap}.dab-search{flex:1;min-width:180px}.dab-project{width:auto;min-width:140px}.dab-query{display:flex;gap:9px;align-items:center;margin:10px 0 16px;padding:10px 12px;border:1px solid var(--dab-line);border-radius:10px;background:var(--dab-softer)}.dab-query label{font-size:11px;font-weight:800;letter-spacing:.06em;opacity:.65}.dab-query .dab-input{border:0;background:transparent;min-height:32px;padding:4px 6px;flex:1}.dab-query .dab-input:focus{box-shadow:none}.dab-selection{display:flex;align-items:center;gap:8px;flex-wrap:wrap;padding:10px 12px;margin:0 0 16px;border:1px solid rgba(105,145,255,.3);border-radius:10px;background:rgba(105,145,255,.08)}.dab-selection-count{font-size:12px;font-weight:700;margin-right:5px}
67
+ .dab-columns{display:flex;align-items:flex-start;gap:12px;overflow-x:auto;padding-bottom:12px}.dab-column{min-width:230px;flex:1;border:1px solid var(--dab-line);border-radius:12px;background:var(--dab-softer);padding:10px}.dab-column-head{display:flex;justify-content:space-between;align-items:center;gap:8px;padding:3px 3px 9px;font-size:12px;font-weight:700}.dab-column-count{font-size:11px;font-weight:600;opacity:.6}.dab-issue{border:1px solid var(--dab-line);border-radius:10px;background:var(--dab-soft);padding:11px;margin:0 0 8px;cursor:pointer;transition:border-color .15s,transform .15s}.dab-issue:hover{border-color:rgba(105,145,255,.5);transform:translateY(-1px)}.dab-issue:focus-visible{outline:2px solid #7196ff;outline-offset:2px}.dab-issue-key{display:flex;align-items:center;gap:6px;font-size:11px;font-weight:700;color:#7a9cff}.dab-issue-key input{accent-color:#5984f3}.dab-issue-summary{font-weight:600;font-size:13px;line-height:1.4;margin-top:7px}.dab-issue-meta{display:block;margin-top:8px;font-size:11px;opacity:.6}.dab-empty{padding:36px 18px;text-align:center;border:1px dashed var(--dab-line);border-radius:12px;opacity:.65;font-size:13px}
68
+ .dab-detail{position:fixed;right:0;top:0;bottom:0;width:min(520px,90vw);overflow:auto;background:var(--dab-detail-bg,Canvas);color:CanvasText;border-left:1px solid var(--dab-line);padding:22px;z-index:50;box-shadow:0 0 24px #0004}.dab-detail-head{display:flex;justify-content:space-between;align-items:center;gap:12px}.dab-detail pre{white-space:pre-wrap;overflow-wrap:anywhere;font:inherit;opacity:.85;margin:18px 0}.dab-message{font-size:13px;opacity:.8;margin:10px 0!important}.dab-root svg{display:block}
69
+ @media(max-width:640px){.dab-root{padding:18px 16px 28px}.dab-hero{gap:11px}.dab-mode{display:none}.dab-field-grid{grid-template-columns:1fr}.dab-status-count{padding-left:10px}.dab-action-note{width:100%;margin-left:0}.dab-board-head{display:block}.dab-toolbar>*{min-width:0}.dab-project{flex:1}}
70
70
  `;
71
71
  document.head.appendChild(style);
72
72
  }
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 = Object.assign(config, configureEndpoints(config, input));
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
+ }
@@ -0,0 +1,28 @@
1
+ import { parentPort } from 'node:worker_threads';
2
+ import { AjvJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/ajv';
3
+ const MAX_SCHEMAS = 16;
4
+ const MAX_TASKS = 64;
5
+ const cache = new Map();
6
+ let tasks = 0;
7
+ parentPort?.on('message', ({ id, schema, value }) => {
8
+ let valid = false;
9
+ let error;
10
+ try {
11
+ let validator = cache.get(id);
12
+ if (!validator) {
13
+ if (!schema || ('$async' in schema && schema.$async))
14
+ throw new Error('expected a synchronous output schema');
15
+ // AJV also caches by remote $id. Compile new schema identities independently.
16
+ validator = new AjvJsonSchemaValidator().getValidator(schema);
17
+ cache.set(id, validator);
18
+ }
19
+ const result = validator(value);
20
+ valid = result.valid;
21
+ error = result.errorMessage;
22
+ }
23
+ catch (failure) {
24
+ error = failure instanceof Error ? failure.message : 'invalid output schema';
25
+ }
26
+ tasks++;
27
+ parentPort?.postMessage({ valid, error: error?.slice(0, 1000), cached: cache.has(id), retire: cache.size >= MAX_SCHEMAS || tasks >= MAX_TASKS });
28
+ });
@@ -0,0 +1,133 @@
1
+ import { Worker } from 'node:worker_threads';
2
+ // The SDK's validator API is synchronous. The bridge validates successful
3
+ // results against their discovered schema before they leave the bridge.
4
+ export const deferredOutputValidation = {
5
+ getValidator() {
6
+ return (data) => ({ valid: true, data: data, errorMessage: undefined });
7
+ },
8
+ };
9
+ const MAX_ACTIVE = 4;
10
+ const MAX_WAITING = 8;
11
+ const MAX_LIVE = 8;
12
+ const MAX_VALIDATION_MS = 5000;
13
+ const CANCELLED = 'atlassian: output validation timed out or was cancelled';
14
+ let active = 0;
15
+ const waiting = [];
16
+ async function acquire(signal) {
17
+ if (signal.aborted)
18
+ throw new Error(CANCELLED);
19
+ if (active < MAX_ACTIVE) {
20
+ active++;
21
+ return;
22
+ }
23
+ if (waiting.length >= MAX_WAITING)
24
+ throw new Error('atlassian: too many pending output validations');
25
+ await new Promise((resolve, reject) => {
26
+ const waiter = {
27
+ resume: () => { signal.removeEventListener('abort', waiter.cancel); resolve(); },
28
+ cancel: () => {
29
+ const index = waiting.indexOf(waiter);
30
+ if (index >= 0)
31
+ waiting.splice(index, 1);
32
+ reject(new Error(CANCELLED));
33
+ },
34
+ };
35
+ waiting.push(waiter);
36
+ signal.addEventListener('abort', waiter.cancel, { once: true });
37
+ });
38
+ }
39
+ const live = new Set();
40
+ const idle = [];
41
+ const schemaIds = new WeakMap();
42
+ let nextSchemaId = 1;
43
+ function spawn() {
44
+ // A retiring worker still counts until it exits. Native schema processing
45
+ // can delay V8's response to terminate(), so do not replace it indefinitely.
46
+ if (live.size >= MAX_LIVE)
47
+ throw new Error('atlassian: output validation workers are unavailable');
48
+ const worker = new Worker(new URL('./output-validator-worker.js', import.meta.url), {
49
+ execArgv: [],
50
+ resourceLimits: { maxOldGenerationSizeMb: 64, maxYoungGenerationSizeMb: 16, stackSizeMb: 4 },
51
+ });
52
+ const entry = { worker, schemas: new Set() };
53
+ live.add(entry);
54
+ worker.on('error', () => { }); // A worker can fail after its caller has cancelled.
55
+ worker.once('exit', () => {
56
+ live.delete(entry);
57
+ const index = idle.indexOf(entry);
58
+ if (index >= 0)
59
+ idle.splice(index, 1);
60
+ });
61
+ return entry;
62
+ }
63
+ function runTask(entry, schema, value, signal) {
64
+ const { worker, schemas } = entry;
65
+ let schemaId = schemaIds.get(schema);
66
+ if (schemaId === undefined) {
67
+ schemaId = nextSchemaId++;
68
+ schemaIds.set(schema, schemaId);
69
+ }
70
+ const id = schemaId;
71
+ return new Promise((resolve, reject) => {
72
+ const cleanup = () => {
73
+ worker.off('message', onResult);
74
+ worker.off('error', onError);
75
+ worker.off('exit', onExit);
76
+ signal.removeEventListener('abort', onAbort);
77
+ };
78
+ const onResult = (result) => {
79
+ cleanup();
80
+ if (result.cached)
81
+ schemas.add(id);
82
+ resolve(result);
83
+ };
84
+ const onError = (error) => { cleanup(); reject(error); };
85
+ const onExit = () => onError(new Error('atlassian: output validation worker exited'));
86
+ const onAbort = () => onError(new Error(CANCELLED));
87
+ worker.once('message', onResult);
88
+ worker.once('error', onError);
89
+ worker.once('exit', onExit);
90
+ if (signal.aborted) {
91
+ onAbort();
92
+ return;
93
+ }
94
+ signal.addEventListener('abort', onAbort, { once: true });
95
+ try {
96
+ worker.postMessage({ id, value, schema: schemas.has(id) ? undefined : schema });
97
+ }
98
+ catch (error) {
99
+ cleanup();
100
+ reject(error);
101
+ }
102
+ });
103
+ }
104
+ export async function validateOutput(schema, value, timeoutMs, caller) {
105
+ const signal = AbortSignal.any([caller, AbortSignal.timeout(Math.min(timeoutMs, MAX_VALIDATION_MS))]);
106
+ await acquire(signal);
107
+ let entry;
108
+ let result;
109
+ try {
110
+ if (signal.aborted)
111
+ throw new Error(CANCELLED);
112
+ entry = idle.pop() ?? spawn();
113
+ entry.worker.ref();
114
+ result = await runTask(entry, schema, value, signal);
115
+ signal.throwIfAborted();
116
+ if (!result.valid)
117
+ throw new Error(`atlassian: structured output does not match its schema: ${result.error ?? 'invalid output'}`);
118
+ }
119
+ finally {
120
+ if (entry) {
121
+ entry.worker.unref();
122
+ if (result && !result.retire && !signal.aborted)
123
+ idle.push(entry);
124
+ else
125
+ void entry.worker.terminate().catch(() => undefined);
126
+ }
127
+ const next = waiting.shift();
128
+ if (next)
129
+ next.resume();
130
+ else
131
+ active--;
132
+ }
133
+ }
@@ -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({}, generation);
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, this.#generation);
108
+ await this.#begin(input);
108
109
  else
109
110
  await this.#running;
110
111
  return this.snapshot();
111
112
  }
112
- async #begin(input, generation) {
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) => {