dsh-desktop-kit 2.7.6 → 2.7.8

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.
@@ -32,8 +32,17 @@ async function readEnvelope(request) {
32
32
  return { rpcId: body.rpcId, method: body.method, payload: body.payload ?? {} };
33
33
  }
34
34
 
35
- function publicServer(server) {
36
- return {
35
+ function promptText(result) {
36
+ const messages = Array.isArray(result?.messages) ? result.messages : [];
37
+ return messages.map((message) => {
38
+ const content = message?.content;
39
+ if (typeof content === "string") return content;
40
+ if (Array.isArray(content)) return content.map((block) => block?.text ?? "").filter(Boolean).join("\n");
41
+ return content?.text ?? "";
42
+ }).filter(Boolean).join("\n\n");
43
+ }
44
+
45
+ function publicServer(server) { return {
37
46
  id: server.id,
38
47
  scope: server.scope,
39
48
  transport: server.url ? "http" : "stdio",
@@ -239,6 +248,28 @@ export function registerApi(ctx, manager) {
239
248
  error: record.error,
240
249
  };
241
250
  });
251
+ operation("prompts", async (payload) => {
252
+ const config = loadConfig({ cwd: process.cwd() });
253
+ const server = config.servers.find((item) => item.id === String(payload.id ?? ""));
254
+ if (!server) throw new Error("server not found");
255
+ const record = await manager.connect(server);
256
+ if (!record.client?.connected) return { prompts: [], error: record.error };
257
+ try {
258
+ const prompts = await manager.prompts(server.id);
259
+ record.prompts = prompts;
260
+ return { prompts, error: "" };
261
+ } catch (error) {
262
+ return { prompts: [], error: error instanceof Error ? error.message : String(error) };
263
+ }
264
+ });
265
+ operation("prompt", async (payload) => {
266
+ const config = loadConfig({ cwd: process.cwd() });
267
+ const server = config.servers.find((item) => item.id === String(payload.id ?? ""));
268
+ if (!server) throw new Error("server not found");
269
+ await manager.connect(server);
270
+ const result = await manager.prompt(server.id, String(payload.name ?? ""), payload.arguments ?? {});
271
+ return { text: promptText(result), description: result?.description ?? "" };
272
+ });
242
273
  operation("call", async (payload) => {
243
274
  const config = loadConfig({ cwd: process.cwd() });
244
275
  const server = config.servers.find((item) => item.id === String(payload.id ?? ""));
@@ -165,6 +165,7 @@ export class McpClient {
165
165
  this.capabilities = {};
166
166
  this.tools = [];
167
167
  this.resources = [];
168
+ this.prompts = [];
168
169
  }
169
170
 
170
171
  async connect() {
@@ -212,6 +213,23 @@ export class McpClient {
212
213
  return this.transport.request("resources/read", { uri }, this.config.timeoutMs);
213
214
  }
214
215
 
216
+ async listPrompts() {
217
+ if (!this.capabilities.prompts) return [];
218
+ const prompts = [];
219
+ let cursor;
220
+ do {
221
+ const result = await this.transport.request("prompts/list", cursor ? { cursor } : {}, this.config.timeoutMs);
222
+ if (Array.isArray(result?.prompts)) prompts.push(...result.prompts);
223
+ cursor = result?.nextCursor;
224
+ } while (cursor);
225
+ this.prompts = prompts;
226
+ return prompts;
227
+ }
228
+
229
+ async getPrompt(name, args = {}) {
230
+ return this.transport.request("prompts/get", { name, arguments: args }, this.config.timeoutMs);
231
+ }
232
+
215
233
  async close() {
216
234
  await this.transport.close?.();
217
235
  this.connected = false;
@@ -53,7 +53,7 @@ export class McpManager {
53
53
  throw new Error("MCP manager is closed");
54
54
  }
55
55
  const tools = await client.listTools();
56
- const record = { server, client, tools, resources: [], error: "" };
56
+ const record = { server, client, tools, resources: [], prompts: [], error: "" };
57
57
  this.clients.set(server.id, record);
58
58
  for (const tool of tools) {
59
59
  const name = this.toolName(server.id, tool.name);
@@ -62,7 +62,7 @@ export class McpManager {
62
62
  return record;
63
63
  } catch (error) {
64
64
  await client.close().catch(() => {});
65
- const record = { server, client: null, tools: [], resources: [], error: error instanceof Error ? error.message : String(error) };
65
+ const record = { server, client: null, tools: [], resources: [], prompts: [], error: error instanceof Error ? error.message : String(error) };
66
66
  this.clients.set(server.id, record);
67
67
  return record;
68
68
  }
@@ -122,6 +122,18 @@ export class McpManager {
122
122
  return record.client.readResource(uri);
123
123
  }
124
124
 
125
+ async prompts(serverId) {
126
+ const record = this.clients.get(serverId);
127
+ if (!record?.client?.connected) throw new Error(`MCP server not connected: ${serverId}`);
128
+ return record.client.listPrompts();
129
+ }
130
+
131
+ async prompt(serverId, name, args) {
132
+ const record = this.clients.get(serverId);
133
+ if (!record?.client?.connected) throw new Error(`MCP server not connected: ${serverId}`);
134
+ return record.client.getPrompt(name, args);
135
+ }
136
+
125
137
  status() {
126
138
  return [...this.clients.values()].map((record) => ({
127
139
  id: record.server.id,