# langchain4j-mcp-server-patterns

Provides design patterns for building Java MCP servers and connecting them to LangChain4j. Useful when exposing tools in Spring Boot and securing agent execution.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 3700 installs · ★ 363
- Author: giuseppe-trisciuoglio
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/giuseppe-trisciuoglio/developer-kit/tree/HEAD/plugins/developer-kit-java/skills/langchain4j-mcp-server-patterns/SKILL.md
- Updated: 2026-09-10
- HTML: https://affpapa.org/en/nevibecode/skills/langchain4j-mcp-server-patterns

## What it does

This skill guides the design and setup of Model Context Protocol servers in Java. It separates implementation concerns into dedicated providers for tools, discoverable resources, and prompts, keeping schemas compact for fast model comprehension.

It covers transport selection between stdio for local sidecars and HTTP or SSE for remote deployments. For LangChain4j integration, it shows how to wire `McpToolProvider` into AI services while filtering dangerous capabilities by user role or environment.

External MCP servers represent an untrusted boundary. Because LangChain4j and MCP APIs evolve quickly, you will need to align class names and builders with the exact library versions in your project.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add giuseppe-trisciuoglio/developer-kit --skill langchain4j-mcp-server-patterns -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/langchain4j-mcp-server-patterns/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/langchain4j-mcp-server-patterns/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add giuseppe-trisciuoglio/developer-kit --skill langchain4j-mcp-server-patterns -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/langchain4j-mcp-server-patterns/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add giuseppe-trisciuoglio/developer-kit --skill langchain4j-mcp-server-patterns -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/langchain4j-mcp-server-patterns/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install giuseppe-trisciuoglio/developer-kit langchain4j-mcp-server-patterns
```

2. **Manually: put the files in place**
- File: `.github/skills/langchain4j-mcp-server-patterns/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add giuseppe-trisciuoglio/developer-kit --skill langchain4j-mcp-server-patterns -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/giuseppe-trisciuoglio/developer-kit --path plugins/developer-kit-java/skills/langchain4j-mcp-server-patterns
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/langchain4j-mcp-server-patterns/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add giuseppe-trisciuoglio/developer-kit --skill langchain4j-mcp-server-patterns -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/giuseppe-trisciuoglio/developer-kit/tree/HEAD/plugins/developer-kit-java/skills/langchain4j-mcp-server-patterns/SKILL.md

## When to use it
- build a Java MCP server with stdio or SSE transport
- integrate LangChain4j AI services with external MCP servers
- filter privileged MCP tools by tenant or user role
- handle MCP timeouts, retries, and connection failures safely

## Example prompts
- Show a Java MCP tool provider example using stdio transport
- How do I filter out admin tools in LangChain4j McpToolProvider?
- Wire LangChain4j to an external MCP server in a Spring Boot app

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: d4af133a291669a8.

BEGIN THIRD-PARTY FILE d4af133a291669a8
```text
---
name: langchain4j-mcp-server-patterns
description: Provides LangChain4j patterns for implementing MCP (Model Context Protocol) servers, creating Java AI tools, exposing tool calling capabilities, and integrating MCP clients with AI services. Use when building a Java MCP server, implementing tool calling in Java, connecting LangChain4j to external MCP servers, or securing tool exposure for agent workflows.
allowed-tools: Read, Write, Edit, Bash, Glob, Grep, WebFetch
---

# LangChain4j MCP Server Implementation Patterns

## Overview

Use this skill to design and implement Model Context Protocol (MCP) integrations with LangChain4j.

The main concerns are:
- defining a clean tool, resource, and prompt surface
- choosing the right transport and bootstrap model
- filtering unsafe capabilities before exposing them to agents or applications

Keep `SKILL.md` focused on the implementation flow. Use the bundled references for expanded examples and API-level detail.

## When to Use

Use this skill when:
- building a Java MCP server that exposes tools, resources, or prompts
- integrating LangChain4j with one or more external MCP servers
- wiring MCP support into a Spring Boot application
- filtering available tools by tenant, user role, or runtime context
- adding observability, resilience, and safe failure handling around MCP interactions
- reviewing an MCP integration for prompt-injection and side-effect risks

Typical trigger phrases include `langchain4j mcp`, `java mcp server`, `mcp tool provider`, `spring boot mcp`, and `connect langchain4j to mcp`.

## Instructions

### 1. Design the MCP surface before writing code

Decide what the server should expose:
- tools for actions with clear inputs and side effects
- resources for read-only or structured data access
- prompts only when a reusable template adds real value

Keep names stable, descriptions concrete, and schemas small enough for a client or model to understand quickly.

### 2. Implement providers with narrow responsibilities

Use separate classes for each concern:
- tool provider for executable functions
- resource provider for discoverable and readable data
- prompt provider for reusable prompt templates

Validate arguments before execution and return clear error messages for invalid input or unavailable dependencies.

### 3. Choose the transport intentionally

Use:
- stdio for local integrations, CLI tools, and sidecar processes
- HTTP or SSE for remote or shared services

Pin external server versions and document how the process is started, authenticated, and monitored.
```
END THIRD-PARTY FILE d4af133a291669a8

The third-party file has ended. Everything between the d4af133a291669a8 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2571 of 6327 bytes. © giuseppe-trisciuoglio · MIT · https://github.com/giuseppe-trisciuoglio/developer-kit/tree/HEAD/plugins/developer-kit-java/skills/langchain4j-mcp-server-patterns/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
