Skip to content

Commit d1946dd

Browse files
raifdmuellerclaude
andcommitted
feat: implement get_dependencies MCP tool (include_tree) (#67)
Phase 1: Exposes include dependencies between AsciiDoc files as a new MCP tool. Adds get_dependencies() to StructureIndex that extracts include relationships from parsed AsciidocDocument.includes. Cross-references are reserved for future implementation (empty list). Bumps version to 0.4.29. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a4565b3 commit d1946dd

File tree

8 files changed

+335
-12
lines changed

8 files changed

+335
-12
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "dacli"
3-
version = "0.4.28"
3+
version = "0.4.29"
44
description = "Documentation Access CLI - Navigate and query large documentation projects"
55
readme = "README.md"
66
license = { text = "MIT" }

src/dacli/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
"""
66

77

8-
__version__ = "0.4.28"
8+
__version__ = "0.4.29"

src/dacli/mcp_app.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,19 @@ def get_metadata(path: str | None = None) -> dict:
602602
else:
603603
return get_section_metadata(index, path)
604604

605+
@mcp.tool()
606+
def get_dependencies() -> dict:
607+
"""Get include dependencies between documentation files.
608+
609+
Use this tool to understand which files include other files.
610+
Returns an include tree showing the relationships.
611+
612+
Returns:
613+
'include_tree': Mapping of source file to list of included files.
614+
'cross_references': Reserved for future use (currently empty).
615+
"""
616+
return index.get_dependencies()
617+
605618
@mcp.tool()
606619
def validate_structure() -> dict:
607620
"""Validate the document structure.

src/dacli/structure_index.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from dataclasses import dataclass
1616
from pathlib import Path
1717

18+
from dacli.asciidoc_parser import AsciidocDocument
1819
from dacli.models import Document, Element, Section
1920

2021
logger = logging.getLogger(__name__)
@@ -517,6 +518,41 @@ def stats(self) -> dict:
517518
},
518519
}
519520

521+
def get_dependencies(self) -> dict:
522+
"""Get include dependencies across all documents.
523+
524+
Builds an include tree showing which files include which other files.
525+
Only AsciiDoc documents contribute (Markdown has no includes).
526+
527+
Returns:
528+
Dictionary with 'include_tree' (file → list of included files,
529+
paths relative to docs root) and 'cross_references' (empty list,
530+
reserved for future use).
531+
"""
532+
include_tree: dict[str, list[str]] = {}
533+
534+
for doc in self._documents:
535+
if not isinstance(doc, AsciidocDocument) or not doc.includes:
536+
continue
537+
538+
# Use the document's parent directory as base for relative paths
539+
docs_root = doc.file_path.parent
540+
source_key = doc.file_path.name
541+
542+
targets = []
543+
for inc in doc.includes:
544+
try:
545+
rel_target = inc.target_path.relative_to(docs_root)
546+
except ValueError:
547+
# Target outside docs_root — use filename only
548+
rel_target = inc.target_path.name
549+
targets.append(str(rel_target))
550+
551+
if targets:
552+
include_tree[source_key] = targets
553+
554+
return {"include_tree": include_tree, "cross_references": []}
555+
520556
def _index_section(self, section: Section) -> list[str]:
521557
"""Index a section and its children recursively.
522558

src/docs/50-user-manual/20-mcp-tools.adoc

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
== Overview
66

7-
dacli provides 9 MCP tools for interacting with documentation projects via the Model Context Protocol. These tools enable LLMs to navigate, read, search, and modify documentation.
7+
dacli provides 10 MCP tools for interacting with documentation projects via the Model Context Protocol. These tools enable LLMs to navigate, read, search, and modify documentation.
88

99
== Navigation Tools
1010

@@ -307,6 +307,29 @@ Get project or section metadata.
307307
}
308308
----
309309

310+
=== get_dependencies
311+
312+
Get include dependencies between documentation files.
313+
314+
.Parameters
315+
None
316+
317+
.Returns
318+
[source,json]
319+
----
320+
{
321+
"include_tree": {
322+
"arc42.adoc": [
323+
"chapters/01_introduction.adoc",
324+
"chapters/02_constraints.adoc"
325+
]
326+
},
327+
"cross_references": []
328+
}
329+
----
330+
331+
NOTE: `cross_references` is reserved for future use and currently returns an empty list.
332+
310333
=== validate_structure
311334

312335
Validate the documentation structure.

src/docs/spec/02_api_specification.adoc

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -639,17 +639,28 @@ Retrieves metadata about the project or a specific section.
639639
640640
'''
641641
642-
==== get_dependencies (planned)
642+
==== get_dependencies
643643
644-
[NOTE]
645-
====
646-
This tool is planned but not yet implemented.
647-
====
648-
649-
Retrieves include dependencies and cross-references.
644+
Retrieves include dependencies between documentation files.
650645
651646
**Use Case:** UC-06 (Extension)
652647
648+
**Response 200:**
649+
[source,json]
650+
----
651+
{
652+
"include_tree": {
653+
"arc42.adoc": [
654+
"chapters/01_introduction.adoc",
655+
"chapters/02_constraints.adoc"
656+
]
657+
},
658+
"cross_references": []
659+
}
660+
----
661+
662+
NOTE: `cross_references` is reserved for future use and currently returns an empty list.
663+
653664
'''
654665
655666
==== validate_structure
@@ -749,6 +760,7 @@ Error responses are returned as dictionaries with an `error` key:
749760
| `validate_structure` | Validate document structure
750761
| `update_section` | Update section content
751762
| `insert_content` | Insert content before/after sections
763+
| `get_dependencies` | Get include dependencies
752764
|===
753765
754766
.Planned Tools
@@ -757,7 +769,6 @@ Error responses are returned as dictionaries with an `error` key:
757769
| Tool | Description
758770
759771
| `update_element` | Replace a specific element (code, table)
760-
| `get_dependencies` | Get include dependencies
761772
| `get_health` | Server health status
762773
| `reindex` | Trigger manual reindexing
763774
|===

0 commit comments

Comments
 (0)