From f10bc70ce51be683d3fc17b7683aafe9c07a2185 Mon Sep 17 00:00:00 2001 From: Troy Simeon Taylor <44444967+troystaylor@users.noreply.github.com> Date: Thu, 16 Oct 2025 20:03:59 -0400 Subject: [PATCH] Add Kotlin MCP Server Development collection (#327) --- README.chatmodes.md | 1 + README.collections.md | 1 + README.instructions.md | 1 + README.prompts.md | 1 + chatmodes/kotlin-mcp-expert.chatmode.md | 181 +++++++ .../kotlin-mcp-development.collection.yml | 35 ++ collections/kotlin-mcp-development.md | 41 ++ .../kotlin-mcp-server.instructions.md | 481 ++++++++++++++++++ prompts/kotlin-mcp-server-generator.prompt.md | 449 ++++++++++++++++ 9 files changed, 1191 insertions(+) create mode 100644 chatmodes/kotlin-mcp-expert.chatmode.md create mode 100644 collections/kotlin-mcp-development.collection.yml create mode 100644 collections/kotlin-mcp-development.md create mode 100644 instructions/kotlin-mcp-server.instructions.md create mode 100644 prompts/kotlin-mcp-server-generator.prompt.md diff --git a/README.chatmodes.md b/README.chatmodes.md index d03ecaf..bebda64 100644 --- a/README.chatmodes.md +++ b/README.chatmodes.md @@ -46,6 +46,7 @@ Custom chat modes define specific behaviors and tools for GitHub Copilot Chat, e | [High-Level Big Picture Architect (HLBPA)](chatmodes/hlbpa.chatmode.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fhlbpa.chatmode.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode-insiders%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fhlbpa.chatmode.md) | Your perfect AI chat mode for high-level architectural documentation and review. Perfect for targeted updates after a story or researching that legacy system when nobody remembers what it's supposed to be doing. | | [Idea Generator mode instructions](chatmodes/simple-app-idea-generator.chatmode.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fsimple-app-idea-generator.chatmode.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode-insiders%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fsimple-app-idea-generator.chatmode.md) | Brainstorm and develop new application ideas through fun, interactive questioning until ready for specification creation. | | [Implementation Plan Generation Mode](chatmodes/implementation-plan.chatmode.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fimplementation-plan.chatmode.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode-insiders%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fimplementation-plan.chatmode.md) | Generate an implementation plan for new features or refactoring existing code. | +| [Kotlin MCP Server Development Expert](chatmodes/kotlin-mcp-expert.chatmode.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fkotlin-mcp-expert.chatmode.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode-insiders%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fkotlin-mcp-expert.chatmode.md) | Expert assistant for building Model Context Protocol (MCP) servers in Kotlin using the official SDK. | | [Kusto Assistant: Azure Data Explorer (Kusto) Engineering Assistant](chatmodes/kusto-assistant.chatmode.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fkusto-assistant.chatmode.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode-insiders%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fkusto-assistant.chatmode.md) | Expert KQL assistant for live Azure Data Explorer analysis via Azure MCP server | | [Mentor mode instructions](chatmodes/mentor.chatmode.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fmentor.chatmode.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode-insiders%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fmentor.chatmode.md) | Help mentor the engineer by providing guidance and support. | | [Meta Agentic Project Scaffold](chatmodes/meta-agentic-project-scaffold.chatmode.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fmeta-agentic-project-scaffold.chatmode.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode-insiders%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fmeta-agentic-project-scaffold.chatmode.md) | Meta agentic project creation assistant to help users create and manage project workflows effectively. | diff --git a/README.collections.md b/README.collections.md index b7a4230..96ae44d 100644 --- a/README.collections.md +++ b/README.collections.md @@ -24,6 +24,7 @@ Curated collections of related prompts, instructions, and chat modes organized a | [Frontend Web Development](collections/frontend-web-dev.md) | Essential prompts, instructions, and chat modes for modern frontend web development including React, Angular, Vue, TypeScript, and CSS frameworks. | 11 items | frontend, web, react, typescript, javascript, css, html, angular, vue | | [Go MCP Server Development](collections/go-mcp-development.md) | Complete toolkit for building Model Context Protocol (MCP) servers in Go using the official github.com/modelcontextprotocol/go-sdk. Includes instructions for best practices, a prompt for generating servers, and an expert chat mode for guidance. | 3 items | go, golang, mcp, model-context-protocol, server-development, sdk | | [Java Development](collections/java-development.md) | Comprehensive collection of prompts and instructions for Java development including Spring Boot, Quarkus, testing, documentation, and best practices. | 12 items | java, springboot, quarkus, jpa, junit, javadoc | +| [Kotlin MCP Server Development](collections/kotlin-mcp-development.md) | Complete toolkit for building Model Context Protocol (MCP) servers in Kotlin using the official io.modelcontextprotocol:kotlin-sdk library. Includes instructions for best practices, a prompt for generating servers, and an expert chat mode for guidance. | 3 items | kotlin, mcp, model-context-protocol, kotlin-multiplatform, server-development, ktor | | [Power Apps Code Apps Development](collections/power-apps-code-apps.md) | Complete toolkit for Power Apps Code Apps development including project scaffolding, development standards, and expert guidance for building code-first applications with Power Platform integration. | 3 items | power-apps, power-platform, typescript, react, code-apps, dataverse, connectors | | [Power BI Development](collections/power-bi-development.md) | Comprehensive Power BI development resources including data modeling, DAX optimization, performance tuning, visualization design, security best practices, and DevOps/ALM guidance for building enterprise-grade Power BI solutions. | 14 items | power-bi, dax, data-modeling, performance, visualization, security, devops, business-intelligence | | [Power Platform MCP Connector Development](collections/power-platform-mcp-connector-development.md) | Complete toolkit for developing Power Platform custom connectors with Model Context Protocol integration for Microsoft Copilot Studio | 4 items | power-platform, mcp, copilot-studio, custom-connector, json-rpc | diff --git a/README.instructions.md b/README.instructions.md index 55b9f8a..553a9a5 100644 --- a/README.instructions.md +++ b/README.instructions.md @@ -63,6 +63,7 @@ Team and project-specific instructions to enhance GitHub Copilot's behavior for | [Java Development](instructions/java.instructions.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fjava.instructions.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fjava.instructions.md) | Guidelines for building Java base applications | | [Joyride User Scripts Project Assistant](instructions/joyride-user-project.instructions.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fjoyride-user-project.instructions.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fjoyride-user-project.instructions.md) | Expert assistance for Joyride User Script projects - REPL-driven ClojureScript and user space automation of VS Code | | [Joyride Workspace Automation Assistant](instructions/joyride-workspace-automation.instructions.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fjoyride-workspace-automation.instructions.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fjoyride-workspace-automation.instructions.md) | Expert assistance for Joyride Workspace automation - REPL-driven and user space ClojureScript automation within specific VS Code workspaces | +| [Kotlin MCP Server Development Guidelines](instructions/kotlin-mcp-server.instructions.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fkotlin-mcp-server.instructions.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fkotlin-mcp-server.instructions.md) | Best practices and patterns for building Model Context Protocol (MCP) servers in Kotlin using the official io.modelcontextprotocol:kotlin-sdk library. | | [Kubernetes Deployment Best Practices](instructions/kubernetes-deployment-best-practices.instructions.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fkubernetes-deployment-best-practices.instructions.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fkubernetes-deployment-best-practices.instructions.md) | Comprehensive best practices for deploying and managing applications on Kubernetes. Covers Pods, Deployments, Services, Ingress, ConfigMaps, Secrets, health checks, resource limits, scaling, and security contexts. | | [LangChain Python Instructions](instructions/langchain-python.instructions.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Flangchain-python.instructions.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Flangchain-python.instructions.md) | Instructions for using LangChain with Python | | [Markdown](instructions/markdown.instructions.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fmarkdown.instructions.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fmarkdown.instructions.md) | Documentation and content creation standards | diff --git a/README.prompts.md b/README.prompts.md index 1a7bcb6..b16f457 100644 --- a/README.prompts.md +++ b/README.prompts.md @@ -68,6 +68,7 @@ Ready-to-use prompt templates for specific development scenarios and tasks, defi | [Java Documentation (Javadoc) Best Practices](prompts/java-docs.prompt.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fjava-docs.prompt.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fjava-docs.prompt.md) | Ensure that Java types are documented with Javadoc comments and follow best practices for documentation. | | [Javascript Typescript Jest](prompts/javascript-typescript-jest.prompt.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fjavascript-typescript-jest.prompt.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fjavascript-typescript-jest.prompt.md) | Best practices for writing JavaScript/TypeScript tests using Jest, including mocking strategies, test structure, and common patterns. | | [JUnit 5+ Best Practices](prompts/java-junit.prompt.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fjava-junit.prompt.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fjava-junit.prompt.md) | Get best practices for JUnit 5 unit testing, including data-driven tests | +| [Kotlin MCP Server Project Generator](prompts/kotlin-mcp-server-generator.prompt.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fkotlin-mcp-server-generator.prompt.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fkotlin-mcp-server-generator.prompt.md) | Generate a complete Kotlin MCP server project with proper structure, dependencies, and implementation using the official io.modelcontextprotocol:kotlin-sdk library. | | [Memory Keeper](prompts/remember.prompt.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fremember.prompt.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fremember.prompt.md) | Transforms lessons learned into domain-organized memory instructions (global or workspace). Syntax: `/remember [>domain [scope]] lesson clue` where scope is `global` (default), `user`, `workspace`, or `ws`. | | [Memory Merger](prompts/memory-merger.prompt.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fmemory-merger.prompt.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fmemory-merger.prompt.md) | Merges mature lessons from a domain memory file into its instruction file. Syntax: `/memory-merger >domain [scope]` where scope is `global` (default), `user`, `workspace`, or `ws`. | | [Microsoft 365 Declarative Agents Development Kit](prompts/declarative-agents.prompt.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fdeclarative-agents.prompt.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fdeclarative-agents.prompt.md) | Complete development kit for Microsoft 365 Copilot declarative agents with three comprehensive workflows (basic, advanced, validation), TypeSpec support, and Microsoft 365 Agents Toolkit integration | diff --git a/chatmodes/kotlin-mcp-expert.chatmode.md b/chatmodes/kotlin-mcp-expert.chatmode.md new file mode 100644 index 0000000..34874b5 --- /dev/null +++ b/chatmodes/kotlin-mcp-expert.chatmode.md @@ -0,0 +1,181 @@ +--- +model: GPT-4.1 +description: 'Expert assistant for building Model Context Protocol (MCP) servers in Kotlin using the official SDK.' +--- + +# Kotlin MCP Server Development Expert + +You are an expert Kotlin developer specializing in building Model Context Protocol (MCP) servers using the official `io.modelcontextprotocol:kotlin-sdk` library. + +## Your Expertise + +- **Kotlin Programming**: Deep knowledge of Kotlin idioms, coroutines, and language features +- **MCP Protocol**: Complete understanding of the Model Context Protocol specification +- **Official Kotlin SDK**: Mastery of `io.modelcontextprotocol:kotlin-sdk` package +- **Kotlin Multiplatform**: Experience with JVM, Wasm, and native targets +- **Coroutines**: Expert-level understanding of kotlinx.coroutines and suspending functions +- **Ktor Framework**: Configuration of HTTP/SSE transports with Ktor +- **kotlinx.serialization**: JSON schema creation and type-safe serialization +- **Gradle**: Build configuration and dependency management +- **Testing**: Kotlin test utilities and coroutine testing patterns + +## Your Approach + +When helping with Kotlin MCP development: + +1. **Idiomatic Kotlin**: Use Kotlin language features (data classes, sealed classes, extension functions) +2. **Coroutine Patterns**: Emphasize suspending functions and structured concurrency +3. **Type Safety**: Leverage Kotlin's type system and null safety +4. **JSON Schemas**: Use `buildJsonObject` for clear schema definitions +5. **Error Handling**: Use Kotlin exceptions and Result types appropriately +6. **Testing**: Encourage coroutine testing with `runTest` +7. **Documentation**: Recommend KDoc comments for public APIs +8. **Multiplatform**: Consider multiplatform compatibility when relevant +9. **Dependency Injection**: Suggest constructor injection for testability +10. **Immutability**: Prefer immutable data structures (val, data classes) + +## Key SDK Components + +### Server Creation +- `Server()` with `Implementation` and `ServerOptions` +- `ServerCapabilities` for feature declaration +- Transport selection (StdioServerTransport, SSE with Ktor) + +### Tool Registration +- `server.addTool()` with name, description, and inputSchema +- Suspending lambda for tool handler +- `CallToolRequest` and `CallToolResult` types + +### Resource Registration +- `server.addResource()` with URI and metadata +- `ReadResourceRequest` and `ReadResourceResult` +- Resource update notifications with `notifyResourceListChanged()` + +### Prompt Registration +- `server.addPrompt()` with arguments +- `GetPromptRequest` and `GetPromptResult` +- `PromptMessage` with Role and content + +### JSON Schema Building +- `buildJsonObject` DSL for schemas +- `putJsonObject` and `putJsonArray` for nested structures +- Type definitions and validation rules + +## Response Style + +- Provide complete, runnable Kotlin code examples +- Use suspending functions for async operations +- Include necessary imports +- Use meaningful variable names +- Add KDoc comments for complex logic +- Show proper coroutine scope management +- Demonstrate error handling patterns +- Include JSON schema examples with `buildJsonObject` +- Reference kotlinx.serialization when appropriate +- Suggest testing patterns with coroutine test utilities + +## Common Tasks + +### Creating Tools +Show complete tool implementation with: +- JSON schema using `buildJsonObject` +- Suspending handler function +- Parameter extraction and validation +- Error handling with try/catch +- Type-safe result construction + +### Transport Setup +Demonstrate: +- Stdio transport for CLI integration +- SSE transport with Ktor for web services +- Proper coroutine scope management +- Graceful shutdown patterns + +### Testing +Provide: +- `runTest` for coroutine testing +- Tool invocation examples +- Assertion patterns +- Mock patterns when needed + +### Project Structure +Recommend: +- Gradle Kotlin DSL configuration +- Package organization +- Separation of concerns +- Dependency injection patterns + +### Coroutine Patterns +Show: +- Proper use of `suspend` modifier +- Structured concurrency with `coroutineScope` +- Parallel operations with `async`/`await` +- Error propagation in coroutines + +## Example Interaction Pattern + +When a user asks to create a tool: + +1. Define JSON schema with `buildJsonObject` +2. Implement suspending handler function +3. Show parameter extraction and validation +4. Demonstrate error handling +5. Include tool registration +6. Provide testing example +7. Suggest improvements or alternatives + +## Kotlin-Specific Features + +### Data Classes +Use for structured data: +```kotlin +data class ToolInput( + val query: String, + val limit: Int = 10 +) +``` + +### Sealed Classes +Use for result types: +```kotlin +sealed class ToolResult { + data class Success(val data: String) : ToolResult() + data class Error(val message: String) : ToolResult() +} +``` + +### Extension Functions +Organize tool registration: +```kotlin +fun Server.registerSearchTools() { + addTool("search") { /* ... */ } + addTool("filter") { /* ... */ } +} +``` + +### Scope Functions +Use for configuration: +```kotlin +Server(serverInfo, options) { + "Description" +}.apply { + registerTools() + registerResources() +} +``` + +### Delegation +Use for lazy initialization: +```kotlin +val config by lazy { loadConfig() } +``` + +## Multiplatform Considerations + +When applicable, mention: +- Common code in `commonMain` +- Platform-specific implementations +- Expect/actual declarations +- Supported targets (JVM, Wasm, iOS) + +Always write idiomatic Kotlin code that follows the official SDK patterns and Kotlin best practices, with proper use of coroutines and type safety. diff --git a/collections/kotlin-mcp-development.collection.yml b/collections/kotlin-mcp-development.collection.yml new file mode 100644 index 0000000..66d71df --- /dev/null +++ b/collections/kotlin-mcp-development.collection.yml @@ -0,0 +1,35 @@ +id: kotlin-mcp-development +name: Kotlin MCP Server Development +description: Complete toolkit for building Model Context Protocol (MCP) servers in Kotlin using the official io.modelcontextprotocol:kotlin-sdk library. Includes instructions for best practices, a prompt for generating servers, and an expert chat mode for guidance. +tags: [kotlin, mcp, model-context-protocol, kotlin-multiplatform, server-development, ktor] +items: + - path: instructions/kotlin-mcp-server.instructions.md + kind: instruction + - path: prompts/kotlin-mcp-server-generator.prompt.md + kind: prompt + - path: chatmodes/kotlin-mcp-expert.chatmode.md + kind: chat-mode + usage: | + recommended + + This chat mode provides expert guidance for building MCP servers in Kotlin. + + This chat mode is ideal for: + - Creating new MCP server projects with Kotlin + - Implementing type-safe tools with coroutines and kotlinx.serialization + - Setting up stdio or SSE transports with Ktor + - Debugging coroutine patterns and JSON schema issues + - Learning Kotlin MCP best practices with the official SDK + - Building multiplatform MCP servers (JVM, Wasm, iOS) + + To get the best results, consider: + - Using the instruction file to set context for Kotlin MCP development + - Using the prompt to generate initial project structure with Gradle + - Switching to the expert chat mode for detailed implementation help + - Specifying whether you need stdio or SSE/HTTP transport + - Providing details about what tools or functionality you need + - Mentioning if you need multiplatform support or specific targets + +display: + ordering: manual + show_badge: true diff --git a/collections/kotlin-mcp-development.md b/collections/kotlin-mcp-development.md new file mode 100644 index 0000000..2949337 --- /dev/null +++ b/collections/kotlin-mcp-development.md @@ -0,0 +1,41 @@ +# Kotlin MCP Server Development + +Complete toolkit for building Model Context Protocol (MCP) servers in Kotlin using the official io.modelcontextprotocol:kotlin-sdk library. Includes instructions for best practices, a prompt for generating servers, and an expert chat mode for guidance. + +**Tags:** kotlin, mcp, model-context-protocol, kotlin-multiplatform, server-development, ktor + +## Items in this Collection + +| Title | Type | Description | +| ----- | ---- | ----------- | +| [Kotlin MCP Server Development Guidelines](../instructions/kotlin-mcp-server.instructions.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fkotlin-mcp-server.instructions.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/instructions?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fkotlin-mcp-server.instructions.md) | Instruction | Best practices and patterns for building Model Context Protocol (MCP) servers in Kotlin using the official io.modelcontextprotocol:kotlin-sdk library. | +| [Kotlin MCP Server Project Generator](../prompts/kotlin-mcp-server-generator.prompt.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fkotlin-mcp-server-generator.prompt.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fkotlin-mcp-server-generator.prompt.md) | Prompt | Generate a complete Kotlin MCP server project with proper structure, dependencies, and implementation using the official io.modelcontextprotocol:kotlin-sdk library. | +| [Kotlin MCP Server Development Expert](../chatmodes/kotlin-mcp-expert.chatmode.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fkotlin-mcp-expert.chatmode.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/chatmode?url=vscode-insiders%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fkotlin-mcp-expert.chatmode.md) | Chat Mode | Expert assistant for building Model Context Protocol (MCP) servers in Kotlin using the official SDK. [see usage](#kotlin-mcp-server-development-expert) | + +## Collection Usage + +### Kotlin MCP Server Development Expert + +recommended + +This chat mode provides expert guidance for building MCP servers in Kotlin. + +This chat mode is ideal for: +- Creating new MCP server projects with Kotlin +- Implementing type-safe tools with coroutines and kotlinx.serialization +- Setting up stdio or SSE transports with Ktor +- Debugging coroutine patterns and JSON schema issues +- Learning Kotlin MCP best practices with the official SDK +- Building multiplatform MCP servers (JVM, Wasm, iOS) + +To get the best results, consider: +- Using the instruction file to set context for Kotlin MCP development +- Using the prompt to generate initial project structure with Gradle +- Switching to the expert chat mode for detailed implementation help +- Specifying whether you need stdio or SSE/HTTP transport +- Providing details about what tools or functionality you need +- Mentioning if you need multiplatform support or specific targets + +--- + +*This collection includes 3 curated items for kotlin mcp server development.* \ No newline at end of file diff --git a/instructions/kotlin-mcp-server.instructions.md b/instructions/kotlin-mcp-server.instructions.md new file mode 100644 index 0000000..c450165 --- /dev/null +++ b/instructions/kotlin-mcp-server.instructions.md @@ -0,0 +1,481 @@ +--- +description: 'Best practices and patterns for building Model Context Protocol (MCP) servers in Kotlin using the official io.modelcontextprotocol:kotlin-sdk library.' +applyTo: "**/*.kt, **/*.kts, **/build.gradle.kts, **/settings.gradle.kts" +--- + +# Kotlin MCP Server Development Guidelines + +When building MCP servers in Kotlin, follow these best practices and patterns using the official Kotlin SDK. + +## Server Setup + +Create an MCP server using the `Server` class: + +```kotlin +import io.modelcontextprotocol.kotlin.sdk.server.Server +import io.modelcontextprotocol.kotlin.sdk.server.ServerOptions +import io.modelcontextprotocol.kotlin.sdk.Implementation +import io.modelcontextprotocol.kotlin.sdk.ServerCapabilities + +val server = Server( + serverInfo = Implementation( + name = "my-server", + version = "1.0.0" + ), + options = ServerOptions( + capabilities = ServerCapabilities( + tools = ServerCapabilities.Tools(), + resources = ServerCapabilities.Resources( + subscribe = true, + listChanged = true + ), + prompts = ServerCapabilities.Prompts(listChanged = true) + ) + ) +) { + "Server description goes here" +} +``` + +## Adding Tools + +Use `server.addTool()` to register tools with typed request/response handling: + +```kotlin +import io.modelcontextprotocol.kotlin.sdk.CallToolRequest +import io.modelcontextprotocol.kotlin.sdk.CallToolResult +import io.modelcontextprotocol.kotlin.sdk.TextContent + +server.addTool( + name = "search", + description = "Search for information", + inputSchema = buildJsonObject { + put("type", "object") + putJsonObject("properties") { + putJsonObject("query") { + put("type", "string") + put("description", "The search query") + } + putJsonObject("limit") { + put("type", "integer") + put("description", "Maximum results to return") + } + } + putJsonArray("required") { + add("query") + } + } +) { request: CallToolRequest -> + val query = request.params.arguments["query"] as? String + ?: throw IllegalArgumentException("query is required") + val limit = (request.params.arguments["limit"] as? Number)?.toInt() ?: 10 + + // Perform search + val results = performSearch(query, limit) + + CallToolResult( + content = listOf( + TextContent( + text = results.joinToString("\n") + ) + ) + ) +} +``` + +## Adding Resources + +Use `server.addResource()` to provide accessible data: + +```kotlin +import io.modelcontextprotocol.kotlin.sdk.ReadResourceRequest +import io.modelcontextprotocol.kotlin.sdk.ReadResourceResult +import io.modelcontextprotocol.kotlin.sdk.TextResourceContents + +server.addResource( + uri = "file:///data/example.txt", + name = "Example Data", + description = "Example resource data", + mimeType = "text/plain" +) { request: ReadResourceRequest -> + val content = loadResourceContent(request.uri) + + ReadResourceResult( + contents = listOf( + TextResourceContents( + text = content, + uri = request.uri, + mimeType = "text/plain" + ) + ) + ) +} +``` + +## Adding Prompts + +Use `server.addPrompt()` for reusable prompt templates: + +```kotlin +import io.modelcontextprotocol.kotlin.sdk.GetPromptRequest +import io.modelcontextprotocol.kotlin.sdk.GetPromptResult +import io.modelcontextprotocol.kotlin.sdk.PromptMessage +import io.modelcontextprotocol.kotlin.sdk.Role + +server.addPrompt( + name = "analyze", + description = "Analyze a topic", + arguments = listOf( + PromptArgument( + name = "topic", + description = "The topic to analyze", + required = true + ) + ) +) { request: GetPromptRequest -> + val topic = request.params.arguments?.get("topic") as? String + ?: throw IllegalArgumentException("topic is required") + + GetPromptResult( + description = "Analyze the given topic", + messages = listOf( + PromptMessage( + role = Role.User, + content = TextContent( + text = "Analyze this topic: $topic" + ) + ) + ) + ) +} +``` + +## Transport Configuration + +### Stdio Transport + +For communication over stdin/stdout: + +```kotlin +import io.modelcontextprotocol.kotlin.sdk.server.StdioServerTransport + +suspend fun main() { + val transport = StdioServerTransport() + server.connect(transport) +} +``` + +### SSE Transport with Ktor + +For HTTP-based communication using Server-Sent Events: + +```kotlin +import io.ktor.server.application.* +import io.ktor.server.engine.* +import io.ktor.server.netty.* +import io.modelcontextprotocol.kotlin.sdk.server.mcp + +fun main() { + embeddedServer(Netty, port = 8080) { + mcp { + Server( + serverInfo = Implementation( + name = "sse-server", + version = "1.0.0" + ), + options = ServerOptions( + capabilities = ServerCapabilities( + tools = ServerCapabilities.Tools() + ) + ) + ) { + "SSE-based MCP server" + } + } + }.start(wait = true) +} +``` + +## Coroutine Usage + +All MCP operations are suspending functions. Use Kotlin coroutines properly: + +```kotlin +import kotlinx.coroutines.coroutineScope +import kotlinx.coroutines.async + +server.addTool( + name = "parallel-search", + description = "Search multiple sources in parallel" +) { request -> + coroutineScope { + val source1 = async { searchSource1(query) } + val source2 = async { searchSource2(query) } + + val results = source1.await() + source2.await() + + CallToolResult( + content = listOf(TextContent(text = results.joinToString("\n"))) + ) + } +} +``` + +## Error Handling + +Use Kotlin's exception handling and provide meaningful error messages: + +```kotlin +server.addTool( + name = "validate-input", + description = "Process validated input" +) { request -> + try { + val input = request.params.arguments["input"] as? String + ?: throw IllegalArgumentException("input is required") + + require(input.isNotBlank()) { "input cannot be blank" } + + val result = processInput(input) + + CallToolResult( + content = listOf(TextContent(text = result)) + ) + } catch (e: IllegalArgumentException) { + CallToolResult( + isError = true, + content = listOf(TextContent(text = "Validation error: ${e.message}")) + ) + } +} +``` + +## JSON Schema with kotlinx.serialization + +Use kotlinx.serialization for type-safe JSON schemas: + +```kotlin +import kotlinx.serialization.Serializable +import kotlinx.serialization.json.* + +@Serializable +data class SearchInput( + val query: String, + val limit: Int = 10, + val filters: List = emptyList() +) + +fun createToolSchema(): JsonObject = buildJsonObject { + put("type", "object") + putJsonObject("properties") { + putJsonObject("query") { + put("type", "string") + put("description", "Search query") + } + putJsonObject("limit") { + put("type", "integer") + put("default", 10) + } + putJsonObject("filters") { + put("type", "array") + putJsonObject("items") { + put("type", "string") + } + } + } + putJsonArray("required") { + add("query") + } +} +``` + +## Gradle Configuration + +Set up your `build.gradle.kts` properly: + +```kotlin +plugins { + kotlin("jvm") version "2.1.0" + kotlin("plugin.serialization") version "2.1.0" +} + +repositories { + mavenCentral() +} + +dependencies { + implementation("io.modelcontextprotocol:kotlin-sdk:0.7.2") + + // For client transport + implementation("io.ktor:ktor-client-cio:3.0.0") + + // For server transport + implementation("io.ktor:ktor-server-netty:3.0.0") + + // For JSON serialization + implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3") + + // For coroutines + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0") +} +``` + +## Multiplatform Support + +The Kotlin SDK supports Kotlin Multiplatform (JVM, Wasm, iOS): + +```kotlin +kotlin { + jvm() + js(IR) { + browser() + nodejs() + } + wasmJs() + + sourceSets { + commonMain.dependencies { + implementation("io.modelcontextprotocol:kotlin-sdk:0.7.2") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0") + } + } +} +``` + +## Resource Lifecycle + +Handle resource updates and subscriptions: + +```kotlin +server.addResource( + uri = "file:///dynamic/data", + name = "Dynamic Data", + description = "Frequently updated data", + mimeType = "application/json" +) { request -> + // Provide current state + ReadResourceResult( + contents = listOf( + TextResourceContents( + text = getCurrentData(), + uri = request.uri, + mimeType = "application/json" + ) + ) + ) +} + +// Notify clients when resource changes +server.notifyResourceListChanged() +``` + +## Testing + +Test your MCP tools using Kotlin coroutines test utilities: + +```kotlin +import kotlinx.coroutines.test.runTest +import kotlin.test.Test +import kotlin.test.assertEquals + +class ServerTest { + @Test + fun testSearchTool() = runTest { + val server = createTestServer() + + val request = CallToolRequest( + params = CallToolParams( + name = "search", + arguments = mapOf("query" to "test", "limit" to 5) + ) + ) + + val result = server.callTool(request) + + assertEquals(false, result.isError) + assert(result.content.isNotEmpty()) + } +} +``` + +## Common Patterns + +### Logging + +Use structured logging with a Kotlin logging library: + +```kotlin +import io.github.oshai.kotlinlogging.KotlinLogging + +private val logger = KotlinLogging.logger {} + +server.addTool( + name = "logged-operation", + description = "Operation with logging" +) { request -> + logger.info { "Tool called with args: ${request.params.arguments}" } + + try { + val result = performOperation(request) + logger.info { "Operation succeeded" } + result + } catch (e: Exception) { + logger.error(e) { "Operation failed" } + throw e + } +} +``` + +### Configuration + +Use data classes for configuration: + +```kotlin +import kotlinx.serialization.Serializable + +@Serializable +data class ServerConfig( + val name: String = "my-server", + val version: String = "1.0.0", + val port: Int = 8080, + val enableTools: Boolean = true +) + +fun loadConfig(): ServerConfig { + // Load from environment or config file + return ServerConfig( + name = System.getenv("SERVER_NAME") ?: "my-server", + version = System.getenv("VERSION") ?: "1.0.0" + ) +} +``` + +### Dependency Injection + +Use constructor injection for testability: + +```kotlin +class MyServer( + private val dataService: DataService, + private val config: ServerConfig +) { + fun createServer() = Server( + serverInfo = Implementation( + name = config.name, + version = config.version + ) + ) { + "MCP Server with DI" + }.apply { + addTool( + name = "fetch-data", + description = "Fetch data using injected service" + ) { request -> + val data = dataService.fetchData() + CallToolResult( + content = listOf(TextContent(text = data)) + ) + } + } +} +``` diff --git a/prompts/kotlin-mcp-server-generator.prompt.md b/prompts/kotlin-mcp-server-generator.prompt.md new file mode 100644 index 0000000..a009901 --- /dev/null +++ b/prompts/kotlin-mcp-server-generator.prompt.md @@ -0,0 +1,449 @@ +--- +mode: agent +description: 'Generate a complete Kotlin MCP server project with proper structure, dependencies, and implementation using the official io.modelcontextprotocol:kotlin-sdk library.' +--- + +# Kotlin MCP Server Project Generator + +Generate a complete, production-ready Model Context Protocol (MCP) server project in Kotlin. + +## Project Requirements + +You will create a Kotlin MCP server with: + +1. **Project Structure**: Gradle-based Kotlin project layout +2. **Dependencies**: Official MCP SDK, Ktor, and kotlinx libraries +3. **Server Setup**: Configured MCP server with transports +4. **Tools**: At least 2-3 useful tools with typed inputs/outputs +5. **Error Handling**: Proper exception handling and validation +6. **Documentation**: README with setup and usage instructions +7. **Testing**: Basic test structure with coroutines + +## Template Structure + +``` +myserver/ +├── build.gradle.kts +├── settings.gradle.kts +├── gradle.properties +├── src/ +│ ├── main/ +│ │ └── kotlin/ +│ │ └── com/example/myserver/ +│ │ ├── Main.kt +│ │ ├── Server.kt +│ │ ├── config/ +│ │ │ └── Config.kt +│ │ └── tools/ +│ │ ├── Tool1.kt +│ │ └── Tool2.kt +│ └── test/ +│ └── kotlin/ +│ └── com/example/myserver/ +│ └── ServerTest.kt +└── README.md +``` + +## build.gradle.kts Template + +```kotlin +plugins { + kotlin("jvm") version "2.1.0" + kotlin("plugin.serialization") version "2.1.0" + application +} + +group = "com.example" +version = "1.0.0" + +repositories { + mavenCentral() +} + +dependencies { + implementation("io.modelcontextprotocol:kotlin-sdk:0.7.2") + + // Ktor for transports + implementation("io.ktor:ktor-server-netty:3.0.0") + implementation("io.ktor:ktor-client-cio:3.0.0") + + // Serialization + implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3") + + // Coroutines + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0") + + // Logging + implementation("io.github.oshai:kotlin-logging-jvm:7.0.0") + implementation("ch.qos.logback:logback-classic:1.5.12") + + // Testing + testImplementation(kotlin("test")) + testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0") +} + +application { + mainClass.set("com.example.myserver.MainKt") +} + +tasks.test { + useJUnitPlatform() +} + +kotlin { + jvmToolchain(17) +} +``` + +## settings.gradle.kts Template + +```kotlin +rootProject.name = "{{PROJECT_NAME}}" +``` + +## Main.kt Template + +```kotlin +package com.example.myserver + +import io.modelcontextprotocol.kotlin.sdk.server.StdioServerTransport +import kotlinx.coroutines.runBlocking +import io.github.oshai.kotlinlogging.KotlinLogging + +private val logger = KotlinLogging.logger {} + +fun main() = runBlocking { + logger.info { "Starting MCP server..." } + + val config = loadConfig() + val server = createServer(config) + + // Use stdio transport + val transport = StdioServerTransport() + + logger.info { "Server '${config.name}' v${config.version} ready" } + server.connect(transport) +} +``` + +## Server.kt Template + +```kotlin +package com.example.myserver + +import io.modelcontextprotocol.kotlin.sdk.server.Server +import io.modelcontextprotocol.kotlin.sdk.server.ServerOptions +import io.modelcontextprotocol.kotlin.sdk.Implementation +import io.modelcontextprotocol.kotlin.sdk.ServerCapabilities +import com.example.myserver.tools.registerTools + +fun createServer(config: Config): Server { + val server = Server( + serverInfo = Implementation( + name = config.name, + version = config.version + ), + options = ServerOptions( + capabilities = ServerCapabilities( + tools = ServerCapabilities.Tools(), + resources = ServerCapabilities.Resources( + subscribe = true, + listChanged = true + ), + prompts = ServerCapabilities.Prompts(listChanged = true) + ) + ) + ) { + config.description + } + + // Register all tools + server.registerTools() + + return server +} +``` + +## Config.kt Template + +```kotlin +package com.example.myserver.config + +import kotlinx.serialization.Serializable + +@Serializable +data class Config( + val name: String = "{{PROJECT_NAME}}", + val version: String = "1.0.0", + val description: String = "{{PROJECT_DESCRIPTION}}" +) + +fun loadConfig(): Config { + return Config( + name = System.getenv("SERVER_NAME") ?: "{{PROJECT_NAME}}", + version = System.getenv("VERSION") ?: "1.0.0", + description = System.getenv("DESCRIPTION") ?: "{{PROJECT_DESCRIPTION}}" + ) +} +``` + +## Tool1.kt Template + +```kotlin +package com.example.myserver.tools + +import io.modelcontextprotocol.kotlin.sdk.server.Server +import io.modelcontextprotocol.kotlin.sdk.CallToolRequest +import io.modelcontextprotocol.kotlin.sdk.CallToolResult +import io.modelcontextprotocol.kotlin.sdk.TextContent +import kotlinx.serialization.json.buildJsonObject +import kotlinx.serialization.json.put +import kotlinx.serialization.json.putJsonObject +import kotlinx.serialization.json.putJsonArray + +fun Server.registerTool1() { + addTool( + name = "tool1", + description = "Description of what tool1 does", + inputSchema = buildJsonObject { + put("type", "object") + putJsonObject("properties") { + putJsonObject("param1") { + put("type", "string") + put("description", "First parameter") + } + putJsonObject("param2") { + put("type", "integer") + put("description", "Optional second parameter") + } + } + putJsonArray("required") { + add("param1") + } + } + ) { request: CallToolRequest -> + // Extract and validate parameters + val param1 = request.params.arguments["param1"] as? String + ?: throw IllegalArgumentException("param1 is required") + val param2 = (request.params.arguments["param2"] as? Number)?.toInt() ?: 0 + + // Perform tool logic + val result = performTool1Logic(param1, param2) + + CallToolResult( + content = listOf( + TextContent(text = result) + ) + ) + } +} + +private fun performTool1Logic(param1: String, param2: Int): String { + // Implement tool logic here + return "Processed: $param1 with value $param2" +} +``` + +## tools/ToolRegistry.kt Template + +```kotlin +package com.example.myserver.tools + +import io.modelcontextprotocol.kotlin.sdk.server.Server + +fun Server.registerTools() { + registerTool1() + registerTool2() + // Register additional tools here +} +``` + +## ServerTest.kt Template + +```kotlin +package com.example.myserver + +import kotlinx.coroutines.test.runTest +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertFalse + +class ServerTest { + + @Test + fun `test server creation`() = runTest { + val config = Config( + name = "test-server", + version = "1.0.0", + description = "Test server" + ) + + val server = createServer(config) + + assertEquals("test-server", server.serverInfo.name) + assertEquals("1.0.0", server.serverInfo.version) + } + + @Test + fun `test tool1 execution`() = runTest { + val config = Config() + val server = createServer(config) + + // Test tool execution + // Note: You'll need to implement proper testing utilities + // for calling tools in the server + } +} +``` + +## README.md Template + +```markdown +# {{PROJECT_NAME}} + +A Model Context Protocol (MCP) server built with Kotlin. + +## Description + +{{PROJECT_DESCRIPTION}} + +## Requirements + +- Java 17 or higher +- Kotlin 2.1.0 + +## Installation + +Build the project: + +\`\`\`bash +./gradlew build +\`\`\` + +## Usage + +Run the server with stdio transport: + +\`\`\`bash +./gradlew run +\`\`\` + +Or build and run the jar: + +\`\`\`bash +./gradlew installDist +./build/install/{{PROJECT_NAME}}/bin/{{PROJECT_NAME}} +\`\`\` + +## Configuration + +Configure via environment variables: + +- `SERVER_NAME`: Server name (default: "{{PROJECT_NAME}}") +- `VERSION`: Server version (default: "1.0.0") +- `DESCRIPTION`: Server description + +## Available Tools + +### tool1 +{{TOOL1_DESCRIPTION}} + +**Input:** +- `param1` (string, required): First parameter +- `param2` (integer, optional): Second parameter + +**Output:** +- Text result of the operation + +## Development + +Run tests: + +\`\`\`bash +./gradlew test +\`\`\` + +Build: + +\`\`\`bash +./gradlew build +\`\`\` + +Run with auto-reload (development): + +\`\`\`bash +./gradlew run --continuous +\`\`\` + +## Multiplatform + +This project uses Kotlin Multiplatform and can target JVM, Wasm, and iOS. +See `build.gradle.kts` for platform configuration. + +## License + +MIT +``` + +## Generation Instructions + +When generating a Kotlin MCP server: + +1. **Gradle Setup**: Create proper `build.gradle.kts` with all dependencies +2. **Package Structure**: Follow Kotlin package conventions +3. **Type Safety**: Use data classes and kotlinx.serialization +4. **Coroutines**: All operations should be suspending functions +5. **Error Handling**: Use Kotlin exceptions and validation +6. **JSON Schemas**: Use `buildJsonObject` for tool schemas +7. **Testing**: Include coroutine test utilities +8. **Logging**: Use kotlin-logging for structured logging +9. **Configuration**: Use data classes and environment variables +10. **Documentation**: KDoc comments for public APIs + +## Best Practices + +- Use suspending functions for all async operations +- Leverage Kotlin's null safety and type system +- Use data classes for structured data +- Apply kotlinx.serialization for JSON handling +- Use sealed classes for result types +- Implement proper error handling with Result/Either patterns +- Write tests using kotlinx-coroutines-test +- Use dependency injection for testability +- Follow Kotlin coding conventions +- Use meaningful names and KDoc comments + +## Transport Options + +### Stdio Transport +```kotlin +val transport = StdioServerTransport() +server.connect(transport) +``` + +### SSE Transport (Ktor) +```kotlin +embeddedServer(Netty, port = 8080) { + mcp { + Server(/*...*/) { "Description" } + } +}.start(wait = true) +``` + +## Multiplatform Configuration + +For multiplatform projects, add to `build.gradle.kts`: + +```kotlin +kotlin { + jvm() + js(IR) { nodejs() } + wasmJs() + + sourceSets { + commonMain.dependencies { + implementation("io.modelcontextprotocol:kotlin-sdk:0.7.2") + } + } +} +```