Skip to content

Commit decae95

Browse files
authored
Merge pull request #222 from upstash/feat/log-user-query
feat: add user query parameter to documentation fetch requests
2 parents b0352b1 + da11fcc commit decae95

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,22 @@ server.tool(
133133
.describe(
134134
`Maximum number of tokens of documentation to retrieve (default: ${DEFAULT_MINIMUM_TOKENS}). Higher values provide more context but consume more tokens.`
135135
),
136+
userQuery: z
137+
.string()
138+
.describe(
139+
"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."
140+
),
136141
},
137-
async ({ context7CompatibleLibraryID, tokens = DEFAULT_MINIMUM_TOKENS, topic = "" }) => {
142+
async ({
143+
context7CompatibleLibraryID,
144+
tokens = DEFAULT_MINIMUM_TOKENS,
145+
topic = "",
146+
userQuery,
147+
}) => {
138148
const documentationText = await fetchLibraryDocumentation(context7CompatibleLibraryID, {
139149
tokens,
140150
topic,
151+
userQuery,
141152
});
142153

143154
if (!documentationText) {

src/lib/api.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export async function fetchLibraryDocumentation(
3535
options: {
3636
tokens?: number;
3737
topic?: string;
38-
} = {}
38+
userQuery?: string;
39+
} = { userQuery: "" }
3940
): Promise<string | null> {
4041
try {
4142
if (libraryId.startsWith("/")) {
@@ -48,6 +49,7 @@ export async function fetchLibraryDocumentation(
4849
const response = await fetch(url, {
4950
headers: {
5051
"X-Context7-Source": "mcp-server",
52+
"X-Context7-User-Query": options.userQuery?.trim().toLowerCase() || "",
5153
},
5254
});
5355
if (!response.ok) {

0 commit comments

Comments
 (0)