( server: McpServer, context: McpAuthContext, )
| 4 | import { withErrorHandling } from './shared'; |
| 5 | |
| 6 | export function registerProjectTools( |
| 7 | server: McpServer, |
| 8 | context: McpAuthContext, |
| 9 | ) { |
| 10 | server.tool( |
| 11 | 'list_projects', |
| 12 | context.clientType === 'root' |
| 13 | ? 'List all projects in your organization. Use the returned project IDs when calling other tools that require a projectId.' |
| 14 | : 'Returns the single project this client has access to.', |
| 15 | {}, |
| 16 | async () => |
| 17 | withErrorHandling(async () => { |
| 18 | if (context.clientType === 'root') { |
| 19 | const projects = await db.project.findMany({ |
| 20 | where: { organizationId: context.organizationId }, |
| 21 | orderBy: { eventsCount: 'desc' }, |
| 22 | select: { |
| 23 | id: true, |
| 24 | name: true, |
| 25 | organizationId: true, |
| 26 | eventsCount: true, |
| 27 | domain: true, |
| 28 | types: true, |
| 29 | }, |
| 30 | }); |
| 31 | return { clientType: 'root', projects }; |
| 32 | } |
| 33 | |
| 34 | const project = context.projectId |
| 35 | ? await db.project.findUnique({ |
| 36 | where: { id: context.projectId }, |
| 37 | select: { |
| 38 | id: true, |
| 39 | name: true, |
| 40 | organizationId: true, |
| 41 | eventsCount: true, |
| 42 | domain: true, |
| 43 | types: true, |
| 44 | }, |
| 45 | }) |
| 46 | : null; |
| 47 | |
| 48 | return { |
| 49 | clientType: 'read', |
| 50 | projects: project ? [project] : [], |
| 51 | }; |
| 52 | }), |
| 53 | ); |
| 54 | } |
no test coverage detected