@composio/mastra 0.9.3 → 0.10.1

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;
@@ -43,12 +42,12 @@ declare class MastraProvider extends BaseAgenticProvider<MastraToolCollection, M
43
42
  strict?: boolean;
44
43
  });
45
44
  /**
46
- * Transform MCP URL response into Anthropic-specific format.
47
- * By default, Anthropic uses the standard format (same as default),
48
- * but this method is here to show providers can customize if needed.
45
+ * Transform an MCP URL response into the Mastra provider's format.
46
+ * Mastra expects a URL map keyed by server name, so each entry is
47
+ * reduced into an object of `{ [name]: { url } }`.
49
48
  *
50
49
  * @param data - The MCP URL response data
51
- * @returns Standard MCP server response format
50
+ * @returns The MCP servers as a Mastra URL map
52
51
  */
53
52
  wrapMcpServerResponse(data: McpUrlResponse): MastraUrlMap;
54
53
  wrapTool(tool: Tool, executeTool: ExecuteToolFn): MastraTool;
package/dist/index.mjs CHANGED
@@ -2,6 +2,90 @@ import { BaseAgenticProvider, dereferenceJsonSchema, logger, normalizeToolArgume
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
@@ -41,12 +125,12 @@ var MastraProvider = class extends BaseAgenticProvider {
41
125
  this.strict = strict;
42
126
  }
43
127
  /**
44
- * Transform MCP URL response into Anthropic-specific format.
45
- * By default, Anthropic uses the standard format (same as default),
46
- * but this method is here to show providers can customize if needed.
128
+ * Transform an MCP URL response into the Mastra provider's format.
129
+ * Mastra expects a URL map keyed by server name, so each entry is
130
+ * reduced into an object of `{ [name]: { url } }`.
47
131
  *
48
132
  * @param data - The MCP URL response data
49
- * @returns Standard MCP server response format
133
+ * @returns The MCP servers as a Mastra URL map
50
134
  */
51
135
  wrapMcpServerResponse(data) {
52
136
  return data.reduce((acc, item) => {
@@ -67,10 +151,10 @@ var MastraProvider = class extends BaseAgenticProvider {
67
151
  mode: "jsonSchema"
68
152
  });
69
153
  const outputSchema = applyCompatLayer({
70
- schema: dereferenceJsonSchema(tool.outputParameters ?? {}, {
154
+ schema: relaxOutputSchema(dereferenceJsonSchema(tool.outputParameters ?? {}, {
71
155
  onUnresolved: "sentinel",
72
156
  onReplace
73
- }),
157
+ })),
74
158
  compatLayers: [],
75
159
  mode: "jsonSchema"
76
160
  });
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@composio/mastra",
3
- "version": "0.9.3",
3
+ "version": "0.10.1",
4
4
  "description": "Agentic Provider for mastra in Composio SDK",
5
5
  "main": "dist/index.mjs",
6
+ "type": "module",
6
7
  "repository": {
7
8
  "type": "git",
8
9
  "url": "https://github.com/ComposioHQ/composio.git",
@@ -17,18 +18,8 @@
17
18
  },
18
19
  "exports": {
19
20
  ".": {
20
- "import": {
21
- "types": "./dist/index.d.mts",
22
- "default": "./dist/index.mjs"
23
- },
24
- "require": {
25
- "types": "./dist/index.d.cts",
26
- "default": "./dist/index.cjs"
27
- },
28
- "default": {
29
- "types": "./dist/index.d.cts",
30
- "default": "./dist/index.cjs"
31
- }
21
+ "types": "./dist/index.d.mts",
22
+ "default": "./dist/index.mjs"
32
23
  }
33
24
  },
34
25
  "files": [
@@ -44,23 +35,23 @@
44
35
  "license": "ISC",
45
36
  "peerDependencies": {
46
37
  "@composio/core": ">=0.10.0 <1.0.0",
47
- "@mastra/core": "^1.0.4",
38
+ "@mastra/core": "^1.46.0",
48
39
  "zod": "^3.25 || ^4"
49
40
  },
50
41
  "devDependencies": {
51
- "@mastra/core": "^1.0.4",
52
- "tsdown": "^0.18.4",
53
- "typescript": "^5.9.2",
54
- "vitest": "^4.1.0",
55
- "zod": "^4.1.0",
56
- "@composio/core": "0.11.0"
42
+ "@mastra/core": "^1.46.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.13.1"
57
48
  },
58
49
  "dependencies": {
59
50
  "@mastra/schema-compat": "^1.2.9"
60
51
  },
61
52
  "scripts": {
62
53
  "clean": "git clean -xdf node_modules",
63
- "build": "pnpm exec tsdown",
54
+ "build": "tsdown",
64
55
  "test": "vitest run",
65
56
  "typecheck": "pnpm exec tsgo --noEmit --skipLibCheck",
66
57
  "typecheck:tsc": "tsc --noEmit --skipLibCheck"
package/dist/index.cjs DELETED
@@ -1,114 +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
- warnedDanglingRefs = /* @__PURE__ */ new Set();
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({ strict = false } = {}) {
40
- super();
41
- this.strict = strict;
42
- }
43
- /**
44
- * Transform MCP URL response into Anthropic-specific format.
45
- * By default, Anthropic uses the standard format (same as default),
46
- * but this method is here to show providers can customize if needed.
47
- *
48
- * @param data - The MCP URL response data
49
- * @returns Standard MCP server response format
50
- */
51
- wrapMcpServerResponse(data) {
52
- return data.reduce((acc, item) => {
53
- acc[item.name] = { url: item.url };
54
- return acc;
55
- }, {});
56
- }
57
- wrapTool(tool, executeTool) {
58
- const inputParams = tool.inputParameters;
59
- const parameters = this.strict && inputParams?.type === "object" ? (0, _composio_core.removeNonRequiredProperties)(inputParams) : inputParams;
60
- const onReplace = (ref, reason) => this.warnDanglingRefOnce(tool, ref, reason);
61
- const inputSchema = (0, _mastra_schema_compat.applyCompatLayer)({
62
- schema: (0, _composio_core.dereferenceJsonSchema)(parameters ?? {}, {
63
- onUnresolved: "sentinel",
64
- onReplace
65
- }),
66
- compatLayers: [],
67
- mode: "jsonSchema"
68
- });
69
- const outputSchema = (0, _mastra_schema_compat.applyCompatLayer)({
70
- schema: (0, _composio_core.dereferenceJsonSchema)(tool.outputParameters ?? {}, {
71
- onUnresolved: "sentinel",
72
- onReplace
73
- }),
74
- compatLayers: [],
75
- mode: "jsonSchema"
76
- });
77
- return (0, _mastra_core_tools.createTool)({
78
- id: tool.slug,
79
- description: tool.description ?? "",
80
- inputSchema,
81
- outputSchema,
82
- execute: async (inputData, _context) => {
83
- return await executeTool(tool.slug, (0, _composio_core.normalizeToolArguments)(inputData, tool.slug));
84
- }
85
- });
86
- }
87
- wrapTools(tools, executeTool) {
88
- return tools.reduce((acc, tool) => {
89
- acc[tool.slug] = this.wrapTool(tool, executeTool);
90
- return acc;
91
- }, {});
92
- }
93
- warnDanglingRefOnce(tool, ref, reason) {
94
- const key = `${tool.slug}::${ref}`;
95
- if (this.warnedDanglingRefs.has(key)) return;
96
- this.warnedDanglingRefs.add(key);
97
- const toolkitSlug = tool.toolkit?.slug ?? "unknown";
98
- _composio_core.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.`);
99
- _composio_core.telemetry.sendMetric([{
100
- functionName: "composio.mastra.wrapTool.danglingRef",
101
- timestamp: Date.now() / 1e3,
102
- props: {
103
- toolSlug: tool.slug,
104
- toolkitSlug,
105
- ref,
106
- reason
107
- },
108
- metadata: { provider: "mastra" }
109
- }]);
110
- }
111
- };
112
-
113
- //#endregion
114
- exports.MastraProvider = MastraProvider;
package/dist/index.d.cts DELETED
@@ -1,59 +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
- private warnedDanglingRefs;
19
- /**
20
- * Creates a new instance of the MastraProvider.
21
- *
22
- * This provider enables integration with the Mastra AI SDK,
23
- * allowing Composio tools to be used with Mastra AI applications.
24
- *
25
- * @param param0
26
- * @param param0.strict - Whether to use strict mode for tool execution
27
- * @returns A new instance of the MastraProvider
28
- *
29
- * @example
30
- * ```typescript
31
- * import { Composio } from '@composio/core';
32
- * import { MastraProvider } from '@composio/mastra';
33
- *
34
- * const composio = new Composio({
35
- * apiKey: 'your-composio-api-key',
36
- * provider: new MastraProvider(),
37
- * });
38
- * ```
39
- */
40
- constructor({
41
- strict
42
- }?: {
43
- strict?: boolean;
44
- });
45
- /**
46
- * Transform MCP URL response into Anthropic-specific format.
47
- * By default, Anthropic uses the standard format (same as default),
48
- * but this method is here to show providers can customize if needed.
49
- *
50
- * @param data - The MCP URL response data
51
- * @returns Standard MCP server response format
52
- */
53
- wrapMcpServerResponse(data: McpUrlResponse): MastraUrlMap;
54
- wrapTool(tool: Tool, executeTool: ExecuteToolFn): MastraTool;
55
- wrapTools(tools: Tool[], executeTool: ExecuteToolFn): MastraToolCollection;
56
- private warnDanglingRefOnce;
57
- }
58
- //#endregion
59
- export { MastraProvider, MastraTool, MastraToolCollection, MastraUrlMap };