What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use the official Java SDK, io.modelcontextprotocol.sdk:mcp, to build a Java MCP server. First choose how the client will connect: STDIO for a host that launches your server as a process, or an HTTP transport for a server deployed behind an endpoint. Then configure only the capabilities you implement, register a narrowly scoped tool, validate its inputs, and shut the server down cleanly. Spring projects should use the current Spring AI 2.0+ integrations for WebFlux or WebMVC transports.

This guide walks through those decisions and shows the SDK’s server shape. The registration example is an API-shape sketch, not a complete copy-and-run application: the transport provider and tool specification must match your chosen SDK version and transport.

Choose the Java MCP SDK dependency

For a small Maven or Gradle project, start with the official SDK’s convenience artifact, io.modelcontextprotocol.sdk:mcp. The quickstart describes it as combining core functionality with Jackson 3 JSON support. If you need to select the JSON implementation yourself, the quickstart also documents mcp-core; for a project that needs Jackson 2.x, it documents mcp-json-jackson2. Keep related SDK artifacts aligned with the SDK BOM rather than mixing versions by hand.

The quickstart’s sample BOM coordinate uses version 2.0.0, but it directs developers to use the latest version available from Maven Central. The SDK documentation’s version selector lists v2.0.1 as released and shows 2.1.0-SNAPSHOT separately. Do not treat the sample BOM version as the latest release; check Maven Central and the project’s compatibility information before pinning a version.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Maven dependency shape

In Maven, add the SDK BOM to <dependencyManagement> and then declare the mcp artifact without a separate version. Use the BOM version you have verified for your project. The exact BOM and dependency declaration should follow the current official quickstart for that release, since the version example is not itself a current-release guarantee.

Gradle dependency shape

In Gradle, use the same verified SDK release and align SDK modules through its BOM or the dependency-management mechanism used by your build. Avoid combining artifacts from different release lines simply because one version appears in an older sample.

Pick the transport before writing the server

The transport determines how the client starts or reaches the server, which SDK transport provider you configure, and what you must operate in production. STDIO, Streamable HTTP, and legacy HTTP-with-SSE are not interchangeable deployment labels.

Transport Use it when Implementation and operational implications
STDIO An MCP host launches your server as a local process. The client and server communicate through standard input and output. Reserve stdout for protocol messages; send diagnostics to a logging channel such as stderr. Document the launch command and required environment configuration for the host.
Streamable HTTP You need an HTTP-hosted MCP endpoint. The Java SDK documentation covers core Servlet support; its Servlet example configures an endpoint such as /mcp. Plan how the service is hosted, authenticated, and exposed to clients.
HTTP with SSE An existing client or deployment requires the older transport. The SDK documentation still describes SSE, while the server reference labels the older HTTP-with-SSE transport “Legacy.” Check client and protocol compatibility before choosing it for a new service.

Also decide whether the service should be stateful or stateless and whether synchronous or asynchronous handlers fit its workload. Those choices affect lifecycle and application integration; they do not replace the client’s transport requirements.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Build a minimal server around one tool

An MCP server declares the capabilities it implements, then registers the corresponding operations. Begin with one tool that has a clear purpose and bounded effects. For example, a Java service might expose a tool that looks up an order by an order ID, rather than a generic tool that accepts arbitrary queries and can perform unrestricted actions.

The official Java server reference shows this basic synchronous shape:

McpSyncServer server = McpServer.sync(transportProvider)
    .serverInfo("example-server", "1.0.0")
    .capabilities(ServerCapabilities.builder()
        .tools(true)
        .build())
    .build();

server.addTool(toolSpecification);

This fragment illustrates the SDK API shape; it is not a standalone runnable program. You must provide a transport provider configured for your selected transport and a tool specification with its own input schema and handler. Confirm the corresponding factory and transport configuration in the documentation for the SDK version you actually use before turning the fragment into application code.

Define the tool contract

Before registering a handler, decide what the client is allowed to ask it to do. A useful tool contract includes:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • A stable, descriptive tool name and a description that tells an AI client when to use it.
  • An input schema with required fields, types, and any meaningful limits.
  • Validation in the application handler as well as schema-level validation; never assume a remote caller’s input is trustworthy.
  • A result that distinguishes a successful answer from an expected tool-level problem, such as an unknown record, without leaking internal exceptions.
  • Effects restricted to the minimum permissions needed for that operation.

The SDK server guide covers tool specifications, input validation, result content, and error handling. Use those APIs to build the specification for your chosen SDK version; do not treat the short registration fragment above as a substitute for defining the tool’s schema and behavior.

Choose synchronous or asynchronous handling

The Java SDK provides synchronous and asynchronous server APIs: the reference uses McpServer.sync(...) for a synchronous server and also provides McpServer.async(...). A synchronous handler is a straightforward fit when its work is naturally bounded and fits the application’s execution model. Use the asynchronous API when your application is already built around asynchronous work or needs that model for its handlers.

Asynchronous registrations produce reactive results. Compose them into the application’s lifecycle or subscribe appropriately; creating a reactive result without arranging for it to be consumed is not a completed request-handling flow. Whichever model you choose, close the server during application shutdown.

Register only the capabilities you provide

Tools are one MCP capability, not the whole server. The Java reference also exposes APIs for URI-addressed resources, resource templates, and prompts. Add these only when your application has meaningful data or prompt behavior to expose. Enable the matching capability and register its specifications; avoid advertising functionality that the server does not implement.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Tools: operations a client can ask the server to perform.
  • Resources: URI-addressed data the server makes available.
  • Resource templates: parameterized resource patterns where the application supports them.
  • Prompts: reusable prompt definitions provided by the server.

Use Spring through the current Spring AI integration

If your application uses Spring, distinguish the standalone Java SDK from Spring’s transport integration. Current Spring WebFlux and WebMVC MCP transports and server boot starters belong to Spring AI 2.0+, rather than modules shipped as part of the standalone Java SDK. Follow the Spring AI documentation version that matches your application. Older examples online may describe earlier module ownership or configuration and should not be copied into a current project without checking compatibility.

Secure and operate an HTTP server deliberately

The Java SDK documentation describes pluggable authorization hooks and DNS rebinding protection using Host and Origin validation. Those hooks do not amount to a complete authorization system included in the core SDK. Integrate your application’s established authentication and authorization approach, then authorize each tool or resource according to the caller and operation.

  • Validate all tool inputs and constrain tool effects to the minimum necessary.
  • Do not expose sensitive resources or powerful operations by default.
  • For HTTP deployments, document the endpoint, authentication requirements, and network boundary for clients and operators.
  • For STDIO deployments, document how the host launches the process and provides configuration; keep protocol output separate from diagnostics.
  • Close the server gracefully as part of application shutdown.

Test the server before connecting an AI client

Test the contract at the same boundary the client will use. Verify that the selected transport starts successfully, that the advertised capabilities match registered operations, and that valid and invalid tool inputs produce the intended results. Include shutdown in the test plan so a server that handles one request correctly does not leave background work or transport resources running.

  • Test a valid request and confirm the result content is useful to a caller.
  • Test missing, malformed, and out-of-range inputs and confirm they are rejected safely.
  • Test an expected application failure separately from a transport or server failure.
  • For STDIO, check that logs do not corrupt stdout protocol messages.
  • For HTTP, check the endpoint and the authentication and authorization behavior expected in deployment.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common Java MCP server problems

The dependency or class is missing

Check that the project uses the intended SDK artifact and that all SDK modules resolve to one compatible release. The convenience mcp artifact is the documented starting point; if you instead compose mcp-core and a JSON module, include the JSON implementation appropriate to the project. Recheck the release metadata rather than copying an old sample version.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The client cannot start a STDIO server

Confirm the host’s process launch configuration, working directory, environment, and Java runtime configuration. Then inspect whether application output is being written to stdout: in a STDIO transport, stdout carries protocol messages, so diagnostics belong on a logging channel instead.

An HTTP client cannot connect

Verify that the application actually registers the selected HTTP transport and exposes the endpoint path the client is configured to call. If using Spring, confirm that the project follows the Spring AI 2.0+ integration matching its WebFlux or WebMVC stack, rather than an older standalone-SDK module example.

A tool is not visible or its call fails

Check that the server advertises the tools capability and that the tool specification is registered on the server instance. Then compare the client’s submitted input with the tool schema and handler validation. Keep application-level tool failures distinct from protocol and server failures so a caller can respond appropriately.

An asynchronous handler appears not to run

Check that its reactive result is composed or subscribed as part of the request and application lifecycle. Returning an unconsumed reactive result does not ensure that the work executes.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Or skip the browser setup

If one of your Java MCP tools needs to return a website screenshot, you can call ScreenshotNeo’s screenshot API instead of managing browser installation, page rendering, and capture in your own service. It is a website screenshot API and MCP server; see the ScreenshotNeo site and its API documentation.

For example, a Java tool handler can make an HTTP GET request to the API endpoint with an access key and target URL, then return the response image or a link to it according to your tool contract. The API accepts one GET request with a URL and can return PNG, JPEG, WebP, or PDF. Keep the access key in server-side configuration, not in tool input exposed to the model.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

ScreenshotNeo removes cookie and consent banners, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, with response headers indicating the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients. The free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month with no card.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Frequently Asked Questions

Can an MCP server in Java expose data as well as actions?

Yes. In addition to tools, the Java SDK reference includes resources, resource templates, and prompts; register and advertise only the capabilities the application actually implements.

Does the standalone Java SDK include Spring WebFlux and WebMVC transports?

No. Current Spring WebFlux and WebMVC MCP transports and server boot starters are Spring AI 2.0+ integrations.

Does the Java SDK provide a complete authentication system for remote servers?

The SDK documents pluggable authorization hooks, but the core SDK does not claim to include a complete authorization system. Integrate an application-appropriate policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.