import { McpContext, Resolver, Tool } from '@nestjs-mcp/server'; import { z } from 'zod'; import { TaskStreamApi } from '../api/taskstream-api'; import { limit } from './params'; import { toolResult } from './tool-result'; const READ = { readOnlyHint: true, openWorldHint: false } as const; @Resolver() export class UsersResolver { constructor(private readonly api: TaskStreamApi) {} @Tool({ name: 'whoami', description: 'The user this MCP acts as (from the Pireon token the client sends).', annotations: READ, }) whoami(ctx: McpContext) { return toolResult(() => this.api.data(this.api.as(ctx).GET('/api/users/me')), ); } @Tool({ name: 'search_users', description: 'Find Pireon users by name or email (to assign tickets: use their id).', paramsSchema: z.object({ search: z.string().min(2), limit: limit(50, 10), }), annotations: READ, }) search( { search, limit }: { search: string; limit: number }, ctx: McpContext, ) { return toolResult(async () => ( await this.api.data( this.api .as(ctx) .GET('/api/users', { params: { query: { search, limit } } }), ) ).map((u) => ({ id: u.id, name: u.name, email: u.email })), ); } }