Skip to main content

Game of Thrones Quotes Server

This example demonstrates how to build a complete MCP server that integrates with an external API, implements multiple tools, resources, and prompts.

Overview

The Game of Thrones Quotes server showcases:
  • External API Integration: Fetching data from a third-party API
  • Multiple Tools: Different operations with validation
  • Resources: Exposing data through MCP resources
  • Resource Templates: Dynamic resource URIs with parameters
  • Prompts: Pre-configured AI interactions

Server Implementation

Basic Setup

server.ts

Type Definitions

Define TypeScript interfaces for the API responses:

External API Integration

Fetching Quotes

Formatting Output

Implementing Tools

Get Random Quotes Tool

This tool fetches a specified number of random quotes:

LCM Tool (Math Operations)

A mathematical tool to calculate the least common multiple:

Resources

Static Resource

Resources expose data that can be read by MCP clients:

Resource Templates (Dynamic Resources)

Resource templates allow parameterized URIs:

Prompts

Quotes Analysis Prompt

Prompts provide pre-configured conversation starters:

Code Review Prompt

A generic code review prompt:

Starting the Server

Installation & Setup

Dependencies

package.json

Building and Running

Using with MCP Clients

Claude Desktop Configuration

claude_desktop_config.json

Programmatic Usage

Key Patterns

  1. Error Handling: Always validate inputs and handle API errors gracefully
  2. Type Safety: Use TypeScript interfaces for API responses
  3. Validation: Use Zod schemas for runtime validation
  4. Resource URIs: Follow URI conventions (e.g., got://quotes/random)
  5. Prompt Design: Structure prompts with clear system and user messages

API Reference

The server uses the Game of Thrones Quotes API:
  • GET /v1/random/{count} - Get random quotes (1-10)
  • Response includes character name, house, and quote text

Next Steps