Quarkus MCP 服务端

Quarkus MCP Server 是 Quarkus 生态中用于实现模型上下文协议(MCP)服务端的扩展,通过声明式和编程式 API 提供 Tool、Prompt、Resource 等功能,适用于让 LLM 应用连接外部数据源与工具的集成场景。

  • by quarkiverse
  • Java
  • 本地部署
  • 203 星标
  • 更新于
在 GitHub 查看 quarkiverse/quarkus-mcp-server

使用说明

Quarkus MCP Server

This Quarkus extension provides both declarative and programmatic APIs that enable developers to easily implement MCP[^1] server features.

[^1]: "Model Context Protocol (MCP) is an open protocol that enables seamless integration between LLM applications and external data sources and tools."

[!NOTE]
The LangChain4j project provides the MCP client functionality, either as a low-level programmatic API or as a full-fledged integration into AI-infused applications.

Get Started

Step #1

Add the following dependency to your POM file:

<dependency>
    <groupId>io.quarkiverse.mcp</groupId>
    <artifactId>quarkus-mcp-server-http</artifactId>
    <version>${quarkus-mcp-server-version}</version>
</dependency>

[!NOTE]
This dependency includes both the legacy "HTTP/SSE" and the "Streamable HTTP" transport. Use the quarkus-mcp-server-stdio artifactId if you want to use the STDIO transport instead. See also the Transports section in the docs for more information.

Step #2

Add server features (prompts, resources and tools) represented by annotated business methods of CDI beans.

import jakarta.inject.Inject;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import io.quarkiverse.mcp.server.BlobResourceContents;
import io.quarkiverse.mcp.server.Prompt;
import io.quarkiverse.mcp.server.PromptArg;
import io.quarkiverse.mcp.server.PromptMessage;
import io.quarkiverse.mcp.server.Resource;
import io.quarkiverse.mcp.server.TextContent;
import io.quarkiverse.mcp.server.Tool;

// This class is automatically registered as a @Singleton CDI bean
public class MyFeatures {

    @Inject
    CodeService codeService;

    @Tool(description = "Converts the string value to lower case")
    String toLowerCase(String value) {
        return value.toLowerCase();
    }

    @Prompt(name = "code_assist")
    PromptMessage codeAssist(@PromptArg(name = "lang") String language) {
        return PromptMessage.withUserRole(new TextContent(codeService.assist(language)));
    }

    @Resource(uri = "file:///project/alpha.txt")
    byte[] alpha() throws IOException{
        return Files.readAllBytes(Path.of("alpha.txt"));
    }

}

Step #3

Run your Quarkus app and have fun!

Documentation

The full documentation is available at https://quarkiverse.github.io/quarkiverse-docs/quarkus-mcp-server/dev/index.html.

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Martin Kouba

💻 🚧

Georgios Andrianakis

💻

Max Rydahl Andersen

💡

Rostislav Svoboda

💻

George Gastaldi

🚇

Jan Martiska

📖

Ioannis Canellos

💻

Sergey Beryozkin

💡

Konstantin Pavlov

⚠️ 🚇

Martijn van Duijnhoven

💻 ⚠️ 📖

Pierre Beitz

💻 ⚠️

Matthieu Recouly

📖

Willem Jan Glerum

🚇

Sascha Steffen

💻 ⚠️

Clement Escoffier

📖

Rolfe Dlugy-Hegwer

📖 💻

Bruno Baptista

📖 💻

Moayad Alyaghshi

🐛 💻

David Kornel

🐛 💻

Ian Stewart

🐛 💻

Eric Hare

🐛 💻

Nagi KaTou

🐛 💻

Matej Novotny

🐛 ⚠️ 💻

This project follows the all-contributors specification. Contributions of any kind welcome!