Files
mcpctl/src/mcpd/src/services/mcp-config-generator.ts
Michal c5147e8270 feat: granular RBAC with resource/operation bindings, users, groups
- Replace admin role with granular roles: view, create, delete, edit, run
- Two binding types: resource bindings (role+resource+optional name) and
  operation bindings (role:run + action like backup, logs, impersonate)
- Name-scoped resource bindings for per-instance access control
- Remove role from project members (all permissions via RBAC)
- Add users, groups, RBAC CRUD endpoints and CLI commands
- describe user/group shows all RBAC access (direct + inherited)
- create rbac supports --subject, --binding, --operation flags
- Backup/restore handles users, groups, RBAC definitions
- mcplocal project-based MCP endpoint discovery
- Full test coverage for all new functionality

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 11:05:19 +00:00

46 lines
1.2 KiB
TypeScript

import type { McpServer } from '@prisma/client';
export interface McpConfigServer {
command?: string;
args?: string[];
url?: string;
headers?: Record<string, string>;
env?: Record<string, string>;
}
export interface McpConfig {
mcpServers: Record<string, McpConfigServer>;
}
/**
* Generate .mcp.json config from servers with their resolved env vars.
*/
export function generateMcpConfig(
servers: Array<{ server: McpServer; resolvedEnv: Record<string, string> }>,
): McpConfig {
const mcpServers: Record<string, McpConfigServer> = {};
for (const { server, resolvedEnv } of servers) {
if (server.transport === 'SSE' || server.transport === 'STREAMABLE_HTTP') {
// Point at mcpd proxy URL for non-STDIO transports
mcpServers[server.name] = {
url: `http://localhost:3100/api/v1/mcp/proxy/${server.name}`,
};
} else {
// STDIO — npx command approach
const config: McpConfigServer = {
command: 'npx',
args: ['-y', server.packageName ?? server.name],
};
if (Object.keys(resolvedEnv).length > 0) {
config.env = resolvedEnv;
}
mcpServers[server.name] = config;
}
}
return { mcpServers };
}