Skip to content

kencopas/JavaSampleMCP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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_presentations which returns a list of sample presentations.
  • A Presentation record and PresentationTools helper class containing example data and simple lookup methods.

Requirements

  • Java 21
  • Maven

Build and Run

  1. Clone the repository.

  2. Build the project with Maven:

    mvn clean package
  3. 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 the mcp.json file.

  • Visual Studio Code:
    Open the command palette (Ctrl+Shift+P or Cmd+Shift+P on Mac) → type MCP: Open User Configuration → select it to open the mcp.json file.

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:

  1. Make sure Node.js is installed.

  2. Run:

    npx @modelcontextprotocol/inspector

This launches the MCP Inspector in your browser.
Set:

  • Commandjava
  • 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:
    Edit Application.java to register additional SyncToolSpecification or other SDK-supported features.

  • Change or extend data:
    Update PresentationTools.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 the ObjectMapper used 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.


About

This is a sample Java MCP Server that I created following this guys tutorial exactly:https://www.youtube.com/watch?v=Y_Rk6QgWUbE&t=1169s

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages