Skip to content

Commit 0592040

Browse files
committed
Add delete_index Tool
Agent-Id: agent-8cf675a5-fcdf-402a-a3a1-f3fa2a8c3f1b Linked-Note-Id: 18ee4796-4931-48c2-80e4-e85d51fe2ccd
1 parent 6447099 commit 0592040

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

src/clients/mcp-server.ts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,86 @@ export async function createMCPServer(
376376
}
377377
}
378378

379+
// Handle index_repo separately (uses 'name' not 'index_name')
380+
if (name === "index_repo") {
381+
const indexName = args?.name as string;
382+
const sourceType = args?.source_type as string;
383+
384+
if (!indexName) {
385+
return { content: [{ type: "text", text: "Error: name is required" }], isError: true };
386+
}
387+
if (!sourceType) {
388+
return { content: [{ type: "text", text: "Error: source_type is required" }], isError: true };
389+
}
390+
391+
try {
392+
let source: Source;
393+
let sourceDesc: string;
394+
395+
if (sourceType === "github") {
396+
const owner = args?.owner as string;
397+
const repo = args?.repo as string;
398+
if (!owner || !repo) {
399+
return { content: [{ type: "text", text: "Error: github requires owner and repo" }], isError: true };
400+
}
401+
const { GitHubSource } = await import("../sources/github.js");
402+
source = new GitHubSource({ owner, repo, ref: (args?.ref as string) || "HEAD" });
403+
sourceDesc = `github://${owner}/${repo}`;
404+
} else if (sourceType === "gitlab") {
405+
const projectId = args?.project_id as string;
406+
if (!projectId) {
407+
return { content: [{ type: "text", text: "Error: gitlab requires project_id" }], isError: true };
408+
}
409+
const { GitLabSource } = await import("../sources/gitlab.js");
410+
source = new GitLabSource({ projectId, ref: (args?.ref as string) || "HEAD" });
411+
sourceDesc = `gitlab://${projectId}`;
412+
} else if (sourceType === "bitbucket") {
413+
const workspace = args?.workspace as string;
414+
const repo = args?.repo as string;
415+
if (!workspace || !repo) {
416+
return { content: [{ type: "text", text: "Error: bitbucket requires workspace and repo" }], isError: true };
417+
}
418+
const { BitBucketSource } = await import("../sources/bitbucket.js");
419+
source = new BitBucketSource({ workspace, repo, ref: (args?.ref as string) || "HEAD" });
420+
sourceDesc = `bitbucket://${workspace}/${repo}`;
421+
} else if (sourceType === "website") {
422+
const url = args?.url as string;
423+
if (!url) {
424+
return { content: [{ type: "text", text: "Error: website requires url" }], isError: true };
425+
}
426+
const { WebsiteSource } = await import("../sources/website.js");
427+
source = new WebsiteSource({ url });
428+
sourceDesc = `website://${url}`;
429+
} else {
430+
return { content: [{ type: "text", text: `Error: Unknown source_type: ${sourceType}` }], isError: true };
431+
}
432+
433+
// Run indexer - need IndexStore for this
434+
const { Indexer } = await import("../core/indexer.js");
435+
const indexer = new Indexer();
436+
437+
// Check if store supports write operations
438+
if (!('save' in config.store)) {
439+
return { content: [{ type: "text", text: "Error: Store does not support write operations (index_repo requires IndexStore)" }], isError: true };
440+
}
441+
442+
const result = await indexer.index(source, config.store as IndexStore, indexName);
443+
444+
// Refresh runner state
445+
await runner.refreshIndexList();
446+
runner.invalidateClient(indexName);
447+
448+
return {
449+
content: [{
450+
type: "text",
451+
text: `Created index "${indexName}" from ${sourceDesc}\n- Type: ${result.type}\n- Files indexed: ${result.filesIndexed}\n- Duration: ${result.duration}ms`
452+
}],
453+
};
454+
} catch (error) {
455+
return { content: [{ type: "text", text: `Error indexing: ${error}` }], isError: true };
456+
}
457+
}
458+
379459
try {
380460
const indexName = args?.index_name as string;
381461
const client = await runner.getClient(indexName);

0 commit comments

Comments
 (0)