Skip to content

Conversation

@MQ37
Copy link
Contributor

@MQ37 MQ37 commented Mar 16, 2025

mastra.ai agent failed to run WCC because of the nested properties, the object input properties: had to infer their schema based on the editor provided; This helps the agent to call the WCC with the correct options.

@MQ37 MQ37 self-assigned this Mar 16, 2025
@MQ37 MQ37 marked this pull request as draft March 16, 2025 21:29
@MQ37 MQ37 changed the title fix: tool schema array fix: tool schema array type inference and nested props Mar 17, 2025
@MQ37 MQ37 changed the title fix: tool schema array type inference and nested props fix: tool schema array type infer and nested props Mar 17, 2025
@MQ37 MQ37 marked this pull request as ready for review March 17, 2025 12:01
@MQ37
Copy link
Contributor Author

MQ37 commented Mar 17, 2025

closes #44

@MQ37 MQ37 requested a review from jirispilka March 17, 2025 12:02
Copy link
Collaborator

@jirispilka jirispilka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be a bit complicated .... can you please provide more documentation, why we need it? Maybe including examples?

The doc will become handy for developing standalone MCP Serve (at the level of Apify Api)

Comment on lines 153 to 181
export function filterSchemaProperties(properties: { [key: string]: ISchemaProperties }): { [key: string]: ISchemaProperties } {
const filteredProperties: { [key: string]: ISchemaProperties } = {};
for (const [key, property] of Object.entries(properties)) {
const { title, description, enum: enumValues, type, default: defaultValue, prefill } = property;
filteredProperties[key] = { title, description, enum: enumValues, type, default: defaultValue, prefill };
if (type === 'array') {
const { title, description, enum: enumValues, type,
default: defaultValue, prefill, properties: subProperties,
items, required } = property;
filteredProperties[key] = { title,
description,
enum: enumValues,
type,
default: defaultValue,
prefill,
properties: subProperties,
items,
required };
if (type === 'array' && !items?.type) {
const itemsType = inferArrayItemType(property);
if (itemsType) {
filteredProperties[key].items = { type: itemsType };
filteredProperties[key].items = {
...filteredProperties[key].items,
title: filteredProperties[key].title ?? 'Item',
description: filteredProperties[key].description ?? 'Item',
type: itemsType,
};
}
}
}
return filteredProperties;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be nicer like this?

I haven't tested it, only draft.

export function filterSchemaProperties(properties: { [key: string]: ISchemaProperties }): { [key: string]: ISchemaProperties } {
    const filteredProperties: { [key: string]: ISchemaProperties } = {};
    for (const [key, property] of Object.entries(properties)) {
        filteredProperties[key] = {
            title: property.title,
            description: property.description,
            enum: property.enum,
            type: property.type,
            default: property.default,
            prefill: property.prefill,
            properties: property.properties,
            items: property.items,
            required: property.required,
        };
        if (property.type === 'array' && !property.items?.type) {
            const itemsType = inferArrayItemType(property);
            if (itemsType) {
                filteredProperties[key].items = {
                    ...filteredProperties[key].items,
                    title: filteredProperties[key].title ?? 'Item',
                    description: filteredProperties[key].description ?? 'Item',
                    type: itemsType,
                };
            }
        }
    }
    return filteredProperties;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jirispilka yes, I haven't refactored the original code, but I think once we have a fully functional version a refactor would be great 👍

@MQ37 MQ37 requested a review from jirispilka March 17, 2025 14:48
Copy link
Collaborator

@jirispilka jirispilka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me. I hope you've tested it with a set of different Actors

@MQ37
Copy link
Contributor Author

MQ37 commented Mar 18, 2025

It looks good to me. I hope you've tested it with a set of different Actors

Tested with set of different Actors and seems to be working, the only issue currently with mastra.ai agent is the timeout: when tool call takes longer than 60 s it times out. Will check with the mastra.ai guys.

@MQ37 MQ37 merged commit 25fd5ad into master Mar 18, 2025
2 checks passed
@jirispilka jirispilka deleted the fix/tool-schema-array branch March 27, 2025 20:22
@MQ37 MQ37 mentioned this pull request Apr 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants