@lornatang/dsh-atlassian 0.1.15 → 0.1.17

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 CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.17 - 2026-11-23
4
+
5
+ - Validate connector tool output in a worker and enforce limits on discovered tools and returned data.
6
+ - Clean up the connector and its registered tools if initialization fails.
7
+ - Publish from the shared repository using npm Trusted Publishing.
8
+
9
+ ## 0.1.16 - 2026-11-21
10
+
11
+ - Move the source and release metadata to the shared dsh-plugin repository.
12
+
3
13
  ## 0.1.15 - 2026-11-19
4
14
 
5
15
  - Serialize connection replacement and refresh the Jira site cache when the connection changes.
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.15/lornatang-dsh-atlassian-0.1.15.tgz`.
37
+ Prebuilt tarballs are available in [GitHub Releases](https://github.com/Lornatang/dsh-plugin/releases) under tags such as `dsh-atlassian-v<version>`.
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.15/lornatang-dsh-atlassian-0.1.15.tgz`。
37
+ 预构建压缩包见新仓库的 [GitHub Releases](https://github.com/Lornatang/dsh-plugin/releases),标签格式为 `dsh-atlassian-v<version>`。
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/bridge.js CHANGED
@@ -7,7 +7,10 @@ import { AtlassianOAuthProvider, CallbackServer, RedirectRegistrationChanged, cr
7
7
  import { OAuthTokensSchema } from '@modelcontextprotocol/sdk/shared/auth.js';
8
8
  import { decodeToolJson, selectJiraResource } from './jira-resource.js';
9
9
  import { openInBrowser } from './open-url.js';
10
+ import { deferredOutputValidation, validateOutput } from './output-validator.js';
10
11
  import { sameTokens } from './store.js';
12
+ const MAX_DISCOVERY_BYTES = 8 * 1024 * 1024;
13
+ const MAX_TOOL_BYTES = 512 * 1024;
11
14
  async function waitForFlight(flight, signal) {
12
15
  if (signal.aborted)
13
16
  throw new Error('atlassian: connection cancelled');
@@ -264,7 +267,7 @@ export class AtlassianBridge {
264
267
  // would reach an unbound callback listener and fail with an HTTP 400.
265
268
  return { status: this.#status, authorizationUrl: this.#waiting ? this.#url : undefined, site, siteMismatch: mismatch, toolCount: this.#tools.size, error: this.#error };
266
269
  }
267
- rawNames() { return [...this.#tools.values()].map((value) => value.raw); }
270
+ rawNames() { return [...this.#tools.keys()]; }
268
271
  rawNameMatching(pattern) { return this.rawNames().find((name) => pattern.test(name)); }
269
272
  async start() {
270
273
  if (this.#boot)
@@ -352,7 +355,7 @@ export class AtlassianBridge {
352
355
  for (let attempt = 0; attempt < 2; attempt++) {
353
356
  check();
354
357
  this.#setStatus('connecting');
355
- const client = new Client({ name: 'dsh-atlassian', version: '0.1.15' });
358
+ const client = new Client({ name: 'dsh-atlassian', version: '0.1.15' }, { jsonSchemaValidator: deferredOutputValidation });
356
359
  // Releasing the session lease here would race the SDK's saveTokens; an
357
360
  // exchange that is still in flight is released by its own finally block.
358
361
  client.onerror = () => { const operation = this.#operation.getStore(); if (operation?.exchangePending)
@@ -407,27 +410,42 @@ export class AtlassianBridge {
407
410
  continue;
408
411
  }
409
412
  this.#client = client;
410
- await this.#registerTools(client);
411
- check();
412
- await this.#readSite(client, generation, signal);
413
- check();
414
- this.#setUrl(undefined);
415
- 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
+ }
416
426
  return;
417
427
  }
418
428
  throw new Error('Atlassian authorization did not establish a connection');
419
429
  }
420
- async #registerTools(client) {
430
+ async #registerTools(client, signal) {
421
431
  const found = [];
422
432
  const seen = new Set();
423
433
  let cursor;
434
+ let bytes = 0;
424
435
  do {
425
436
  if (seen.size >= 100)
426
437
  throw new Error('MCP server returned too many tool pages');
427
- const page = await client.listTools(cursor ? { cursor } : {});
428
- found.push(...page.tools);
429
- 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)
430
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
+ }
431
449
  cursor = page.nextCursor;
432
450
  if (cursor && seen.has(cursor))
433
451
  throw new Error('MCP server repeated a continuation cursor');
@@ -441,29 +459,21 @@ export class AtlassianBridge {
441
459
  throw new Error('MCP server returned duplicate tool names');
442
460
  names.add(name);
443
461
  }
444
- this.#clearTools();
445
- try {
446
- for (const tool of found) {
447
- const name = publicToolName(this.#options.serverName, tool.name);
448
- const definition = {
449
- name, description: tool.description ?? '', parameters: tool.inputSchema,
450
- output: {
451
- schema: { type: 'object', properties: { content: { type: 'array', items: {} } }, required: ['content'], additionalProperties: false },
452
- render: (_args, result) => [{ type: 'text', text: display(result?.content) }],
453
- },
454
- execute: async (args, context) => {
455
- const result = await client.callTool({ name: tool.name, arguments: (typeof args === 'object' && args !== null ? args : {}) }, undefined, { timeout: this.#options.toolCallTimeoutMs, signal: context.signal });
456
- if (result.isError)
457
- throw new Error(display(result.content));
458
- return { content: result.content };
459
- },
460
- };
461
- this.#tools.set(name, { raw: tool.name, dispose: this.#host.register(definition) });
462
- }
463
- }
464
- catch (error) {
465
- this.#clearTools();
466
- 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) });
467
477
  }
468
478
  }
469
479
  async #readSite(client, generation, signal) {
@@ -471,10 +481,10 @@ export class AtlassianBridge {
471
481
  if (!name)
472
482
  return;
473
483
  try {
474
- const result = await client.callTool({ name, arguments: {} }, undefined, { timeout: 20000, signal });
475
- if (result.isError || signal.aborted)
484
+ const content = await this.#callTool(client, name, {}, 20_000, signal);
485
+ if (signal.aborted)
476
486
  return;
477
- const site = selectJiraResource(decodeToolJson(result.content), (url) => this.allowsHttpResource(url));
487
+ const site = selectJiraResource(decodeToolJson(content), (url) => this.allowsHttpResource(url));
478
488
  if (!site)
479
489
  return;
480
490
  this.#resource = { epoch: generation, ...site };
@@ -485,9 +495,22 @@ export class AtlassianBridge {
485
495
  async callTool(rawName, args, timeoutMs) {
486
496
  if (!this.#client || this.#status !== 'ready')
487
497
  throw new Error('Atlassian is not connected');
488
- 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 });
489
506
  if (result.isError)
490
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();
491
514
  return Array.isArray(result.content) ? result.content : [];
492
515
  }
493
516
  async disconnect() {
@@ -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
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { jsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/types';
2
+ export declare const deferredOutputValidation: jsonSchemaValidator;
3
+ export declare function validateOutput(schema: object, value: unknown, timeoutMs: number, caller: AbortSignal): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lornatang/dsh-atlassian",
3
- "version": "0.1.15",
3
+ "version": "0.1.17",
4
4
  "description": "Connect Atlassian Cloud or self-hosted Jira and Confluence to DeepSeek Harness with tools and a Jira board.",
5
5
  "keywords": [
6
6
  "deepseek-harness",
@@ -75,20 +75,21 @@
75
75
  },
76
76
  "devDependencies": {
77
77
  "@deepseek-ai/cordis": "~4.1.0",
78
- "@deepseek-ai/dsh-llm": "0.2.2-rc.2",
79
- "@deepseek-ai/dsh-tools": "0.2.2-rc.2",
80
- "@types/node": "^22.18.0",
78
+ "@deepseek-ai/dsh-llm": "*",
79
+ "@deepseek-ai/dsh-tools": "*",
80
+ "@types/node": "^26.6.6",
81
81
  "@types/react": "^19.3.0",
82
- "typescript": "^5.9.0"
82
+ "typescript": "^7.0.2"
83
83
  },
84
84
  "author": "Lornatang",
85
85
  "repository": {
86
86
  "type": "git",
87
- "url": "git+https://github.com/Lornatang/dsh-atlassian.git"
87
+ "url": "git+https://github.com/Lornatang/dsh-plugin.git",
88
+ "directory": "packages/integrations/dsh-atlassian"
88
89
  },
89
- "homepage": "https://github.com/Lornatang/dsh-atlassian#readme",
90
+ "homepage": "https://github.com/Lornatang/dsh-plugin/tree/main/packages/integrations/dsh-atlassian#readme",
90
91
  "bugs": {
91
- "url": "https://github.com/Lornatang/dsh-atlassian/issues"
92
+ "url": "https://github.com/Lornatang/dsh-plugin/issues"
92
93
  },
93
94
  "publishConfig": {
94
95
  "access": "public"