@@ -40,6 +40,7 @@ def create_server(
40
40
follow_redirects : bool = False ,
41
41
timeout : float = 10 ,
42
42
settings : dict | None = None ,
43
+ allowed_domains : list [str ] | None = None ,
43
44
) -> FastMCP :
44
45
"""Create the server and generate documentation retrieval tools.
45
46
@@ -48,6 +49,10 @@ def create_server(
48
49
follow_redirects: Whether to follow HTTP redirects when fetching docs
49
50
timeout: HTTP request timeout in seconds
50
51
settings: Additional settings to pass to FastMCP
52
+ allowed_domains: Additional domains to allow fetching from.
53
+ Use ['*'] to allow all domains
54
+ The domain hosting the llms.txt file is always appended to the list
55
+ of allowed domains.
51
56
52
57
Returns:
53
58
A FastMCP server instance configured with documentation tools
@@ -81,7 +86,14 @@ def list_doc_sources() -> str:
81
86
return content
82
87
83
88
# Parse the domain names in the llms.txt URLs
84
- allowed_domains = set (extract_domain (entry ["llms_txt" ]) for entry in doc_source )
89
+ domains = set (extract_domain (entry ["llms_txt" ]) for entry in doc_source )
90
+
91
+ # Add additional allowed domains if specified
92
+ if allowed_domains :
93
+ if "*" in allowed_domains :
94
+ domains = {"*" } # Special marker for allowing all domains
95
+ else :
96
+ domains .update (allowed_domains )
85
97
86
98
@server .tool ()
87
99
async def fetch_docs (url : str ) -> str :
@@ -99,11 +111,11 @@ async def fetch_docs(url: str) -> str:
99
111
The fetched documentation content converted to markdown, or an error message
100
112
if the request fails or the URL is not from an allowed domain.
101
113
"""
102
- nonlocal allowed_domains
103
- if not any (url .startswith (domain ) for domain in allowed_domains ):
114
+ nonlocal domains
115
+ if "*" not in domains and not any (url .startswith (domain ) for domain in domains ):
104
116
return (
105
117
"Error: URL not allowed. Must start with one of the following domains: "
106
- + ", " .join (allowed_domains )
118
+ + ", " .join (domains )
107
119
)
108
120
109
121
try :
0 commit comments