# OpenTrivia MCP

> OpenTrivia gives you immediate access to a massive database of trivia questions. Use it to pull quizzes by category, filter by difficulty (easy/hard), or manage session tokens so your AI agent never repeats a question. You can also check global stats or discover every available knowledge area with simple tool calls.

## Overview
- **Category:** learning-training
- **Price:** Free
- **Tags:** trivia, quiz-generator, knowledge-base, gamification, educational-tools

## Description

Listen up. If you're building anything that needs actual trivia—the good stuff, the random facts people actually remember—you need this server. It gives your AI client direct access to a massive quiz database. Forget relying on canned content; here’s how you pull real-world knowledge for quizzes and tests.

To get started, you gotta know what's available. You run `get_categories` and it spits out every single topic in the whole damn thing. That list tells you all the buckets of knowledge—history, pop culture, science, ya know—so you can decide where to focus your quiz.

Once you've picked a category, you gotta check the volume before you commit. You use `get_category_count` with that specific ID and it’ll tell you exactly how many questions are sitting there for that topic. Wanna know if 'Film Noir' has ten solid questions or five hundred? This tool tells ya. If you need a big-picture view, you can run `get_global_count`, which gives you the total question count across every single category in the entire database.

Now, for the actual quiz content. You execute `get_questions` and you pass it filters: how many questions you want (the amount), what difficulty level you're aiming for (easy, medium, or hard), and which topic ID you found earlier. This pull gives your agent a structured set of trivia ready to go. It’s the core function; it delivers the content.

But here's the kicker: nobody wants their quiz repeating 'Who was the first president?' three times in a row, right? To keep things fresh, you call `request_token`. This generates a brand-new session token for your quiz. Using this token ensures that your agent won't reuse old questions—it keeps the content unique for six hours of active quizzing. If you need to manually force a restart or if something goes sideways with the token flow, you use `reset_token` to wipe out the existing session ID and start fresh.

You stack these tools together: You run `get_categories` first; that tells you what topics exist. Then, your agent pulls a new guardrail using `request_token`, getting that unique session ID. After that, it runs `get_questions`, feeding in the category filter, the desired difficulty, and the fresh token ID. That workflow gives you reliable, non-repeating quiz material.

If you're building an educational tool or a trivia night experience, this server manages all the mechanics. You don't just get questions; you get controlled access to massive, filtered databases of facts. It’s how you ensure that your AI client always has fresh content and can precisely measure the depth of knowledge available in each niche topic.

## Tools

### get_categories
Looks up and returns a list of all potential quiz categories available in the database.

### get_category_count
Retrieves the total number of questions written for a specific category ID you provide.

### get_global_count
Returns the overall count of all questions across every single category in the database.

### get_questions
Pulls a set of trivia questions based on specific criteria like difficulty, amount, and topic ID.

### request_token
Generates a new session token for your quiz to prevent the same questions from appearing twice in a row.

### reset_token
Manually resets an existing session token, useful if you need to restart a quiz cycle immediately.

## Prompt Examples

**Prompt:** 
```
Get 5 medium difficulty multiple choice questions about Geography.
```

**Response:** 
```
I've retrieved 5 medium-difficulty Geography questions for you. Topics include European capitals and world landmarks. Ready to start the quiz?
```

**Prompt:** 
```
List all available trivia categories and their IDs.
```

**Response:** 
```
Here are the available categories: General Knowledge (9), Entertainment: Books (10), Science & Nature (17), History (23), and many more. Which one interests you?
```

**Prompt:** 
```
Show me the global question statistics for the entire database.
```

**Response:** 
```
The global database currently contains over 4,000 verified questions, with several hundred pending review. Total questions across all categories are distributed between multiple choice and true/false formats.
```

## Capabilities

### Discover all available topics
Run `get_categories` to list every quiz topic currently in the database.

### Check question volume per category
Use `get_category_count` to find out exactly how many questions exist for a specific knowledge area.

### Pull a quiz set
Execute `get_questions` with filters (amount, difficulty, category) to retrieve the actual trivia content.

### Ensure unique questions
Call `request_token` to get a session ID that prevents your agent from reusing old quiz material for six hours.

### View global stats
Get an aggregate count of all verified and pending questions across the entire database using `get_global_count`.

## Use Cases

### Building a Classroom Quiz Generator
An educator needs 10 medium-difficulty questions about World History. They first call `get_categories` for the 'History' ID, then run `request_token` to get a fresh session key, and finally use `get_questions`, specifying the ID, difficulty, and token. The agent spits out a perfect quiz set.

### Checking Content Depth for an Article
A content team is writing about 'Marine Biology.' Before they start, they call `get_category_count` with the relevant ID. If the count is low, they know to pivot and check related categories using `get_categories` first.

### Running a Marathon Trivia Event
A game host runs a quiz over several hours. To ensure fairness, every hour, they call `reset_token` or `request_token`. This forces the system to pull new data and guarantees fresh questions for the next round.

### Analyzing Database Trends
A database administrator calls `get_global_count` to see the total question count. They also use `get_categories` to check if any major topics have been neglected or are growing rapidly.

## Benefits

- Never repeat a question. Using `request_token` guarantees that your AI agent pulls unique quiz material, even during long testing sessions.
- Pinpoint knowledge gaps instantly. Run `get_category_count` to see exactly how much content exists for a specific subject (e.g., 'Astronomy').
- Filter precisely. The `get_questions` tool lets you specify the question amount, difficulty level, and format—no guessing required.
- Understand the scope. Need to know if your database is big enough? Use `get_global_count` for a comprehensive look at total questions.
- Easy topic discovery. Start with `get_categories`. It provides the full list of topics and their IDs, so you never have to guess what content exists.

## How It Works

The bottom line is: You tell the agent what kind of quiz you want, it handles the topic lookup, session management, and data retrieval automatically.

1. Start by calling `get_categories` to get a list of available topic IDs.
2. Next, call `request_token` to secure a fresh session token. This is required before pulling questions.
3. Finally, use the retrieved ID and token in `get_questions` to pull your specific quiz set.

## Frequently Asked Questions

**How do I find out what topics are available using get_categories?**
You call the `get_categories` tool. It returns a full list of all quiz categories, including their names and unique IDs. Use these IDs to filter your questions later.

**What is the difference between request_token and reset_token?**
`request_token` gets you a fresh session token when you start a new quiz. `reset_token` forces an immediate token renewal, letting you restart a running session without waiting for inactivity.

**How many questions can I get with get_questions?**
You can request up to 50 questions in one call when using `get_questions`. Make sure to specify the desired amount and difficulty level.

**Can I check how many questions are available for a specific topic?**
Yes. Use the `get_category_count` tool, passing it the category ID you found with `get_categories`. This tells you the total content depth.

**How do I find the total number of questions available across all categories using get_global_count?**
The tool provides a single, real-time count of every question in the entire database. This is useful for understanding the overall scale of knowledge before targeting specific topics.

**If my session token expires or becomes invalid, what should I do to continue using get_questions?**
You must call request_token() first to generate a fresh session key. Once you have the new token, use it with your subsequent calls to ensure continuous access.

**What is the practical difference between calling request_token and reset_token?**
Requesting a token generates a brand-new one when there’s no active session. Resetting forces an immediate renewal, effectively kicking out the old key without waiting for the 6-hour inactivity window.

**What happens if I try to retrieve more than 50 questions using get_questions?**
The system limits retrievals to a maximum of 50 questions per call. If you need a larger quiz, run the tool multiple times or adjust your agent's workflow to handle data in chunks.

**How do I ensure I don't get the same trivia question twice?**
First, use the `request_token` tool to generate a session token. Then, include this token in your `get_questions` requests. The API will track your history and exclude previously seen questions for 6 hours.

**How can I find the ID for a specific category like 'Science & Nature'?**
Use the `get_categories` tool. It returns a complete list of all available trivia categories along with their unique numerical IDs, which you can then use to filter your questions.

**Is there a way to check how many questions are available in a specific category?**
Yes, use the `get_category_count` tool and provide the category ID. It will return the total number of questions available for that specific topic, including difficulty breakdowns.