Skip to content

Commit b0352b1

Browse files
authored
Merge pull request #221 from upstash/pr-207
feat: version support
2 parents 886a655 + e50ee0d commit b0352b1

File tree

5 files changed

+14
-19
lines changed

5 files changed

+14
-19
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,5 @@ dist
172172
.idea
173173

174174
# Finder (MacOS) folder config
175-
.DS_Store
175+
.DS_Store
176+
package-lock.json

src/index.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ server.tool(
3939
"resolve-library-id",
4040
`Resolves a package/product name to a Context7-compatible library ID and returns a list of matching libraries.
4141
42-
You MUST call this function before 'get-library-docs' to obtain a valid Context7-compatible library ID.
42+
You MUST call this function before 'get-library-docs' to obtain a valid Context7-compatible library ID UNLESS the user explicitly provides a library ID in the format '/org/project' or '/org/project/version' in their query.
4343
4444
Selection Process:
4545
1. Analyze the query to understand what library/package the user is looking for
@@ -95,11 +95,12 @@ For ambiguous queries, request clarification before proceeding with a best-guess
9595
text: `Available Libraries (top matches):
9696
9797
Each result includes:
98-
- Library ID: Context7-compatible identifier (format: /org/repo)
98+
- Library ID: Context7-compatible identifier (format: /org/project)
9999
- Name: Library or package name
100100
- Description: Short summary
101101
- Code Snippets: Number of available code examples
102102
- Trust Score: Authority indicator
103+
- Versions: List of versions if available. Use one of those versions if and only if the user explicitly provides a version in their query.
103104
104105
For best results, select libraries based on name match, trust score, snippet coverage, and relevance to your use case.
105106
@@ -114,12 +115,12 @@ ${resultsText}`,
114115

115116
server.tool(
116117
"get-library-docs",
117-
"Fetches up-to-date documentation for a library. You must call 'resolve-library-id' first to obtain the exact Context7-compatible library ID required to use this tool.",
118+
"Fetches up-to-date documentation for a library. You must call 'resolve-library-id' first to obtain the exact Context7-compatible library ID required to use this tool, UNLESS the user explicitly provides a library ID in the format '/org/project' or '/org/project/version' in their query.",
118119
{
119120
context7CompatibleLibraryID: z
120121
.string()
121122
.describe(
122-
"Exact Context7-compatible library ID (e.g., 'mongodb/docs', 'vercel/nextjs') retrieved from 'resolve-library-id'."
123+
"Exact Context7-compatible library ID (e.g., '/mongodb/docs', '/vercel/next.js', '/supabase/supabase', '/vercel/next.js/v14.3.0-canary.87') retrieved from 'resolve-library-id' or directly from user query in the format '/org/project' or '/org/project/version'."
123124
),
124125
topic: z
125126
.string()
@@ -134,20 +135,9 @@ server.tool(
134135
),
135136
},
136137
async ({ context7CompatibleLibraryID, tokens = DEFAULT_MINIMUM_TOKENS, topic = "" }) => {
137-
// Extract folders parameter if present in the ID
138-
let folders = "";
139-
let libraryId = context7CompatibleLibraryID;
140-
141-
if (context7CompatibleLibraryID.includes("?folders=")) {
142-
const [id, foldersParam] = context7CompatibleLibraryID.split("?folders=");
143-
libraryId = id;
144-
folders = foldersParam;
145-
}
146-
147-
const documentationText = await fetchLibraryDocumentation(libraryId, {
138+
const documentationText = await fetchLibraryDocumentation(context7CompatibleLibraryID, {
148139
tokens,
149140
topic,
150-
folders,
151141
});
152142

153143
if (!documentationText) {

src/lib/api.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export async function fetchLibraryDocumentation(
3535
options: {
3636
tokens?: number;
3737
topic?: string;
38-
folders?: string;
3938
} = {}
4039
): Promise<string | null> {
4140
try {
@@ -45,7 +44,6 @@ export async function fetchLibraryDocumentation(
4544
const url = new URL(`${CONTEXT7_API_BASE_URL}/v1/${libraryId}`);
4645
if (options.tokens) url.searchParams.set("tokens", options.tokens.toString());
4746
if (options.topic) url.searchParams.set("topic", options.topic);
48-
if (options.folders) url.searchParams.set("folders", options.folders);
4947
url.searchParams.set("type", DEFAULT_TYPE);
5048
const response = await fetch(url, {
5149
headers: {

src/lib/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface SearchResult {
1010
totalPages: number;
1111
stars?: number;
1212
trustScore?: number;
13+
versions?: string[];
1314
}
1415

1516
export interface SearchResponse {

src/lib/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ export function formatSearchResult(result: SearchResult): string {
2525
formattedResult.push(`- Trust Score: ${result.trustScore}`);
2626
}
2727

28+
// Only add versions if it's a valid value
29+
if (result.versions !== undefined && result.versions.length > 0) {
30+
formattedResult.push(`- Versions: ${result.versions.join(", ")}`);
31+
}
32+
2833
// Join all parts with newlines
2934
return formattedResult.join("\n");
3035
}

0 commit comments

Comments
 (0)