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
- 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_presentations
which returns a list of sample presentations. - A
Presentation
record andPresentationTools
helper class containing example data and simple lookup methods.
- Java 21
- Maven
-
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).
You can use GitHub Copilot to interact with the MCP server.
-
IntelliJ IDEA:
Open the GitHub Copilot chat window → click the toolset icon → Add MCP Tools → this will open themcp.json
file. -
Visual Studio Code:
Open the command palette (Ctrl+Shift+P
orCmd+Shift+P
on Mac) → type MCP: Open User Configuration → select it to open themcp.json
file.
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.
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.
-
Add new tools:
EditApplication.java
to register additionalSyncToolSpecification
or other SDK-supported features. -
Change or extend data:
UpdatePresentationTools.java
to 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 theObjectMapper
used by the transport provider.
-
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
.