Index of every page on this site: llms.txt
All skills
github avatar

/java-mcp-server-generator

@f10fdb8 official
by githubgithub/awesome-copilot41k stars
5,399
Run it yourself

Use this skill when the user wants to create a Model Context Protocol (MCP) server in Java or in a Spring Boot app. Also use it when the user wants AI agents, such as GitHub Copilot or Claude, to use Java code, an API, or a database. Use it even if the user does not say "MCP". The skill makes a Maven or Gradle project with the MCP Java SDK 2.x, tools, JUnit tests, and client configuration. Do not use it for Quarkus/Quarkiverse MCP servers (use the `quarkus-mcp-server-sse` instruction), for an MCP client or for a server in another language.

Use this Skill: https://skilld.dev/gh/github/awesome-copilot/java-mcp-server-generator

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesstreamable-http.md

≈1.3k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Streamable HTTP Servers

Use this transport only for a remote server. A local server uses stdio.

Servlet server

HttpServletStreamableServerTransportProvider is a Jakarta Servlet. It is in the mcp artifact. Add a servlet container to pom.xml, for example embedded Tomcat:

<dependency>
  <groupId>org.apache.tomcat.embed</groupId>
  <artifactId>tomcat-embed-core</artifactId>
  <version>11.0.26</version>
</dependency>

In Gradle, add implementation("org.apache.tomcat.embed:tomcat-embed-core:11.0.26").

Replace the main method in McpServerApp.java:

public static void main(String[] args) throws Exception {
    int port = Integer.parseInt(System.getenv().getOrDefault("PORT", "8080"));

    HttpServletStreamableServerTransportProvider transport = HttpServletStreamableServerTransportProvider.builder()
            .jsonMapper(McpJsonDefaults.getMapper())
            .mcpEndpoint("/mcp")
            .securityValidator(DefaultServerTransportSecurityValidator.builder()
                    .allowedHost("localhost:" + port)
                    .allowedHost("127.0.0.1:" + port)
                    .allowedOrigin("http://localhost:*")
                    .build())
            .build();

    McpServer.sync(transport)
            .serverInfo("demo", "0.1.0")
            .capabilities(ServerCapabilities.builder().tools(false).build())
            .tools(divideTool())
            .build();

    Tomcat tomcat = new Tomcat();
    tomcat.setPort(port);
    tomcat.getConnector();
    Context context = tomcat.addContext("", null);
    Tomcat.addServlet(context, "mcp", transport).setAsyncSupported(true);
    context.addServletMappingDecoded("/mcp", "mcp");
    tomcat.start();
    tomcat.getServer().await();
}

Add these imports: org.apache.catalina.Context, org.apache.catalina.startup.Tomcat, io.modelcontextprotocol.server.transport.DefaultServerTransportSecurityValidator, and io.modelcontextprotocol.server.transport.HttpServletStreamableServerTransportProvider. Remove the import of StdioServerTransportProvider.

Clients connect to http://HOST:PORT/mcp. For VS Code, write .vscode/mcp.json:

{
  "servers": {
    "demo": {
      "type": "http",
      "url": "http://localhost:8080/mcp"
    }
  }
}

Spring Boot server

Use the MCP starters of Spring AI 2.0 or later. Spring AI 2.0 uses Spring Boot 4. Use spring-boot-starter-parent 4.0.x. Import org.springframework.ai:spring-ai-bom version 2.0.1 and add spring-ai-starter-mcp-server-webmvc. For WebFlux, add spring-ai-starter-mcp-server-webflux.

Write the tools as annotated methods on a Spring bean:

@Component
class CalculatorTools {

    @McpTool(name = "add", description = "Add two integers")
    public int add(@McpToolParam(description = "First number") int a,
            @McpToolParam(description = "Second number") int b) {
        return a + b;
    }
}

The annotations are in org.springframework.ai.mcp.annotation. Set the server identity and the transport in application.properties:

spring.ai.mcp.server.name=demo
spring.ai.mcp.server.version=0.1.0
spring.ai.mcp.server.protocol=STREAMABLE

The starter serves the endpoint at /mcp.

Gotchas

  • The HTTP transports do not check the Host and Origin headers by default. This also applies to the Spring AI starters. Without a check, a malicious web page can use DNS rebinding to call a local server. Always set securityValidator(DefaultServerTransportSecurityValidator.builder()...build()). The validator rejects an unknown Origin with HTTP 403 and an unknown Host with HTTP 421.

  • In Spring AI, declare your own WebMvcStreamableServerTransportProvider bean to set the validator. The starter then does not make its own bean:

    @Bean
    WebMvcStreamableServerTransportProvider webMvcStreamableServerTransportProvider() {
        return WebMvcStreamableServerTransportProvider.builder()
                .jsonMapper(McpJsonDefaults.getMapper())
                .mcpEndpoint("/mcp")
                .securityValidator(DefaultServerTransportSecurityValidator.builder()
                        .allowedHost("localhost:8080")
                        .allowedOrigin("http://localhost:*")
                        .build())
                .build();
    }
  • For WebFlux, declare a WebFluxStreamableServerTransportProvider bean in the same way. Its builder uses messageEndpoint("/mcp"), not mcpEndpoint.

  • Embedded Tomcat listens on all network interfaces. For a public host, add its name to allowedHost. Put authentication in front of the server.

  • The SDK has no authorization. For a remote server, add authorization in a servlet filter or with Spring Security.

  • HttpServletStatelessServerTransport makes a server without sessions. Use it with McpServer.sync(transport) when more than one replica must answer the requests. A stateless server cannot send requests to the client. Also set securityValidator on its builder.

  • For browser clients, add CORS to the servlet container. Allow the Mcp-* request headers. Expose the Mcp-Session-Id response header.

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

1 warning28d5 checks · Risk SAFE
  • Gen Agent Trust Hub28d

    This skill provides templates and instructions for generating Model Context Protocol (MCP) servers in Java using Maven or Gradle. It follows standard software development practices, uses official SDK libraries, and includes security-focused guidance for implementing HTTP transports with Host and Origin validation to prevent DNS rebinding attacks.

  • Socket28d

    No alerts

  • Snyk28d

    Risk: LOW · No issues

  • Runlayer8mo

    1/1 file flagged

  • ZeroLeaks7mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at f10fdb8. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated last month
Other metadata
compatibility
JDK 17 or later, Maven 3.9 or later or Gradle 9 or later, and network access to download dependencies. The MCP Inspector also uses Node.js.
  • MCP
  • java
  • model-context-protocol
  • sdk
  • maven
  • gradle
  • reactive
  • spring-boot

README badge

README badge for github/awesome-copilot/java-mcp-server-generator

Generates a complete Model Context Protocol server project in Java using the official MCP Java SDK with Maven or Gradle build configuration. Includes templates for tool, resource, and prompt handlers with reactive streams support via Project Reactor.

Generated from the current SKILL.md.

Does this skill support both Maven and Gradle?
Yes. The skill provides complete templates for both Maven (pom.xml) and Gradle (build.gradle.kts) project setups.
What Java version is required?
Java 17 or later. Both the Maven and Gradle templates target Java 17 as the minimum version.
Does this use the official MCP Java SDK?
Yes. The skill generates projects using the official Model Context Protocol Java SDK (io.modelcontextprotocol.sdk:mcp).
Can I use Spring Boot with this skill?
The skill mentions optional Spring Boot integration but does not provide Spring Boot-specific templates or configuration in the SKILL.md content shown.
What capabilities does the generated server support?
The generated server supports tools, resources, and prompts as core MCP capabilities, with handlers for each included in the templates.

Generated from the current SKILL.md. These answers refresh after source changes.