plaier-mcp-server
Version:
MCP Server for Plaier Football API - Advanced football analytics and predictions
327 lines • 15.6 kB
JavaScript
import { validateInput, TeamSearchSchema, TeamDetailsSchema, TeamsByTournamentSchema, TeamPerformanceSchema, TeamImprovementSchema, MostImportantPlayersSchema, AllTeamsSchema } from '../utils/validation.js';
import { formatTeamInfo, formatTeamsList, formatTeamPerformance, formatTeamImprovement, formatMostImportantPlayers, formatError, formatWarning } from '../utils/formatting.js';
export function createTeamTools(client) {
return [
{
name: "search_teams",
description: "Search for football teams by name using fuzzy search. Supports team nicknames and partial matches.",
inputSchema: {
type: "object",
properties: {
team_name: {
type: "string",
description: "Team name to search for (minimum 3 characters). Supports nicknames and partial matches."
},
show_details: {
type: "boolean",
description: "If true, returns full team details including scores and market value. If false, returns only team ID.",
default: false
}
},
required: ["team_name"]
}
},
{
name: "get_team_details",
description: "Get detailed information about a specific team including scores, market value, and tournament info.",
inputSchema: {
type: "object",
properties: {
team_id: {
type: "number",
description: "The unique ID of the team"
}
},
required: ["team_id"]
}
},
{
name: "get_teams_by_tournament",
description: "Get all teams in a specific tournament with their details and rankings.",
inputSchema: {
type: "object",
properties: {
tournament_id: {
type: "number",
description: "The unique ID of the tournament"
}
},
required: ["tournament_id"]
}
},
{
name: "get_team_performance_in_tournament",
description: "Get team performance analysis in a specific tournament, including scores and comparisons.",
inputSchema: {
type: "object",
properties: {
tournament_id: {
type: "number",
description: "The unique ID of the tournament"
},
team_id: {
type: "number",
description: "The unique ID of the team (optional, returns all teams if omitted)"
},
report_type: {
type: "string",
enum: ["nominal-score", "effective-score", "effective-score-vs-nominal-score", "goal-difference-per-season"],
description: "Type of performance report to generate",
default: "effective-score-vs-nominal-score"
},
position_group: {
type: "string",
description: "Optional position group filter (e.g., 'defenders', 'midfielders')"
},
only_best_player: {
type: "boolean",
description: "If true, only returns the best player for each team",
default: false
}
},
required: ["tournament_id", "report_type"]
}
},
{
name: "get_team_improvement",
description: "Get suggestions for improving a team by position, showing expected goal difference improvement.",
inputSchema: {
type: "object",
properties: {
team_id: {
type: "number",
description: "The unique ID of the team"
},
report_type: {
type: "string",
enum: ["matrix"],
description: "Type of improvement report to generate",
default: "matrix"
}
},
required: ["team_id", "report_type"]
}
},
{
name: "get_team_most_important_players",
description: "Get analysis of the most important players for a team based on their impact on team performance.",
inputSchema: {
type: "object",
properties: {
team_id: {
type: "number",
description: "The unique ID of the team"
},
format: {
type: "string",
enum: ["json", "csv"],
description: "Format of the output",
default: "json"
}
},
required: ["team_id"]
}
},
{
name: "get_all_teams",
description: "Get a list of all teams known to the Plaier API, sorted by team score in descending order.",
inputSchema: {
type: "object",
properties: {
skip_national_teams: {
type: "boolean",
description: "If true, excludes national teams from the results. Default is true.",
default: true
}
}
}
}
];
}
export async function handleTeamTool(toolName, args, client) {
try {
switch (toolName) {
case "search_teams": {
const params = validateInput(TeamSearchSchema, args);
try {
const result = await client.searchTeam(params.team_name, params.show_details);
if (params.show_details) {
const team = result;
return `Found team:\n\n${formatTeamInfo(team)}`;
}
else {
const teamId = result;
return `Found team ID: ${teamId}\n\nUse get_team_details with this ID to get full team information.`;
}
}
catch (error) {
return formatError(`No team found matching "${params.team_name}". The search requires at least 3 characters and uses fuzzy matching.`);
}
}
case "get_team_details": {
const params = validateInput(TeamDetailsSchema, args);
try {
const result = await client.getTeams({ team_id: params.team_id });
const team = result;
return formatTeamInfo(team);
}
catch (error) {
return formatError(`Error retrieving team details for ID ${params.team_id}: ${error}`);
}
}
case "get_teams_by_tournament": {
const params = validateInput(TeamsByTournamentSchema, args);
try {
const result = await client.getTeams({ tournament_id: params.tournament_id });
const teams = Array.isArray(result) ? result : [result];
if (teams.length === 0) {
return `No teams found for tournament ID ${params.tournament_id}`;
}
// Sort teams by score (highest first) if score is available
const sortedTeams = teams.sort((a, b) => {
const scoreA = a.team_score || a.effective_team_score || 0;
const scoreB = b.team_score || b.effective_team_score || 0;
return scoreB - scoreA;
});
return formatTeamsList(sortedTeams, `Teams in Tournament ID ${params.tournament_id} (${teams.length} teams)`);
}
catch (error) {
return formatError(`Error retrieving teams for tournament ID ${params.tournament_id}: ${error}`);
}
}
case "get_team_performance_in_tournament": {
const params = validateInput(TeamPerformanceSchema, args);
try {
const performanceParams = {
tournament_id: params.tournament_id,
report_type: params.report_type
};
if (params.team_id !== undefined) {
performanceParams.team_id = params.team_id;
}
if (params.position_group) {
performanceParams.position_group = params.position_group;
}
if (params.only_best_player !== undefined) {
performanceParams.only_best_player = params.only_best_player;
}
const performance = await client.getTeamPerformance(performanceParams);
if (!performance || (Array.isArray(performance) && performance.length === 0)) {
return formatWarning(`No performance data available for the specified parameters.`);
}
// Get tournament name for better display
let tournamentName = `Tournament ID ${params.tournament_id}`;
try {
const tournaments = await client.getTournaments();
const tournament = tournaments.find(t => t.tournament_id === params.tournament_id);
if (tournament) {
tournamentName = tournament.tournament_name;
}
}
catch {
// Continue with tournament ID if name can't be retrieved
}
// Get team name if team_id is provided
let teamName = params.team_id ? `Team ID ${params.team_id}` : "All Teams";
if (params.team_id) {
try {
const team = await client.getTeams({ team_id: params.team_id });
if (!Array.isArray(team)) {
teamName = team.team_name;
}
}
catch {
// Continue with team ID if name can't be retrieved
}
}
return formatTeamPerformance(performance, teamName, tournamentName, params.report_type);
}
catch (error) {
return formatError(`Error retrieving team performance: ${error}`);
}
}
case "get_team_improvement": {
const params = validateInput(TeamImprovementSchema, args);
try {
const improvements = await client.getTeamImprovement({
team_id: params.team_id,
report_type: params.report_type || 'matrix'
});
if (!improvements || (Array.isArray(improvements) && improvements.length === 0)) {
return formatWarning(`No improvement suggestions available for team ID ${params.team_id}.`);
}
// Get team name for better display
let teamName = `Team ID ${params.team_id}`;
try {
const team = await client.getTeams({ team_id: params.team_id });
if (!Array.isArray(team)) {
teamName = team.team_name;
}
}
catch {
// Continue with team ID if name can't be retrieved
}
return formatTeamImprovement(improvements, teamName);
}
catch (error) {
return formatError(`Error retrieving team improvement suggestions: ${error}`);
}
}
case "get_team_most_important_players": {
const params = validateInput(MostImportantPlayersSchema, args);
try {
const importantPlayers = await client.getMostImportantPlayers({
team_id: params.team_id
});
if (!importantPlayers || (Array.isArray(importantPlayers) && importantPlayers.length === 0)) {
return formatWarning(`No important player data available for team ID ${params.team_id}.`);
}
// Get team name for better display
let teamName = `Team ID ${params.team_id}`;
try {
const team = await client.getTeams({ team_id: params.team_id });
if (!Array.isArray(team)) {
teamName = team.team_name;
}
}
catch {
// Continue with team ID if name can't be retrieved
}
return formatMostImportantPlayers(importantPlayers, teamName);
}
catch (error) {
return formatError(`Error retrieving most important players: ${error}`);
}
}
case "get_all_teams": {
const params = validateInput(AllTeamsSchema, args);
try {
const teamParams = {};
if (params.skip_national_teams !== undefined) {
teamParams.skip_national_teams = params.skip_national_teams;
}
const result = await client.getTeams(teamParams);
const teams = Array.isArray(result) ? result : [result];
const totalTeams = teams.length;
const teamType = params.skip_national_teams ? "club teams" : "teams";
// Show top 25 by default for all teams view
const topTeams = teams.slice(0, 25);
let result_text = formatTeamsList(topTeams, `Top 25 ${teamType.charAt(0).toUpperCase() + teamType.slice(1)} (${totalTeams} total)`, 25);
if (totalTeams > 25) {
result_text += `\n💡 **Tip:** Use get_teams_by_tournament to see all teams in a specific league, or search_teams to find specific teams.`;
}
return result_text;
}
catch (error) {
return formatError(`Error retrieving teams: ${error}`);
}
}
default:
throw new Error(`Unknown team tool: ${toolName}`);
}
}
catch (error) {
return formatError(`Tool execution failed: ${error}`);
}
}
//# sourceMappingURL=team-tools.js.map