feat: [OSS26] 按方法名读取方法源码 read_method_source_by_method_name (#137) - #154
Open
wryyyds7 wants to merge 6 commits into
Open
feat: [OSS26] 按方法名读取方法源码 read_method_source_by_method_name (#137)#154wryyyds7 wants to merge 6 commits into
wryyyds7 wants to merge 6 commits into
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 06:22
5 tasks
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.
概述
实现
read_method_source_by_method_nameMCP 工具,给定方法的全限定名(可选形参类型用于重载消歧),精准返回该方法的源码片段(可选携带 Javadoc 与注解),不带文件其他部分。实现
方法体边界识别
复用 #134 的 O(n) 花括号深度状态机 (
_compute_line_depths),一次遍历计算每行的花括号嵌套深度,跟踪字符串/字符/注释状态。修复了_strip_comments的 bug:原来块注释替换时把换行符也替换为空格,导致行号偏移;现在保留换行符,只替换非换行字符。方法范围提取 (
_extract_all_method_ranges)_METHOD_LINE_PATTERN匹配methodName(params) {或;depth == class_depth + 1过滤,只接受类体级别的方法定义,排除方法体内的方法调用{结尾(有方法体)和;结尾(抽象方法/接口声明)static { ... }静态初始化块 (_STATIC_INIT_PATTERN)重载消歧
method_name+containing_class筛选候选方法parameter_types:返回ambiguous: true+ 候选签名列表parameter_types:按参数类型精确匹配消歧getUser(HttpServletRequest, String): ResponseEntity<User>Javadoc 和注解控制
include_javadoc=true(默认): 从方法声明行向上搜索/** ... */,作为独立javadoc字段返回include_javadoc=false: 不返回javadoc字段include_annotations=true(默认): source 包含方法上方的@xxx注解行include_annotations=false: source 从方法声明行开始特殊方法类型支持
User.User返回所有构造器重载;结尾,start_line == end_line(单行声明)static { ... }通过_STATIC_INIT_PATTERN检测,方法名为<static_init>参数类型解析 (
_parse_param_types)@PathVariable)、final修饰符、可变参数..._split_params),忽略泛型尖括号内的逗号List<String>、Map<String, Object>等泛型参数文件定位 (
_find_class_file)src/main/java/、src/、根目录复用 #134/#135 的核心组件
_compute_line_depths(): O(n) 花括号深度状态机_build_class_ranges_by_depth(): 利用 depth 确定类范围_METHOD_LINE_PATTERN: 逐行匹配方法声明_CLASS_PATTERN: 逐行匹配类声明_strip_comments(): 注释移除(已修复换行符保留 bug)_MODIFIERS/_CONTROL_FLOW_KEYWORDS: 关键字过滤验收标准对照
ambiguous=True, 2 candidatesinclude_javadoc=Falseomits,include_annotations=Falseomits<static_init>returnsstatic { ... }start==end, hasabstract测试
单元测试
$、无包名、空集成测试
Closes #137