Skip to content

Commit b0f7a8e

Browse files
authored
mcpdoc: update server description based on available tools (#35)
1 parent c9b45f0 commit b0f7a8e

File tree

1 file changed

+47
-5
lines changed

1 file changed

+47
-5
lines changed

mcpdoc/main.py

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,52 @@ def _normalize_path(path: str) -> str:
9191
)
9292

9393

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+
94140
def create_server(
95141
doc_sources: list[DocSource],
96142
*,
@@ -117,11 +163,7 @@ def create_server(
117163
settings = settings or {}
118164
server = FastMCP(
119165
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),
125167
**settings,
126168
)
127169
httpx_client = httpx.AsyncClient(follow_redirects=follow_redirects, timeout=timeout)

0 commit comments

Comments
 (0)