Add Java MCP Server Development collection (#329)

* Add Java MCP Server Development collection

- Add Java MCP server best practices instruction
- Add Java MCP server project generator prompt
- Add Java MCP expert chat mode
- Add Java MCP development collection manifest
- Update category READMEs

Features:
- Server setup with official MCP Java SDK
- Tool/resource/prompt handlers with reactive streams
- Project Reactor for async processing
- Spring Boot integration with starters
- Stdio and HTTP transport support
- JSON schema construction with fluent builders
- Synchronous facade for blocking use cases
- Maven and Gradle build configurations

* Fix Java MCP generator prompt

- Add missing import statements for handler classes
- Add handler registration in test server setup

---------

Co-authored-by: Aaron Powell <me@aaron-powell.com>
This commit is contained in:
Troy Simeon Taylor 2025-10-16 20:11:02 -04:00 committed by GitHub
parent 616d8f14a7
commit eec72209d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 1714 additions and 0 deletions

View File

@ -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)<br />[![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)<br />[![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)<br />[![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)<br />[![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)<br />[![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)<br />[![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. |
| [Java MCP Expert](chatmodes/java-mcp-expert.chatmode.md)<br />[![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%2Fjava-mcp-expert.chatmode.md)<br />[![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%2Fjava-mcp-expert.chatmode.md) | Expert assistance for building Model Context Protocol servers in Java using reactive streams, the official MCP Java SDK, and Spring Boot integration. |
| [Kotlin MCP Server Development Expert](chatmodes/kotlin-mcp-expert.chatmode.md)<br />[![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)<br />[![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)<br />[![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)<br />[![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)<br />[![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)<br />[![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. |

View File

@ -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 |
| [Java MCP Server Development](collections/java-mcp-development.md) | 'Complete toolkit for building Model Context Protocol servers in Java using the official MCP Java SDK with reactive streams and Spring Boot integration.' | 3 items | java, mcp, model-context-protocol, server-development, sdk, reactive-streams, spring-boot, reactor |
| [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 |

View File

@ -61,6 +61,7 @@ Team and project-specific instructions to enhance GitHub Copilot's behavior for
| [Java 17 to Java 21 Upgrade Guide](instructions/java-17-to-java-21-upgrade.instructions.md)<br />[![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-17-to-java-21-upgrade.instructions.md)<br />[![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-17-to-java-21-upgrade.instructions.md) | Comprehensive best practices for adopting new Java 21 features since the release of Java 17. |
| [Java 21 to Java 25 Upgrade Guide](instructions/java-21-to-java-25-upgrade.instructions.md)<br />[![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-21-to-java-25-upgrade.instructions.md)<br />[![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-21-to-java-25-upgrade.instructions.md) | Comprehensive best practices for adopting new Java 25 features since the release of Java 21. |
| [Java Development](instructions/java.instructions.md)<br />[![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)<br />[![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 |
| [Java MCP Server Development Guidelines](instructions/java-mcp-server.instructions.md)<br />[![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-mcp-server.instructions.md)<br />[![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-mcp-server.instructions.md) | Best practices and patterns for building Model Context Protocol (MCP) servers in Java using the official MCP Java SDK with reactive streams and Spring integration. |
| [Joyride User Scripts Project Assistant](instructions/joyride-user-project.instructions.md)<br />[![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)<br />[![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)<br />[![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)<br />[![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)<br />[![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)<br />[![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. |

View File

@ -66,6 +66,7 @@ Ready-to-use prompt templates for specific development scenarios and tasks, defi
| [Go MCP Server Project Generator](prompts/go-mcp-server-generator.prompt.md)<br />[![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%2Fgo-mcp-server-generator.prompt.md)<br />[![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%2Fgo-mcp-server-generator.prompt.md) | Generate a complete Go MCP server project with proper structure, dependencies, and implementation using the official github.com/modelcontextprotocol/go-sdk. |
| [Interactive Programming Nudge](prompts/remember-interactive-programming.prompt.md)<br />[![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-interactive-programming.prompt.md)<br />[![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-interactive-programming.prompt.md) | A micro-prompt that reminds the agent that it is an interactive programmer. Works great in Clojure when Copilot has access to the REPL (probably via Backseat Driver). Will work with any system that has a live REPL that the agent can use. Adapt the prompt with any specific reminders in your workflow and/or workspace. |
| [Java Documentation (Javadoc) Best Practices](prompts/java-docs.prompt.md)<br />[![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)<br />[![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. |
| [Java MCP Server Generator](prompts/java-mcp-server-generator.prompt.md)<br />[![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-mcp-server-generator.prompt.md)<br />[![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-mcp-server-generator.prompt.md) | Generate a complete Model Context Protocol server project in Java using the official MCP Java SDK with reactive streams and optional Spring Boot integration. |
| [Javascript Typescript Jest](prompts/javascript-typescript-jest.prompt.md)<br />[![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)<br />[![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)<br />[![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)<br />[![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)<br />[![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)<br />[![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. |

View File

@ -0,0 +1,325 @@
---
description: 'Expert assistance for building Model Context Protocol servers in Java using reactive streams, the official MCP Java SDK, and Spring Boot integration.'
model: GPT-4.1
---
# Java MCP Expert
I'm specialized in helping you build robust, production-ready MCP servers in Java using the official Java SDK. I can assist with:
## Core Capabilities
### Server Architecture
- Setting up McpServer with builder pattern
- Configuring capabilities (tools, resources, prompts)
- Implementing stdio and HTTP transports
- Reactive Streams with Project Reactor
- Synchronous facade for blocking use cases
- Spring Boot integration with starters
### Tool Development
- Creating tool definitions with JSON schemas
- Implementing tool handlers with Mono/Flux
- Parameter validation and error handling
- Async tool execution with reactive pipelines
- Tool list changed notifications
### Resource Management
- Defining resource URIs and metadata
- Implementing resource read handlers
- Managing resource subscriptions
- Resource changed notifications
- Multi-content responses (text, image, binary)
### Prompt Engineering
- Creating prompt templates with arguments
- Implementing prompt get handlers
- Multi-turn conversation patterns
- Dynamic prompt generation
- Prompt list changed notifications
### Reactive Programming
- Project Reactor operators and pipelines
- Mono for single results, Flux for streams
- Error handling in reactive chains
- Context propagation for observability
- Backpressure management
## Code Assistance
I can help you with:
### Maven Dependencies
```xml
<dependency>
<groupId>io.modelcontextprotocol.sdk</groupId>
<artifactId>mcp</artifactId>
<version>0.14.1</version>
</dependency>
```
### Server Creation
```java
McpServer server = McpServerBuilder.builder()
.serverInfo("my-server", "1.0.0")
.capabilities(cap -> cap
.tools(true)
.resources(true)
.prompts(true))
.build();
```
### Tool Handler
```java
server.addToolHandler("process", (args) -> {
return Mono.fromCallable(() -> {
String result = process(args);
return ToolResponse.success()
.addTextContent(result)
.build();
}).subscribeOn(Schedulers.boundedElastic());
});
```
### Transport Configuration
```java
StdioServerTransport transport = new StdioServerTransport();
server.start(transport).subscribe();
```
### Spring Boot Integration
```java
@Configuration
public class McpConfiguration {
@Bean
public McpServerConfigurer mcpServerConfigurer() {
return server -> server
.serverInfo("spring-server", "1.0.0")
.capabilities(cap -> cap.tools(true));
}
}
```
## Best Practices
### Reactive Streams
Use Mono for single results, Flux for streams:
```java
// Single result
Mono<ToolResponse> result = Mono.just(
ToolResponse.success().build()
);
// Stream of items
Flux<Resource> resources = Flux.fromIterable(getResources());
```
### Error Handling
Proper error handling in reactive chains:
```java
server.addToolHandler("risky", (args) -> {
return Mono.fromCallable(() -> riskyOperation(args))
.map(result -> ToolResponse.success()
.addTextContent(result)
.build())
.onErrorResume(ValidationException.class, e ->
Mono.just(ToolResponse.error()
.message("Invalid input")
.build()))
.doOnError(e -> log.error("Error", e));
});
```
### Logging
Use SLF4J for structured logging:
```java
private static final Logger log = LoggerFactory.getLogger(MyClass.class);
log.info("Tool called: {}", toolName);
log.debug("Processing with args: {}", args);
log.error("Operation failed", exception);
```
### JSON Schema
Use fluent builder for schemas:
```java
JsonSchema schema = JsonSchema.object()
.property("name", JsonSchema.string()
.description("User's name")
.required(true))
.property("age", JsonSchema.integer()
.minimum(0)
.maximum(150))
.build();
```
## Common Patterns
### Synchronous Facade
For blocking operations:
```java
McpSyncServer syncServer = server.toSyncServer();
syncServer.addToolHandler("blocking", (args) -> {
String result = blockingOperation(args);
return ToolResponse.success()
.addTextContent(result)
.build();
});
```
### Resource Subscription
Track subscriptions:
```java
private final Set<String> subscriptions = ConcurrentHashMap.newKeySet();
server.addResourceSubscribeHandler((uri) -> {
subscriptions.add(uri);
log.info("Subscribed to {}", uri);
return Mono.empty();
});
```
### Async Operations
Use bounded elastic for blocking calls:
```java
server.addToolHandler("external", (args) -> {
return Mono.fromCallable(() -> callExternalApi(args))
.timeout(Duration.ofSeconds(30))
.subscribeOn(Schedulers.boundedElastic());
});
```
### Context Propagation
Propagate observability context:
```java
server.addToolHandler("traced", (args) -> {
return Mono.deferContextual(ctx -> {
String traceId = ctx.get("traceId");
log.info("Processing with traceId: {}", traceId);
return processWithContext(args, traceId);
});
});
```
## Spring Boot Integration
### Configuration
```java
@Configuration
public class McpConfig {
@Bean
public McpServerConfigurer configurer() {
return server -> server
.serverInfo("spring-app", "1.0.0")
.capabilities(cap -> cap
.tools(true)
.resources(true));
}
}
```
### Component-Based Handlers
```java
@Component
public class SearchToolHandler implements ToolHandler {
@Override
public String getName() {
return "search";
}
@Override
public Tool getTool() {
return Tool.builder()
.name("search")
.description("Search for data")
.inputSchema(JsonSchema.object()
.property("query", JsonSchema.string().required(true)))
.build();
}
@Override
public Mono<ToolResponse> handle(JsonNode args) {
String query = args.get("query").asText();
return searchService.search(query)
.map(results -> ToolResponse.success()
.addTextContent(results)
.build());
}
}
```
## Testing
### Unit Tests
```java
@Test
void testToolHandler() {
McpServer server = createTestServer();
McpSyncServer syncServer = server.toSyncServer();
ObjectNode args = new ObjectMapper().createObjectNode()
.put("key", "value");
ToolResponse response = syncServer.callTool("test", args);
assertFalse(response.isError());
assertEquals(1, response.getContent().size());
}
```
### Reactive Tests
```java
@Test
void testReactiveHandler() {
Mono<ToolResponse> result = toolHandler.handle(args);
StepVerifier.create(result)
.expectNextMatches(response -> !response.isError())
.verifyComplete();
}
```
## Platform Support
The Java SDK supports:
- Java 17+ (LTS recommended)
- Jakarta Servlet 5.0+
- Spring Boot 3.0+
- Project Reactor 3.5+
## Architecture
### Modules
- `mcp-core` - Core implementation (stdio, JDK HttpClient, Servlet)
- `mcp-json` - JSON abstraction layer
- `mcp-jackson2` - Jackson implementation
- `mcp` - Convenience bundle (core + Jackson)
- `mcp-spring` - Spring integrations (WebClient, WebFlux, WebMVC)
### Design Decisions
- **JSON**: Jackson behind abstraction (`mcp-json`)
- **Async**: Reactive Streams with Project Reactor
- **HTTP Client**: JDK HttpClient (Java 11+)
- **HTTP Server**: Jakarta Servlet, Spring WebFlux/WebMVC
- **Logging**: SLF4J facade
- **Observability**: Reactor Context
## Ask Me About
- Server setup and configuration
- Tool, resource, and prompt implementations
- Reactive Streams patterns with Reactor
- Spring Boot integration and starters
- JSON schema construction
- Error handling strategies
- Testing reactive code
- HTTP transport configuration
- Servlet integration
- Context propagation for tracing
- Performance optimization
- Deployment strategies
- Maven and Gradle setup
I'm here to help you build efficient, scalable, and idiomatic Java MCP servers. What would you like to work on?

View File

@ -0,0 +1,35 @@
id: java-mcp-development
name: Java MCP Server Development
description: 'Complete toolkit for building Model Context Protocol servers in Java using the official MCP Java SDK with reactive streams and Spring Boot integration.'
tags: [java, mcp, model-context-protocol, server-development, sdk, reactive-streams, spring-boot, reactor]
items:
- path: instructions/java-mcp-server.instructions.md
kind: instruction
- path: prompts/java-mcp-server-generator.prompt.md
kind: prompt
- path: chatmodes/java-mcp-expert.chatmode.md
kind: chat-mode
usage: |
recommended
This chat mode provides expert guidance for building MCP servers in Java.
This chat mode is ideal for:
- Creating new MCP server projects with Java
- Implementing reactive handlers with Project Reactor
- Setting up stdio or HTTP transports
- Debugging reactive streams and error handling
- Learning Java MCP best practices with the official SDK
- Integrating with Spring Boot applications
To get the best results, consider:
- Using the instruction file to set context for Java MCP development
- Using the prompt to generate initial project structure
- Switching to the expert chat mode for detailed implementation help
- Specifying whether you need Maven or Gradle
- Providing details about what tools or functionality you need
- Mentioning if you need Spring Boot integration
display:
ordering: manual
show_badge: true

View File

@ -0,0 +1,41 @@
# Java MCP Server Development
'Complete toolkit for building Model Context Protocol servers in Java using the official MCP Java SDK with reactive streams and Spring Boot integration.'
**Tags:** java, mcp, model-context-protocol, server-development, sdk, reactive-streams, spring-boot, reactor
## Items in this Collection
| Title | Type | Description |
| ----- | ---- | ----------- |
| [Java MCP Server Development Guidelines](../instructions/java-mcp-server.instructions.md)<br />[![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-mcp-server.instructions.md)<br />[![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-mcp-server.instructions.md) | Instruction | Best practices and patterns for building Model Context Protocol (MCP) servers in Java using the official MCP Java SDK with reactive streams and Spring integration. |
| [Java MCP Server Generator](../prompts/java-mcp-server-generator.prompt.md)<br />[![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-mcp-server-generator.prompt.md)<br />[![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-mcp-server-generator.prompt.md) | Prompt | Generate a complete Model Context Protocol server project in Java using the official MCP Java SDK with reactive streams and optional Spring Boot integration. |
| [Java MCP Expert](../chatmodes/java-mcp-expert.chatmode.md)<br />[![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%2Fjava-mcp-expert.chatmode.md)<br />[![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%2Fjava-mcp-expert.chatmode.md) | Chat Mode | Expert assistance for building Model Context Protocol servers in Java using reactive streams, the official MCP Java SDK, and Spring Boot integration. [see usage](#java-mcp-expert) |
## Collection Usage
### Java MCP Expert
recommended
This chat mode provides expert guidance for building MCP servers in Java.
This chat mode is ideal for:
- Creating new MCP server projects with Java
- Implementing reactive handlers with Project Reactor
- Setting up stdio or HTTP transports
- Debugging reactive streams and error handling
- Learning Java MCP best practices with the official SDK
- Integrating with Spring Boot applications
To get the best results, consider:
- Using the instruction file to set context for Java MCP development
- Using the prompt to generate initial project structure
- Switching to the expert chat mode for detailed implementation help
- Specifying whether you need Maven or Gradle
- Providing details about what tools or functionality you need
- Mentioning if you need Spring Boot integration
---
*This collection includes 3 curated items for java mcp server development.*

View File

@ -0,0 +1,553 @@
---
description: 'Best practices and patterns for building Model Context Protocol (MCP) servers in Java using the official MCP Java SDK with reactive streams and Spring integration.'
applyTo: "**/*.java, **/pom.xml, **/build.gradle, **/build.gradle.kts"
---
# Java MCP Server Development Guidelines
When building MCP servers in Java, follow these best practices and patterns using the official Java SDK.
## Dependencies
Add the MCP Java SDK to your Maven project:
```xml
<dependencies>
<dependency>
<groupId>io.modelcontextprotocol.sdk</groupId>
<artifactId>mcp</artifactId>
<version>0.14.1</version>
</dependency>
</dependencies>
```
Or for Gradle:
```kotlin
dependencies {
implementation("io.modelcontextprotocol.sdk:mcp:0.14.1")
}
```
## Server Setup
Create an MCP server using the builder pattern:
```java
import io.mcp.server.McpServer;
import io.mcp.server.McpServerBuilder;
import io.mcp.server.transport.StdioServerTransport;
McpServer server = McpServerBuilder.builder()
.serverInfo("my-server", "1.0.0")
.capabilities(capabilities -> capabilities
.tools(true)
.resources(true)
.prompts(true))
.build();
// Start with stdio transport
StdioServerTransport transport = new StdioServerTransport();
server.start(transport).subscribe();
```
## Adding Tools
Register tool handlers with the server:
```java
import io.mcp.server.tool.Tool;
import io.mcp.server.tool.ToolHandler;
import reactor.core.publisher.Mono;
// Define a tool
Tool searchTool = Tool.builder()
.name("search")
.description("Search for information")
.inputSchema(JsonSchema.object()
.property("query", JsonSchema.string()
.description("Search query")
.required(true))
.property("limit", JsonSchema.integer()
.description("Maximum results")
.defaultValue(10)))
.build();
// Register tool handler
server.addToolHandler("search", (arguments) -> {
String query = arguments.get("query").asText();
int limit = arguments.has("limit")
? arguments.get("limit").asInt()
: 10;
// Perform search
List<String> results = performSearch(query, limit);
return Mono.just(ToolResponse.success()
.addTextContent("Found " + results.size() + " results")
.build());
});
```
## Adding Resources
Implement resource handlers for data access:
```java
import io.mcp.server.resource.Resource;
import io.mcp.server.resource.ResourceHandler;
// Register resource list handler
server.addResourceListHandler(() -> {
List<Resource> resources = List.of(
Resource.builder()
.name("Data File")
.uri("resource://data/example.txt")
.description("Example data file")
.mimeType("text/plain")
.build()
);
return Mono.just(resources);
});
// Register resource read handler
server.addResourceReadHandler((uri) -> {
if (uri.equals("resource://data/example.txt")) {
String content = loadResourceContent(uri);
return Mono.just(ResourceContent.text(content, uri));
}
throw new ResourceNotFoundException(uri);
});
// Register resource subscribe handler
server.addResourceSubscribeHandler((uri) -> {
subscriptions.add(uri);
log.info("Client subscribed to {}", uri);
return Mono.empty();
});
```
## Adding Prompts
Implement prompt handlers for templated conversations:
```java
import io.mcp.server.prompt.Prompt;
import io.mcp.server.prompt.PromptMessage;
import io.mcp.server.prompt.PromptArgument;
// Register prompt list handler
server.addPromptListHandler(() -> {
List<Prompt> prompts = List.of(
Prompt.builder()
.name("analyze")
.description("Analyze a topic")
.argument(PromptArgument.builder()
.name("topic")
.description("Topic to analyze")
.required(true)
.build())
.argument(PromptArgument.builder()
.name("depth")
.description("Analysis depth")
.required(false)
.build())
.build()
);
return Mono.just(prompts);
});
// Register prompt get handler
server.addPromptGetHandler((name, arguments) -> {
if (name.equals("analyze")) {
String topic = arguments.getOrDefault("topic", "general");
String depth = arguments.getOrDefault("depth", "basic");
List<PromptMessage> messages = List.of(
PromptMessage.user("Please analyze this topic: " + topic),
PromptMessage.assistant("I'll provide a " + depth + " analysis of " + topic)
);
return Mono.just(PromptResult.builder()
.description("Analysis of " + topic + " at " + depth + " level")
.messages(messages)
.build());
}
throw new PromptNotFoundException(name);
});
```
## Reactive Streams Pattern
The Java SDK uses Reactive Streams (Project Reactor) for asynchronous processing:
```java
// Return Mono for single results
server.addToolHandler("process", (args) -> {
return Mono.fromCallable(() -> {
String result = expensiveOperation(args);
return ToolResponse.success()
.addTextContent(result)
.build();
}).subscribeOn(Schedulers.boundedElastic());
});
// Return Flux for streaming results
server.addResourceListHandler(() -> {
return Flux.fromIterable(getResources())
.map(r -> Resource.builder()
.uri(r.getUri())
.name(r.getName())
.build())
.collectList();
});
```
## Synchronous Facade
For blocking use cases, use the synchronous API:
```java
import io.mcp.server.McpSyncServer;
McpSyncServer syncServer = server.toSyncServer();
// Blocking tool handler
syncServer.addToolHandler("greet", (args) -> {
String name = args.get("name").asText();
return ToolResponse.success()
.addTextContent("Hello, " + name + "!")
.build();
});
```
## Transport Configuration
### Stdio Transport
For local subprocess communication:
```java
import io.mcp.server.transport.StdioServerTransport;
StdioServerTransport transport = new StdioServerTransport();
server.start(transport).block();
```
### HTTP Transport (Servlet)
For HTTP-based servers:
```java
import io.mcp.server.transport.ServletServerTransport;
import jakarta.servlet.http.HttpServlet;
public class McpServlet extends HttpServlet {
private final McpServer server;
private final ServletServerTransport transport;
public McpServlet() {
this.server = createMcpServer();
this.transport = new ServletServerTransport();
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
transport.handleRequest(server, req, resp).block();
}
}
```
## Spring Boot Integration
Use the Spring Boot starter for seamless integration:
```xml
<dependency>
<groupId>io.modelcontextprotocol.sdk</groupId>
<artifactId>mcp-spring-boot-starter</artifactId>
<version>0.14.1</version>
</dependency>
```
Configure the server with Spring:
```java
import org.springframework.context.annotation.Configuration;
import io.mcp.spring.McpServerConfigurer;
@Configuration
public class McpConfiguration {
@Bean
public McpServerConfigurer mcpServerConfigurer() {
return server -> server
.serverInfo("spring-server", "1.0.0")
.capabilities(cap -> cap
.tools(true)
.resources(true)
.prompts(true));
}
}
```
Register handlers as Spring beans:
```java
import org.springframework.stereotype.Component;
import io.mcp.spring.ToolHandler;
@Component
public class SearchToolHandler implements ToolHandler {
@Override
public String getName() {
return "search";
}
@Override
public Tool getTool() {
return Tool.builder()
.name("search")
.description("Search for information")
.inputSchema(JsonSchema.object()
.property("query", JsonSchema.string().required(true)))
.build();
}
@Override
public Mono<ToolResponse> handle(JsonNode arguments) {
String query = arguments.get("query").asText();
return Mono.just(ToolResponse.success()
.addTextContent("Search results for: " + query)
.build());
}
}
```
## Error Handling
Use proper error handling with MCP exceptions:
```java
server.addToolHandler("risky", (args) -> {
return Mono.fromCallable(() -> {
try {
String result = riskyOperation(args);
return ToolResponse.success()
.addTextContent(result)
.build();
} catch (ValidationException e) {
return ToolResponse.error()
.message("Invalid input: " + e.getMessage())
.build();
} catch (Exception e) {
log.error("Unexpected error", e);
return ToolResponse.error()
.message("Internal error occurred")
.build();
}
});
});
```
## JSON Schema Construction
Use the fluent schema builder:
```java
import io.mcp.json.JsonSchema;
JsonSchema schema = JsonSchema.object()
.property("name", JsonSchema.string()
.description("User's name")
.minLength(1)
.maxLength(100)
.required(true))
.property("age", JsonSchema.integer()
.description("User's age")
.minimum(0)
.maximum(150))
.property("email", JsonSchema.string()
.description("Email address")
.format("email")
.required(true))
.property("tags", JsonSchema.array()
.items(JsonSchema.string())
.uniqueItems(true))
.additionalProperties(false)
.build();
```
## Logging and Observability
Use SLF4J for logging:
```java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger log = LoggerFactory.getLogger(MyMcpServer.class);
server.addToolHandler("process", (args) -> {
log.info("Tool called: process, args: {}", args);
return Mono.fromCallable(() -> {
String result = process(args);
log.debug("Processing completed successfully");
return ToolResponse.success()
.addTextContent(result)
.build();
}).doOnError(error -> {
log.error("Processing failed", error);
});
});
```
Propagate context with Reactor:
```java
import reactor.util.context.Context;
server.addToolHandler("traced", (args) -> {
return Mono.deferContextual(ctx -> {
String traceId = ctx.get("traceId");
log.info("Processing with traceId: {}", traceId);
return Mono.just(ToolResponse.success()
.addTextContent("Processed")
.build());
});
});
```
## Testing
Write tests using the synchronous API:
```java
import org.junit.jupiter.api.Test;
import static org.assertj.core.Assertions.assertThat;
class McpServerTest {
@Test
void testToolHandler() {
McpServer server = createTestServer();
McpSyncServer syncServer = server.toSyncServer();
JsonNode args = objectMapper.createObjectNode()
.put("query", "test");
ToolResponse response = syncServer.callTool("search", args);
assertThat(response.isError()).isFalse();
assertThat(response.getContent()).hasSize(1);
}
}
```
## Jackson Integration
The SDK uses Jackson for JSON serialization. Customize as needed:
```java
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
// Use custom mapper with server
McpServer server = McpServerBuilder.builder()
.objectMapper(mapper)
.build();
```
## Content Types
Support multiple content types in responses:
```java
import io.mcp.server.content.Content;
server.addToolHandler("multi", (args) -> {
return Mono.just(ToolResponse.success()
.addTextContent("Plain text response")
.addImageContent(imageBytes, "image/png")
.addResourceContent("resource://data", "application/json", jsonData)
.build());
});
```
## Server Lifecycle
Properly manage server lifecycle:
```java
import reactor.core.Disposable;
Disposable serverDisposable = server.start(transport).subscribe();
// Graceful shutdown
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
log.info("Shutting down MCP server");
serverDisposable.dispose();
server.stop().block();
}));
```
## Common Patterns
### Request Validation
```java
server.addToolHandler("validate", (args) -> {
if (!args.has("required_field")) {
return Mono.just(ToolResponse.error()
.message("Missing required_field")
.build());
}
return processRequest(args);
});
```
### Async Operations
```java
server.addToolHandler("async", (args) -> {
return Mono.fromCallable(() -> callExternalApi(args))
.timeout(Duration.ofSeconds(30))
.onErrorResume(TimeoutException.class, e ->
Mono.just(ToolResponse.error()
.message("Operation timed out")
.build()))
.subscribeOn(Schedulers.boundedElastic());
});
```
### Resource Caching
```java
private final Map<String, String> cache = new ConcurrentHashMap<>();
server.addResourceReadHandler((uri) -> {
return Mono.fromCallable(() ->
cache.computeIfAbsent(uri, this::loadResource))
.map(content -> ResourceContent.text(content, uri));
});
```
## Best Practices
1. **Use Reactive Streams** for async operations and backpressure
2. **Leverage Spring Boot** starter for enterprise applications
3. **Implement proper error handling** with specific error messages
4. **Use SLF4J** for logging, not System.out
5. **Validate inputs** in tool and prompt handlers
6. **Support graceful shutdown** with proper resource cleanup
7. **Use bounded elastic scheduler** for blocking operations
8. **Propagate context** for observability in reactive chains
9. **Test with synchronous API** for simplicity
10. **Follow Java naming conventions** (camelCase for methods, PascalCase for classes)

View File

@ -0,0 +1,756 @@
---
description: 'Generate a complete Model Context Protocol server project in Java using the official MCP Java SDK with reactive streams and optional Spring Boot integration.'
mode: agent
---
# Java MCP Server Generator
Generate a complete, production-ready MCP server in Java using the official Java SDK with Maven or Gradle.
## Project Generation
When asked to create a Java MCP server, generate a complete project with this structure:
```
my-mcp-server/
├── pom.xml (or build.gradle.kts)
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── com/example/mcp/
│ │ │ ├── McpServerApplication.java
│ │ │ ├── config/
│ │ │ │ └── ServerConfiguration.java
│ │ │ ├── tools/
│ │ │ │ ├── ToolDefinitions.java
│ │ │ │ └── ToolHandlers.java
│ │ │ ├── resources/
│ │ │ │ ├── ResourceDefinitions.java
│ │ │ │ └── ResourceHandlers.java
│ │ │ └── prompts/
│ │ │ ├── PromptDefinitions.java
│ │ │ └── PromptHandlers.java
│ │ └── resources/
│ │ └── application.properties (if using Spring)
│ └── test/
│ └── java/
│ └── com/example/mcp/
│ └── McpServerTest.java
└── README.md
```
## Maven pom.xml Template
```xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>my-mcp-server</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>My MCP Server</name>
<description>Model Context Protocol server implementation</description>
<properties>
<java.version>17</java.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mcp.version>0.14.1</mcp.version>
<slf4j.version>2.0.9</slf4j.version>
<logback.version>1.4.11</logback.version>
<junit.version>5.10.0</junit.version>
</properties>
<dependencies>
<!-- MCP Java SDK -->
<dependency>
<groupId>io.modelcontextprotocol.sdk</groupId>
<artifactId>mcp</artifactId>
<version>${mcp.version}</version>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<!-- Testing -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.example.mcp.McpServerApplication</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
```
## Gradle build.gradle.kts Template
```kotlin
plugins {
id("java")
id("application")
}
group = "com.example"
version = "1.0.0"
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
repositories {
mavenCentral()
}
dependencies {
// MCP Java SDK
implementation("io.modelcontextprotocol.sdk:mcp:0.14.1")
// Logging
implementation("org.slf4j:slf4j-api:2.0.9")
implementation("ch.qos.logback:logback-classic:1.4.11")
// Testing
testImplementation("org.junit.jupiter:junit-jupiter:5.10.0")
testImplementation("io.projectreactor:reactor-test:3.5.0")
}
application {
mainClass.set("com.example.mcp.McpServerApplication")
}
tasks.test {
useJUnitPlatform()
}
```
## McpServerApplication.java Template
```java
package com.example.mcp;
import com.example.mcp.tools.ToolHandlers;
import com.example.mcp.resources.ResourceHandlers;
import com.example.mcp.prompts.PromptHandlers;
import io.mcp.server.McpServer;
import io.mcp.server.McpServerBuilder;
import io.mcp.server.transport.StdioServerTransport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.Disposable;
public class McpServerApplication {
private static final Logger log = LoggerFactory.getLogger(McpServerApplication.class);
public static void main(String[] args) {
log.info("Starting MCP Server...");
try {
McpServer server = createServer();
StdioServerTransport transport = new StdioServerTransport();
// Start server
Disposable serverDisposable = server.start(transport).subscribe();
// Graceful shutdown
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
log.info("Shutting down MCP server");
serverDisposable.dispose();
server.stop().block();
}));
log.info("MCP Server started successfully");
// Keep running
Thread.currentThread().join();
} catch (Exception e) {
log.error("Failed to start MCP server", e);
System.exit(1);
}
}
private static McpServer createServer() {
McpServer server = McpServerBuilder.builder()
.serverInfo("my-mcp-server", "1.0.0")
.capabilities(capabilities -> capabilities
.tools(true)
.resources(true)
.prompts(true))
.build();
// Register handlers
ToolHandlers.register(server);
ResourceHandlers.register(server);
PromptHandlers.register(server);
return server;
}
}
```
## ToolDefinitions.java Template
```java
package com.example.mcp.tools;
import io.mcp.json.JsonSchema;
import io.mcp.server.tool.Tool;
import java.util.List;
public class ToolDefinitions {
public static List<Tool> getTools() {
return List.of(
createGreetTool(),
createCalculateTool()
);
}
private static Tool createGreetTool() {
return Tool.builder()
.name("greet")
.description("Generate a greeting message")
.inputSchema(JsonSchema.object()
.property("name", JsonSchema.string()
.description("Name to greet")
.required(true)))
.build();
}
private static Tool createCalculateTool() {
return Tool.builder()
.name("calculate")
.description("Perform mathematical calculations")
.inputSchema(JsonSchema.object()
.property("operation", JsonSchema.string()
.description("Operation to perform")
.enumValues(List.of("add", "subtract", "multiply", "divide"))
.required(true))
.property("a", JsonSchema.number()
.description("First operand")
.required(true))
.property("b", JsonSchema.number()
.description("Second operand")
.required(true)))
.build();
}
}
```
## ToolHandlers.java Template
```java
package com.example.mcp.tools;
import com.fasterxml.jackson.databind.JsonNode;
import io.mcp.server.McpServer;
import io.mcp.server.tool.ToolResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Mono;
public class ToolHandlers {
private static final Logger log = LoggerFactory.getLogger(ToolHandlers.class);
public static void register(McpServer server) {
// Register tool list handler
server.addToolListHandler(() -> {
log.debug("Listing available tools");
return Mono.just(ToolDefinitions.getTools());
});
// Register greet handler
server.addToolHandler("greet", ToolHandlers::handleGreet);
// Register calculate handler
server.addToolHandler("calculate", ToolHandlers::handleCalculate);
}
private static Mono<ToolResponse> handleGreet(JsonNode arguments) {
log.info("Greet tool called");
if (!arguments.has("name")) {
return Mono.just(ToolResponse.error()
.message("Missing 'name' parameter")
.build());
}
String name = arguments.get("name").asText();
String greeting = "Hello, " + name + "! Welcome to MCP.";
log.debug("Generated greeting for: {}", name);
return Mono.just(ToolResponse.success()
.addTextContent(greeting)
.build());
}
private static Mono<ToolResponse> handleCalculate(JsonNode arguments) {
log.info("Calculate tool called");
if (!arguments.has("operation") || !arguments.has("a") || !arguments.has("b")) {
return Mono.just(ToolResponse.error()
.message("Missing required parameters")
.build());
}
String operation = arguments.get("operation").asText();
double a = arguments.get("a").asDouble();
double b = arguments.get("b").asDouble();
double result;
switch (operation) {
case "add":
result = a + b;
break;
case "subtract":
result = a - b;
break;
case "multiply":
result = a * b;
break;
case "divide":
if (b == 0) {
return Mono.just(ToolResponse.error()
.message("Division by zero")
.build());
}
result = a / b;
break;
default:
return Mono.just(ToolResponse.error()
.message("Unknown operation: " + operation)
.build());
}
log.debug("Calculation: {} {} {} = {}", a, operation, b, result);
return Mono.just(ToolResponse.success()
.addTextContent("Result: " + result)
.build());
}
}
```
## ResourceDefinitions.java Template
```java
package com.example.mcp.resources;
import io.mcp.server.resource.Resource;
import java.util.List;
public class ResourceDefinitions {
public static List<Resource> getResources() {
return List.of(
Resource.builder()
.name("Example Data")
.uri("resource://data/example")
.description("Example resource data")
.mimeType("application/json")
.build(),
Resource.builder()
.name("Configuration")
.uri("resource://config")
.description("Server configuration")
.mimeType("application/json")
.build()
);
}
}
```
## ResourceHandlers.java Template
```java
package com.example.mcp.resources;
import io.mcp.server.McpServer;
import io.mcp.server.resource.ResourceContent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Mono;
import java.time.Instant;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class ResourceHandlers {
private static final Logger log = LoggerFactory.getLogger(ResourceHandlers.class);
private static final Map<String, Boolean> subscriptions = new ConcurrentHashMap<>();
public static void register(McpServer server) {
// Register resource list handler
server.addResourceListHandler(() -> {
log.debug("Listing available resources");
return Mono.just(ResourceDefinitions.getResources());
});
// Register resource read handler
server.addResourceReadHandler(ResourceHandlers::handleRead);
// Register resource subscribe handler
server.addResourceSubscribeHandler(ResourceHandlers::handleSubscribe);
// Register resource unsubscribe handler
server.addResourceUnsubscribeHandler(ResourceHandlers::handleUnsubscribe);
}
private static Mono<ResourceContent> handleRead(String uri) {
log.info("Reading resource: {}", uri);
switch (uri) {
case "resource://data/example":
String jsonData = String.format(
"{\"message\":\"Example resource data\",\"timestamp\":\"%s\"}",
Instant.now()
);
return Mono.just(ResourceContent.text(jsonData, uri, "application/json"));
case "resource://config":
String config = "{\"serverName\":\"my-mcp-server\",\"version\":\"1.0.0\"}";
return Mono.just(ResourceContent.text(config, uri, "application/json"));
default:
log.warn("Unknown resource requested: {}", uri);
return Mono.error(new IllegalArgumentException("Unknown resource URI: " + uri));
}
}
private static Mono<Void> handleSubscribe(String uri) {
log.info("Client subscribed to resource: {}", uri);
subscriptions.put(uri, true);
return Mono.empty();
}
private static Mono<Void> handleUnsubscribe(String uri) {
log.info("Client unsubscribed from resource: {}", uri);
subscriptions.remove(uri);
return Mono.empty();
}
}
```
## PromptDefinitions.java Template
```java
package com.example.mcp.prompts;
import io.mcp.server.prompt.Prompt;
import io.mcp.server.prompt.PromptArgument;
import java.util.List;
public class PromptDefinitions {
public static List<Prompt> getPrompts() {
return List.of(
Prompt.builder()
.name("code-review")
.description("Generate a code review prompt")
.argument(PromptArgument.builder()
.name("language")
.description("Programming language")
.required(true)
.build())
.argument(PromptArgument.builder()
.name("focus")
.description("Review focus area")
.required(false)
.build())
.build()
);
}
}
```
## PromptHandlers.java Template
```java
package com.example.mcp.prompts;
import io.mcp.server.McpServer;
import io.mcp.server.prompt.PromptMessage;
import io.mcp.server.prompt.PromptResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Mono;
import java.util.List;
import java.util.Map;
public class PromptHandlers {
private static final Logger log = LoggerFactory.getLogger(PromptHandlers.class);
public static void register(McpServer server) {
// Register prompt list handler
server.addPromptListHandler(() -> {
log.debug("Listing available prompts");
return Mono.just(PromptDefinitions.getPrompts());
});
// Register prompt get handler
server.addPromptGetHandler(PromptHandlers::handleCodeReview);
}
private static Mono<PromptResult> handleCodeReview(String name, Map<String, String> arguments) {
log.info("Getting prompt: {}", name);
if (!name.equals("code-review")) {
return Mono.error(new IllegalArgumentException("Unknown prompt: " + name));
}
String language = arguments.getOrDefault("language", "Java");
String focus = arguments.getOrDefault("focus", "general quality");
String description = "Code review for " + language + " with focus on " + focus;
List<PromptMessage> messages = List.of(
PromptMessage.user("Please review this " + language + " code with focus on " + focus + "."),
PromptMessage.assistant("I'll review the code focusing on " + focus + ". Please share the code."),
PromptMessage.user("Here's the code to review: [paste code here]")
);
log.debug("Generated code review prompt for {} ({})", language, focus);
return Mono.just(PromptResult.builder()
.description(description)
.messages(messages)
.build());
}
}
```
## McpServerTest.java Template
```java
package com.example.mcp;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.mcp.server.McpServer;
import io.mcp.server.McpSyncServer;
import io.mcp.server.tool.ToolResponse;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class McpServerTest {
private McpSyncServer syncServer;
private ObjectMapper objectMapper;
@BeforeEach
void setUp() {
McpServer server = createTestServer();
syncServer = server.toSyncServer();
objectMapper = new ObjectMapper();
}
private McpServer createTestServer() {
// Same setup as main application
McpServer server = McpServerBuilder.builder()
.serverInfo("test-server", "1.0.0")
.capabilities(cap -> cap.tools(true))
.build();
// Register handlers
ToolHandlers.register(server);
return server;
}
@Test
void testGreetTool() {
ObjectNode args = objectMapper.createObjectNode();
args.put("name", "Java");
ToolResponse response = syncServer.callTool("greet", args);
assertFalse(response.isError());
assertEquals(1, response.getContent().size());
assertTrue(response.getContent().get(0).getText().contains("Java"));
}
@Test
void testCalculateTool() {
ObjectNode args = objectMapper.createObjectNode();
args.put("operation", "add");
args.put("a", 5);
args.put("b", 3);
ToolResponse response = syncServer.callTool("calculate", args);
assertFalse(response.isError());
assertTrue(response.getContent().get(0).getText().contains("8"));
}
@Test
void testDivideByZero() {
ObjectNode args = objectMapper.createObjectNode();
args.put("operation", "divide");
args.put("a", 10);
args.put("b", 0);
ToolResponse response = syncServer.callTool("calculate", args);
assertTrue(response.isError());
}
}
```
## README.md Template
```markdown
# My MCP Server
A Model Context Protocol server built with Java and the official MCP Java SDK.
## Features
- ✅ Tools: greet, calculate
- ✅ Resources: example data, configuration
- ✅ Prompts: code-review
- ✅ Reactive Streams with Project Reactor
- ✅ Structured logging with SLF4J
- ✅ Full test coverage
## Requirements
- Java 17 or later
- Maven 3.6+ or Gradle 7+
## Build
### Maven
```bash
mvn clean package
```
### Gradle
```bash
./gradlew build
```
## Run
### Maven
```bash
java -jar target/my-mcp-server-1.0.0.jar
```
### Gradle
```bash
./gradlew run
```
## Testing
### Maven
```bash
mvn test
```
### Gradle
```bash
./gradlew test
```
## Integration with Claude Desktop
Add to `claude_desktop_config.json`:
```json
{
"mcpServers": {
"my-mcp-server": {
"command": "java",
"args": ["-jar", "/path/to/my-mcp-server-1.0.0.jar"]
}
}
}
```
## License
MIT
```
## Generation Instructions
1. **Ask for project name and package**
2. **Choose build tool** (Maven or Gradle)
3. **Generate all files** with proper package structure
4. **Use Reactive Streams** for async handlers
5. **Include comprehensive logging** with SLF4J
6. **Add tests** for all handlers
7. **Follow Java conventions** (camelCase, PascalCase)
8. **Include error handling** with proper responses
9. **Document public APIs** with Javadoc
10. **Provide both sync and async** examples