feat: [OSS26] 列出类的全部方法 list_methods_by_class_name (#138) - #155
Open
wryyyds7 wants to merge 6 commits into
Open
Conversation
Implement the unified MCP Server framework as the runtime base for all upcoming YASA MCP tools (Issue antgroup#129). Framework: - Dual transport: stdio (default) / streamable-http - Tool registration via @mcp_tool decorator + auto-discovery - Unified input validation (Pydantic), error handling, logging (stderr) - Health check endpoint GET /healthz in HTTP mode - Built-in demo tool ping returning server status Modules: - yasa_mcp/config.py: CLI args + env var parsing - yasa_mcp/server.py: FastMCP lifecycle management - yasa_mcp/registry.py: decorator-based tool auto-registration - yasa_mcp/transport/http.py: streamable-http + /healthz - yasa_mcp/tools/ping.py: demo health-check tool - yasa_mcp/errors.py: unified error codes - yasa_mcp/logging_config.py: stderr logging with level control Tests (44 passing): - test_registry.py: tool registration, auto-discovery, schema - test_validation.py: param validation, error handling - test_logging.py: stderr output, format, level filtering - test_config.py: CLI parsing, env vars, error exit Docs: - docs/mcp/requirements.md: functional/non-functional requirements - docs/mcp/system-design.md: architecture, module design, data flow - docs/mcp/development-guide.md: step-by-step implementation guide - yasa_mcp/README.md: usage + Claude Desktop/Cline config examples
- registry.py: prevent duplicate tool registration via __module__ check - http.py: use app.add_route() instead of direct app.routes manipulation - http.py: remove unused Route import - http.py + server.py: pass log_level to uvicorn instead of hardcoding - errors.py: fix empty string message fallback bug - test_registry.py: use asyncio.run() instead of deprecated get_event_loop() - test_validation.py: remove unused imports - config.py: convert repo_root to absolute path - logging_config.py: precise logger namespace check - pyproject.toml: fix build-backend to setuptools.build_meta - .gitignore: add .venv/ and Python project ignore rules
…ture pattern Implement MCP tool that matches regex patterns against code element signatures (methods, classes, fields) in Java repositories. Key features: - Supports element_kind: method, class, field, any - Comment filtering (line + block comments stripped before matching) - Field vs local variable disambiguation via brace-depth tracking - Control flow keyword filtering (if/throw/return not matched as methods) - Performance: O(n) single-pass depth computation with string/char/comment state machine Test data: java-design-patterns (~1900 files) + spring-framework (~9200 files) Performance: medium repo < 3s, large repo < 5s All 51 tests passed.
… bodies Reuse the O(n) brace-depth state machine from antgroup#134 to locate method body boundaries, then apply regex search within each method's body lines to return matches with their containing method's fully qualified name. Key features: - Returns containing_method (fully qualified name) for each match - Multi-line matching (multi_line=true by default, re.DOTALL) - Excludes field initializations, imports, and comments - Lambda/anonymous class matches attributed to outer method - Supports path_prefix to limit search scope - Performance: medium repo (JDP ~1900 files) < 5s Test data: java-design-patterns (~1900 files) + spring-framework (~9200 files) All tests passed.
…by fully qualified name Implement MCP tool to read the complete source code of a Java method by its fully qualified name, with overload disambiguation and Javadoc/annotation control. Key features: - Overload disambiguation via parameter_types; returns ambiguous + candidates - include_javadoc / include_annotations control switches - Supports constructors, abstract methods (declaration only), static init blocks - Nested lambda/anonymous class bodies included in parent method source - Reuses O(n) brace-depth state machine from antgroup#134 and method ranges from antgroup#135 - Fixes _strip_comments to preserve newlines (was collapsing multi-line comments) Test data: java-design-patterns (~1900 files) + spring-framework (~9200 files) Performance: JDP < 3s (0.43s measured) All acceptance criteria verified.
wryyyds7
requested review from
AntJiuFo,
Arielwyy and
alipaydeshui
as code owners
July 30, 2026 08:36
6 tasks
wryyyds7
force-pushed
the
feat/oss26-list-methods-by-class-name-138
branch
2 times, most recently
from
July 30, 2026 08:53
6ff0c9b to
e609576
Compare
Implement MCP tool to list all methods of a Java class by its fully qualified name, returning signatures, visibility, line ranges, and optional source code. Key features: - Visibility extraction (public/protected/private/package) - is_static detection - extends_class and implements_interfaces extraction from class declaration - class_start_line / class_end_line - include_private filter (default true) - include_source switch (default true, false for lightweight listing) - include_inherited (find parent class/interface methods, signatures only) - Nested class isolation (only target class methods, not inner classes) - Constructors and static init blocks as special entries - inherited_from field (null for own methods) Reuses antgroup#137's _extract_all_method_ranges, _find_class_file, _build_method_signature, _extract_annotations, _extract_method_info. Test data: java-design-patterns + spring-framework All acceptance criteria covered.
wryyyds7
force-pushed
the
feat/oss26-list-methods-by-class-name-138
branch
from
July 30, 2026 09:02
e609576 to
3115234
Compare
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
实现
list_methods_by_class_nameMCP 工具,给定类全限定名,一次性返回该类的所有方法清单(签名、可见性、起止行号、注解),可选附带方法源码或仅返回签名。实现
方法范围提取
复用 #137 的
_extract_all_method_ranges,提取所有类体级别的方法(含构造器、静态初始化块、抽象方法)。通过depth == class_depth + 1过滤,天然排除方法体内的方法调用和内部类方法。可见性和 static 提取
_extract_visibility_and_static()从方法声明行前缀的 token 列表中解析:visibility: public / protected / private / package (无修饰符时为 package-private)is_static: 是否含 static 关键字类元数据提取
_extract_class_metadata()从类声明行解析:extends_class: 父类名(从extends Xxx提取)implements_interfaces: 接口列表(从implements Aaa, Bbb提取)class_start_line/class_end_line: 类的起止行号嵌套类隔离
通过
containing_class == 目标类全限定名过滤,只返回目标类的方法。_extract_all_method_ranges的 depth 过滤已经排除了内部类的方法(内部类方法的 depth 比 Outer 类体深度大 1)。开关控制
include_private=false: 过滤掉 visibility 为 private 的方法include_source=false: 不返回 source 字段,轻量版include_inherited=true: 查找父类/接口的方法(只返签名 +inherited_from,不返 source)继承方法查找
_find_inherited_methods()递归查找 extends 父类和 implements 接口的方法:inherited_from字段为父类/接口全限定名复用 #137 的核心组件
_extract_all_method_ranges: 方法范围提取(含构造器、静态初始化块、抽象方法)_find_class_file: 文件定位(包路径约定 + 遍历查找)_extract_method_info: 方法信息提取(返回类型、参数类型、是否构造器/抽象)_build_method_signature: 方法签名构建_extract_annotations: 注解提取验收标准对照
<static_init>在列表中, is_static=True测试
单元测试
集成测试
Closes #138