@@ -91,6 +91,52 @@ def _normalize_path(path: str) -> str:
91
91
)
92
92
93
93
94
+ def _get_server_instructions (doc_sources : list [DocSource ]) -> str :
95
+ """Generate server instructions with available documentation source names."""
96
+ # Extract source names from doc_sources
97
+ source_names = []
98
+ for entry in doc_sources :
99
+ if "name" in entry :
100
+ source_names .append (entry ["name" ])
101
+ elif _is_http_or_https (entry ["llms_txt" ]):
102
+ # Use domain name as fallback for HTTP sources
103
+ domain = extract_domain (entry ["llms_txt" ])
104
+ source_names .append (domain .rstrip ("/" ).split ("//" )[- 1 ])
105
+ else :
106
+ # Use filename as fallback for local sources
107
+ source_names .append (os .path .basename (entry ["llms_txt" ]))
108
+
109
+ instructions = [
110
+ "Use the list_doc_sources tool to see available documentation sources." ,
111
+ "This tool will return a URL for each documentation source." ,
112
+ ]
113
+
114
+ if source_names :
115
+ if len (source_names ) == 1 :
116
+ instructions .append (
117
+ f"Documentation URLs are available from this tool "
118
+ f"for { source_names [0 ]} ."
119
+ )
120
+ else :
121
+ names_str = ", " .join (source_names [:- 1 ]) + f", and { source_names [- 1 ]} "
122
+ instructions .append (
123
+ f"Documentation URLs are available from this tool for { names_str } ."
124
+ )
125
+
126
+ instructions .extend (
127
+ [
128
+ "" ,
129
+ "Once you have a source documentation URL, use the fetch_docs tool "
130
+ "to get the documentation contents. " ,
131
+ "If the documentation contents contains a URL for additional documentation "
132
+ "that is relevant to your task, you can use the fetch_docs tool to "
133
+ "fetch documentation from that URL next." ,
134
+ ]
135
+ )
136
+
137
+ return "\n " .join (instructions )
138
+
139
+
94
140
def create_server (
95
141
doc_sources : list [DocSource ],
96
142
* ,
@@ -117,11 +163,7 @@ def create_server(
117
163
settings = settings or {}
118
164
server = FastMCP (
119
165
name = "llms-txt" ,
120
- instructions = (
121
- "Use the list doc sources tool to see available documentation "
122
- "sources. Once you have a source, use fetch docs to get the "
123
- "documentation"
124
- ),
166
+ instructions = _get_server_instructions (doc_sources ),
125
167
** settings ,
126
168
)
127
169
httpx_client = httpx .AsyncClient (follow_redirects = follow_redirects , timeout = timeout )
0 commit comments