JMX MCP 服务器是一款强大的模型上下文协议(MCP)服务器,为像 Claude Desktop 这样的 AI 助手提供全面的 JMX 监控和管理功能。它允许用户通过自然语言交互来监控 Java 应用程序、管理 MBeans 并执行 JMX 操作。
git clone https://github.com/itz4blitz/JMX-MCP.git
cd JMX-MCP
mvn clean package
# 使用综合验证进行测试
python3 comprehensive-test.py
将以下内容添加到你的 Claude Desktop MCP 配置文件中:
~/.config/claude/mcp_servers.json%APPDATA%\Claude\mcp_servers.json{
"mcpServers": {
"jmx-mcp-server": {
"command": "java",
"args": [
"-Xmx512m",
"-Xms256m",
"-Dspring.profiles.active=stdio",
"-Dspring.main.banner-mode=off",
"-Dlogging.level.root=OFF",
"-Dspring.main.log-startup-info=false",
"-jar",
"/path/to/your/jmx-mcp-server-1.0.0.jar"
],
"env": {
"JAVA_OPTS": "-Djava.awt.headless=true"
}
}
}
}
重启 Claude Desktop 并尝试以下查询:
"What JMX tools are available?"
"Show me the current heap memory usage"
"List all MBean domains"
"What's the garbage collection performance?"
User: "What's the current memory situation?"
Claude: I'll check the JMX memory metrics for you.
[Uses getAttribute tool to read HeapMemoryUsage]
The current heap memory usage is:
- Used: 245 MB
- Committed: 512 MB
- Max: 2048 MB
- Usage: 12% of maximum heap
The application is running efficiently with low memory pressure.
User: "Are there any performance issues?"
Claude: Let me analyze the JMX performance metrics.
[Uses multiple tools to check GC, threads, and memory]
Performance analysis:
✅ Memory: Healthy (12% heap usage)
✅ GC: Efficient (avg 15ms collection time)
⚠️ Threads: High count (245 threads) - consider investigation
✅ CPU: Normal load
Recommendation: Monitor thread creation patterns.
| 工具 | 描述 | 示例用法 |
|---|---|---|
listMBeans |
列出所有发现的 MBeans,并可选择按域过滤 | "Show me all memory-related MBeans" |
getMBeanInfo |
获取特定 MBean 的详细信息 | "Tell me about the Runtime MBean" |
getAttribute |
读取 MBean 属性的值 | "What's the current heap memory usage?" |
setAttribute |
设置可写 MBean 属性的值 | "Set the log level to DEBUG" |
listDomains |
列出所有可用的 MBean 域 | "What domains are available?" |
| 工具 | 描述 | 示例用法 |
|---|---|---|
listJmxConnections |
列出所有配置的 JMX 连接 | "Show me all available connections" |
addJmxConnection |
添加新的 JMX 连接 | "Connect to the production server" |
removeJmxConnection |
删除 JMX 连接 | "Remove the old test connection" |
switchJmxConnection |
切换到不同的 JMX 连接 | "Switch to the staging environment" |
getConnectionInfo |
获取当前 JMX 连接的状态和统计信息 | "Is the JMX connection healthy?" |
| 工具 | 描述 | 示例用法 |
|---|---|---|
discoverJmxServices |
发现系统上启用 JMX 的 Java 应用程序 | "Find all Java apps with JMX enabled" |
autoRegisterDiscoveredConnections |
自动注册发现的 JMX 服务 | "Auto-connect to all discovered Java apps" |
服务器自动将所有 JMX 属性作为 MCP 资源公开,使 AI 助手可以发现和访问这些资源:
资源 URI 格式:
jmx://domain:type=Type,name=Name/attributes/AttributeName
示例资源:
jmx://java.lang:type=Memory/attributes/HeapMemoryUsage
jmx://java.lang:type=Runtime/attributes/Uptime
jmx://java.lang:type=GarbageCollector,name=G1_Young_Generation/attributes/CollectionCount
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Claude AI │◄──►│ JMX MCP Server │◄──►│ Java App JMX │
│ │ │ │ │ │
│ Natural Language│ │ • Tools (12) │ │ • MBeans │
│ Queries │ │ • Resources(224+)│ │ • Attributes │
│ │ │ • JSON-RPC 2.0 │ │ • Operations │
│ │ │ • Multi-Connect │ │ • Discovery │
└─────────────────┘ └──────────────────┘ └─────────────────┘
标准配置,具有完整的日志记录,适用于开发和调试。
针对 Claude Desktop 集成进行了优化:
# 运行综合集成测试
python3 comprehensive-test.py
测试覆盖范围:
mvn test
jmx:
security:
enabled: true
allowed-domains:
- "java.lang"
- "java.nio"
- "com.myapp"
blocked-operations:
- "shutdown"
- "restart"
java -jar target/jmx-mcp-server-1.0.0.jar
java -Xmx1g -Xms512m \
-Dspring.profiles.active=production \
-jar jmx-mcp-server-1.0.0.jar
FROM openjdk:17-jre-slim
COPY target/jmx-mcp-server-1.0.0.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/app.jar"]
我们欢迎贡献!请查看我们的 贡献指南 以获取详细信息。
# 在 GitHub 上 Fork 仓库
git clone https://github.com/YOUR_USERNAME/JMX-MCP.git
cd JMX-MCP
# 构建和测试
mvn clean compile
mvn test
# 运行应用程序
mvn spring-boot:run
本项目采用 MIT 许可证 - 有关详细信息,请参阅 LICENSE 文件。
Made with ❤️ for the AI and Java communities