package com.gzzm.lobster.tool.mcp;

import com.gzzm.lobster.common.LobsterException;
import com.gzzm.lobster.common.McpTransportType;

/**
 * MCP client factory.
 */
public class McpClientFactory {

    private final McpClient httpClient = new HttpApiCenterMcpClient();

    public McpClient create(McpServerConfig server) {
        if (server == null) throw new LobsterException("mcp.server", "MCP server config is required");
        String endpoint = server.getEndpoint();
        if (endpoint != null && endpoint.trim().regionMatches(true, 0, "direct://", 0, 9)) {
            throw new LobsterException("mcp.unsupported_transport",
                    "direct:// MCP endpoints are not supported; configure the API Center HTTP MCP endpoint");
        }
        if (server.getTransportType() == null || server.getTransportType() == McpTransportType.STREAMABLE_HTTP) {
            return httpClient;
        }
        throw new LobsterException("mcp.unsupported_transport",
                "MCP transport is not supported yet: " + server.getTransportType());
    }
}
