Catalog npm
Back to packageRELEASE DETAILS

1.1.5

npm

@0x663/read_class

A Model Context Protocol (MCP) service that reads and analyzes Java class files to provide code context for AI models and tools.

aianalysisclassjavamcp
Published31 Jul 2025
Direct dependencies0
Transitive dependenciesNot calculated

README

Current package documentation

MCP Class Reader Service

A Model Context Protocol (MCP) service that reads and analyzes Java class files to provide code context for AI models and tools.

As an MCP Tool

This service can be used as an MCP tool by calling the /mcp/analyze-class endpoint with Base64-encoded class file content.

Endpoint: POST /mcp/analyze-class Content-Type: application/json

Request Body:

{
  "fileContent": "Base64-encoded content of the .class file"
}

Example Usage in MCP Configuration:

{
  "tools": [
    {
      "name": "analyze-java-class",
      "description": "Analyzes Java class files and extracts structural information",
      "inputSchema": {
        "type": "object",
        "properties": {
          "fileContent": {
            "type": "string",
            "description": "Base64-encoded content of the .class file"
          }
        },
        "required": ["fileContent"]
      }
    }
  ]
}

Features

  • Parse Java class files and extract detailed class information
  • Retrieve class metadata, fields, methods, and inheritance information
  • REST API endpoint for class file analysis
  • JSON-formatted responses for easy integration with AI systems

Project Structure

/src
  /main
    /java
      /com/example/mcp
        McpClassReaderApplication.java  # Main application with SparkJava server
        ClassFileAnalyzer.java          # ASM-based class file parser
        ClassInfo.java                  # Model for class metadata
        FieldInfo.java                  # Model for field information
        MethodInfo.java                 # Model for method information
  /test
/pom.xml                                # Maven dependencies and build configuration

Dependencies

  • ASM 9.5: For Java class file parsing
  • SparkJava 2.9.4: Lightweight web framework for REST API
  • Gson 2.10.1: JSON serialization/deserialization
  • Java 11 or higher

Build and Run

Prerequisites

  • Java Development Kit (JDK) 11 or higher
  • Apache Maven 3.6+ or compatible build tool

Build the Project

Option 1: Using Maven directly

mvn clean package

Option 2: Using npm build script (for npm package preparation)

npm run build

Run the Service

java -jar target/mcp-class-reader-1.0-SNAPSHOT.jar

The service will start on port 4567 by default.

Run with NPX

You can also run the service directly with npx without manual building:

npx @0x663/read_class

示例操作

我们提供了一个示例脚本,展示如何使用npx配置方式:

./example-npx-usage.sh

该脚本将:

  1. 创建一个示例Java类文件
  2. 编译该类文件
  3. 展示如何使用Base64编码class文件内容
  4. 提供在AI Agent IDE中配置MCP工具的JSON示例

API Usage

Analyze Class File

Endpoint: POST /analyze-class Content-Type: multipart/form-data

Request Parameters:

  • classFile: The Java .class file to analyze (form-data)

Example Request (curl):

curl -X POST http://localhost:4567/analyze-class \
  -F "classFile=@/path/to/YourClass.class"

Example Response:

{
  "className": "com.example.YourClass",
  "superClassName": "java.lang.Object",
  "interfaces": [],
  "modifiers": ["public"],
  "fields": [
    {
      "name": "exampleField",
      "type": "Ljava/lang/String;",
      "modifiers": ["private", "final"]
    }
  ],
  "methods": [
    {
      "name": "<init>",
      "descriptor": "()V",
      "modifiers": ["public"],
      "exceptions": []
    },
    {
      "name": "exampleMethod",
      "descriptor": "(ILjava/lang/String;)Z",
      "modifiers": ["public"],
      "exceptions": ["java/io/IOException"]
    }
  ]
}

Using as an MCP Tool

To use this service as an MCP tool:

  1. Build and run the service:

    mvn clean package
    java -jar target/mcp-class-reader-1.0-SNAPSHOT.jar
    
  2. Configure your MCP client to call http://localhost:4567/mcp/analyze-class with Base64-encoded class file content.

  3. The service will return structured information about the class, which can be used by AI agents for code analysis and understanding.

For detailed instructions on integrating this tool with an AI Agent IDE, please refer to the MCP Tool Usage Guide.

Using with NPX

This tool can also be configured to run directly with npx. To use this configuration:

  1. Ensure Java 11+ is installed on your system (Maven is no longer required)
  2. Add the following configuration to your MCP client:
{
  "ReadClass": {
    "command": "npx",
    "args": [
      "-y",
      "@0x663/read_class@latest"
    ],
    "env": {}
  }
}
  1. When called, the tool will automatically start the service and analyze the provided Java class file.

Note: The first time you run this tool, it will download the pre-built JAR file which includes all dependencies. Subsequent runs will be faster as the JAR file is cached.

在AI Agent IDE中使用

要在支持MCP的AI Agent IDE中使用此工具,请按照以下步骤操作:

  1. 在IDE的MCP工具配置中添加上述JSON配置
  2. 确保您的项目中有Java class文件
  3. 右键点击任何.class文件并选择分析选项
  4. IDE将自动处理文件读取、Base64编码和结果展示

我们提供了一个完整的IDE配置示例文件 example-mcp-ide-config.json,您可以参考其中的配置说明和使用步骤。

License

MIT

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 0

Native requirements
0 direct targetsNot calculated transitive count
No declared dependencies in this collected response

Declarations describe requirements; they are not a resolved dependency graph.

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "integrity": "sha512-mVA0yCFXO+RSRjAct1nW86Cr9w4YI0dFhC7hVgkO6/vgUS1Ku7gJGamtFBiFc97XPShhBenpLs2LyVm6y/fT7A==",
  "shasum": "2e8c8adf49ede68695e136026c1d2de689dddace",
  "tarball": "https://registry.npmjs.org/@0x663/read_class/-/read_class-1.1.5.tgz",
  "fileCount": 25,
  "unpackedSize": 4259956,
  "signatures": [
    {
      "keyid": "SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U",
      "sig": "MEQCIAM9YQR/mb2HVe7rwt1IsYVY7Ep4Yk/qQxvJfg8usoY7AiAt4DmfYp41+CKwtvNc4CVBZAHiGjeJFx5zK6UApLn0Jw=="
    }
  ]
}

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 22:38 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:bbfbe6a45b043bcd72431db572760bc77b313c13c9c57c33989da5a97cbf5b33

Other collected versions

1.1.431 Jul1.1.331 Jul1.1.231 Jul1.1.131 Jul1.1.031 JulView all collected versions →