kencopas/JavaSampleMCP
If you are the rightful owner of JavaSampleMCP and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
This repository provides a minimal Java sample implementation of an MCP (Model Context Protocol) server.
Java Sample MCP Server
This repository provides a minimal Java sample implementation of an MCP (Model Context Protocol) server.
It is intended for anyone who wants to:
- Clone the project
- Run a small example server that exposes a synchronous tool
- Extend the functionality to implement their own tools and behavior
Features Included
- A small Java application (
com.example.Application) that starts an MCP server using the SDK and a stdio transport provider. - A built-in sync tool named
get_presentationswhich returns a list of sample presentations. - A
Presentationrecord andPresentationToolshelper class containing example data and simple lookup methods.
Requirements
- Java 21
- Maven
Build and Run
-
Clone the repository.
-
Build the project with Maven:
mvn clean package -
Run the shaded JAR produced in
target:java -jar target/gson-demo-1.0-SNAPSHOT.jar
The server is configured to use standard input/output as the transport.
Use an MCP-capable client or a simple wrapper that communicates via STDIO to call the exposed tool(s).
Setup MCP Server with GitHub Copilot
You can use GitHub Copilot to interact with the MCP server.
Open mcp.json
-
IntelliJ IDEA:
Open the GitHub Copilot chat window → click the toolset icon → Add MCP Tools → this will open themcp.jsonfile. -
Visual Studio Code:
Open the command palette (Ctrl+Shift+PorCmd+Shift+Pon Mac) → type MCP: Open User Configuration → select it to open themcp.jsonfile.
Add Custom MCP Server
Once inside mcp.json, add the following configuration:
{
"servers": {
"custom-mcp": {
"command": "java",
"args": [
"-jar",
"C:\\path\\to\\gson-demo-1.0-SNAPSHOT.jar"
]
}
}
}
👉 Replace the path with the actual location of your built JAR file.
After saving, click the toolset icon again — you should now see your custom-mcp server and the get_presentations tool available.
MCP Inspector
To use the MCP Inspector with this server:
-
Make sure Node.js is installed.
-
Run:
npx @modelcontextprotocol/inspector
This launches the MCP Inspector in your browser.
Set:
- Command →
java - Arguments →
-jar path/to/gson-demo-1.0-SNAPSHOT.jar
Once connected, you can run tools, resources, and prompts, and view input/output schemas.
Extending the Sample
-
Add new tools:
EditApplication.javato register additionalSyncToolSpecificationor other SDK-supported features. -
Change or extend data:
UpdatePresentationTools.javato load data from files, a database, or an external API. -
Customize serialization:
The project currently uses Gson as an example. You can replace or configure theObjectMapperused by the transport provider.
Notes
-
This sample is intentionally small — it demonstrates wiring the SDK, a transport, and a simple tool.
It is not production-ready. -
Dependencies include the MCP SDK and SLF4J (simple logger) as declared in
pom.xml.