Artificial Intelligence 11 min read

Build a Java AI Gitee Assistant with LangChain4j and MCP: Step‑by‑Step Guide

This article explains how to integrate Gitee's Model Control Protocol (MCP) with Java using LangChain4j, covering download, Maven setup, configuration, both stdio and SSE transport modes, sample code, output examples, and a comparison of the two modes to create an AI‑powered repository assistant.

Java Architecture Diary
Java Architecture Diary
Java Architecture Diary
Build a Java AI Gitee Assistant with LangChain4j and MCP: Step‑by‑Step Guide

Background

With the rapid development of artificial‑intelligence technology, developer tools are evolving. Gitee, a leading Chinese code‑hosting platform, has introduced the Model Control Protocol (MCP) that lets AI assistants manage repositories, issues, and pull requests more efficiently.

mcp-gitee

is the server implementation of MCP, providing a set of tools that interact with the Gitee API.

MCP illustration
MCP illustration

Although Gitee currently offers only Go and graphical implementations, Java developers can leverage LangChain4j to build a full‑stack MCP integration. This guide shows how to create an enterprise‑grade AI repository assistant with Spring Boot.

What is MCP?

MCP (Model Control Protocol) is a protocol that enables AI models to interact with external tools and services. Through MCP, an AI assistant can perform actions such as creating repositories, committing code, and managing issues and pull requests, making development workflows smarter and more automated.

Key advantages of MCP:

Provides a standard interface for AI models to interact with external systems.

Supports multiple transport modes to suit different scenarios.

Allows AI to execute real operations rather than merely offering suggestions.

Preparation

Download Gitee MCP

Download the appropriate MCP server binary for your operating system from the Gitee MCP release page. On macOS, grant execution permission:

<code>chmod +x mcp-gitee</code>

Build MCP Java client

Add the following Maven dependencies (example using LangChain4j):

<code>&lt;dependency&gt;
  &lt;groupId&gt;dev.langchain4j&lt;/groupId&gt;
  &lt;artifactId&gt;langchain4j-mcp&lt;/artifactId&gt;
  &lt;version&gt;1.0.0-beta2&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
  &lt;groupId&gt;dev.langchain4j&lt;/groupId&gt;
  &lt;artifactId&gt;langchain4j-open-ai-spring-boot-starter&lt;/artifactId&gt;
  &lt;version&gt;1.0.0-beta2&lt;/version&gt;
&lt;/dependency&gt;</code>

Configuration file

Insert AI model settings into

application.yml

:

<code>langchain4j:
  open-ai:
    chat-model:
      api-key: sk-
      base-url: https://api.deepseek.com/v1
      model-name: deepseek-chat
      log-requests: true</code>

MCP Transport Modes

MCP supports two main transport modes: stdio and SSE .

Mode 1: stdio

Concept

StdIO (standard input/output) mode communicates with the MCP server via subprocess I/O streams. It is simple to set up and works well for local development without additional network configuration.

The MCP client launches the MCP server as a child process.

Requests are sent to the server through

stdin

.

Responses are received from

stdout

.

Suitable for local development and testing.

Implementation code

<code>@Autowired
private ChatLanguageModel chatLanguageModel;

@SneakyThrows
@Test
void contextLoads() {
    // Create stdio transport
    McpTransport transport = new StdioMcpTransport.Builder()
            .command(List.of("/Users/lengleng/Downloads/mcp-gitee-darwin-arm64/mcp-gitee", "-token", "GITEE-TOKEN"))
            .logEvents(true)
            .build();

    // Create MCP client
    @Cleanup McpClient mcpClient = new DefaultMcpClient.Builder()
            .transport(transport)
            .build();

    // Create tool provider
    ToolProvider toolProvider = McpToolProvider.builder()
            .mcpClients(List.of(mcpClient))
            .build();

    // Build Gitee AI service
    GiteeAiService giteeAiService = AiServices.builder(GiteeAiService.class)
            .chatLanguageModel(chatLanguageModel)
            .toolProvider(toolProvider)
            .build();

    // Use AI service to query Gitee
    String result = giteeAiService.chat("获取 log4j/pig 开启的 issue 列表 ");
    log.info("gitee mcp result: {}", result);
}</code>

Mode 2: SSE

Concept

SSE (Server‑Sent Events) is an HTTP‑based one‑way push mechanism that allows the server to push data to the client. In MCP, the server runs as an independent process listening for HTTP requests, making it suitable for distributed environments and multiple client connections.

The MCP server runs as a separate process and listens for HTTP requests.

Clients connect via HTTP and receive streamed events.

Supports multiple concurrent clients.

Ideal for distributed deployments.

Implementation steps

Start the MCP server in SSE mode:

<code>mcp-gitee -transport sse -token GITEE-TOKEN</code>

Configure and use the SSE transport in Java:

<code>@Autowired
private ChatLanguageModel chatLanguageModel;

@SneakyThrows
@Test
void contextLoads() {
    // Create SSE transport
    McpTransport sseTransport = new HttpMcpTransport.Builder()
            .sseUrl("http://localhost:8000/sse")
            .logRequests(true)
            .logResponses(true)
            .build();

    // Create MCP client
    @Cleanup McpClient mcpClient = new DefaultMcpClient.Builder()
            .transport(sseTransport)
            .build();

    // Create tool provider
    ToolProvider toolProvider = McpToolProvider.builder()
            .mcpClients(List.of(mcpClient))
            .build();

    // Build Gitee AI service
    GiteeAiService giteeAiService = AiServices.builder(GiteeAiService.class)
            .chatLanguageModel(chatLanguageModel)
            .toolProvider(toolProvider)
            .build();

    // Use AI service to query Gitee
    String result = giteeAiService.chat("获取 log4j/pig 开启的 issue 列表 ");
    log.info("gitee mcp result: {}", result);
}</code>

Sample Output

<code>2025-03-16T23:19:51.211+08:00  INFO 67659 --- [main] com.example.demo.DemoApplicationTests : gitee mcp result: 目前 log4j/pig 仓库中有以下开启的 issue:
1. **JDK17 版本中 oauth2.0 的授权码模式,无法通过 code 获取到 access_token**
   - 编号: IBQJ94
   - 创建时间: 2025-03-04T13:04:53+08:00
   - 链接: https://gitee.com/log4j/pig/issues/IBQJ94</code>

Comparison of the Two Modes

Deployment : stdio runs as a local subprocess; SSE runs as an independent server.

Use case : stdio is ideal for local development; SSE suits distributed environments.

Configuration complexity : stdio is simple; SSE requires additional network setup.

Multi‑client support : stdio does not support multiple clients; SSE supports many concurrent clients.

Network requirement : stdio works offline; SSE needs network connectivity.

Conclusion

By combining Java with MCP, developers can create a powerful Gitee repository assistant that automates code management, boosts productivity, and frees developers to focus on more creative tasks. The stdio mode is perfect for local development, while the SSE mode addresses the needs of distributed, multi‑client scenarios.

JavaMCPSpring BootGiteeAI AssistantServer-Sent EventsLangChain4j
Java Architecture Diary
Written by

Java Architecture Diary

Committed to sharing original, high‑quality technical articles; no fluff or promotional content.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.