本地jar包阅读

freehyy/jar-viewer-mcp
1 Stars 76 次浏览 更新于 2026-08-23

一个MCP服务器,允许LLM浏览JAR内容、附加源JAR文件、使用CFR反编译类文件,并运行Maven/Gradle依赖解析。

MCP 服务配置

复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用

{
  "mcpServers": {
    "jar-viewer": {
      "args": [
        "-y",
        "jar-viewer-mcp@latest"
      ],
      "command": "npx"
    }
  }
}

服务介绍

Java Jar Viewer MCP

MCP server that lets an LLM browse JAR contents, attach *-sources.jar source, and decompile .class files with CFR. It also runs Maven/Gradle dependency resolution to surface absolute paths for local artifacts.

Chinese doc: README.zh-CN.md.

Prerequisites

  • Node.js 18+
  • Java 8+ (JDK with javap) on PATH (for CFR and describe_class)
  • Maven on PATH when using scan_project_dependencies for Maven projects
  • Gradle Wrapper (./gradlew) or Gradle on PATH when using scan_project_dependencies for Gradle projects

Quick start (npx)

npx -y jar-viewer-mcp@latest

MCP config snippet

Use this in your MCP client/registry (example format):

{
  "mcpServers": {
    "jar-viewer": {
      "command": "npx",
      "args": ["-y", "jar-viewer-mcp@latest"]
    }
  }
}

Install options

Global install

npm install -g jar-viewer-mcp
jar-viewer-mcp

Local development

npm install
npm run build
node dist/index.js

Tools

  • list_jar_entries(jarPath, innerPath?): Lists up to 100 items from the JAR, folding by directory level for quick navigation.
  • read_jar_entry(jarPath, entryPath): Reads the requested entry. For .class, it first looks for a sibling *-sources.jar and otherwise decompiles with CFR; falls back to javap signatures if needed.
  • describe_class(jarPath, className?, entryPath?, memberVisibility?, methodQuery?, limit?): Returns method signatures for a class using javap (no decompilation). Use memberVisibility="public" (default) or "all" for all members.
  • resolve_class(projectPath, className, dependencyQuery?, includeMembers?, memberVisibility?, methodQuery?, limit?): Locates the class inside project dependency jars. If includeMembers=true, also returns method signatures (same filters as describe_class).
  • scan_project_dependencies(projectPath, excludeTransitive?, configurations?, includeLogTail?, query?): Detects Maven/Gradle projects (by pom.xml or build.gradle(.kts)/settings.gradle(.kts)), then resolves absolute artifact paths. Uses mvn dependency:list for Maven, and an injected Gradle init script (mcpListDeps) for Gradle. Results are cached per project root. query does a case-insensitive substring match on groupId:artifactId and the artifact path.
    • excludeTransitive: set to true to return only first-level dependencies.
    • configurations: Gradle-only list of configuration names to include (e.g. ["runtimeClasspath"]).
    • includeLogTail: set to true to include the last lines of build output for debugging.

lib/cfr-0.152.jar is bundled and copied into dist/lib during npm run build; paths are resolved at runtime via import.meta.url to avoid hard-coding.

相关 MCP 服务