cfr MCP server

MCPAI代理

提供方 Mr-xn

AI代理 stdio · 本地进程 Token 社区 / 第三方 Claude DesktopClaudeCursor
查看接入方式

一个基于Python的MCP服务器实现,封装了cfr.jar反编译功能,支持SSE传输协议,用于反编译Java类或JAR文件。

一句话选型结论

按资料字段整理

cfr MCP server 属于AI代理类 MCP 服务器,stdio · 本地进程,Token,可直接接入 Claude Desktop、Claude、Cursor,有可直接执行的安装命令。接入前先确认权限范围;涉及写入、删除或付款的操作,建议先在测试环境验证。

分类AI代理 传输方式stdio · 本地进程 鉴权Token 部署方式本地部署
GitHub 星标 3 仓库热度,无公开仓库时显示未标注
工具数 未标注 暴露给模型的工具数量
资源 / 提示词 0 / 0 资源与提示词模板数量
维护方 社区 / 第三方 核验等级 仅资料核对

工具与能力

AI代理
数量来自来源目录的标注,具体工具清单以官方文档为准
工具数量未标注暴露给模型可调用的工具个数
资源数量0可读取的资源条目
提示词数量0内置提示词模板数量

能力标签

支持客户端

适用场景

Java反编译Python本地部署服务器SSE传输MCP协议开发工具

安装与配置

stdio · 本地进程 Token
客户端在本机拉起子进程,数据不出本机
pip install mcp starlette uvicorn

这条命令只是入口,具体启动参数请按官方文档补齐,不要直接照搬到别的服务器。

  1. 1
    准备运行环境

    stdio 服务在本地起进程,需要先装好 Node.js 等运行时,再按安装命令拉取依赖。

  2. 2
    安装服务

    复制上面的安装命令执行;命令里带占位符的位置,换成自己的密钥或路径。

  3. 3
    写入客户端配置

    在客户端的 MCP 配置里填好启动命令和参数,保存后完全退出客户端再打开,让新配置生效。

  4. 4
    验证是否可用

    连接成功后随便调一个只读工具,确认能返回结果,再接入正式流程。

典型使用场景

3 类
按分类与标签整理的常见用法,具体以官方文档为准
给代理接外部能力

让代理在任务中途调用搜索、数据库等真实工具。

多步任务编排

把一串操作拆成步骤,由代理按顺序执行。

自动化重复流程

把固定流程交给代理跑,减少手工操作。

选择建议

选之前先看这几条
按条目字段给出的判断,不替你决定用不用

值得选的地方

  • 有现成的安装命令,不用自己找入口,照着跑就能起服务。
  • 已适配 Claude Desktop、Claude、Cursor,换客户端不用重新研究配置。

先想清楚的地方

  • stdio 方式要求本地装好运行时(如 Node.js),换机器要重新装一遍。
  • 使用前要准备好Token对应的凭据,并按最小权限配置。
  • 资料没标注工具数量,实际能力要装好后确认。
  • 版本更新与行为细节以官方仓库为准。

更适合

  • 需要在AI代理场景里让模型直接调用外部能力的人。
  • 已经在用 Claude Desktop、Claude 的用户,接入路径最短。
  • 想先快速试一下、能接受在本地或自有环境跑服务的人。

不太适合

  • 完全不想在本地装环境的人。
  • 不方便管理密钥或第三方授权的人。
  • 需要厂商级 SLA 和技术支持的生产环境。

同类对比

6 个同类
同分类里挑最接近的几条,字段以各自详情页为准
MCP 服务器工具数传输方式部署方式安装命令最后核验
cfr MCP server当前 未标注 stdio · 本地进程 本地部署 有 2026-05-17
Filesystem 560c4363 13 未标注 本地部署 无 2026-05-17
Server Everything (everything) 11 stdio · 本地进程 本地部署 有 2026-05-17
Time 7365cb6d 2 SSE · 服务端推送 远程部署 有 2026-05-18
Everything Claude Code 未标注 stdio · 本地进程 本地部署 有 2026-05-17
Openmemory 557e1585 未标注 stdio · 本地进程 本地部署 有 2026-05-17

服务器档案

AI代理
字段来自项目仓库与公开索引,中文说明由本站标注
提供方Mr-xn上游标注的维护方 Mr-xn
分类AI代理本站按上游分类展示
连接方式stdio · 本地进程客户端在本机拉起子进程,数据不出本机
鉴权方式Token远程服务建议用最小权限凭据
维护方社区 / 第三方核验等级 仅资料核对
包名 / 运行时未标注 · 未标注本地安装时用到的包标识与运行时
部署类型本地部署上游给出的部署形态
最近核验2026-05-17上游最后核验时间

详细介绍

11.5 KB
来自项目仓库与上游目录的原文,未做删改

前言

这是一个基于 Python 的 MCP (Model Context Protocol) 服务器实现,封装了 cfr.jar 反编译功能,并支持 SSE (Server-Sent Events) 传输协议。

正文

1. 环境准备

确保当前目录下有 cfr.jar。

安装 Python 依赖:```Bash
pip install mcp starlette uvicorn


## 2. 服务器代码 (`cfr_mcp_server.py`)

该脚本封装了 `cfr.jar`,提供了一个名为 `decompile` 的工具。

> 需要注意修改 CFR_JAR_PATH (cfr.jar 文件路径)```Python
import os
import re
import asyncio
import logging
import subprocess
import uvicorn
from pathlib import Path
from functools import partial
from starlette.applications import Starlette
from starlette.routing import Route, Mount
from starlette.responses import Response
from mcp.server import Server
from mcp.server.sse import SseServerTransport
import mcp.types as types

# --- Configuration (配置) ---
# Path to the CFR jar file
# CFR jar 文件路径
CFR_JAR_PATH = "/path/to/cfr.jar"

# Server Host and Port
# 服务器主机和端口
HOST = "0.0.0.0"
PORT = 8000

# Command execution timeout in seconds
# 命令执行超时时间(秒)
CMD_TIMEOUT_SECONDS = 30

# --- Logging (日志) ---
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("cfr_server")

# --- Server Instance (服务器实例) ---
server = Server("cfr-decompiler")

def validate_option_key(key: str) -> bool:
"""
Allow only alphanumeric keys to prevent injection.
仅允许字母数字键名以防止注入。
"""
return bool(re.match(r'^[a-zA-Z0-9]+$', key))

def run_cfr_sync(cmd: list) -> str:
"""
Sync execution wrapper for thread pool.
用于线程池的同步执行包装器。
"""
try:
logger.info(f"Exec: {' '.join(cmd)}")
process = subprocess.run(
cmd,
capture_output=True,
text=True,
check=False,
timeout=CMD_TIMEOUT_SECONDS
)

output = process.stdout
if process.stderr and len(process.stderr.strip()) > 0:
# Append stderr output as comments
# 将错误输出作为注释附加
output += f"\n\n/*\n[CFR STDERR]\n{process.stderr}\n*/"

return output
except subprocess.TimeoutExpired:
return "/* Error: Decompilation timed out. File might be too complex or large. (反编译超时,文件可能过大或过于复杂) */"
except Exception as e:
return f"/* Error executing CFR (执行 CFR 出错): {str(e)} */"

@server.list_tools()
async def list_tools() -> list[types.Tool]:
"""
List available tools.
列出可用工具。
"""
return [
types.Tool(
name="decompile",
description=(
"Decompile a Java class/JAR using CFR. "
"Use this to view the source code of compiled Java files. "
"使用 CFR 反编译 Java class/JAR 文件。用于查看编译后的 Java 文件的源代码。"
),
inputSchema={
"type": "object",
"properties": {
"file_path": {
"type": "string",
"description": "Absolute path to the .class or .jar file. (.class 或 .jar 文件的绝对路径)"
},
"method_name": {
"type": "string",
"description": "Only decompile methods with this name (highly recommended for large classes). (仅反编译指定名称的方法,强烈建议用于大类)"
},
"ignore_exceptions": {
"type": "boolean",
"description": "Drop try-catch blocks to make logic clearer (CFR --ignoreexceptions true). Default: false. (移除 try-catch 块以使逻辑更清晰)"
},
"hide_utf": {
"type": "boolean",
"description": "Hide UTF-8 characters if encoding is messy (CFR --hideutf true). Default: false. (如果编码混乱,隐藏 UTF-8 字符)"
},
"options": {
"type": "object",
"description": "Advanced CFR options (e.g. {'sugarboxing': False}). Key must be alphanumeric. (高级 CFR 选项,键必须是字母数字)"
}
},
"required": ["file_path"]
}
)
]

@server.call_tool()
async def call_tool(name: str, arguments: dict) -> list[types.TextContent]:
"""
Handle tool execution.
处理工具执行。
"""
if name != "decompile":
raise ValueError(f"Unknown tool (未知工具): {name}")

# 1. Validation (验证)
file_path_str = arguments.get("file_path")
if not file_path_str:
raise ValueError("file_path is required (需要 file_path 参数)")

path = Path(file_path_str).resolve()
if not path.exists():
return [types.TextContent(type="text", text=f"Error: File not found (文件未找到): {path}")]

if not Path(CFR_JAR_PATH).exists():
return [types.TextContent(type="text", text=f"Error: CFR jar not found at (CFR jar 未找到): {CFR_JAR_PATH}")]

# 2. Build Command (构建命令)
cmd = ["java", "-jar", CFR_JAR_PATH, str(path)]

if arguments.get("method_name"):
cmd.extend(["--methodname", arguments.get("method_name")])

if arguments.get("ignore_exceptions"):
cmd.extend(["--ignoreexceptions", "true"])

if arguments.get("hide_utf"):
cmd.extend(["--hideutf", "true"])

# Defaults (默认设置)
cmd.extend(["--comments", "false"])    # No header comments (无头部注释)
cmd.extend(["--showversion", "false"]) # No version info (无版本信息)

# Advanced Options (高级选项)
extra_options = arguments.get("options", {})
for key, value in extra_options.items():
if not validate_option_key(key):
logger.warning(f"Ignored invalid option key (忽略无效选项键): {key}")
continue
val_str = str(value).lower() if isinstance(value, bool) else str(value)
cmd.extend([f"--{key}", val_str])

# 3. Async Execution (异步执行)
# Run synchronous subprocess in a thread pool to avoid blocking the event loop
# 在线程池中运行同步 subprocess,避免阻塞事件循环
loop = asyncio.get_running_loop()
result = await loop.run_in_executor(None, partial(run_cfr_sync, cmd))

return [types.TextContent(type="text", text=result)]

# --- SSE Transport (SSE 传输) ---
sse = SseServerTransport("/messages")

async def handle_sse(request):
"""
Handle the initial SSE connection (GET).
处理初始 SSE 连接 (GET)。
"""
async with sse.connect_sse(request.scope, request.receive, request._send) as streams:
await server.run(
streams[0],
streams[1],
server.create_initialization_options()
)
return Response()

app = Starlette(routes=[
Route("/sse", endpoint=handle_sse),
Mount("/messages", app=sse.handle_post_message)
])

if __name__ == "__main__":
# Log Format Configuration (日志格式配置)
log_config = uvicorn.config.LOGGING_CONFIG
log_config["formatters"]["access"]["fmt"] = "%(asctime)s - %(levelname)s - %(message)s"
log_config["formatters"]["default"]["fmt"] = "%(asctime)s - %(levelname)s - %(message)s"
log_config["formatters"]["access"]["datefmt"] = "%Y-%m-%d %H:%M:%S"
log_config["formatters"]["default"]["datefmt"] = "%Y-%m-%d %H:%M:%S"

print(f"Starting Optimized CFR MCP Server on {HOST}:{PORT}")
print(f"SSE Endpoint: http://{HOST}:{PORT}/sse")
uvicorn.run(app, host=HOST, port=PORT, log_config=log_config)

核心逻辑:

  • 使用 mcp SDK 和 Starlette 处理 SSE。
  • 使用 subprocess 调用 Java 命令:java -jar cfr.jar [options]。
  • 捕获标准输出返回给 MCP 客户端。

3. 启动服务器

运行以下命令启动服务(默认端口 8000):```Bash
python cfr_mcp_server.py


输出示例:```Plain
➜  cfr_mcp_server python3 cfr_mcp_server.py
Starting CFR MCP Server on 0.0.0.0:8000
SSE Endpoint: http://0.0.0.0:8000/sse
2026-01-09 16:09:56 - INFO - Started server process [1537138]
2026-01-09 16:09:56 - INFO - Waiting for application startup.
2026-01-09 16:09:56 - INFO - Application startup complete.
2026-01-09 16:09:56 - INFO - Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
2026-01-09 16:10:12 - INFO - 127.0.0.1:46308 - "POST /sse HTTP/1.1" 405
2026-01-09 16:10:12 - INFO - 127.0.0.1:46308 - "GET /sse HTTP/1.1" 200
2026-01-09 16:10:12 - INFO - 127.0.0.1:46314 - "POST /messages?session_id=f951c2ad72a346c18f2c30d1e6d63d9c HTTP/1.1" 307
2026-01-09 16:10:12 - INFO - 127.0.0.1:46314 - "POST /messages/?session_id=f951c2ad72a346c18f2c30d1e6d63d9c HTTP/1.1" 202
2026-01-09 16:10:12 - INFO - 127.0.0.1:46314 - "POST /messages?session_id=f951c2ad72a346c18f2c30d1e6d63d9c HTTP/1.1" 307
2026-01-09 16:10:12 - INFO - 127.0.0.1:46314 - "POST /messages/?session_id=f951c2ad72a346c18f2c30d1e6d63d9c HTTP/1.1" 202
2026-01-09 16:10:12 - INFO - 127.0.0.1:46314 - "POST /messages?session_id=f951c2ad72a346c18f2c30d1e6d63d9c HTTP/1.1" 307
2026-01-09 16:10:12 - INFO - 127.0.0.1:46314 - "POST /messages/?session_id=f951c2ad72a346c18f2c30d1e6d63d9c HTTP/1.1" 202
INFO:mcp.server.lowlevel.server:Processing request of type ListToolsRequest
2026-01-09 16:10:15 - INFO - 127.0.0.1:46314 - "POST /messages?session_id=f951c2ad72a346c18f2c30d1e6d63d9c HTTP/1.1" 307
2026-01-09 16:10:15 - INFO - 127.0.0.1:46314 - "POST /messages/?session_id=f951c2ad72a346c18f2c30d1e6d63d9c HTTP/1.1" 202
2026-01-09 16:10:15 - INFO - 127.0.0.1:46320 - "POST /messages?session_id=f951c2ad72a346c18f2c30d1e6d63d9c HTTP/1.1" 307
INFO:mcp.server.lowlevel.server:Processing request of type ListPromptsRequest
2026-01-09 16:10:15 - INFO - 127.0.0.1:46314 - "POST /messages/?session_id=f951c2ad72a346c18f2c30d1e6d63d9c HTTP/1.1" 202
INFO:mcp.server.lowlevel.server:Processing request of type ListResourcesRequest
2026-01-09 16:11:44 - INFO - 127.0.0.1:48686 - "POST /messages?session_id=f951c2ad72a346c18f2c30d1e6d63d9c HTTP/1.1" 307
2026-01-09 16:11:44 - INFO - 127.0.0.1:48686 - "POST /messages/?session_id=f951c2ad72a346c18f2c30d1e6d63d9c HTTP/1.1" 202
INFO:mcp.server.lowlevel.server:Processing request of type ListToolsRequest
2026-01-09 16:11:56 - INFO - 127.0.0.1:56536 - "POST /messages?session_id=f951c2ad72a346c18f2c30d1e6d63d9c HTTP/1.1" 307
2026-01-09 16:11:56 - INFO - 127.0.0.1:56536 - "POST /messages/?session_id=f951c2ad72a346c18f2c30d1e6d63d9c HTTP/1.1" 202
INFO:mcp.server.lowlevel.server:Processing request of type CallToolRequest
2026-01-09 16:11:56 - INFO - Executing CFR command: java -jar /path/to/cfr.jar /path/to/htoa/temp_class/com/oa8000/traceserver/TraceCreateServer.class --comments false
2026-01-09 16:11:57 - INFO - 127.0.0.1:56536 - "POST /messages?session_id=f951c2ad72a346c18f2c30d1e6d63d9c HTTP/1.1" 307
2026-01-09 16:11:57 - INFO - 127.0.0.1:56536 - "POST /messages/?session_id=f951c2ad72a346c18f2c30d1e6d63d9c HTTP/1.1" 202
INFO:mcp.server.lowlevel.server:Processing request of type ListToolsRequest

4. 客户端配置

方式 A: HTTP/SSE 连接 (推荐)

如果你的 MCP 客户端支持通过 URL 连接(如 Cursor 或某些 Web 客户端):

  • Server URL: http://localhost:8000/sse

opencode

比如在opencode里mcp部分配置```JSON
"cfr-decompiler": {
"type": "remote",
"url": "http://127.0.0.1:8000/sse",
"enabled": true,
"timeout": 300,
"headers": {
"Authorization": "Bearer MY_API_KEY"
},
},


在代码分析过程中,LLM自主决定自动调用反编译class

指定调用

#### Cherry Studio

在 MCP服务器 部分配置类型为 服务器发送事件(sse)的mcp服务器即可

### 方式 B: 本地命令执行 (Claude Desktop)

> 未测试

在配置文件中添加:```JSON
{
"mcpServers": {
"cfr-decompiler": {
"command": "python",
"args": ["/path/to/cfr_mcp_server.py"],
"env": {
"PYTHONUNBUFFERED": "1"
}
}
}
}

5. 工具使用说明

工具名称: decompile

参数说明:

参数名 类型 必填 说明
file_path string 是 目标 .class 或 .jar 文件的绝对路径
method_name string 否 指定方法名。只反编译该方法,减少输出干扰。
options object 否 CFR 的高级选项字典。

调用示例:

  1. 基础反编译:```json
    {
    "file_path": "/path/to/MyClass.class"
    }

2. **反编译特定方法 (忽略异常块)**:```json
{
"file_path": "/path/to/MyClass.class",
"method_name": "complexCalculation",
"options": {
"ignoreexceptions": true
}
}

常见问题

8 问
答案由本站依据条目字段整理,不引用上游原文
cfr MCP server 怎么安装?

在客户端按下面的安装命令接入:pip install mcp starlette uvicorn。装完在客户端配置里引用同一个包或端点。

cfr MCP server 怎么在 Claude Desktop、Claude、Cursor 里配置?

它的传输方式是stdio · 本地进程,在客户端的 MCP 配置里填好启动命令和参数,保存后完全退出客户端再打开,配置才会生效。

cfr MCP server 收费吗?

本站不代收费用,也没有标注具体价格。是否收费取决于服务本身和背后的接口额度,正式使用前按官方说明确认。

cfr MCP server 需要 API Key 吗?

资料标注需要Token认证,使用前准备好对应凭据,并按最小权限配置。

cfr MCP server 支持哪些客户端?

资料标注支持 Claude Desktop、Claude、Cursor;其他客户端只要能配置 MCP Server,也能用同样的命令或地址接入。

cfr MCP server 能提供哪些能力?

资料显示能力标签包括 开发工具、Python、Claude、SSE传输。具体工具清单以官方文档为准。

cfr MCP server 需要什么运行环境?

属于本地进程,需要在本机装好运行环境。

cfr MCP server 是本地还是远程?

它是本地进程(stdio),由客户端在本机拉起。传输方式为stdio · 本地进程。

热门专题

按标签挑服务器
全部专题 →

服务器信息以作者仓库与官方文档为准;分类、传输方式与鉴权方式的中文说明为中文整理,最近核验 2026-05-17。