@mastra/mcp 1.9.2-alpha.0 → 1.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.js CHANGED
@@ -2772,6 +2772,7 @@ var MCPServer = class extends MCPServerBase {
2772
2772
  promptOptions;
2773
2773
  jsonSchemaValidator;
2774
2774
  mapAuthInfoToUser;
2775
+ fga;
2775
2776
  subscriptions = /* @__PURE__ */ new Set();
2776
2777
  currentLoggingLevel;
2777
2778
  /**
@@ -2912,6 +2913,7 @@ var MCPServer = class extends MCPServerBase {
2912
2913
  this.promptOptions = opts.prompts;
2913
2914
  this.jsonSchemaValidator = opts.jsonSchemaValidator;
2914
2915
  this.mapAuthInfoToUser = opts.mapAuthInfoToUser;
2916
+ this.fga = opts.fga;
2915
2917
  const capabilities = {
2916
2918
  tools: {},
2917
2919
  logging: { enabled: true }
@@ -4559,11 +4561,17 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
4559
4561
  if (!user) {
4560
4562
  throw new FGADeniedError({ id: "unknown" }, { type: "tool", id: resourceId }, MastraFGAPermissions.TOOLS_EXECUTE);
4561
4563
  }
4564
+ const { resource, permission } = this.resolveToolFGAParams({
4565
+ user,
4566
+ resourceId,
4567
+ requestContext,
4568
+ permission: MastraFGAPermissions.TOOLS_EXECUTE
4569
+ });
4562
4570
  await requireFGA({
4563
4571
  fgaProvider,
4564
4572
  user,
4565
- resource: { type: "tool", id: resourceId },
4566
- permission: MastraFGAPermissions.TOOLS_EXECUTE,
4573
+ resource,
4574
+ permission,
4567
4575
  requestContext,
4568
4576
  context: {
4569
4577
  resourceId
@@ -4575,6 +4583,28 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
4575
4583
  }
4576
4584
  });
4577
4585
  }
4586
+ resolveToolFGAParams({
4587
+ user,
4588
+ resourceId,
4589
+ requestContext,
4590
+ permission
4591
+ }) {
4592
+ const mappedPermission = this.fga?.permissionMapping?.[permission] ?? permission;
4593
+ const resourceMapping = this.fga?.resourceMapping?.tool ?? this.fga?.resourceMapping?.tools;
4594
+ if (!resourceMapping) {
4595
+ return {
4596
+ resource: { type: "tool", id: resourceId },
4597
+ permission: mappedPermission
4598
+ };
4599
+ }
4600
+ return {
4601
+ resource: {
4602
+ type: resourceMapping.fgaResourceType,
4603
+ id: resourceMapping.deriveId?.({ user, resourceId, requestContext }) ?? resourceId
4604
+ },
4605
+ permission: mappedPermission
4606
+ };
4607
+ }
4578
4608
  /**
4579
4609
  * Executes a specific tool provided by this MCP server.
4580
4610
  *