@momeidejiyi/dsh-general-mcp 0.3.1 → 0.3.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momeidejiyi/dsh-general-mcp",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Single-endpoint MCP bridge for DSH: connects one gateway and registers its tools.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
package/src/catalog.ts CHANGED
@@ -8,7 +8,6 @@ export interface ToolOverride {
8
8
 
9
9
  export interface ToolSettings {
10
10
  disabled?: string[]
11
- hidden?: string[]
12
11
  /** Removed from the tree entirely; separate from "disabled". */
13
12
  removed?: string[]
14
13
  overrides?: Record<string, ToolOverride>
@@ -32,7 +31,6 @@ export interface CatalogEntry {
32
31
  outputSchema?: Record<string, unknown>
33
32
  hash: string
34
33
  disabled: boolean
35
- hidden: boolean
36
34
  removed?: boolean
37
35
  invalid?: ToolDiagnostic
38
36
  warning?: ToolDiagnostic
@@ -172,16 +170,16 @@ export function buildCatalog(
172
170
  settings: ToolSettings = {},
173
171
  ): CatalogEntry[] {
174
172
  const disabled = new Set(settings.disabled ?? [])
175
- const hidden = new Set(settings.hidden ?? [])
176
173
  const removed = new Set(settings.removed ?? [])
177
174
  return tools.map(tool => {
178
175
  const override = settings.overrides?.[tool.name]
179
176
  const invalid = validateTool(tool)
180
177
  const warnings = toolWarnings(tool)
181
178
  const schema = inputSchemaOf(tool).schema
182
- const folder = (override?.folder ?? folderFromMeta(tool) ?? folderFromName(tool.name))
183
- .map(slug)
184
- .filter(Boolean)
179
+ const rawFolder = Array.isArray(override?.folder)
180
+ ? override?.folder
181
+ : (folderFromMeta(tool) ?? folderFromName(tool.name))
182
+ const folder = (Array.isArray(rawFolder) ? rawFolder : []).map(slug).filter(Boolean)
185
183
  const leaf = slug(tool.name.split(/[./]/).pop() ?? tool.name) || 'tool'
186
184
  const path = [...folder, leaf].join('/')
187
185
  const metaTitle = typeof tool._meta?.[CANONICAL_TITLE] === 'string' ? String(tool._meta[CANONICAL_TITLE]).slice(0, MAX_TITLE) : undefined
@@ -202,7 +200,6 @@ export function buildCatalog(
202
200
  ...(tool.outputSchema === undefined ? {} : { outputSchema: tool.outputSchema }),
203
201
  hash: shortHash(description + JSON.stringify(schema) + JSON.stringify(folder)),
204
202
  disabled: disabled.has(tool.name),
205
- hidden: hidden.has(tool.name),
206
203
  ...(removed.has(tool.name) ? { removed: true } : {}),
207
204
  ...(invalid !== undefined ? { invalid } : {}),
208
205
  ...(invalid === undefined && warnings.length > 0
@@ -210,4 +207,4 @@ export function buildCatalog(
210
207
  : {}),
211
208
  }
212
209
  })
213
- }
210
+ }
package/src/client.ts CHANGED
@@ -125,7 +125,13 @@ export class McpClient {
125
125
  const sessionId = this.sessionId
126
126
  this.sessionId = undefined
127
127
  try {
128
- await fetch(this.url, { method: 'DELETE', headers: { 'mcp-session-id': sessionId } })
128
+ // A hung DELETE must not block a reconnect (or the caller closing a
129
+ // half-broken connection).
130
+ await fetch(this.url, {
131
+ method: 'DELETE',
132
+ headers: { 'mcp-session-id': sessionId },
133
+ signal: AbortSignal.timeout(5_000),
134
+ })
129
135
  } catch {}
130
136
  }
131
137
 
package/src/connect.ts CHANGED
@@ -20,7 +20,14 @@ function looksLikeSse(url: string): boolean {
20
20
 
21
21
  async function viaStreamable(url: string, headers: Record<string, string>, timeoutMs: number): Promise<McpConnection> {
22
22
  const client = new McpClient(url, headers, timeoutMs)
23
- const info: any = await client.initialize()
23
+ let info: any
24
+ try {
25
+ info = await client.initialize()
26
+ } catch (error) {
27
+ // A failed probe must release its socket instead of leaving it to the GC.
28
+ await client.close().catch(() => {})
29
+ throw error
30
+ }
24
31
  return {
25
32
  transport: 'streamable',
26
33
  detail: 'POST ' + url,
@@ -35,7 +42,15 @@ async function viaStreamable(url: string, headers: Record<string, string>, timeo
35
42
 
36
43
  async function viaSse(url: string, headers: Record<string, string>, timeoutMs: number): Promise<McpConnection> {
37
44
  const client = new SseClient(url, headers, timeoutMs)
38
- const info: any = await client.initialize()
45
+ let info: any
46
+ try {
47
+ info = await client.initialize()
48
+ } catch (error) {
49
+ // Closing aborts the GET stream; without this a probe leaks an open SSE
50
+ // stream (and a server-side session) on every failed attempt.
51
+ await client.close().catch(() => {})
52
+ throw error
53
+ }
39
54
  return {
40
55
  transport: 'sse',
41
56
  detail: 'GET ' + url + ' → POST ' + (client.messageEndpoint ?? '(pending)'),
@@ -43,7 +58,7 @@ async function viaSse(url: string, headers: Record<string, string>, timeoutMs: n
43
58
  serverInfo: info?.serverInfo,
44
59
  async initialize() {},
45
60
  listTools: async () => (await client.listTools()) as unknown as McpTool[],
46
- callTool: (name, args) => client.callTool(name, args),
61
+ callTool: (name, args, signal) => client.callTool(name, args, signal),
47
62
  close: () => client.close(),
48
63
  }
49
64
  }
@@ -68,4 +83,4 @@ export async function connectMcp(
68
83
  }
69
84
  }
70
85
  throw new Error('无法连接网关(两种传输都失败): ' + errors.join(' | '))
71
- }
86
+ }