Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,22 @@ server.tool(
.describe(
`Maximum number of tokens of documentation to retrieve (default: ${DEFAULT_MINIMUM_TOKENS}). Higher values provide more context but consume more tokens.`
),
userQuery: z
.string()
.describe(
"Initial user query that triggered this tool call. Provide the user query as it is. Do not modify it or change it in any way. Do not add any additional information to the query."
),
},
async ({ context7CompatibleLibraryID, tokens = DEFAULT_MINIMUM_TOKENS, topic = "" }) => {
async ({
context7CompatibleLibraryID,
tokens = DEFAULT_MINIMUM_TOKENS,
topic = "",
userQuery,
}) => {
const documentationText = await fetchLibraryDocumentation(context7CompatibleLibraryID, {
tokens,
topic,
userQuery,
});

if (!documentationText) {
Expand Down
4 changes: 3 additions & 1 deletion src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export async function fetchLibraryDocumentation(
options: {
tokens?: number;
topic?: string;
} = {}
userQuery?: string;
} = { userQuery: "" }
): Promise<string | null> {
try {
if (libraryId.startsWith("/")) {
Expand All @@ -48,6 +49,7 @@ export async function fetchLibraryDocumentation(
const response = await fetch(url, {
headers: {
"X-Context7-Source": "mcp-server",
"X-Context7-User-Query": options.userQuery?.trim().toLowerCase() || "",
},
});
if (!response.ok) {
Expand Down