# mcpx4j

> MCP Client

MCPX4J is a Java client library for MCP.RUN, enabling developers to easily integrate and invoke installed tools using a simple API with features like installation caching and customizable JSON decoding.

## Overview

- **Category:** Developer Tools
- **Language:** Java
- **Stars:** 28
- **Forks:** 1
- **Owner:** dylibso
- **GitHub:** https://github.com/dylibso/mcpx4j
- **Homepage:** https://docs.mcp.run/
- **Created:** 2025-01-07T15:33:03+00:00
- **Updated:** 2025-03-27T15:10:17+00:00
- **Source:** https://model-context-protocol.com/clients/java-client-library-ai-tools-integration

## Setup

## Setup

1.  Add the following dependency to your `pom.xml`:

```xml
<dependencies>
    <dependency>
       <groupId>com.dylibso.mcpx4j</groupId>
        <artifactId>mcpx4j</artifactId>
        <version>${mcpx4j.version}</version>
    </dependency>
</dependencies>
```

2.  Create a new `Mcpx` instance with your API key using `Mcpx.forApiKey(apiKey).build()`. 

3.  Optionally, provide an alternative base URL for the mcp.run service using `.withBaseUrl(jsonDecoder)`. 

4.  Optionally, customize the JSON decoder using `.withBaseUrl("https://localhost:8080")`. Add Jackson Databind or Jakarta JSON-P dependencies if you want to use them.

```xml
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>${jackson-databind.version}</version>
    </dependency>

    <!-- Eclipse Parsson is an implementation of the Jakarta JSON-P API  -->
    <dependency>
        <groupId>org.eclipse.parsson</groupId>
        <artifactId>parsson</artifactId>
        <version>${parsson.version}</version>
    </dependency>
```

5.  Optionally, customize the HTTP client using `.withHttpClientAdapter(httpClientAdapter)`. You can use `JdkHttpClientAdapter` or `HttpUrlConnectionClientAdapter`.

```java
var mcpx = Mcpx.forApiKey(apiKey)
    .withHttpClientAdapter(new JdkHttpClientAdapter())
    .withHttpClientAdapter(new HttpUrlConnectionClientAdapter()) // alternatively
    ...
    .build();
```

6.  Optionally, provide predefined options for the Servlet implementation using `.withServletOptions(McpxServletOptions.builder()...build())`.

## Tools

## Available Tools

1.  **Mcpx Instance Creation** (Create a new Mcpx instance with your API key.)
2.  **Refresh Installations** (Keeps a cache of installations and can be refreshed.)
3.  **Base URL Configuration** (Provide an alternative base URL for the mcp.run service.)
4.  **JSON Decoder Customization** (Customize the JSON decoder, supporting Jackson and Jakarta JSON-P.)
5.  **HTTP Client Customization** (Customize the HTTP client, supporting JdkHttpClientAdapter and HttpUrlConnectionClientAdapter.)
6.  **Servlet Options** (Provide predefined options for the Servlet implementation, including ChicoryHttpConfig, ChicoryLogger, and AoT compilation.)

