Token导航 LogoToken导航TokenDH.com
Vertx MCP logo
运维云端未说明官方级别未说明来源级核验

Vertx MCP

MCP Server

基于Vert.x的轻量级非阻塞传输层实现,为Model Context Protocol (MCP)提供SSE和可流式HTTP传输支持,适用于实时双向通信场景。

工具数

0

提示词数

0

GitHub Stars

9

资源数

0
实时通信Java服务器开发

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

kinotic-ai

提供方

kinotic-ai

最后核验

2026/5/17 20:21

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

详细介绍

Vert.x MCP服务器

基于Vert.x的传输实现 模型上下文协议(MCP)Java SDK该项目提供了一个轻量级、无阻塞的传输层,将MCP服务器与Vert.x应用程序集成在一起。

概述

Vert.x MCP服务器提供:

  • Vert.x运输A. VertxMcpTransport 提供Vert.x路由器的界面,可集成到您的Vert.x应用程序中
  • SSE 运输:用于实时双向通信的服务器发送事件(SSE)实现
  • 可流式HTTP传输:新的MCP 2025-06-18可流式HTTP传输实现
  • 垂直支撑:即用型 McpVerticle 便于部署
  • 非阻塞:基于Vert.x构建,用于高性能、事件驱动的架构
  • 会话管理:自动客户端会话处理,支持优雅关机

⚠️ 实验状态

该项目目前处于实验状态,尚未在生产环境中进行全面测试。

  • 该实现遵循MCP规范,但可能包含错误或不完整的功能
  • 随着项目的成熟,API可能会发生变化
  • 性能特征尚未进行彻底的基准测试
  • 请报告您遇到的任何错误、问题或意外行为
  • 欢迎提供意见和反馈,以帮助改进项目

安装

梅文


    org.kinotic
    vertx-mcp
    4.5.1

Gradle

dependencies {
    implementation 'org.kinotic:vertx-mcp:4.5.1'
}

版本兼容性

  • 4.5.x版本:与Vert.x 4.5.x兼容
  • 5.0.x版本:将与Vert.x 5.x兼容(尚不支持)

快速开始

1.创建MCP服务器

首先,使用官方 Java MCP SDK:

import io.modelcontextprotocol.server.McpServer;
import io.modelcontextprotocol.server.McpServerFeatures;
import io.modelcontextprotocol.spec.McpSchema;
import io.modelcontextprotocol.spec.ServerCapabilities;
import java.util.List;
import reactor.core.publisher.Mono;

// Create a simple calculator tool
var calculatorTool = McpServerFeatures.AsyncToolSpecification.builder()
    .tool(McpSchema.Tool.builder()
        .name("calculator")
        .description("Basic calculator")
        .inputSchema("""
            {
              "type": "object",
              "properties": {
                "operation": {"type": "string", "enum": ["add", "subtract", "multiply", "divide"]},
                "a": {"type": "number"},
                "b": {"type": "number"}
              },
              "required": ["operation", "a", "b"]
            }
            """)
        .build())
    .callHandler((exchange, toolReq) -> {
        String operation = (String) toolReq.arguments().get("operation");
        double a = ((Number) toolReq.arguments().get("a")).doubleValue();
        double b = ((Number) toolReq.arguments().get("b")).doubleValue();
        
        double result = switch (operation) {
            case "add" -> a + b;
            case "subtract" -> a - b;
            case "multiply" -> a * b;
            case "divide" -> a / b;
            default -> throw new IllegalArgumentException("Unknown operation: " + operation);
        };
        
        return Mono.just(McpSchema.CallToolResult.builder()
            .textContent(List.of(String.valueOf(result)))
            .isError(false)
            .build());
    })
    .build();

// Create the MCP server specification (don't call .build() yet)
var mcpServerSpec = McpServer.async(transportProvider)
    .serverInfo("calculator-server", "1.0.0")
    .capabilities(ServerCapabilities.builder()
        .tools(true)
        .build())
    .tools(calculatorTool);

2.创建Vert.x传输

选项A:使用传统的HTTP+SSE传输

import io.vertx.ext.mcp.transport.VertxMcpSseServerTransportProvider;
import com.fasterxml.jackson.databind.ObjectMapper;

// Create the transport
var transport = VertxMcpSseServerTransportProvider.builder()
    .baseUrl("http://localhost:8080")
    .messageEndpoint("/mcp/message")
    .sseEndpoint("/mcp/sse")
    .keepAliveInterval(Duration.ofSeconds(30))
    .objectMapper(new ObjectMapper())
    .vertx(vertx)
    .build();

选项B:使用新的流式HTTP传输

import io.vertx.ext.mcp.transport.VertxMcpStreamableServerTransportProvider;
import com.fasterxml.jackson.databind.ObjectMapper;

// Create the Streamable HTTP transport
var transport = VertxMcpStreamableServerTransportProvider.builder()
    .objectMapper(new ObjectMapper())
    .mcpEndpoint("/mcp")
    .disallowDelete(false)
    .vertx(vertx)
    .build();

3.与您的Vert.x应用程序集成

使用提供的Verticle进行轻松集成:

import io.vertx.ext.mcp.McpVerticle;

// Deploy the MCP verticle (pass transport and server specification)
vertx.deployVerticle(new McpVerticle(8080, transport, mcpServerSpec), ar -> {
    if (ar.succeeded()) {
        System.out.println("MCP Verticle deployed successfully");
    } else {
        System.err.println("Failed to deploy MCP Verticle: " + ar.cause());
    }
});

4.完整示例

示例A:传统HTTP+SSE传输

以下是一个使用传统HTTP+SSE传输的完整工作示例:

import io.vertx.core.Vertx;
import io.vertx.ext.mcp.McpVerticle;
import io.vertx.ext.mcp.transport.VertxMcpSseServerTransportProvider;
import io.modelcontextprotocol.server.McpServer;
import io.modelcontextprotocol.server.McpServerFeatures;
import io.modelcontextprotocol.spec.McpSchema;
import io.modelcontextprotocol.spec.ServerCapabilities;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.time.Duration;
import java.util.List;
import reactor.core.publisher.Mono;

public class LegacyMcpServerExample {
    public static void main(String[] args) {
        Vertx vertx = Vertx.vertx();
        
        // Create MCP server with a simple calculator tool
        var calculatorTool = McpServerFeatures.AsyncToolSpecification.builder()
            .tool(McpSchema.Tool.builder()
                .name("calculator")
                .description("Basic calculator")
                .inputSchema("""
                    {
                      "type": "object",
                      "properties": {
                        "operation": {"type": "string", "enum": ["add", "subtract", "multiply", "divide"]},
                        "a": {"type": "number"},
                        "b": {"type": "number"}
                      },
                      "required": ["operation", "a", "b"]
                    }
                    """)
                .build())
            .callHandler((exchange, toolReq) -> {
                String operation = (String) toolReq.arguments().get("operation");
                double a = ((Number) toolReq.arguments().get("a")).doubleValue();
                double b = ((Number) toolReq.arguments().get("b")).doubleValue();
                
                double result = switch (operation) {
                    case "add" -> a + b;
                    case "subtract" -> a - b;
                    case "multiply" -> a * b;
                    case "divide" -> a / b;
                    default -> throw new IllegalArgumentException("Unknown operation: " + operation);
                };
                
                return Mono.just(McpSchema.CallToolResult.builder()
                    .textContent(List.of(String.valueOf(result)))
                    .isError(false)
                    .build());
            })
            .build();

        // Create legacy HTTP+SSE transport
        var transport = VertxMcpSseServerTransportProvider.builder()
            .baseUrl("http://localhost:8080")
            .messageEndpoint("/mcp/message")
            .sseEndpoint("/mcp/sse")
            .keepAliveInterval(Duration.ofSeconds(30))
            .objectMapper(new ObjectMapper())
            .vertx(vertx)
            .build();

        // Create MCP server specification (don't call .build() yet)
        var mcpServerSpec = McpServer.async(transport)
            .serverInfo("calculator-server", "1.0.0")
            .capabilities(ServerCapabilities.builder()
                .tools(true)
                .build())
            .tools(calculatorTool);

        // Deploy the MCP verticle (pass transport and server specification)
        vertx.deployVerticle(new McpVerticle(8080, transport, mcpServerSpec), ar -> {
            if (ar.succeeded()) {
                System.out.println("MCP Server started on port 8080");
                System.out.println("SSE endpoint: http://localhost:8080/mcp/sse");
                System.out.println("Message endpoint: http://localhost:8080/mcp/message");
            } else {
                System.err.println("Failed to start MCP Server: " + ar.cause());
            }
        });
    }
}

示例B:新的流式HTTP传输

以下是一个使用新的MCP 2025-06-18流式HTTP传输的完整工作示例:

import io.vertx.core.Vertx;
import io.vertx.ext.mcp.McpVerticle;
import io.vertx.ext.mcp.transport.VertxMcpStreamableServerTransportProvider;
import io.modelcontextprotocol.server.McpServer;
import io.modelcontextprotocol.server.McpServerFeatures;
import io.modelcontextprotocol.spec.McpSchema;
import io.modelcontextprotocol.spec.ServerCapabilities;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.time.Duration;
import java.util.List;
import reactor.core.publisher.Mono;

public class StreamableMcpServerExample {
    public static void main(String[] args) {
        Vertx vertx = Vertx.vertx();
        
        // Create MCP server with a simple calculator tool
        var calculatorTool = McpServerFeatures.AsyncToolSpecification.builder()
            .tool(McpSchema.Tool.builder()
                .name("calculator")
                .description("Basic calculator")
                .inputSchema("""
                    {
                      "type": "object",
                      "properties": {
                        "operation": {"type": "string", "enum": ["add", "subtract", "multiply", "divide"]},
                        "a": {"type": "number"},
                        "b": {"type": "number"}
                      },
                      "required": ["operation", "a", "b"]
                    }
                    """)
                .build())
            .callHandler((exchange, toolReq) -> {
                String operation = (String) toolReq.arguments().get("operation");
                double a = ((Number) toolReq.arguments().get("a")).doubleValue();
                double b = ((Number) toolReq.arguments().get("b")).doubleValue();
                
                double result = switch (operation) {
                    case "add" -> a + b;
                    case "subtract" -> a - b;
                    case "multiply" -> a * b;
                    case "divide" -> a / b;
                    default -> throw new IllegalArgumentException("Unknown operation: " + operation);
                };
                
                return Mono.just(McpSchema.CallToolResult.builder()
                    .textContent(List.of(String.valueOf(result)))
                    .isError(false)
                    .build());
            })
            .build();

        // Create Streamable HTTP transport
        var transport = VertxMcpStreamableServerTransportProvider.builder()
            .objectMapper(new ObjectMapper())
            .mcpEndpoint("/mcp")
            .disallowDelete(false)
            .vertx(vertx)
            .keepAliveInterval(Duration.ofSeconds(30))
            .build();

        // Create MCP server specification (don't call .build() yet)
        var mcpServerSpec = McpServer.async(transport)
            .serverInfo("calculator-server", "1.0.0")
            .capabilities(ServerCapabilities.builder()
                .tools(true)
                .build())
            .tools(calculatorTool);

        // Deploy the MCP verticle (pass transport and server specification)
        vertx.deployVerticle(new McpVerticle(8080, transport, mcpServerSpec), ar -> {
            if (ar.succeeded()) {
                System.out.println("MCP Server started on port 8080");
                System.out.println("Streamable HTTP endpoint: http://localhost:8080/mcp");
                System.out.println("Supports: GET (SSE), POST (messages), DELETE (sessions)");
            } else {
                System.err.println("Failed to start MCP Server: " + ar.cause());
            }
        });
    }
}

配置选项

传统HTTP+SSE传输

VertxMcpSseServerTransportProvider 支持多种配置选项:

  • baseUrl:服务器的基本URL(必需)
  • messageEndpoint:用于接收JSON-RPC消息的端点(默认值: /message)
  • sseEndpoint:SSE连接的终结点(默认值: /sse)
  • keepAliveInterval:ping消息保持活动的间隔(默认值:30秒)
  • objectMapper:用于JSON序列化的Jackson ObjectMapper
  • vertx:Vert.x实例

可流式HTTP传输

VertxMcpStreamableServerTransportProvider 支持:

  • objectMapper:用于JSON处理的Jackson ObjectMapper(必需)
  • mcpEndpoint:MCP端点路径(默认值: /mcp)
  • disallowDelete:是否禁用会话删除(默认值: false)
  • vertx:Vert.x实例(必需)
  • keepAliveInterval:ping消息保持活动的间隔(默认值:30秒)

建筑

传统HTTP+SSE传输

传输使用以下方式实现MCP协议:

  1. SSE 连接 (/sse):为服务器到客户端通信建立服务器发送事件连接
  2. 消息端点 (/message):从客户端接收JSON-RPC消息
  3. 会话管理:自动管理客户端会话和清理
  4. 持久连接:定期发送ping消息以防止连接超时

可流式HTTP传输

新的流式HTTP传输遵循MCP 2025-06-18规范:

  1. 单端点 (/mcp):处理所有HTTP方法(GET、POST、DELETE)
  2. 会话管理:使用具有唯一会话ID的MCP SDK会话管理
  3. 流恢复:支持通过Last Event ID标头恢复断开的连接
  4. 协议遵从:完全符合最新的MCP规范

测试

您可以使用任何MCP客户端测试您的MCP服务器:

传统运输

  • SSE 终端: http://localhost:8080/mcp/sse 用于建立连接
  • 消息端点: http://localhost:8080/mcp/message?sessionId= 用于发送请求

可流动运输

  • 单端点: http://localhost:8080/mcp 对于所有操作
  • 获取:建立SSE监听流
  • 发布:发送JSON-RPC消息
  • 删除:终止会话

优雅地关闭

传输支持优雅关机:

// Close the transport gracefully
transport.closeGracefully()
    .doOnSuccess(v -> System.out.println("Transport closed successfully"))
    .doOnError(e -> System.err.println("Error closing transport: " + e))
    .subscribe();

路线图

计划在未来的版本中提供以下功能:

Vert.x 5支持

支持Vert.x 5.x版本,包括:

  • 与Vert.x 5.x API的兼容性
  • 更新了Vert.x 5的传输实施
  • 利用新的Vert.x 5功能提高性能

授权支持

实施 MCP授权 能力包括:

  • 符合OAuth 2.1的授权流程
  • 动态客户端注册
  • 访问令牌验证和受众绑定
  • 安全令牌发行的资源参数支持

贡献

欢迎投稿!请随时提交pull请求或打开bug和功能请求的问题。

许可证

此项目根据Apache许可证2.0版获得许可。

目录标签

目录标签

实时通信Java服务器开发本地部署非阻塞IO协议传输Vert.x集成

接入字段

传输方式(transport,传输协议)

未说明

鉴权方式(authType,认证方式)

oauth

工具数量(toolCount,工具数)

0

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

未说明oauth部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

仍需确认:installCommand

来源信息

继续浏览同类 MCP