Skip to content

Improve workspace fetch with member param#182

Open
shaneer wants to merge 18 commits intomasterfrom
shanee/feature/workspace/workspace-member-improvement
Open

Improve workspace fetch with member param#182
shaneer wants to merge 18 commits intomasterfrom
shanee/feature/workspace/workspace-member-improvement

Conversation

@shaneer
Copy link
Collaborator

@shaneer shaneer commented Dec 30, 2025

https://monday.monday.com/boards/8222767873/views/175916623/pulses/10906328723

TLDR;
Using the new membershipKind enum to fetch first only the workspaces that I am a member of and then falling back to all if not found

  • Main change: workspace fetch now tries first membershipKind='member', recently added by layout team, and falls back to fetching all workspaces if none found - this greatly reduces the number of workspaces returned and the hypothesis is that this is a significant optimization for the tool

Additional Small Changes

  • list-workspace-tool implementation adjusted, added validation to avoid returning undefined, and small renames/unification and formatting clean-ups.
  • updated monday-graphql schema

…improvement

# Conflicts:
#	packages/agent-toolkit/src/core/tools/platform-api-tools/list-workspace-tool/list-workspace-tool.test.ts
#	packages/agent-toolkit/src/core/tools/platform-api-tools/list-workspace-tool/list-workspace-tool.ts
#	packages/agent-toolkit/src/monday-graphql/schema.graphql
@shaneer shaneer requested review from RomKadria and damian-rakus and removed request for RomKadria January 5, 2026 12:31
let workspaces = filterNullWorkspaces(res);
let usedMemberOnly = true;

// If searching with a term and no matches found in member workspaces, try with all workspaces
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hey Shanee, can we include the comment that we don't allow "LLM filtering" at this point as it could cause the MCP to never search for all workspaces?
Cause initially I was surprised why we don't return those workspaces if the length is smaller than DEFAULT_WORKSPACE_LIMIT and comment here would be helpful for other devs

.default(DEFAULT_WORKSPACE_LIMIT)
.describe(`The number of workspaces to return. Default and maximum allowed is ${DEFAULT_WORKSPACE_LIMIT}`),
page: z.number().min(1).default(1).describe('The page number to return. Default is 1.'),
.describe(`Number of workspaces to return. Default and max allowed is ${DEFAULT_WORKSPACE_LIMIT}`),
Copy link
Collaborator

Choose a reason for hiding this comment

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

in general, why would we want the max to be the default, gives no insentive to use something else xD

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For accounts that don't have a large amount of workspaces we want to return 'as much as possible' to hopefully catch all of them, hence setting the default to max here however we do want to allow peple to lower it since the whole reasoning behind Damian's original limit here was to limit the # of workspaces returned to the context so it doesn't crash - not suree this will ever be used tho since it's not specified so I'll add a explanation

});

// First, try to get workspaces where the user is a member (more relevant results)
let res = await this.mondayApi.request<ListWorkspacesQueryResponse>(
Copy link
Collaborator

Choose a reason for hiding this comment

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

its funny to me we are trying t create search logic here 😂
I wonder how good does it work, we dont have metric on the misses which is unfortunate here
if we have a lot of misses we just make doulbe api queries...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Once the MCP is internal we can add logs for things like this :)
For now I guess our only option would be thru BB events
We can examine in BB or in your tracing tool how many times one user calls this tools multiple times right after the other

Copy link
Collaborator

Choose a reason for hiding this comment

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

its not about one tool one after the other, as this is two gql calls in the same tool call. we can trace it today I think anyway and check it but yeah looks...

…improvement

# Conflicts:
#	packages/agent-toolkit/src/core/tools/platform-api-tools/get-board-items-page-tool/get-board-items-page-tool.ts
#	packages/agent-toolkit/src/monday-graphql/generated/graphql.dev/graphql.ts
#	packages/agent-toolkit/src/monday-graphql/generated/graphql/graphql.ts
#	packages/agent-toolkit/src/monday-graphql/schema.dev.graphql
#	packages/agent-toolkit/src/monday-graphql/schema.graphql
@shaneer shaneer requested a review from damian-rakus February 3, 2026 10:29
@shaneer shaneer requested a review from RomKadria February 3, 2026 10:29
Copy link
Collaborator

@damian-rakus damian-rakus left a comment

Choose a reason for hiding this comment

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

Looks great, just need to update version in package.json I believe as some time has passed

.default(DEFAULT_WORKSPACE_LIMIT)
.describe(`The number of workspaces to return. Default and maximum allowed is ${DEFAULT_WORKSPACE_LIMIT}`),
page: z.number().min(1).default(1).describe('The page number to return. Default is 1.'),
.describe(`Number of workspaces to return. Set to max (${DEFAULT_WORKSPACE_LIMIT}) lower for smaller response size`),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I dont understand this sentence xD

@@ -0,0 +1,3 @@
export function hasElements<T>(arr: readonly T[] | null | undefined): arr is readonly T[] & { length: number } {
Copy link
Collaborator

Choose a reason for hiding this comment

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

if you dont mind xD I think better name would have the array word in it just so itl be more redable in the code itself as we dont know by looking straight its from array utils

so something like arrayHasElements or arrayNotEmpty


const shouldIncludeNoFilteringDisclaimer = searchTermNormalized && workspaces.length <= DEFAULT_WORKSPACE_LIMIT;
const filteredWorkspaces = this.filterWorkspacesIfNeeded(searchTermNormalized, workspaces, input);
// If the number of workspaces is small we prefer not filter and return all workspaces to LLM to filter
Copy link
Collaborator

Choose a reason for hiding this comment

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

I understand its the same logic so just as fyi, I dont understand why would we want to pollute context in this scneario with more data, but I think this is the kind of query that will be removed if we ahve proper search

Actually I wonder, dont we get this from search? can we remove this tool???

Copy link
Collaborator

Choose a reason for hiding this comment

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

" // WORKSPACES = 'WORKSPACES', // already supported by list_workspaces tool"
I. wonder why cant we add this there instead?

Copy link
Collaborator

Choose a reason for hiding this comment

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

and remove this tool

import { DEFAULT_WORKSPACE_LIMIT } from './list-workspace.consts';
import { ListWorkspacesQuery } from '../../../../monday-graphql/generated/graphql/graphql';

type Workspace = NonNullable<NonNullable<ListWorkspacesQuery['workspaces']>[number]>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

beautiful

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.

3 participants