@cubis/foundry 0.3.68 → 0.3.69

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/mcp/dist/index.js CHANGED
@@ -2434,6 +2434,31 @@ async function withUpstreamClient({
2434
2434
  await client.close();
2435
2435
  }
2436
2436
  }
2437
+ function isCallToolResult(result) {
2438
+ return Array.isArray(
2439
+ result.content
2440
+ );
2441
+ }
2442
+ function normalizeUpstreamToolResult(result) {
2443
+ if (isCallToolResult(result)) {
2444
+ return result;
2445
+ }
2446
+ return {
2447
+ content: [
2448
+ {
2449
+ type: "text",
2450
+ text: JSON.stringify(
2451
+ {
2452
+ toolResult: result.toolResult
2453
+ },
2454
+ null,
2455
+ 2
2456
+ )
2457
+ }
2458
+ ],
2459
+ _meta: result._meta
2460
+ };
2461
+ }
2437
2462
  async function persistCatalog(catalog) {
2438
2463
  if (!catalog.configPath) return;
2439
2464
  const catalogDir = resolveCatalogDir(catalog.configPath);
@@ -2563,10 +2588,12 @@ async function callUpstreamTool({
2563
2588
  return withUpstreamClient({
2564
2589
  url: auth.mcpUrl,
2565
2590
  headers: auth.headers,
2566
- fn: async (client) => client.callTool({
2567
- name,
2568
- arguments: argumentsValue
2569
- })
2591
+ fn: async (client) => normalizeUpstreamToolResult(
2592
+ await client.callTool({
2593
+ name,
2594
+ arguments: argumentsValue
2595
+ })
2596
+ )
2570
2597
  });
2571
2598
  }
2572
2599
 
@@ -2631,7 +2658,10 @@ async function createServer({
2631
2658
  const registeredDynamicToolNames = /* @__PURE__ */ new Set();
2632
2659
  for (const catalog of [upstreamCatalogs.postman, upstreamCatalogs.stitch]) {
2633
2660
  for (const tool of catalog.tools) {
2634
- const registrationNames = [tool.namespacedName, ...tool.aliasNames || []];
2661
+ const registrationNames = [
2662
+ tool.namespacedName,
2663
+ ...tool.aliasNames || []
2664
+ ];
2635
2665
  const uniqueRegistrationNames = [...new Set(registrationNames)];
2636
2666
  for (const registrationName of uniqueRegistrationNames) {
2637
2667
  if (registeredDynamicToolNames.has(registrationName)) {
@@ -2648,7 +2678,7 @@ async function createServer({
2648
2678
  inputSchema: dynamicSchema,
2649
2679
  annotations: {}
2650
2680
  },
2651
- async (args) => {
2681
+ async (args, _extra) => {
2652
2682
  try {
2653
2683
  const result = await callUpstreamTool({
2654
2684
  service: catalog.service,
@@ -2657,9 +2687,8 @@ async function createServer({
2657
2687
  scope: defaultConfigScope
2658
2688
  });
2659
2689
  return {
2660
- // SDK content is typed broadly; cast to the expected array shape.
2690
+ ...result,
2661
2691
  content: result.content ?? [],
2662
- structuredContent: result.structuredContent,
2663
2692
  isError: Boolean(result.isError)
2664
2693
  };
2665
2694
  } catch (error) {
package/mcp/src/server.ts CHANGED
@@ -6,6 +6,7 @@
6
6
  */
7
7
 
8
8
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
9
+ import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
9
10
  import { z } from "zod";
10
11
  import type { ServerConfig } from "./config/schema.js";
11
12
  import type { ConfigScope } from "./cbxConfig/types.js";
@@ -102,7 +103,10 @@ export async function createServer({
102
103
 
103
104
  for (const catalog of [upstreamCatalogs.postman, upstreamCatalogs.stitch]) {
104
105
  for (const tool of catalog.tools) {
105
- const registrationNames = [tool.namespacedName, ...(tool.aliasNames || [])];
106
+ const registrationNames = [
107
+ tool.namespacedName,
108
+ ...(tool.aliasNames || []),
109
+ ];
106
110
  const uniqueRegistrationNames = [...new Set(registrationNames)];
107
111
  for (const registrationName of uniqueRegistrationNames) {
108
112
  if (registeredDynamicToolNames.has(registrationName)) {
@@ -119,7 +123,10 @@ export async function createServer({
119
123
  inputSchema: dynamicSchema,
120
124
  annotations: {},
121
125
  },
122
- async (args: Record<string, unknown>) => {
126
+ async (
127
+ args: Record<string, unknown>,
128
+ _extra,
129
+ ): Promise<CallToolResult> => {
123
130
  try {
124
131
  const result = await callUpstreamTool({
125
132
  service: catalog.service,
@@ -131,14 +138,8 @@ export async function createServer({
131
138
  scope: defaultConfigScope,
132
139
  });
133
140
  return {
134
- // SDK content is typed broadly; cast to the expected array shape.
135
- content: (result.content ?? []) as Array<{
136
- type: string;
137
- [k: string]: unknown;
138
- }>,
139
- structuredContent: result.structuredContent as
140
- | Record<string, unknown>
141
- | undefined,
141
+ ...result,
142
+ content: result.content ?? [],
142
143
  isError: Boolean(result.isError),
143
144
  };
144
145
  } catch (error) {
@@ -12,6 +12,7 @@
12
12
  */
13
13
 
14
14
  import { z } from "zod";
15
+ import type { ToolCallback } from "@modelcontextprotocol/sdk/server/mcp.js";
15
16
  import type { VaultManifest } from "../vault/types.js";
16
17
  import type { RouteManifest } from "../routes/types.js";
17
18
  import type { ConfigScope } from "../cbxConfig/types.js";
@@ -35,7 +36,7 @@ export interface ToolRegistryEntry {
35
36
  */
36
37
  createHandler: (
37
38
  ctx: ToolRuntimeContext,
38
- ) => (args: unknown) => Promise<unknown>;
39
+ ) => ToolCallback<z.ZodObject<z.ZodRawShape>>;
39
40
  }
40
41
 
41
42
  export interface ToolRuntimeContext {
@@ -359,7 +359,7 @@ async function fileExists(target: string) {
359
359
 
360
360
  async function detectLanguageSkillHint() {
361
361
  const cwd = process.cwd();
362
- const candidates = await fs.readdir(cwd).catch(() => []);
362
+ const candidates: string[] = await fs.readdir(cwd).catch(() => []);
363
363
  const has = (fileName: string) => candidates.includes(fileName);
364
364
 
365
365
  for (const entry of LANGUAGE_SIGNAL_FILES) {
@@ -6,6 +6,7 @@ import { mkdir, readFile, writeFile } from "node:fs/promises";
6
6
  import path from "node:path";
7
7
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
8
8
  import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
9
+ import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
9
10
  import {
10
11
  parsePostmanState,
11
12
  parseStitchState,
@@ -209,6 +210,40 @@ async function withUpstreamClient<T>({
209
210
  }
210
211
  }
211
212
 
213
+ function isCallToolResult(
214
+ result: Awaited<ReturnType<Client["callTool"]>>,
215
+ ): result is CallToolResult {
216
+ return Array.isArray(
217
+ (result as {
218
+ content?: unknown;
219
+ }).content,
220
+ );
221
+ }
222
+
223
+ function normalizeUpstreamToolResult(
224
+ result: Awaited<ReturnType<Client["callTool"]>>,
225
+ ): CallToolResult {
226
+ if (isCallToolResult(result)) {
227
+ return result;
228
+ }
229
+
230
+ return {
231
+ content: [
232
+ {
233
+ type: "text",
234
+ text: JSON.stringify(
235
+ {
236
+ toolResult: result.toolResult,
237
+ },
238
+ null,
239
+ 2,
240
+ ),
241
+ },
242
+ ],
243
+ _meta: result._meta,
244
+ };
245
+ }
246
+
212
247
  async function persistCatalog(catalog: UpstreamCatalog): Promise<void> {
213
248
  if (!catalog.configPath) return;
214
249
  const catalogDir = resolveCatalogDir(catalog.configPath);
@@ -344,7 +379,7 @@ export async function callUpstreamTool({
344
379
  name: string;
345
380
  argumentsValue: Record<string, unknown>;
346
381
  scope?: ConfigScope | "auto";
347
- }) {
382
+ }): Promise<CallToolResult> {
348
383
  const effective = readEffectiveConfig(scope);
349
384
  if (!effective) {
350
385
  throw new Error("cbx_config.json not found");
@@ -360,10 +395,12 @@ export async function callUpstreamTool({
360
395
  return withUpstreamClient({
361
396
  url: auth.mcpUrl,
362
397
  headers: auth.headers,
363
- fn: async (client) =>
364
- client.callTool({
365
- name,
366
- arguments: argumentsValue,
367
- }),
398
+ fn: async (client): Promise<CallToolResult> =>
399
+ normalizeUpstreamToolResult(
400
+ await client.callTool({
401
+ name,
402
+ arguments: argumentsValue,
403
+ }),
404
+ ),
368
405
  });
369
406
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cubis/foundry",
3
- "version": "0.3.68",
3
+ "version": "0.3.69",
4
4
  "description": "Cubis Foundry CLI for workflow-first AI agent environments",
5
5
  "type": "module",
6
6
  "bin": {