/**
 * Forge Management MCP — server factory.
 *
 * Transport-agnostic: this builds the McpServer and registers tools. It knows
 * nothing about stdio vs HTTP. The Next.js route (`app/api/mcp`) hosts it over
 * Streamable HTTP today; a hosted entrypoint can wrap the same server later.
 *
 * All tools run IN-PROCESS inside the Forge server and call `lib/` directly.
 * The client never touches the database — see mcp/README.md (the contract).
 */

import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { registerTools } from './tools/index';

/** Per-connection context, resolved server-side from the authenticated request. */
export interface ManagementContext {
  /** Reserved for future per-key audit logging — not yet wired into tools. */
  actor?: string;
}

export function createManagementMcpServer(ctx: ManagementContext = {}): McpServer {
  const server = new McpServer({
    name: 'forge-management',
    version: '0.1.0',
  });

  registerTools(server, ctx);

  return server;
}
