Skip to content

feat(mcp): add code navigation tools (code_outline / code_search / code_expand)#2146

Merged
Mijamind719 merged 1 commit into
volcengine:mainfrom
wlff123:for_coding
May 21, 2026
Merged

feat(mcp): add code navigation tools (code_outline / code_search / code_expand)#2146
Mijamind719 merged 1 commit into
volcengine:mainfrom
wlff123:for_coding

Conversation

@wlff123
Copy link
Copy Markdown
Contributor

@wlff123 wlff123 commented May 20, 2026

Three new MCP tools backed by the existing @mcp.tool() endpoint, letting agents navigate code via structural outlines, leaf-name symbol search, and targeted symbol expansion — all operating on viking:// URIs only.

  • New code_tools.py pure-formatter module turns CodeSkeleton into the three agent-facing text views.

  • All 9 language extractors (Python, JS/TS, Go, Rust, Java, C/C++, C#, PHP, Lua) now populate line_start / line_end on every class, method, and function via tree-sitter's start_point / end_point (1-indexed). Skeleton dataclasses default these fields to 0 for back-compat.

  • code_search caps at 200 files (warns the agent on overflow) and uses Semaphore(10) for fs.read concurrency, matching the existing read tool.

  • Extension filter is applied before any fs.read so unsupported files (e.g. *.md) never hit storage.

  • Full coverage: 18 pure-function tests in tests/parse/test_code_tools.py plus integration tests in tests/server/test_mcp_endpoint_code.py for URI validation, filtering, capping, and the three tool entry points.

Testing

img_v3_0211t_fc017f75-a8c0-458c-86e2-d91544af818g img_v3_0211t_0c6d5bae-e8ad-4ca9-8c1b-6c6b170293bg
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this on the following platforms:
    • Linux
    • macOS
    • Windows

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Screenshots (if applicable)

Additional Notes

@github-actions
Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🏅 Score: 85
🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 Multiple PR themes

Sub-PR theme: Add line numbers to AST skeletons

Relevant files:

  • openviking/parse/parsers/code/ast/skeleton.py
  • openviking/parse/parsers/code/ast/extractor.py
  • openviking/parse/parsers/code/ast/languages/*.py

Sub-PR theme: Add code navigation MCP tools

Relevant files:

  • openviking/parse/parsers/code/ast/code_tools.py
  • openviking/server/mcp_endpoint.py
  • tests/parse/test_code_tools.py
  • tests/server/test_mcp_endpoint_code.py
  • docs/design/2026-05-20-code-tools-design.md

⚡ Recommended focus areas for review

Minor log message regression

The new extract() method's warning log no longer includes "falling back to LLM", which was present in the old extract_skeleton() path. Behavior is unchanged, but log observability is slightly reduced.

def extract(self, file_name: str, content: str) -> Optional[CodeSkeleton]:
    """Return raw CodeSkeleton, or None for unsupported language / parse failure.

    Consumers that need the structured object (line numbers, traversal) call
    this; consumers that want the legacy formatted text use extract_skeleton.
    """
    lang = self._detect_language(file_name)
    extractor = self._get_extractor(lang)
    if extractor is None:
        return None

    try:
        return extractor.extract(file_name, content)
    except Exception as e:
        logger.warning(
            "AST extraction failed for '%s' (language: %s): %s", file_name, lang, e
        )
        return None

@github-actions
Copy link
Copy Markdown

PR Code Suggestions ✨

No code suggestions found for the PR.

@wlff123 wlff123 force-pushed the for_coding branch 4 times, most recently from 1d6754f to 262d13e Compare May 21, 2026 10:28
@wlff123 wlff123 changed the title [WIP]测试中-feat(mcp): add code navigation tools (code_outline / code_search / co… feat(mcp): add code navigation tools (code_outline / code_search / code_expand) May 21, 2026
Adds three code-navigation MCP tools backed by tree-sitter AST parsing:
- code_outline: show file symbol structure with line ranges
- code_search: case-insensitive symbol search across files (≤200)
- code_expand: return full source of a named symbol or qualified method

All language extractors now populate line_start/line_end from
node.start_point / end_point (was always 0 before).

code_search matching: queries containing '.' match the full qualified
name (e.g. 'Greeter.greet'); plain queries match leaf name only,
avoiding false positives on class-prefixed symbols.

_filter_code_uris: cap triggers only when a 201st entry exists;
exactly 200 files no longer mis-reports capped=True.

Tests: 27 pure-function unit tests + 31 MCP endpoint unit tests;
tests/parse/run_code_tests.py provides a stub loader to run parse
tests without the full openviking dependency stack.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@wlff123 wlff123 requested a review from Mijamind719 May 21, 2026 11:19
@Mijamind719 Mijamind719 merged commit 9a37e75 into volcengine:main May 21, 2026
6 of 7 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in OpenViking project May 21, 2026
r266-tech added a commit to r266-tech/OpenViking that referenced this pull request May 21, 2026
r266-tech added a commit to r266-tech/OpenViking that referenced this pull request May 21, 2026
qin-ctx pushed a commit that referenced this pull request May 22, 2026
… (#2176)

* docs(mcp): add code_outline / code_search / code_expand rows for #2146

* docs(mcp): 中文同步 code_outline / code_search / code_expand for #2146
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants