8000 GitHub - ingorewho/mcp-declarative-java-sdk: Annotation-driven MCP (Model Context Protocol) Development with Java - No Spring Framework Required
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

ingorewho/mcp-declarative-java-sdk

 
 

Repository files navigation

Annotation-driven MCP Java SDK

Declarative MCP Java SDK Development with Java Annotations - No Spring Framework Required.

Focus on your core logic (resources/prompts/tools) - Not SDK low-level details. Instant MCP Java server in 1 LOC.

Showcase

Just put this one line code in your main method:

// You can use this annotation to specify the base package
// to scan for MCP resources, prompts, tools, but it's not required.
@McpComponentScan(basePackage = "com.github.codeboyzhou.mcp.examples")
public class MyMcpServer {

    public static void main(String[] args) {
        // Start a STDIO MCP server
        McpServers.run(MyMcpServer.class, args).startSyncStdioServer("mcp-server", "1.0.0");
        // or a HTTP SSE MCP server
        // McpServers.run(MyMcpServer.class, args).startSyncSseServer("mcp-server", "1.0.0");
    }

}

No need to care about the low-level details of native MCP Java SDK and how to create the MCP resources, prompts, and tools. Just annotate them like this:

@McpResources
public class MyMcpResources {

    // This method defines a MCP resource to expose the OS env variables
    @McpResource(uri = "env://variables", name = "env", description = "OS env variables")
    public String getSystemEnv() {
        // Just put your logic code here, forget about the MCP SDK details.
        return System.getenv().toString();
    }

    // Your other MCP resources here...
}
@McpTools
public class MyMcpTools {

    // This method defines a MCP tool to read a file
    @McpTool(name = "read_file", description = "Read complete file contents with UTF-8 encoding")
    public String readFile(
        @McpToolParam(name = "path", description = "filepath", required = true) String path) {
        // Just put your logic code here, forget about the MCP SDK details.
        return Files.readString(Path.of(path));
    }

    // Your other MCP tools here...
}

Now it’s all set, run your MCP server, choose one MCP client you like and start your MCP exploration journey.

Warning
Please note that this project is under development and is not ready for production use.

Getting Started

Requirements

  • Java 17 or later (Restricted by MCP Java SDK)

Installation

Add the following Maven dependency to your project:

<dependency>
    <groupId>io.github.codeboyzhou</groupId>
    <artifactId>mcp-declarative-java-sdk</artifactId>
    <version>0.1.0</version>
</dependency>

Examples

You can find more examples and usages in this repository.

What is MCP?

The Model Context Protocol (MCP) lets you build servers that expose data and functionality to LLM applications in a secure, standardized way. Think of it like a web API, but specifically designed for LLM interactions. MCP servers can:

  • Expose data through Resources (think of these sort of like GET endpoints; they are used to load information into the LLM’s context)

  • Provide functionality through Tools (sort of like POST endpoints; they are used to execute code or otherwise produce a side effect)

  • Define interaction patterns through Prompts (reusable templates for LLM interactions)

  • And more!

You can start exploring everything about MCP from here.

About

Annotation-driven MCP (Model Context Protocol) Development with Java - No Spring Framework Required

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%
0