Skip to main content
Glama
opgginc

opgg-esports

Official
by opgginc

get-lol-matches

Retrieve upcoming League of Legends match schedules from OP.GG Esports to access structured tournament information and enhance AI capabilities with real-time esports data.

Instructions

Get upcoming LoL match schedules from OP.GG Esports

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Inline handler for the 'get-lol-matches' MCP tool. Fetches upcoming LoL matches from OP.GG Esports GraphQL API using helper function, formats into MatchInfo objects, generates a formatted text response with match details and links, handles errors gracefully.
    server.tool('get-lol-matches', 'Get upcoming LoL match schedules from OP.GG Esports', async () => {
      try {
        // Fetch match schedules
        const matches = await fetchUpcomingMatches();
    
        // Format results
        const formattedMatches = matches.map((match: any): MatchInfo => {
          const league = match.tournament?.serie?.league || {};
          return {
            id: match.id,
            name: match.name,
            status: match.status?.toUpperCase(),
            awayScore: match.awayScore,
            homeScore: match.homeScore,
            scheduledAt: match.scheduledAt,
            numberOfGames: match.numberOfGames,
            league: league.shortName || 'Unknown',
          };
        });
    
        return {
          content: [
            {
              type: 'text',
              text: `Upcoming match schedules:\n\n${formattedMatches
                .map(
                  (match: MatchInfo) =>
                    `Match: ${match.name}\nLeague: ${match.league}\nStatus: ${match.status}\nScore: ${match.homeScore} - ${match.awayScore}\nScheduled at: ${new Date(match.scheduledAt).toLocaleString()}\nDetails: https://esports.op.gg/matches/${match.id}\n---`
                )
                .join('\n')}`,
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `Error fetching match schedules: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
        };
      }
    });
  • TypeScript interface defining the structure of formatted match information used within the tool handler for type safety.
    interface MatchInfo {
      id: number;
      name: string;
      status: string;
      homeScore: number;
      awayScore: number;
      scheduledAt: string | number | Date;
      league: string;
      numberOfGames?: number;
    }
  • Helper utility function that performs the HTTP POST request to OP.GG's GraphQL endpoint to retrieve raw upcoming matches data, with error handling.
    async function fetchUpcomingMatches() {
      try {
        const response = await fetch(GRAPHQL_ENDPOINT, {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
            'User-Agent': 'MCP',
          },
          body: JSON.stringify({
            query: UPCOMING_MATCHES_QUERY,
          }),
        });
    
        if (!response.ok) {
          throw new Error(`API request failed: ${response.status} ${response.statusText}`);
        }
    
        const data = (await response.json()) as any;
    
        if (data.errors) {
          throw new Error(`GraphQL error: ${JSON.stringify(data.errors)}`);
        }
    
        return data.data.upcomingMatches;
      } catch (error) {
        console.error('Error calling OP.GG Esports API:', error);
        throw error;
      }
    }
  • GraphQL query constant used by the fetch helper to retrieve specific fields for upcoming LoL matches including scores, schedule, league info.
    const UPCOMING_MATCHES_QUERY = `
      query MCPListUpcomingMatches {
        upcomingMatches {
          id
          name
          status
          awayScore
          homeScore
          scheduledAt
          numberOfGames
          tournament {
            serie {
              league {
                shortName
              }
            }
          }
        }
      }
    `;
Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/opgginc/esports-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server