@composio/mastra 0.9.2 → 0.10.0

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/dist/index.d.mts CHANGED
@@ -2,7 +2,6 @@ import { BaseAgenticProvider, ExecuteToolFn, McpUrlResponse, Tool } from "@compo
2
2
  import { createTool } from "@mastra/core/tools";
3
3
 
4
4
  //#region src/index.d.ts
5
-
6
5
  type MastraTool = ReturnType<typeof createTool>;
7
6
  interface MastraToolCollection {
8
7
  [key: string]: MastraTool;
@@ -15,6 +14,7 @@ interface MastraUrlMap {
15
14
  declare class MastraProvider extends BaseAgenticProvider<MastraToolCollection, MastraTool, MastraUrlMap> {
16
15
  readonly name = "mastra";
17
16
  private strict;
17
+ private warnedDanglingRefs;
18
18
  /**
19
19
  * Creates a new instance of the MastraProvider.
20
20
  *
@@ -52,6 +52,7 @@ declare class MastraProvider extends BaseAgenticProvider<MastraToolCollection, M
52
52
  wrapMcpServerResponse(data: McpUrlResponse): MastraUrlMap;
53
53
  wrapTool(tool: Tool, executeTool: ExecuteToolFn): MastraTool;
54
54
  wrapTools(tools: Tool[], executeTool: ExecuteToolFn): MastraToolCollection;
55
+ private warnDanglingRefOnce;
55
56
  }
56
57
  //#endregion
57
58
  export { MastraProvider, MastraTool, MastraToolCollection, MastraUrlMap };
package/dist/index.mjs CHANGED
@@ -1,7 +1,91 @@
1
- import { BaseAgenticProvider, dereferenceJsonSchema, removeNonRequiredProperties } from "@composio/core";
1
+ import { BaseAgenticProvider, dereferenceJsonSchema, logger, normalizeToolArguments, removeNonRequiredProperties, telemetry } from "@composio/core";
2
2
  import { applyCompatLayer } from "@mastra/schema-compat";
3
3
  import { createTool } from "@mastra/core/tools";
4
4
 
5
+ //#region src/relax-output-schema.ts
6
+ /**
7
+ * Output-schema leniency for the Mastra provider.
8
+ *
9
+ * Mastra validates every tool result against the tool's `outputSchema` via
10
+ * `validateToolOutput`; on a mismatch it drops the data and substitutes an
11
+ * error. Composio's API-supplied output schemas, however, are strict: optional
12
+ * fields are typed as non-nullable primitives (`{ type: 'string' }`) and
13
+ * objects carry `additionalProperties: false`. Real third-party APIs (Linear,
14
+ * Notion, Jira, Slack, …) routinely return `null` for unset optional fields and
15
+ * occasionally extra keys, so strict validation rejects perfectly good
16
+ * responses and truncates the tool output the model sees.
17
+ *
18
+ * Output validation of opaque third-party pass-through payloads provides little
19
+ * value and causes real breakage, so we relax the output schema before handing
20
+ * it to `@mastra/schema-compat`:
21
+ *
22
+ * - every typed node is made nullable (`type: 'string'` → `['string', 'null']`)
23
+ * - objects with `additionalProperties: false` (or unset) allow extra keys
24
+ * - `enum`/`const` are widened to also admit `null` — they constrain the
25
+ * *value* independently of `type`, so making the type nullable is not enough
26
+ * - `required` is dropped, since real APIs omit unset fields entirely rather
27
+ * than returning `null` for them, so requiring any field rejects good output
28
+ *
29
+ * All four changes only *widen* what validates, so any payload that passed
30
+ * before still passes — there is no behavioural change for already-valid output.
31
+ *
32
+ * See https://github.com/ComposioHQ/composio/issues/3047.
33
+ */
34
+ const SUBSCHEMA_KEYS = [
35
+ "items",
36
+ "additionalItems",
37
+ "contains"
38
+ ];
39
+ const SUBSCHEMA_LIST_KEYS = [
40
+ "anyOf",
41
+ "oneOf",
42
+ "allOf",
43
+ "prefixItems"
44
+ ];
45
+ const SUBSCHEMA_MAP_KEYS = [
46
+ "properties",
47
+ "patternProperties",
48
+ "$defs",
49
+ "definitions"
50
+ ];
51
+ function isPlainObject(value) {
52
+ return typeof value === "object" && value !== null && !Array.isArray(value);
53
+ }
54
+ function addNullToType(type) {
55
+ if (typeof type === "string") return type === "null" ? type : [type, "null"];
56
+ if (Array.isArray(type)) return type.includes("null") ? type : [...type, "null"];
57
+ return type;
58
+ }
59
+ /**
60
+ * Recursively returns a leniency-relaxed copy of a JSON schema for use as a
61
+ * Mastra `outputSchema`. The input is never mutated.
62
+ */
63
+ function relaxOutputSchema(schema) {
64
+ if (!isPlainObject(schema)) return schema;
65
+ const result = { ...schema };
66
+ const originalType = result.type;
67
+ const isObjectSchema = originalType === "object" || Array.isArray(originalType) && originalType.includes("object") || "properties" in result || "patternProperties" in result;
68
+ if ("type" in result) result.type = addNullToType(result.type);
69
+ if ("const" in result) {
70
+ result.enum = [result.const, null];
71
+ delete result.const;
72
+ } else if (Array.isArray(result.enum) && !result.enum.includes(null)) result.enum = [...result.enum, null];
73
+ if ("required" in result) delete result.required;
74
+ if (isPlainObject(result.additionalProperties)) result.additionalProperties = relaxOutputSchema(result.additionalProperties);
75
+ else if (isObjectSchema && (result.additionalProperties === false || result.additionalProperties === void 0)) result.additionalProperties = true;
76
+ for (const key of SUBSCHEMA_KEYS) if (key in result) result[key] = relaxOutputSchema(result[key]);
77
+ for (const key of SUBSCHEMA_LIST_KEYS) {
78
+ const value = result[key];
79
+ if (Array.isArray(value)) result[key] = value.map((entry) => relaxOutputSchema(entry));
80
+ }
81
+ for (const key of SUBSCHEMA_MAP_KEYS) {
82
+ const value = result[key];
83
+ if (isPlainObject(value)) result[key] = Object.fromEntries(Object.entries(value).map(([name, sub]) => [name, relaxOutputSchema(sub)]));
84
+ }
85
+ return result;
86
+ }
87
+
88
+ //#endregion
5
89
  //#region src/index.ts
6
90
  /**
7
91
  * Mastra Provider
@@ -14,6 +98,7 @@ import { createTool } from "@mastra/core/tools";
14
98
  var MastraProvider = class extends BaseAgenticProvider {
15
99
  name = "mastra";
16
100
  strict;
101
+ warnedDanglingRefs = /* @__PURE__ */ new Set();
17
102
  /**
18
103
  * Creates a new instance of the MastraProvider.
19
104
  *
@@ -55,13 +140,21 @@ var MastraProvider = class extends BaseAgenticProvider {
55
140
  }
56
141
  wrapTool(tool, executeTool) {
57
142
  const inputParams = tool.inputParameters;
143
+ const parameters = this.strict && inputParams?.type === "object" ? removeNonRequiredProperties(inputParams) : inputParams;
144
+ const onReplace = (ref, reason) => this.warnDanglingRefOnce(tool, ref, reason);
58
145
  const inputSchema = applyCompatLayer({
59
- schema: dereferenceJsonSchema((this.strict && inputParams?.type === "object" ? removeNonRequiredProperties(inputParams) : inputParams) ?? {}),
146
+ schema: dereferenceJsonSchema(parameters ?? {}, {
147
+ onUnresolved: "sentinel",
148
+ onReplace
149
+ }),
60
150
  compatLayers: [],
61
151
  mode: "jsonSchema"
62
152
  });
63
153
  const outputSchema = applyCompatLayer({
64
- schema: dereferenceJsonSchema(tool.outputParameters ?? {}),
154
+ schema: relaxOutputSchema(dereferenceJsonSchema(tool.outputParameters ?? {}, {
155
+ onUnresolved: "sentinel",
156
+ onReplace
157
+ })),
65
158
  compatLayers: [],
66
159
  mode: "jsonSchema"
67
160
  });
@@ -71,7 +164,7 @@ var MastraProvider = class extends BaseAgenticProvider {
71
164
  inputSchema,
72
165
  outputSchema,
73
166
  execute: async (inputData, _context) => {
74
- return await executeTool(tool.slug, inputData);
167
+ return await executeTool(tool.slug, normalizeToolArguments(inputData, tool.slug));
75
168
  }
76
169
  });
77
170
  }
@@ -81,6 +174,24 @@ var MastraProvider = class extends BaseAgenticProvider {
81
174
  return acc;
82
175
  }, {});
83
176
  }
177
+ warnDanglingRefOnce(tool, ref, reason) {
178
+ const key = `${tool.slug}::${ref}`;
179
+ if (this.warnedDanglingRefs.has(key)) return;
180
+ this.warnedDanglingRefs.add(key);
181
+ const toolkitSlug = tool.toolkit?.slug ?? "unknown";
182
+ logger.warn(`[composio/mastra] Tool ${JSON.stringify(tool.slug)} (toolkit ${JSON.stringify(toolkitSlug)}) declares $ref ${JSON.stringify(ref)} but no matching $defs/definitions entry (${reason}). Falling back to a permissive object schema for this branch — the wrapped Mastra tool will validate this property loosely. Tracked in https://github.com/ComposioHQ/composio/issues/3307.`);
183
+ telemetry.sendMetric([{
184
+ functionName: "composio.mastra.wrapTool.danglingRef",
185
+ timestamp: Date.now() / 1e3,
186
+ props: {
187
+ toolSlug: tool.slug,
188
+ toolkitSlug,
189
+ ref,
190
+ reason
191
+ },
192
+ metadata: { provider: "mastra" }
193
+ }]);
194
+ }
84
195
  };
85
196
 
86
197
  //#endregion
package/package.json CHANGED
@@ -1,25 +1,25 @@
1
1
  {
2
2
  "name": "@composio/mastra",
3
- "version": "0.9.2",
3
+ "version": "0.10.0",
4
4
  "description": "Agentic Provider for mastra in Composio SDK",
5
5
  "main": "dist/index.mjs",
6
+ "type": "module",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/ComposioHQ/composio.git",
10
+ "directory": "ts/packages/providers/mastra"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/ComposioHQ/composio/issues"
14
+ },
15
+ "homepage": "https://github.com/ComposioHQ/composio/tree/main/ts/packages/providers/mastra#readme",
6
16
  "publishConfig": {
7
17
  "access": "public"
8
18
  },
9
19
  "exports": {
10
20
  ".": {
11
- "import": {
12
- "types": "./dist/index.d.mts",
13
- "default": "./dist/index.mjs"
14
- },
15
- "require": {
16
- "types": "./dist/index.d.cts",
17
- "default": "./dist/index.cjs"
18
- },
19
- "default": {
20
- "types": "./dist/index.d.cts",
21
- "default": "./dist/index.cjs"
22
- }
21
+ "types": "./dist/index.d.mts",
22
+ "default": "./dist/index.mjs"
23
23
  }
24
24
  },
25
25
  "files": [
@@ -39,19 +39,19 @@
39
39
  "zod": "^3.25 || ^4"
40
40
  },
41
41
  "devDependencies": {
42
- "@mastra/core": "^1.0.4",
43
- "tsdown": "^0.18.4",
44
- "typescript": "^5.9.2",
45
- "vitest": "^3.1.4",
46
- "zod": "^4.1.0",
47
- "@composio/core": "0.10.0"
42
+ "@mastra/core": "^1.42.0",
43
+ "tsdown": "^0.22.3",
44
+ "typescript": "^6.0.3",
45
+ "vitest": "^4.1.9",
46
+ "zod": "^4.4.3",
47
+ "@composio/core": "0.12.0"
48
48
  },
49
49
  "dependencies": {
50
50
  "@mastra/schema-compat": "^1.2.9"
51
51
  },
52
52
  "scripts": {
53
53
  "clean": "git clean -xdf node_modules",
54
- "build": "pnpm exec tsdown",
54
+ "build": "tsdown",
55
55
  "test": "vitest run",
56
56
  "typecheck": "pnpm exec tsgo --noEmit --skipLibCheck",
57
57
  "typecheck:tsc": "tsc --noEmit --skipLibCheck"
package/dist/index.cjs DELETED
@@ -1,87 +0,0 @@
1
- let _composio_core = require("@composio/core");
2
- let _mastra_schema_compat = require("@mastra/schema-compat");
3
- let _mastra_core_tools = require("@mastra/core/tools");
4
-
5
- //#region src/index.ts
6
- /**
7
- * Mastra Provider
8
- *
9
- * This provider provides a set of tools for interacting with Mastra.ai
10
- *
11
- * @packageDocumentation
12
- * @module providers/mastra
13
- */
14
- var MastraProvider = class extends _composio_core.BaseAgenticProvider {
15
- name = "mastra";
16
- strict;
17
- /**
18
- * Creates a new instance of the MastraProvider.
19
- *
20
- * This provider enables integration with the Mastra AI SDK,
21
- * allowing Composio tools to be used with Mastra AI applications.
22
- *
23
- * @param param0
24
- * @param param0.strict - Whether to use strict mode for tool execution
25
- * @returns A new instance of the MastraProvider
26
- *
27
- * @example
28
- * ```typescript
29
- * import { Composio } from '@composio/core';
30
- * import { MastraProvider } from '@composio/mastra';
31
- *
32
- * const composio = new Composio({
33
- * apiKey: 'your-composio-api-key',
34
- * provider: new MastraProvider(),
35
- * });
36
- * ```
37
- */
38
- constructor({ strict = false } = {}) {
39
- super();
40
- this.strict = strict;
41
- }
42
- /**
43
- * Transform MCP URL response into Anthropic-specific format.
44
- * By default, Anthropic uses the standard format (same as default),
45
- * but this method is here to show providers can customize if needed.
46
- *
47
- * @param data - The MCP URL response data
48
- * @returns Standard MCP server response format
49
- */
50
- wrapMcpServerResponse(data) {
51
- return data.reduce((acc, item) => {
52
- acc[item.name] = { url: item.url };
53
- return acc;
54
- }, {});
55
- }
56
- wrapTool(tool, executeTool) {
57
- const inputParams = tool.inputParameters;
58
- const inputSchema = (0, _mastra_schema_compat.applyCompatLayer)({
59
- schema: (0, _composio_core.dereferenceJsonSchema)((this.strict && inputParams?.type === "object" ? (0, _composio_core.removeNonRequiredProperties)(inputParams) : inputParams) ?? {}),
60
- compatLayers: [],
61
- mode: "jsonSchema"
62
- });
63
- const outputSchema = (0, _mastra_schema_compat.applyCompatLayer)({
64
- schema: (0, _composio_core.dereferenceJsonSchema)(tool.outputParameters ?? {}),
65
- compatLayers: [],
66
- mode: "jsonSchema"
67
- });
68
- return (0, _mastra_core_tools.createTool)({
69
- id: tool.slug,
70
- description: tool.description ?? "",
71
- inputSchema,
72
- outputSchema,
73
- execute: async (inputData, _context) => {
74
- return await executeTool(tool.slug, inputData);
75
- }
76
- });
77
- }
78
- wrapTools(tools, executeTool) {
79
- return tools.reduce((acc, tool) => {
80
- acc[tool.slug] = this.wrapTool(tool, executeTool);
81
- return acc;
82
- }, {});
83
- }
84
- };
85
-
86
- //#endregion
87
- exports.MastraProvider = MastraProvider;
package/dist/index.d.cts DELETED
@@ -1,57 +0,0 @@
1
- import { BaseAgenticProvider, ExecuteToolFn, McpUrlResponse, Tool } from "@composio/core";
2
- import { createTool } from "@mastra/core/tools";
3
-
4
- //#region src/index.d.ts
5
-
6
- type MastraTool = ReturnType<typeof createTool>;
7
- interface MastraToolCollection {
8
- [key: string]: MastraTool;
9
- }
10
- interface MastraUrlMap {
11
- [name: string]: {
12
- url: string;
13
- };
14
- }
15
- declare class MastraProvider extends BaseAgenticProvider<MastraToolCollection, MastraTool, MastraUrlMap> {
16
- readonly name = "mastra";
17
- private strict;
18
- /**
19
- * Creates a new instance of the MastraProvider.
20
- *
21
- * This provider enables integration with the Mastra AI SDK,
22
- * allowing Composio tools to be used with Mastra AI applications.
23
- *
24
- * @param param0
25
- * @param param0.strict - Whether to use strict mode for tool execution
26
- * @returns A new instance of the MastraProvider
27
- *
28
- * @example
29
- * ```typescript
30
- * import { Composio } from '@composio/core';
31
- * import { MastraProvider } from '@composio/mastra';
32
- *
33
- * const composio = new Composio({
34
- * apiKey: 'your-composio-api-key',
35
- * provider: new MastraProvider(),
36
- * });
37
- * ```
38
- */
39
- constructor({
40
- strict
41
- }?: {
42
- strict?: boolean;
43
- });
44
- /**
45
- * Transform MCP URL response into Anthropic-specific format.
46
- * By default, Anthropic uses the standard format (same as default),
47
- * but this method is here to show providers can customize if needed.
48
- *
49
- * @param data - The MCP URL response data
50
- * @returns Standard MCP server response format
51
- */
52
- wrapMcpServerResponse(data: McpUrlResponse): MastraUrlMap;
53
- wrapTool(tool: Tool, executeTool: ExecuteToolFn): MastraTool;
54
- wrapTools(tools: Tool[], executeTool: ExecuteToolFn): MastraToolCollection;
55
- }
56
- //#endregion
57
- export { MastraProvider, MastraTool, MastraToolCollection, MastraUrlMap };