* Handle a tool call by name and return the result.
(name: string, args: Record<string, unknown> | undefined, authContext?: MCPAuthContext)
| 609 | * Handle a tool call by name and return the result. |
| 610 | */ |
| 611 | async handleToolCall(name: string, args: Record<string, unknown> | undefined, authContext?: MCPAuthContext): Promise<{ |
| 612 | content: Array<{ type: string; text?: string; resource?: { uri: string; mimeType: string; text: string } }>; |
| 613 | isError?: boolean; |
| 614 | }> { |
| 615 | switch (name) { |
| 616 | // Member tools |
| 617 | case "list_members": { |
| 618 | const offerings = args?.offerings as MemberOffering[] | undefined; |
| 619 | const markets = args?.markets as string[] | undefined; |
| 620 | const search = args?.search as string | undefined; |
| 621 | const limit = args?.limit as number | undefined; |
| 622 | const viewerHasApiAccess = await this.callerHasApiAccess(authContext); |
| 623 | |
| 624 | // API-access viewers can see orgs that opted out of the public |
| 625 | // directory as long as those orgs have at least one members_only |
| 626 | // agent — the entire point of the tier. |
| 627 | const members = viewerHasApiAccess |
| 628 | ? await this.memberDb.listProfiles({ offerings, markets, search, limit }) |
| 629 | : await this.memberDb.getPublicProfiles({ offerings, markets, search, limit }); |
| 630 | |
| 631 | const visible = viewerHasApiAccess |
| 632 | ? members.filter((m) => |
| 633 | m.is_public || |
| 634 | (m.agents || []).some((a) => a.visibility === 'public' || a.visibility === 'members_only') |
| 635 | ) |
| 636 | : members; |
| 637 | |
| 638 | const simplified = visible.map((m) => ({ |
| 639 | slug: m.slug, |
| 640 | display_name: m.display_name, |
| 641 | tagline: m.tagline, |
| 642 | logo_url: m.resolved_brand?.logo_url, |
| 643 | offerings: m.offerings, |
| 644 | headquarters: m.headquarters, |
| 645 | markets: m.markets, |
| 646 | profile_visibility: m.is_public ? 'public' : 'members_only', |
| 647 | agents: m.agents |
| 648 | .filter((a) => a.visibility === 'public' || (viewerHasApiAccess && a.visibility === 'members_only')) |
| 649 | .map((a) => ({ |
| 650 | url: a.url, |
| 651 | type: a.type, |
| 652 | name: a.name, |
| 653 | // Only surface `visibility` when the caller can actually see |
| 654 | // more than one state — otherwise it is always 'public'. |
| 655 | ...(viewerHasApiAccess ? { visibility: a.visibility } : {}), |
| 656 | })), |
| 657 | contact_website: m.contact_website, |
| 658 | })); |
| 659 | |
| 660 | return { |
| 661 | content: [ |
| 662 | { |
| 663 | type: "resource", |
| 664 | resource: { |
| 665 | uri: "members://directory", |
| 666 | mimeType: "application/json", |
| 667 | text: JSON.stringify({ members: simplified, count: simplified.length }, null, 2), |
| 668 | }, |
no test coverage detected