$npx -y skills add github/awesome-copilot --skill kotlin-mcp-server-generatorGenerate a complete Kotlin MCP server project with proper structure, dependencies, and implementation using the official io.modelcontextprotocol:kotlin-sdk library.
| 1 | # Kotlin MCP Server Project Generator |
| 2 | |
| 3 | Generate a complete, production-ready Model Context Protocol (MCP) server project in Kotlin. |
| 4 | |
| 5 | ## Project Requirements |
| 6 | |
| 7 | You will create a Kotlin MCP server with: |
| 8 | |
| 9 | 1. **Project Structure**: Gradle-based Kotlin project layout |
| 10 | 2. **Dependencies**: Official MCP SDK, Ktor, and kotlinx libraries |
| 11 | 3. **Server Setup**: Configured MCP server with transports |
| 12 | 4. **Tools**: At least 2-3 useful tools with typed inputs/outputs |
| 13 | 5. **Error Handling**: Proper exception handling and validation |
| 14 | 6. **Documentation**: README with setup and usage instructions |
| 15 | 7. **Testing**: Basic test structure with coroutines |
| 16 | |
| 17 | ## Template Structure |
| 18 | |
| 19 | ``` |
| 20 | myserver/ |
| 21 | ├── build.gradle.kts |
| 22 | ├── settings.gradle.kts |
| 23 | ├── gradle.properties |
| 24 | ├── src/ |
| 25 | │ ├── main/ |
| 26 | │ │ └── kotlin/ |
| 27 | │ │ └── com/example/myserver/ |
| 28 | │ │ ├── Main.kt |
| 29 | │ │ ├── Server.kt |
| 30 | │ │ ├── config/ |
| 31 | │ │ │ └── Config.kt |
| 32 | │ │ └── tools/ |
| 33 | │ │ ├── Tool1.kt |
| 34 | │ │ └── Tool2.kt |
| 35 | │ └── test/ |
| 36 | │ └── kotlin/ |
| 37 | │ └── com/example/myserver/ |
| 38 | │ └── ServerTest.kt |
| 39 | └── README.md |
| 40 | ``` |
| 41 | |
| 42 | ## build.gradle.kts Template |
| 43 | |
| 44 | ```kotlin |
| 45 | plugins { |
| 46 | kotlin("jvm") version "2.1.0" |
| 47 | kotlin("plugin.serialization") version "2.1.0" |
| 48 | application |
| 49 | } |
| 50 | |
| 51 | group = "com.example" |
| 52 | version = "1.0.0" |
| 53 | |
| 54 | repositories { |
| 55 | mavenCentral() |
| 56 | } |
| 57 | |
| 58 | dependencies { |
| 59 | implementation("io.modelcontextprotocol:kotlin-sdk:0.7.2") |
| 60 | |
| 61 | // Ktor for transports |
| 62 | implementation("io.ktor:ktor-server-netty:3.0.0") |
| 63 | implementation("io.ktor:ktor-client-cio:3.0.0") |
| 64 | |
| 65 | // Serialization |
| 66 | implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3") |
| 67 | |
| 68 | // Coroutines |
| 69 | implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0") |
| 70 | |
| 71 | // Logging |
| 72 | implementation("io.github.oshai:kotlin-logging-jvm:7.0.0") |
| 73 | implementation("ch.qos.logback:logback-classic:1.5.12") |
| 74 | |
| 75 | // Testing |
| 76 | testImplementation(kotlin("test")) |
| 77 | testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0") |
| 78 | } |
| 79 | |
| 80 | application { |
| 81 | mainClass.set("com.example.myserver.MainKt") |
| 82 | } |
| 83 | |
| 84 | tasks.test { |
| 85 | useJUnitPlatform() |
| 86 | } |
| 87 | |
| 88 | kotlin { |
| 89 | jvmToolchain(17) |
| 90 | } |
| 91 | ``` |
| 92 | |
| 93 | ## settings.gradle.kts Template |
| 94 | |
| 95 | ```kotlin |
| 96 | rootProject.name = "{{PROJECT_NAME}}" |
| 97 | ``` |
| 98 | |
| 99 | ## Main.kt Template |
| 100 | |
| 101 | ```kotlin |
| 102 | package com.example.myserver |
| 103 | |
| 104 | import io.modelcontextprotocol.kotlin.sdk.server.StdioServerTransport |
| 105 | import kotlinx.coroutines.runBlocking |
| 106 | import io.github.oshai.kotlinlogging.KotlinLogging |
| 107 | |
| 108 | private val logger = KotlinLogging.logger {} |
| 109 | |
| 110 | fun main() = runBlocking { |
| 111 | logger.info { "Starting MCP server..." } |
| 112 | |
| 113 | val config = loadConfig() |
| 114 | val server = createServer(config) |
| 115 | |
| 116 | // Use stdio transport |
| 117 | val transport = StdioServerTransport() |
| 118 | |
| 119 | logger.info { "Server '${config.name}' v${config.version} ready" } |
| 120 | server.connect(transport) |
| 121 | } |
| 122 | ``` |
| 123 | |
| 124 | ## Server.kt Template |
| 125 | |
| 126 | ```kotlin |
| 127 | package com.example.myserver |
| 128 | |
| 129 | import io.modelcontextprotocol.kotlin.sdk.server.Server |
| 130 | import io.modelcontextprotocol.kotlin.sdk.server.ServerOptions |
| 131 | import io.modelcontextprotocol.kotlin.sdk.Implementation |
| 132 | import io.modelcontextprotocol.kotlin.sdk.ServerCapabilities |
| 133 | import com.example.myserver.tools.registerTools |
| 134 | |
| 135 | fun createServer(config: Config): Server { |
| 136 | val server = Server( |
| 137 | serverInfo = Implementation( |
| 138 | name = config.name, |
| 139 | version = config.version |
| 140 | ), |
| 141 | options = ServerOptions( |
| 142 | capabilities = ServerCapabilities( |
| 143 | tools = ServerCapabilities.Tools(), |
| 144 | resources = ServerCapabilities.Resources( |
| 145 | subscribe = true, |
| 146 | listChanged = true |
| 147 | ), |
| 148 | prompts = ServerCapabilities.Prompts(listChanged = true) |
| 149 | ) |
| 150 | ) |
| 151 | ) { |
| 152 | config.description |
| 153 | } |
| 154 | |
| 155 | // Register all tools |
| 156 | server.registerTools() |
| 157 | |
| 158 | return server |
| 159 | } |
| 160 | ``` |
| 161 | |
| 162 | ## Config.kt Template |
| 163 | |
| 164 | ```kotlin |
| 165 | package com.example.myserver.config |
| 166 | |
| 167 | import kotlinx.serialization.Serializable |
| 168 | |
| 169 | @Serializable |
| 170 | data class Config( |
| 171 | val name: String = "{{PROJECT_NAME}}", |
| 172 | val version: String = "1.0.0", |
| 173 | val description: String = "{{PROJECT_DESCRIPTION}}" |
| 174 | ) |
| 175 | |
| 176 | fun loadConfig(): Config { |
| 177 | return Config( |
| 178 | name = System.getenv("SERVER_NAME") ?: "{{PROJECT_NAME}}", |
| 179 | version = System.getenv("VERSION") ?: "1.0.0", |
| 180 | description = System.getenv("DESCRIPTION") ?: "{{PROJECT_DESCRIPTION}}" |
| 181 | ) |
| 182 | } |
| 183 | ``` |
| 184 | |
| 185 | ## Tool1.kt Template |
| 186 | |
| 187 | ```kotlin |
| 188 | package com.example.myserver.tools |
| 189 | |
| 190 | import io.modelcontextprotocol.kotlin.sdk.server.Server |
| 191 | import io.modelcontextprotocol.kotlin.sdk.CallToolRequest |
| 192 | import io.modelcontextprotocol.kotlin.sdk.CallToolResult |
| 193 | import io.modelcontextprotocol. |