plaier-mcp-server
Version:
MCP Server for Plaier Football API - Advanced football analytics and predictions
75 lines • 3.48 kB
JavaScript
import { formatTransferImpact, formatError, formatWarning, } from '../utils/formatting.js';
export function createTransferTools(client) {
return [
{
name: "get_transfer_impact",
description: "Analyze the impact of transferring a player to specific teams or all teams in a tournament.",
inputSchema: {
type: "object",
properties: {
player_id: {
type: "number",
description: "The unique ID of the player to analyze"
},
team_ids: {
type: "string",
description: "Identifies the teams or team to which the player is to be transferred, in case of several teams provided, a comma-separated list of team IDs needs to be provided."
},
tournament_id: {
type: "number",
description: "Tournament ID to analyze impact on all teams in the tournament (cannot be used with team_ids)"
}
},
required: ["player_id"]
}
}
];
}
export async function handleTransferTool(toolName, args, client) {
try {
switch (toolName) {
case "get_transfer_impact": {
// Validate that either team_ids or tournament_id is provided, but not both
if (args.team_ids && args.tournament_id) {
return formatError('Cannot specify both team_ids and tournament_id. Please use one or the other.');
}
if (!args.team_ids && !args.tournament_id) {
return formatError('Must specify either team_ids or tournament_id.');
}
try {
// Get player information first
let playerName = `Player ${args.player_id}`;
try {
const player = await client.getPlayers({ player_id: args.player_id });
playerName = player.player_name || playerName;
}
catch {
// Continue with player ID if name can't be retrieved
}
// Create parameters for the API call
const transferParams = { player_id: args.player_id };
if (args.team_ids && args.team_ids.length > 0) {
transferParams.team_ids = args.team_ids;
}
if (args.tournament_id !== undefined) {
transferParams.tournament_id = args.tournament_id;
}
const impacts = await client.getTransferImpact(transferParams);
if (!impacts || impacts.length === 0) {
return formatWarning(`No transfer impact data available for ${playerName}.`);
}
return formatTransferImpact(impacts, playerName);
}
catch (error) {
return formatError(`Error retrieving transfer impact: ${error}`);
}
}
default:
throw new Error(`Unknown transfer tool: ${toolName}`);
}
}
catch (error) {
return formatError(`Tool execution failed: ${error}`);
}
}
//# sourceMappingURL=transfer-tools.js.map