001/*
002 * SPDX-License-Identifier: Apache-2.0
003 *
004 * Copyright 2025-2026 The Enola <https://enola.dev> Authors
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 *     https://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package dev.enola.ai.mcp.cli;
019
020import dev.enola.cli.common.Application;
021import dev.enola.cli.common.CLI;
022import dev.enola.cli.common.LoggingMixin;
023import dev.enola.cli.common.VersionProvider;
024import dev.enola.common.io.mediatype.MarkdownMediaTypes;
025import dev.enola.common.io.mediatype.MediaTypeProviders;
026import dev.enola.common.io.mediatype.StandardMediaTypes;
027import dev.enola.common.io.mediatype.YamlMediaType;
028
029import picocli.AutoComplete;
030import picocli.CommandLine;
031import picocli.CommandLine.Command;
032
033@Command(
034        name = "mcp",
035        mixinStandardHelpOptions = true,
036        showDefaultValues = true,
037        synopsisSubcommandLabel = "COMMAND",
038        description = VersionProvider.DESCRIPTION,
039        versionProvider = VersionProvider.class,
040        subcommands = {
041            // Generic to all CLIs
042            CommandLine.HelpCommand.class,
043            AutoComplete.GenerateCompletion.class,
044
045            // Specific to this CLI
046            ListToolsCommand.class,
047            CallToolCommand.class
048        })
049public class McpApplication extends Application {
050
051    @CommandLine.Mixin LoggingMixin loggingMixin;
052
053    public static void main(String[] args) {
054        System.exit(cli(args).execute());
055    }
056
057    static CLI cli(String... args) {
058        return new CLI(args, new McpApplication());
059    }
060
061    @Override
062    protected void start() {
063        MediaTypeProviders.SINGLETON.set(MTP);
064    }
065
066    private static final MediaTypeProviders MTP =
067            new MediaTypeProviders(
068                    // NB: The order in which we list the MediaTypeProvider here matters!
069                    new MarkdownMediaTypes(), new StandardMediaTypes(), new YamlMediaType());
070}