Skip to content

Commit 7a896dc

Browse files
feedback
1 parent bf3720d commit 7a896dc

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

packages/mcp/src/index.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,21 @@ server.tool(
103103
let isResponseTruncated = false;
104104

105105
for (const file of response.files) {
106-
const snippets = file.chunks.map(chunk => {
107-
const content = base64Decode(chunk.content);
108-
return `\`\`\`\n${content}\n\`\`\``
109-
}).join('\n');
110106
const numMatches = file.chunks.reduce(
111107
(acc, chunk) => acc + chunk.matchRanges.length,
112108
0,
113109
);
114-
const text = `file: ${file.url}\nnum_matches: ${numMatches}\nrepository: ${file.repository}\nlanguage: ${file.language}\n${includeCodeSnippets ? `snippets:\n${snippets}` : ''}`;
110+
let text = `file: ${file.url}\nnum_matches: ${numMatches}\nrepository: ${file.repository}\nlanguage: ${file.language}`;
111+
112+
if (includeCodeSnippets) {
113+
const snippets = file.chunks.map(chunk => {
114+
const content = base64Decode(chunk.content);
115+
return `\`\`\`\n${content}\n\`\`\``
116+
}).join('\n');
117+
text += `\n\n${snippets}`;
118+
}
119+
120+
115121
// Rough estimate of the number of tokens in the text
116122
// @see: https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them
117123
const tokens = text.length / 4;

0 commit comments

Comments
 (0)