-
Notifications
You must be signed in to change notification settings - Fork 14
feat: integrate llms.txt documentation tools #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aravindsriraj
wants to merge
16
commits into
main
Choose a base branch
from
feature/docstool
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
79d9689
feat: integrate llms.txt documentation tools with enhanced MCP client…
aravindsriraj 88e5df8
fix: apply pre-commit formatting and linting fixes
aravindsriraj e190997
fix: resolve MCP timeout issues and improve HTTP client error handling
aravindsriraj 3c6ccd7
docs: update README with llms.txt documentation tools integration
aravindsriraj 3b45801
feat: unify 4 documentation tools into single documentation_tool
aravindsriraj 9249191
refactor: remove add_source functionality from documentation_tool
aravindsriraj b1b319a
refactor: remove add_doc_source functionality from docs.py module
aravindsriraj 49c7568
refactor: simplify documentation tool to use versatile fetch_content …
aravindsriraj bb96da5
fix: downgrade fastmcp dependency to version 2.11.0
aravindsriraj 9b97711
docs: expose only list_sources for documentation tool
aravindsriraj be27ca0
Revert "docs: expose only list_sources for documentation tool"
aravindsriraj a532676
Revert "fix: downgrade fastmcp dependency to version 2.11.0"
aravindsriraj 7a33143
build: pin fastmcp to 2.11.0
aravindsriraj 3a1ff19
feat: optimize HTML-to-markdown conversion and remove beautifulsoup4
aravindsriraj 5fabd94
fix: improve script tag regex to address CodeQL security warning
aravindsriraj f275d6b
fix: propagate asyncio cancellations and make docs fetch timeout conf…
aravindsriraj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
""" | ||
|
||
from typing import List, Set, Optional | ||
import asyncio | ||
from fastmcp.server.middleware import Middleware, MiddlewareContext | ||
from fastmcp.exceptions import ToolError | ||
import logging | ||
|
@@ -103,6 +104,9 @@ async def on_call_tool(self, context: MiddlewareContext, call_next): | |
|
||
return await call_next(context) | ||
|
||
except asyncio.CancelledError: | ||
# Propagate cancellations so FastMCP can handle them properly | ||
raise | ||
except ToolError: | ||
# Re-raise ToolError as-is | ||
raise | ||
|
@@ -151,6 +155,9 @@ async def on_list_tools(self, context: MiddlewareContext, call_next): | |
|
||
return filtered_tools | ||
|
||
except asyncio.CancelledError: | ||
# Propagate cancellations during list operations as well | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will break existing functionality |
||
raise | ||
except Exception as e: | ||
logger.error( | ||
f"Error filtering tool list: {str(e)}", | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
create_glossary_category_assets, | ||
create_glossary_assets, | ||
create_glossary_term_assets, | ||
list_doc_sources, | ||
fetch_documentation, | ||
UpdatableAttribute, | ||
CertificateStatus, | ||
UpdatableAsset, | ||
|
@@ -694,6 +696,103 @@ def create_glossary_categories(categories) -> List[Dict[str, Any]]: | |
return create_glossary_category_assets(categories) | ||
|
||
|
||
@mcp.tool() | ||
async def documentation_tool( | ||
action: str, url: str = None, source_names: str = None | ||
) -> Dict[str, Any]: | ||
""" | ||
UNIFIED DOCUMENTATION TOOL - Your one-stop solution for all Atlan documentation needs! | ||
|
||
WHEN TO USE: Call this tool whenever users ask questions about Atlan products, features, | ||
integrations, APIs, usage instructions, or any other Atlan-related topics. | ||
|
||
This powerful unified tool handles all Atlan documentation operations through different actions: | ||
- list_sources: Discover available Atlan documentation sources with their llms.txt URLs | ||
- fetch_content: Retrieve Atlan documentation content from any valid URL | ||
|
||
Args: | ||
action (str): The operation to perform. Must be one of: | ||
- "list_sources": List all available Atlan documentation sources with llms.txt URLs | ||
- "fetch_content": Fetch content from any Atlan documentation URL | ||
|
||
url (str, optional): Documentation URL to fetch content from (for fetch_content) | ||
source_names (str, optional): Comma-separated source names for domain checking (for fetch_content) | ||
|
||
Returns: | ||
Dict[str, Any]: Response varies by action: | ||
|
||
list_sources: List of available Atlan sources with names, llms.txt URLs, allowed domains, and descriptions | ||
fetch_content: Documentation content, success status, and metadata | ||
|
||
FETCH_CONTENT USE CASES: | ||
The fetch_content action is versatile and supports multiple scenarios: | ||
|
||
1. **Fetch llms.txt index**: Get all available documentation URLs | ||
- Use the llms.txt URL from list_sources to see what topics are available | ||
- This returns the raw llms.txt content with all documentation URLs | ||
|
||
2. **Fetch specific documentation pages**: Read any documentation webpage | ||
- Main documentation URLs listed in llms.txt | ||
- Nested/linked pages within the documentation site | ||
- Any docs.atlan.com URL for detailed content | ||
|
||
Examples: | ||
# 1. Discover available Atlan documentation sources and their llms.txt URLs | ||
await documentation_tool(action="list_sources") | ||
|
||
# 2. Fetch llms.txt to see all available documentation topics | ||
await documentation_tool( | ||
action="fetch_content", | ||
url="https://docs.atlan.com/llms.txt", | ||
source_names="Atlan Docs" | ||
) | ||
|
||
# 3. Fetch specific documentation page to answer user questions | ||
await documentation_tool( | ||
action="fetch_content", | ||
url="https://docs.atlan.com/integrations/snowflake", | ||
source_names="Atlan Docs" | ||
) | ||
|
||
# 4. Fetch any nested documentation page | ||
await documentation_tool( | ||
action="fetch_content", | ||
url="https://docs.atlan.com/setup-and-settings/admin/lineage-settings", | ||
source_names="Atlan Docs" | ||
) | ||
|
||
Security Features: | ||
- Domain validation prevents access to unauthorized websites | ||
- Source management ensures only trusted Atlan documentation sources | ||
- Comprehensive error handling for network and parsing issues | ||
""" | ||
|
||
if action == "list_sources": | ||
return {"sources": list_doc_sources(), "action": "list_sources"} | ||
|
||
elif action == "fetch_content": | ||
if not url: | ||
return { | ||
"error": "url is required for fetch_content action", | ||
"action": "fetch_content", | ||
} | ||
|
||
# Parse source_names if provided | ||
parsed_source_names = None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this required? |
||
if source_names: | ||
parsed_source_names = [name.strip() for name in source_names.split(",")] | ||
|
||
result = await fetch_documentation(url, parsed_source_names) | ||
result["action"] = "fetch_content" | ||
return result | ||
|
||
else: | ||
return { | ||
"error": f"Invalid action '{action}'. Must be one of: list_sources, fetch_content", | ||
"available_actions": ["list_sources", "fetch_content"], | ||
} | ||
|
||
|
||
def main(): | ||
mcp.run() | ||
|
||
|
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any specific reason for adding these?