n8n/packages/cli/src/modules/agents/agent-mcp-access.controller.ts
Anne Aguirre 3b3ac393ba
feat(editor): Add a write lock to the agent builder (#38758)
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-24 09:22:54 +00:00

39 lines
1.3 KiB
TypeScript

import { ListAgentsQueryDto, UpdateAgentsMcpAvailabilityDto } from '@n8n/api-types';
import type { AuthenticatedRequest } from '@n8n/db';
import { Body, Get, Patch, Query, RestController } from '@n8n/decorators';
import type { Response } from 'express';
import { AgentMcpAccessService } from './agent-mcp-access.service';
/**
* Per-agent MCP availability endpoints, mirroring the per-workflow ones on
* `McpSettingsController` (`/mcp/workflows`). They live in the agents module
* so they only exist when the module is active.
*
* No `@ProjectScope` decorators: these routes carry no project in their URL,
* so `AgentMcpAccessService` enforces the `agent:update` scope per project
* instead — same reasoning as the workflow toggle endpoint.
*/
@RestController('/mcp/agents')
export class AgentMcpAccessController {
constructor(private readonly agentMcpAccessService: AgentMcpAccessService) {}
@Get('/')
async getMcpAgents(req: AuthenticatedRequest, res: Response, @Query query: ListAgentsQueryDto) {
res.json(await this.agentMcpAccessService.getAgents(req.user, query));
}
@Patch('/toggle-access')
async toggleAgentsMCPAccess(
req: AuthenticatedRequest,
_res: Response,
@Body dto: UpdateAgentsMcpAvailabilityDto,
) {
return await this.agentMcpAccessService.bulkSetAvailableInMCP(
req.user,
dto,
req.headers?.['push-ref'],
);
}
}