Logo fastMCP4J

fastMCP4J

Cộng đồng
tersePrompts

Annotate a Java class → production MCP server. Tools, memory, prompts + a sandboxed bash terminal where the host is unreachable by construction. Java 17+, 12 deps, no containers.

Nhà phát hànhtersePrompts
Kho mãfastMCP4J
Ngôn ngữJava
Bản fork
0
Sao
11
Công cụ có sẵn
0
Phương thức truyền tảistdio
Danh mục
Giấy phépMIT
Liên kết
  • Kết nối công cụ với quy trình làm việc AI

    fastMCP4J cung cấp các khả năng MCP mà ứng dụng khách và tác nhân AI tương thích có thể sử dụng.

  • 0 công cụ có sẵn

    Xem các thao tác có thể gọi bên dưới, kèm tên và mô tả nếu máy chủ cung cấp.

  • Cấu hình sẵn để sao chép

    Dùng các đoạn cấu hình cài đặt mẫu để thiết lập máy chủ này trong ứng dụng khách MCP bạn muốn dùng.

  • Chỉ số quan tâm đến mã nguồn mở

    11 sao và 0 bản fork từ kho mã được liên kết.

FastMCP4J

Maven Central Java CI License Tests MCP Marketplace

Annotate a Java class. Ship an MCP server.

Tools, resources, prompts, memory — and a sandboxed bash terminal that can't touch your machine. No boilerplate, no containers, no 50-jar framework.

AI Agents → Share this skill with Claude for code generation

FastMCP4J is an annotation-driven SDK for the Model Context Protocol (spec 2.0.1) on Java 17+. One annotation turns a class into an MCP server; one more gives your AI agent a real terminal — a bash sandbox where the host is unreachable by construction. Cold start in under 500 ms, twelve dependencies, everything testable in-process.

Status: beta (v0.5.0-beta) — API stable, 235 tests passing, published to Maven Central.


Quick start (2 minutes)

Maven

xml
<dependency>
    <groupId>io.github.terseprompts.fastmcp</groupId>
    <artifactId>fastmcp-java</artifactId>
    <version>0.5.0-beta</version>
</dependency>

Gradle

groovy
implementation 'io.github.terseprompts.fastmcp:fastmcp-java:0.5.0-beta'

That's the whole install story: Java 17+, one artifact on Maven Central, MCP Java SDK 2.0.1 underneath. No annotation processor, no codegen step, no container runtime.

Create your server

java
@McpServer(name = "Assistant", version = "1.0")
public class MyAssistant {

    @McpTool(description = "Summarize text")
    public String summarize(@McpParam(description = "Text") String text) {
        return "Summary: " + text.substring(0, Math.min(100, text.length()));
    }

    public static void main(String[] args) {
        FastMCP.server(MyAssistant.class)
            .stdio()           // or .sse() or .streamable()
            .run();
    }
}
bash
mvn exec:java -Dexec.mainClass="com.example.MyAssistant"

That's it. Your MCP server is running.

Working example: EchoServer.java


Why this exists

Every Java team wiring AI agents to tools faces the same choice, and every option hurts:

Raw MCP SDKSpring AI / LangChain4jFastMCP4J
Lines per tool35+varies, plus framework glue~8
Dependencies1 + your patience30–50+ jars12 jars
Startupfastframework-sized<500 ms, ~64 MB
Sandboxed bashroll your ownnot included✅ built-in (bashkit4j)
Built-in memory / todo / planner / file toolsnono✅ one annotation each
Lock-innoneframeworknone — MCP in, MCP out

Before: a day of JSON-schema plumbing per tool, and shell access means a rogue prompt is a node down. After: annotations on Tuesday, agents in production Wednesday — and the terminal they use can't touch your disk.


The API tour

1 · Make a tool — sync or async

java
@McpTool(description = "Add two numbers")
public int add(int a, int b) {
    return a + b;
}

@McpTool(description = "Process data")
@McpAsync  // ← just add this; return Mono<?>
public Mono<String> process(@McpContext Context ctx, String input) {
    return Mono.fromCallable(() -> {
        ctx.reportProgress(50, "Processing...");
        return slowOperation(input);
    });
}

2 · Built-in brains — one annotation each

java
@McpServer(name = "MyServer", version = "1.0")
@McpMemory     // AI remembers things across sessions
@McpTodo       // AI manages tasks
@McpPlanner    // AI breaks work into plans
@McpFileRead   // AI reads your files
@McpFileWrite  // AI writes files
public class MyServer {
    // complete tool sets enabled, zero implementation
}
AnnotationTools you get
@McpMemorylist, read, create, replace, insert, delete, rename
@McpTodoadd, list, updateStatus, updateTask, delete, clearCompleted
@McpPlannercreatePlan, listPlans, getPlan, addTask, addSubtask
@McpFileReadreadLines, readFile, grep, getStats
@McpFileWritewriteFile, appendFile, writeLines, deleteFile, createDirectory

3 · Sandboxed bash — give the agent a terminal, not your machine

java
@McpServer(name = "Reviewer", version = "1.0")
@McpBash(
    allowMountsUnder = "C:/dev",           // opt in: all it may ever see
    mounts = {"/project=C:/dev/my-app"},   // mount the project — read-only
    timeout = 30, maxCommands = 10_000     // bounds runaway scripts
)
public class Reviewer { }

Scripts run in a bashkit4j in-memory sandbox: POSIX-style bash with 160+ commands re-implemented natively, a virtual filesystem, network denied by default. No real bash is ever spawned. Then the agent calls the bash tool:

grep -rn TODO /project/src | head -5      # real files, zero risk
echo "findings..." > /notes.md            # writes stay in the sandbox
Host shell (ProcessBuilder, Docker)Sandbox mode
Real bash on the host✅ runs — full attack surface❌ never — bash re-implemented natively
Host filesystem visible✅ all of it❌ invisible until you mount, read-only by default
OS processes per command✅ one per call❌ zero — in-process
Network access✅ open❌ denied by default
One rogue scriptnode downsandbox reset

State persists across calls (cwd, env, files) — multi-step agent workflows work. Mounts are enforced inside the native library: canonicalized, symlink-safe, and impossible without allowMountsUnder. Need the real shell for trusted automation? mode = BashMode.HOST keeps the legacy tool with its path guardrails.

Sandbox mode requires the optional io.github.terseprompts:bashkit4j:0.2.0 dependency — native libs for Windows/Linux/macOS (x86-64 + ARM64) are bundled and auto-detected.

🔭 Future scope — a third mode, BashMode.DOCKER. The isolation ladder gets one more rung: HOST = the full computer (trusted use) → SANDBOX = a virtual computer, no real code execution (default) → DOCKER = real bash inside a per-session container jail. The sketch: one container per MCP session, lazy-created and hardened at run (--network none --memory 512m --cpus 1 --pids-limit 64 --security-opt no-new-privileges --read-only --tmpfs /tmp); the command passed as a single argv element (no host-shell interpolation → no injection surface); the timeout enforced inside the container so the wall-clock survives a server crash; named exit codes ([exit 124: timed out], [exit 137: OOM]), capped output, idle-TTL eviction with a reaper backstop — containers stay stateless, durable state lives only in the mounted worktree. Config stays env-only (FASTMCP_DOCKER_IMAGE, timeout). Not started — see Roadmap; help wanted.

4 · Pick a transport

java
FastMCP.server(MyServer.class)
    .stdio()       // CLI tools, local agents
    .sse()         // web clients, long-lived connections
    .streamable()  // bidirectional streaming (recommended)
    .run();
java
FastMCP.server(MyServer.class)
    .port(3000)                              // HTTP port
    .requestTimeout(Duration.ofMinutes(5))   // request timeout
    .keepAliveSeconds(30)                    // keep-alive interval
    .capabilities(c -> c
        .tools(true)
        .resources(true, true)
        .prompts(true))
    .run();

5 · Resources & prompts

java
@McpResource(uri = "config://settings")
public String getSettings() {
    return "{\"theme\": \"dark\"}";
}

@McpPrompt(name = "code-review")
public String codeReviewPrompt(@McpParam(description = "Code to review") String code) {
    return "Review this code:\n" + code;
}

6 · Hooks — before/after every tool call

java
// Run before ALL tools (*)
@McpPreHook(toolName = "*", order = 1)
void authenticate(Map<String, Object> args) {
    String token = (String) args.get("token");
    if (!isValid(token)) throw new SecurityException("Unauthorized");
}

// Run after a specific tool only
@McpPostHook(toolName = "calculate", order = 1)
void logResult(Map<String, Object> args, Object result) {
    System.out.println("Result: " + result);
}
  • toolName — target tool, or "*" for all (empty = inferred from method name)
  • order — execution priority, lower runs first (default 0)
  • Pre-hooks receive the arguments; post-hooks receive arguments + result

7 · Request context

java
@McpTool(description = "Read file with auth")
public String readFile(@McpContext Context context, String path) {
    context.info("Reading file: " + path);
    String auth = context.getRequestHeaders().get("Authorization");
    // ...
}

Context gives you getClientId(), getSessionId(), getToolName(), getRequestHeaders(), info/warning/error logging, reportProgress, listResources(), listPrompts().

8 · Organize at scale

java
// explicit modules
@McpServer(name = "MyServer", version = "1.0",
    modules = {StringTools.class, MathTools.class})

// or package scanning
@McpServer(name = "MyServer", version = "1.0",
    scanBasePackage = "com.example.tools")

9 · Icons & telemetry

java
@McpServer(
    name = "my-server",
    icons = {"data:image/svg+xml;base64,...:image/svg+xml:64x64:light"}
)
@McpTelemetry(enabled = true, exportConsole = true, sampleRate = 1.0)
public class MyServer { }

Telemetry collects tool invocation counters, duration histograms, and error rates — console or OpenTelemetry export.


Annotations reference

AnnotationTargetPurpose
@McpServerTYPEDefine your MCP server
@McpToolMETHODExpose as callable tool
@McpResourceMETHODExpose as resource
@McpPromptMETHODExpose as prompt template
@McpParamPARAMETERDescription, examples, constraints, defaults
@McpAsyncMETHODMake tool async (return Mono<?>)
@McpContextPARAMETERInject request context
@McpPreHook / @McpPostHookMETHODRun code before/after tool calls
@McpBashTYPEBash tool — sandboxed (default) or host shell via mode
@McpTelemetryTYPEMetrics and tracing
@McpMemory / @McpTodo / @McpPlannerTYPEBuilt-in tool sets
@McpFileRead / @McpFileWriteTYPEBuilt-in file tools

@McpParam advanced options:

java
@McpTool(description = "Create task")
public String createTask(
    @McpParam(
        description = "Task name",
        examples = {"backup", "sync"},
        constraints = "Cannot be empty",
        defaultValue = "default",
        required = false
    ) String taskName
) { return "Created: " + taskName; }

What the sandbox actually does (measured, not claimed)

FastMCP4J ships 235 tests (mvn test) — the sandbox suite runs against the real native library on Windows and Linux CI, including deliberate escape probes:

ProbeResult
ls / inside the sandboxvirtual root only — pom.xml, target, host paths absent
whoami / hostnameagent@sandbox — virtual identity, not your OS user
Write to a read-only mountfails; host file provably never appears
Read-write mountround-trips to the host through the Java API
cd + file across tool callspersists inside a server; sealed between servers
Script exceeding timeoutcaller gets TIMEOUT; sandbox replaced fresh for next call
4 concurrent tool callsall complete — calls serialize on the sandbox
Sandbox without bashkit4j on classpathclear startup error naming the dependency

Who it's for

  • AI/LLM engineers — expose Java services to Claude, Cursor, or any MCP client with annotation-level effort.
  • Teams shipping agent tools — memory, todo, planning, file access, and a sandboxed terminal out of the box; hooks and telemetry for production.
  • Security-conscious platforms — agent terminal access with the host unreachable by construction, not by prompt-engineering.
  • Existing Spring/DI codebases — drop-in server, no framework lock-in; your beans become tools with an annotation.

Requirements & performance

Just Java 17+ and Maven 3.8+. MCP spec 2.0.1 via the official Java SDK (mcp-core + mcp-json-jackson2).

  • Cold start: <500 ms
  • Tool invocation: <5 ms
  • Memory: ~64 MB
  • Purpose-built for MCP — not a general AI framework

CI/CD

BranchWhat runs
development (staging)Full test suite + MCP integration tests (STDIO / SSE / Streamable / Sandboxed Bash) on every push and PR
mainSame suite + publish to Maven Central (staged; manual approval in Sonatype Central)

Flow: feature branch → development → main (release).


Documentation


License

MIT © 2026


Less boilerplate. More shipping.

Get started • Examples • Docs

Made with ❤️ for the Java community

Dùng MCP fastMCP4J với nhiều mô hình AI

TypingMind kết nối các công cụ MCP ở cấp không gian làm việc, nên sau khi kết nối fastMCP4J, bạn có thể dùng với nhiều mô hình AI khác nhau trong TypingMind thay vì phải thiết lập riêng cho từng mô hình. MCP này chạy cục bộ thông qua trình kết nối MCP của TypingMind trên thiết bị của bạn.

Hướng dẫn thiết lập để dùng trình kết nối cục bộ

Dùng cách này khi máy chủ MCP cần truy cập các tệp, ứng dụng hoặc tài nguyên riêng tư trên máy tính của bạn.

1

Mở cài đặt MCP

Trong TypingMind, vào Cài đặt, Cài đặt nâng cao, rồi đến Giao thức ngữ cảnh mô hình và chọn Cài trình kết nối.

  1. Mở TypingMind trong trình duyệt của bạn.
  2. Nhấp vào biểu tượng Cài đặt.
  3. Vào Cài đặt nâng cao.
  4. Mở mục Giao thức ngữ cảnh mô hình.
  5. Nhấp vào Cài trình kết nối rồi chọn Thiết bị này.
Màn hình thiết lập trình kết nối MCP của TypingMind với tùy chọn Thiết bị này được chọn
2

Chạy lệnh trình kết nối

Chọn Thiết bị này, sao chép lệnh từ TypingMind và chạy trong Terminal. Giữ tiến trình chạy trong khi bạn dùng MCP.

  1. Sao chép lệnh thiết lập hiển thị trong TypingMind.
  2. Mở Terminal trên macOS hoặc Windows Terminal trên Windows.
  3. Dán và chạy lệnh.
  4. Xác nhận cài đặt gói nếu Terminal hỏi bạn có muốn tiếp tục không.
  5. Giữ tiến trình trong cửa sổ Terminal chạy trong khi dùng các công cụ MCP.
3

Thêm fastMCP4J làm máy chủ

Khi trạng thái trình kết nối là Sẵn sàng, nhấp vào Sửa máy chủ và dán cấu hình máy chủ MCP.

  1. Đợi đến khi trạng thái trình kết nối hiển thị Sẵn sàng.
  2. Nhấp vào Sửa máy chủ.
  3. Dán cấu hình máy chủ MCP của fastMCP4J.
  4. Lưu danh sách máy chủ.
  5. Làm mới nếu bạn muốn xác nhận trình kết nối vẫn sẵn sàng.
Cài đặt MCP của TypingMind hiển thị máy chủ đang hoạt động và nút Sửa máy chủ
{
  "mcpServers": {
    "fastmcp4j": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

Dùng kết nối với nhiều mô hình

Lưu danh sách máy chủ, mở Plugin, bật các công cụ MCP của fastMCP4J, sau đó chọn bất kỳ mô hình AI nào được hỗ trợ trong TypingMind và dùng các công cụ trong cuộc trò chuyện hoặc gán chúng cho một tác nhân AI.

  1. Mở trang Plugin trong TypingMind.
  2. Bật các công cụ MCP của fastMCP4J.
  3. Bắt đầu cuộc trò chuyện và chọn mô hình AI bạn muốn dùng.
  4. Dùng các công cụ MCP trong cuộc trò chuyện hoặc gán chúng cho một tác nhân AI.
  5. Chuyển sang mô hình AI khác bất cứ khi nào cần mà không phải kết nối lại MCP.
Cuộc trò chuyện TypingMind dùng các công cụ MCP đã bật với một mô hình AI được chọn
Bạn có thể dùng fastMCP4J giúp tôi làm việc này không?
fastMCP4J
Được. Tôi đã đọc.
Đây là kết quả tôi tìm được bằng fastMCP4J.

Câu hỏi thường gặp

Máy chủ MCP fastMCP4J dùng để làm gì?

fastMCP4J là máy chủ MCP cho phép các ứng dụng AI tương thích kết nối với công cụ và ngữ cảnh bên ngoài. Trong TypingMind, bạn chỉ cần thêm máy chủ MCP này một lần để các công cụ của nó có sẵn trong không gian làm việc AI của bạn.

Bạn có thể dùng MCP fastMCP4J với nhiều mô hình AI trong TypingMind không?

Có. TypingMind kết nối các công cụ MCP ở cấp không gian làm việc, nên bạn có thể dùng fastMCP4J với nhiều mô hình AI như Claude, ChatGPT, Gemini hoặc các mô hình khác đã cấu hình trong TypingMind mà không cần thiết lập máy chủ MCP riêng cho từng mô hình.

Vì sao nên dùng MCP fastMCP4J với TypingMind?

TypingMind là một trong những giao diện trò chuyện với LLM tốt nhất vì tập hợp nhiều mô hình AI, prompt, plugin, tác nhân AI, khóa API và công cụ MCP vào một không gian làm việc. Khi kết nối fastMCP4J, bạn có thể dùng các công cụ MCP của dịch vụ này với những mô hình ưa thích, đồng thời giữ quy trình trò chuyện gọn gàng trong TypingMind.

Làm cách nào để kết nối MCP fastMCP4J với TypingMind?

fastMCP4J hoạt động thông qua trình kết nối MCP cục bộ của TypingMind. Đây là lựa chọn phù hợp nhất khi máy chủ MCP cần truy cập tệp cục bộ, ứng dụng máy tính, công cụ dòng lệnh hoặc tài nguyên riêng trên máy tính của bạn.

MCP fastMCP4J cung cấp những công cụ nào trong TypingMind?

fastMCP4J cung cấp các chức năng MCP mà bạn có thể bật từ trang Plugin của TypingMind để dùng trong trò chuyện hoặc gán cho tác nhân AI.

Bạn có cần chia sẻ khóa API với TypingMind để dùng MCP fastMCP4J không?

Không. TypingMind ưu tiên xử lý cục bộ và cho phép bạn kiểm soát nhà cung cấp mô hình, khóa API, prompt và cấu hình MCP. Nếu fastMCP4J yêu cầu xác thực, hãy thêm các header, cài đặt OAuth hoặc cấu hình cục bộ cần thiết cho máy chủ MCP đó khi tạo kết nối.

Máy chủ MCP liên quan

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇