MCP HubMCP Hub
quarkiverse

quarkus-mcp-server

by: quarkiverse

This extension enables developers to implement the MCP server features easily.

83created 11/12/2024
Visit
extension
development

📌Overview

Purpose: To provide a framework for enabling seamless integration between large language model (LLM) applications and external data sources through the Model Context Protocol (MCP).

Overview: The Quarkus Model Context Protocol (MCP) Server facilitates the implementation of the MCP, offering developers both declarative and programmatic APIs to easily build server features that integrate with LLM applications. This allows for enhanced interactions with external resources and tools, making development streamlined and efficient.

Key Features:

  • Declarative and Programmatic APIs: Enables developers to define server features through annotations on business methods, simplifying the creation and management of functionalities like prompts and tools.

  • Integration with LangChain4j: Provides client functionality for MCP, either through a low-level programmatic API or full integration into AI-infused applications, enhancing its versatility and usability.


Quarkus Model Context Protocol (MCP) Server

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

This extension provides declarative and programmatic APIs that enable developers to easily implement MCP server features.

Note:
The LangChain4j project provides 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 Dependency

Add the following dependency to your POM file:

<dependency>
    <groupId>io.quarkiverse.mcp</groupId>
    <!-- use 'quarkus-mcp-server-stdio' if you want to use the STDIO transport instead of the HTTP/SSE transport -->
    <artifactId>quarkus-mcp-server-sse</artifactId>
    <version>${project-version}</version>
</dependency>

Step 2: Add Server Features

Define server features (prompts, resources, and tools) as annotated business methods of CDI beans:

import jakarta.inject.Inject;
import java.io.IOException;
import java.nio.file.Files;
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.Tool;
import io.quarkiverse.mcp.server.Resource;
import io.quarkiverse.mcp.server.TextContent;

public class ServerFeatures {

    @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")
    BlobResourceContents alpha(RequestUri uri) throws IOException{
        return BlobResourceContents.create(uri.value(), Files.readAllBytes(Paths.ALPHA));
    }
}

Step 3: Run Your Application

Run your Quarkus application and enjoy the MCP server features!

Documentation

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

Contributors ✨

Thanks to these wonderful people:

  • Martin Kouba
  • Georgios Andrianakis
  • Max Rydahl Andersen
  • Rostislav Svoboda
  • George Gastaldi
  • Jan Martiska
  • Ioannis Canellos

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