- Explore MCP Servers
- mcp-declarative-java-sdk
Mcp Declarative Java Sdk
What is Mcp Declarative Java Sdk
The Model Context Protocol (MCP) is designed to facilitate secure and standardized interactions between servers and large language model (LLM) applications. It allows developers to expose data and functionality through a structured framework, enabling efficient communication and interaction patterns tailored for LLM scenarios.
Use cases
MCP can be utilized for a variety of applications, including providing data resources to LLMs, executing code through tools, and defining interaction templates through prompts. This versatility makes it suitable for building systems that require dynamic data retrieval and processing, as well as enhancing the LLM’s contextual understanding.
How to use
To get started, developers can create a Java application by adding the MCP Declarative Java SDK dependency to their project. By annotating classes with specific MCP annotations for resources, prompts, and tools, developers can easily set up an MCP server. The main method can invoke server startup methods with minimal configuration, leveraging YAML files for settings.
Key features
This SDK does not require the Spring Framework, allowing developers to create an MCP server in a single line of code. It emphasizes reduced boilerplate code, supports multiple languages, and is compatible with Spring AI configuration files. Annotations simplify the process of defining MCP components without delving into low-level SDK details.
Where to use
The MCP framework is ideal for use in applications that integrate LLMs, such as chatbots, data analysis tools, and any system requiring dynamic interaction with large datasets or computations. It can be applied across various domains, including data processing, file management, and interactive AI solutions.
Clients Supporting MCP
The following are the main client software that supports the Model Context Protocol. Click the link to visit the official website for more information.
Overview
What is Mcp Declarative Java Sdk
The Model Context Protocol (MCP) is designed to facilitate secure and standardized interactions between servers and large language model (LLM) applications. It allows developers to expose data and functionality through a structured framework, enabling efficient communication and interaction patterns tailored for LLM scenarios.
Use cases
MCP can be utilized for a variety of applications, including providing data resources to LLMs, executing code through tools, and defining interaction templates through prompts. This versatility makes it suitable for building systems that require dynamic data retrieval and processing, as well as enhancing the LLM’s contextual understanding.
How to use
To get started, developers can create a Java application by adding the MCP Declarative Java SDK dependency to their project. By annotating classes with specific MCP annotations for resources, prompts, and tools, developers can easily set up an MCP server. The main method can invoke server startup methods with minimal configuration, leveraging YAML files for settings.
Key features
This SDK does not require the Spring Framework, allowing developers to create an MCP server in a single line of code. It emphasizes reduced boilerplate code, supports multiple languages, and is compatible with Spring AI configuration files. Annotations simplify the process of defining MCP components without delving into low-level SDK details.
Where to use
The MCP framework is ideal for use in applications that integrate LLMs, such as chatbots, data analysis tools, and any system requiring dynamic interaction with large datasets or computations. It can be applied across various domains, including data processing, file management, and interactive AI solutions.
Clients Supporting MCP
The following are the main client software that supports the Model Context Protocol. Click the link to visit the official website for more information.
Content
Annotation-driven MCP Java SDK
Declarative MCP Java SDK Development with Java Annotations.
Advantages
- No Spring Framework Required.
- Instant MCP Java server in 1 LOC.
- No need to write more SDK low-level codes.
- Get rid of complex and lengthy JSON schema definitions.
- Just focus on your core logic (resources/prompts/tools).
- Configuration file compatible with the Spring AI framework.
- Built-in multi-languages support for MCP server (resources/prompts/tools).
Showcase
Just put this one line code in your main method:
import com.github.codeboyzhou.mcp.declarative.McpServers;
// You can use this annotation to specify the base package
// to scan for MCP resources, prompts, tools, but it's optional.
// If not specified, it will scan the package where the main method is located.
@McpComponentScan(basePackage = "com.github.codeboyzhou.mcp.server.examples")
public class MyMcpServer {
public static void main(String[] args) {
McpServers servers = McpServers.run(MyMcpServer.class, args);
// Start a STDIO MCP server
servers.startStdioServer(McpServerInfo.builder().name("mcp-server").version("1.0.0").build());
// or a HTTP SSE MCP server
servers.startSseServer(McpSseServerInfo.builder().name("mcp-server").version("1.0.0").port(8080).build());
// or start with yaml config file (compatible with the Spring AI framework)
servers.startServer();
// or start with a custom config file (compatible with the Spring AI framework)
servers.startServer("my-mcp-server.yml");
}
}
This is a yaml configuration file example (named mcp-server.yml by default) only if you are using startServer() method:
enabled: true
stdio: false
name: mcp-server
version: 1.0.0
type: ASYNC
request-timeout: 20000
capabilities:
resource: true
prompt: true
tool: true
change-notification:
resource: true
prompt: true
tool: true
sse:
message-endpoint: /mcp/message
endpoint: /sse
base-url: http://localhost:8080
port: 8080
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", description = "OS env variables")
// or you can use it like this to support multi-languages
@McpResource(uri = "env://variables", descriptionI18nKey = "your_i18n_key_in_properties_file")
public String getSystemEnv() {
// Just put your logic code here, forget about the MCP SDK details.
return System.getenv().toString();
}
// Your other MCP resources here...
}
@McpPrompts
public class MyMcpPrompts {
// This method defines a MCP prompt to read a file
@McpPrompt(description = "A simple prompt to read a file")
// or you can use it like this to support multi-languages
@McpPrompt(descriptionI18nKey = "your_i18n_key_in_properties_file")
public String readFile(
@McpPromptParam(name = "path", description = "filepath", required = true) String path) {
// Just put your logic code here, forget about the MCP SDK details.
return String.format("What is the complete contents of the file: %s", path);
}
}
@McpTools
public class MyMcpTools {
// This method defines a MCP tool to read a file
@McpTool(description = "Read complete file contents with UTF-8 encoding")
// or you can use it like this to support multi-languages
@McpTool(descriptionI18nKey = "your_i18n_key_in_properties_file")
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:
<!-- Internally relies on native MCP Java SDK 0.10.0 -->
<dependency>
<groupId>io.github.codeboyzhou</groupId>
<artifactId>mcp-declarative-java-sdk</artifactId>
<version>0.5.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.
Dev Tools Supporting MCP
The following are the main code editors that support the Model Context Protocol. Click the link to visit the official website for more information.










