Skip to content

Conversation

@Yeaury
Copy link
Contributor

@Yeaury Yeaury commented Jul 7, 2025

#3013

协议部分 (2024-11-05)

采用分层架构,主要分为以下几层:

  • 传输层(Transport Layer):主要负责连接管理、消息和响应的处理
  • 会话层(Session Layer):主要负责维护会话状态、实现断线重连、以及 消息路由和分发
  • 服务器层(Server Layer):负责服务端生命周期管理、功能特性注册和管理
  • 功能特性层(Features Layer):负责定义和管理服务器的功能

TransportProvider : Transport : McpSession : 客户端 = 1 : N : N : N

TransportProvider 作为工厂类,为每个新的客户端连接创建新的 Transport,Transport 负责与单个客户端之间的消息传输 ,McpSession 管理单个客户端的所有会话状态。

工具架构

image

由于现在仅支持旧版本的mcp协议(2024-11-05),暂未支持Streamable http,支持的工具只是单次调用的,支持列表:

jvm相关

  • getstatic - 查看类的静态属性
  • jvm - 查看当前 JVM 的信息
  • memory - 查看 JVM 的内存信息
  • ognl - 执行 ognl 表达式
  • perfcounter - 查看当前 JVM 的 Perf Counter 信息
  • sysenv - 查看 JVM 的环境变量
  • sysprop - 查看和修改 JVM 的系统属性
  • vmoption - 查看和修改 JVM 里诊断相关的 option
  • vmtool - 从 jvm 里查询对象,执行 forceGc

class/classloader 相关

  • classloader - 查看 classloader 的继承树,urls,类加载信息,使用 classloader 去 getResource
  • jad - 反编译指定已加载类的源码
  • mc - 内存编译器,内存编译.java文件为.class文件
  • redefine - 加载外部的.class文件,redefine 到 JVM 里
  • retransform - 加载外部的.class文件,retransform 到 JVM 里
  • sc - 查看 JVM 已加载的类信息
  • sm - 查看已加载类的方法信息

Todo

  • 在 CommandExecutorImpl 中实现异步执行命令:由于现在的协议仅支持的单次sse回复,待升级到streamable http模式会支持异步执行命令的方式
  • 执行命令session的管理与复用:现在的模式是每次执行命令就创建一个新的,命令执行结束之后进行销毁,需要支持对命令session的统一管理和复用,与mcp server session进行绑定
  • Streamable http的支持:计划在 exchange 中实现 server 主动向 client 端推送信息(如阶段执行结果,进度,状态等),实现流式的响应;把 exchange 放在 context 中提供给工具使用,在工具中主动的推送流程
  • 支持连续型诊断的工具,通过异步执行命令的方式不断轮询结果,进行阶段性的结果推送
  • 部分工具的执行结果用资源的形式返回给 client
  • 事件存储系统,为断线重连时的事件重播做准备
@hengyunabc hengyunabc requested a review from Copilot July 16, 2025 15:49

This comment was marked as outdated.

@hengyunabc
Copy link
Collaborator

使用 inspector 来调用,返回的好像不是合法的 json:

image
@hengyunabc
Copy link
Collaborator

好像没有把具体的 field name 转换为 mcp tool 的参数名:

image
@Yeaury
Copy link
Contributor Author

Yeaury commented Jul 17, 2025

好像没有把具体的 field name 转换为 mcp tool 的参数名:

image

用反射的方法获取到参数的名字并返回,已经解决了

@Yeaury
Copy link
Contributor Author

Yeaury commented Jul 17, 2025

使用 inspector 来调用,返回的好像不是合法的 json:

image

done

@hengyunabc hengyunabc requested a review from Copilot July 17, 2025 14:30

This comment was marked as outdated.

@hengyunabc hengyunabc requested a review from Copilot July 17, 2025 15:28

This comment was marked as outdated.

@Yeaury Yeaury changed the base branch from master to mcp July 27, 2025 01:49
@hengyunabc hengyunabc requested a review from Copilot July 28, 2025 03:18

This comment was marked as outdated.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@hengyunabc hengyunabc requested a review from Copilot July 28, 2025 07:10
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a comprehensive MCP (Model Context Protocol) base protocol implementation using Netty for Arthas. The purpose is to enable Arthas to expose its diagnostic capabilities through a standardized protocol that can be consumed by AI models and other clients.

Key changes include:

  • Implements MCP 2024-11-05 protocol specification with JSON-RPC message handling
  • Provides HTTP/SSE transport layer using Netty for real-time communication
  • Integrates 20+ Arthas diagnostic tools (JVM, class loading, memory analysis) as MCP tools
  • Establishes layered architecture with transport, session, server, and features layers

Reviewed Changes

Copilot reviewed 60 out of 60 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
pom.xml Adds new arthas-mcp-server module to the build
McpSchema.java Comprehensive MCP protocol schema definitions and JSON-RPC message types
McpServer.java Main server interface and builder for configuring MCP server instances
McpRequestHandler.java HTTP request handler managing SSE connections and message routing
Tool implementations 20+ tool classes wrapping Arthas commands (jvm, memory, classloader, etc.)
Utility classes JSON parsing, schema generation, assertion helpers, and type conversion utilities
@hengyunabc hengyunabc merged commit 1522341 into alibaba:mcp Jul 30, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants