mirror of
https://github.com/github/awesome-copilot.git
synced 2026-10-14 15:51:45 +00:00
- Target MCP Java SDK 2.0.1 and specification revision 2025-11-25. - Rewrite the description with user intent triggers and exclusions. - Add the compatibility field. - Add a five-step workflow checklist with a build loop. - Add a Maven template, a stdio server template, and a JUnit test that starts the server as a subprocess with the SDK client. - Add Gotchas for SDK 2.x changes, schema validation, error results, stdout in stdio servers, and the features that SEP-2577 deprecates. - Add references/gradle.md for Gradle projects. - Add references/streamable-http.md for Servlet, Spring AI, and transport security. - Update the skill description in docs/README.skills.md.
2.3 KiB
2.3 KiB
Gradle Projects
Use this file only when the project uses Gradle or the user asks for Gradle. The Java code and the tests do not change.
Create the project
Make this layout. Do not write pom.xml:
project-name/
├── settings.gradle.kts
├── build.gradle.kts
└── src/
├── main/java/com/example/McpServerApp.java
└── test/java/com/example/McpServerAppTest.java
Write settings.gradle.kts:
rootProject.name = "mcp-server-demo"
Write build.gradle.kts:
plugins {
application
}
group = "com.example"
version = "0.1.0"
repositories {
mavenCentral()
}
dependencies {
implementation(platform("io.modelcontextprotocol.sdk:mcp-bom:2.0.1"))
implementation("io.modelcontextprotocol.sdk:mcp")
runtimeOnly("org.slf4j:slf4j-simple:2.0.17")
testImplementation(platform("org.junit:junit-bom:6.1.3"))
testImplementation("org.junit.jupiter:junit-jupiter")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
tasks.withType<JavaCompile> {
options.release = 17
}
application {
mainClass = "com.example.McpServerApp"
}
tasks.test {
useJUnitPlatform()
}
Build until the tests pass
- If the project has no
gradlewfile, rungradle wrapperone time. - Run
./gradlew build installDist. This command compiles the code and runs the tests. It also makes the start scriptbuild/install/mcp-server-demo/bin/mcp-server-demo. - If a test fails, read the error. Fix the server or the test.
- Run
./gradlew build installDistagain. - Continue only when the build is successful.
Configure the client
For VS Code, write .vscode/mcp.json:
{
"servers": {
"demo": {
"type": "stdio",
"command": "/absolute/path/to/project/build/install/mcp-server-demo/bin/mcp-server-demo"
}
}
}
On Windows, use mcp-server-demo.bat.
Gotchas
- Gradle 9 does not add the JUnit Platform launcher. Without
junit-platform-launcher, thetesttask fails. - The
applicationplugin does not make an executable JAR. The JAR inbuild/libshas noMain-Classand no dependencies. Use the start script frominstallDist. - Do not use
./gradlew runas the client command. Theruntask does not send stdin to the server. Gradle also writes its own output to stdout.