mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-25 17:42:25 +01:00
- Implemented database tools for CRUD operations and connection testing. - Added git tools for managing repositories including create, update, delete, clone, and pull functionalities. - Enhanced node tools with update, enable, and disable functionalities. - Updated spider tools to include new parameters for database integration, git repository association, and task execution modes. - Improved schedule tools with additional parameters for task execution modes and priority settings. - Introduced system overview tool for comprehensive system health and status reporting. - Updated task filtering to include new task statuses.
75 lines
1.9 KiB
Go
75 lines
1.9 KiB
Go
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
import { CrawlabClient } from "../client.js";
|
|
import { z } from "zod";
|
|
|
|
const STATS_TOOLS = {
|
|
get_spider_stats: "crawlab_get_spider_stats",
|
|
get_task_stats: "crawlab_get_task_stats",
|
|
};
|
|
|
|
export function configureStatsTools(server: McpServer, client: CrawlabClient) {
|
|
server.tool(
|
|
STATS_TOOLS.get_spider_stats,
|
|
"Get statistics for a specific spider",
|
|
{
|
|
spider_id: z.string().describe("The ID of the spider to get statistics for"),
|
|
},
|
|
async ({ spider_id }) => {
|
|
try {
|
|
const response = await client.getSpiderStats(spider_id);
|
|
return {
|
|
content: [
|
|
{
|
|
type: "text",
|
|
text: JSON.stringify(response, null, 2),
|
|
},
|
|
],
|
|
};
|
|
} catch (error) {
|
|
return {
|
|
content: [
|
|
{
|
|
type: "text",
|
|
text: `Error getting spider statistics: ${error instanceof Error ? error.message : String(error)}`,
|
|
},
|
|
],
|
|
isError: true,
|
|
};
|
|
}
|
|
}
|
|
);
|
|
|
|
server.tool(
|
|
STATS_TOOLS.get_task_stats,
|
|
"Get statistics for a specific task",
|
|
{
|
|
task_id: z.string().describe("The ID of the task to get statistics for"),
|
|
},
|
|
async ({ task_id }) => {
|
|
try {
|
|
const response = await client.getTaskStats(task_id);
|
|
return {
|
|
content: [
|
|
{
|
|
type: "text",
|
|
text: JSON.stringify(response, null, 2),
|
|
},
|
|
],
|
|
};
|
|
} catch (error) {
|
|
return {
|
|
content: [
|
|
{
|
|
type: "text",
|
|
text: `Error getting task statistics: ${error instanceof Error ? error.message : String(error)}`,
|
|
},
|
|
],
|
|
isError: true,
|
|
};
|
|
}
|
|
}
|
|
);
|
|
}
|
|
|
|
export { STATS_TOOLS };
|