Number Guessing Game MCP Server

Number Guessing Game MCP Server

number-guessing-game-mcp-server•byportal-labs-infrastructure

A TypeScript demonstration MCP server that hosts a session-based number guessing game with per-user dynamic tools and resources.

License: MIT•Runtime: Awaiting documentation review•Category: ai agents-models

WHAT IT DOES

  • •Provides MCP tools for starting a game, guessing a number, and giving up, enabled or disabled per user based on game state.
  • •Creates and destroys a per-user game_state MCP resource as users start and end games.
  • •Gives each connecting user an isolated game state and set of MCP entities through a single global server and Express controller.
  • •Persists game state and high scores in Firestore to keep the server stateless and scalable.

BEST FOR

  • •Learning how to build dynamic, multi-user MCP applications with session-scoped tools and resources.
  • •Demonstrating stateful services over HTTP with persistent, isolated user sessions.
  • •Testing MCP clients that support dynamic tool and resource discovery.

ABOUT NUMBER-GUESSING-GAME-MCP-SERVER

Number Guessing Game MCP Server is cataloged as an MCP server attributed to portal-labs-infrastructure. A TypeScript demonstration MCP server that hosts a session-based number guessing game with per-user dynamic tools and resources. It is categorized under ai agents-models. See the capability inspector for recorded interfaces and their independent review status; consult upstream documentation for the current interface.

HOW TO INSTALL

Installation configuration is not reviewed. No executable setup is offered for this entry; inspect the source repository before proceeding.

LICENSE

Catalog license label: MIT. Check the source repository's current license and terms before using, modifying or distributing this software.

Capability inspector

Capability definitions are not reviewed. Unreviewed imports are not exposed as trusted interfaces.

Tools (0)

No reviewed records to display. This does not establish that upstream lacks this capability.

Resources (0)

No reviewed records to display. This does not establish that upstream lacks this capability.

Prompts (0)

No reviewed records to display. This does not establish that upstream lacks this capability.

NEWSLETTER - COMING LATER

Newsletter subscriptions are not open yet

Email delivery is not connected. This page does not collect email addresses or create subscriptions.

Browse the registry for current listings instead.

Community Reviews

Coming later

Reviews for Number Guessing Game MCP Server are not available yet

Review publishing and storage are not connected. This page does not collect or publish ratings or comments, including after sign-in.

FREQUENTLY ASKED QUESTIONS

Does each user get their own tools and game state?

Yes, each connecting user gets an isolated game state and set of MCP entities, with tools enabled or disabled per user.

Where is game state stored?

Game state and high scores are persisted in Firestore, which decouples the server's runtime from the game state.

What game tools does the server expose?

The server exposes start_game, guess_number, and give_up tools that change availability with game state.

Upstream README

View this exact version on GitHub

README.md · 07de26169c05 · Fetched 2026-11-13 10:47:57 UTC

Original upstream text, without AI rewriting. Scripts, forms and unsafe links are filtered for safety.

Showing the last retrieved documentation snapshot; check the source for current changes.

Number Guessing Game MCP Server

License: MIT

A demonstration Model Context Protocol (MCP) server implemented in TypeScript. It showcases a dynamic, session-based architecture where each user gets their own set of tools and resources, managed by a central controller. This server hosts a simple number guessing game.

Access it at: https://mcp.number-guessing-game.portal.one/mcp

Find more remote servers at: https://remote-mcp-servers.com/

Read our article talking about the benefits of dynamic MCP servers:

https://portal.one/blog/dynamic-mcp-servers-tame-complexity/

Here's an example of interacting with the server manually. Notice the tools change depending on the current game state.

https://github.com/user-attachments/assets/8bb15870-2adc-4412-a072-4fc4eb14bbef

And a video of an agent interacting with the server. You can't see in the video, but the tools available to the agent are changing as well based on the game state.

https://github.com/user-attachments/assets/d7d338a2-8a93-46c3-b4a9-1a6b4caf9dc0

This project is intended as a learning resource and a practical example for building dynamic, multi-user MCP applications.

Table of Contents

  1. Key Features
  2. Architectural Overview
  3. Prerequisites
  4. Getting Started
  5. Running the Server
  6. Interacting with the Server
  7. Project Structure
  8. Key Concepts Demonstrated
  9. Contributing
  10. License

Key Features

  • True Multi-User Sessions: Each connecting user gets their own isolated game state and set of MCP entities.
  • Dynamic MCP Tools: Tools (start_game, guess_number, give_up) are enabled or disabled on a per-user basis, reflecting their individual game state.
  • Dynamic MCP Resources: The game_state resource is created and destroyed per-user as they start and end games.
  • Clean, Scalable Architecture:
    • A single global McpServer handles all connections.
    • An Express.js controller manages the lifecycle of each user session.
    • Session-scoped entities (tools, resources, game logic) are created on-demand.
    • State Pattern: Manages the game's flow (Lobby, Playing) for each user.
  • TypeScript Implementation: Fully typed for better maintainability and developer experience.
  • Firestore Integration: Persists game state and high scores, making the server stateless and scalable.

Architectural Overview

The server follows a modern, scalable pattern where a central controller manages ephemeral, session-specific resources.

  1. Global Server Config (src/mcp_setup/index.ts): A McpServer instance is created when the application starts. It acts as a "blank slate" connection manager and does not contain any tools or resources itself.

  2. HTTP Controller (src/controllers/mcp.controller.ts): This is the brain of the application.

    • It handles all incoming HTTP requests to the /mcp endpoint.
    • When a new user connects, it creates a StreamableHTTPServerTransport.
    • It uses the transport's lifecycle hooks (onsessioninitialized and onclose) to manage the user's session.
  3. Session Initialization (onsessioninitialized): When a user's transport is ready, the controller:

    • Creates a new, unique set of MCP entities for that user by calling the setup functions in src/mcp_setup/tools and src/mcp_setup/resources.
    • Creates a new GameContext instance, linking it to the user's session ID and their unique MCP entities.
    • Loads the user's state from Firestore (via GameSessionService) and uses the State Pattern (LobbyState or PlayingState) to enable/disable the correct tools for their session.
  4. Session Destruction (onclose): When a user disconnects, the controller:

    • Unregisters and destroys all tools and resources that were created for that specific user, preventing memory leaks.
    • Cleans up the transport from its list of active connections.

This architecture ensures that each user's UI state (e.g., which tools are enabled) is completely isolated, stateful, and managed dynamically, while the server itself remains scalable.

Prerequisites

  • Node.js (v18.x or later recommended)
  • npm or yarn
  • Access to a Google Cloud project with Firestore enabled.

Getting Started

Installation

  1. Clone the repository:
    git clone https://github.com/portal-labs-infrastructure/number-guessing-game-mcp-server
    cd number-guessing-game-mcp-server
    
  2. Install dependencies:
    npm install
    # or
    yarn install
    

Configuration

  1. Set up Google Cloud Authentication: Ensure your environment is authenticated to your Google Cloud project. For local development, you can use the gcloud CLI:
    gcloud auth application-default login
    
  2. Create a .env file: Copy the example file.
    cp .env.example .env
    
  3. Edit .env: Fill in the required environment variables.
    • PORT: The port for the server to run on (e.g., 8083).
    • GCP_PROJECT_ID: Your Google Cloud Project ID.
    • BASE_URL: The public-facing URL of your server (e.g., http://localhost:8083).
    • OAUTH_ISSUER_URL: The base URL of your OAuth provider.
    • DOCS_URL: A link to your service's documentation.

Running the Server

Dev Mode (for development with hot-reloading):

npm run dev

Production Mode:

Compile TypeScript:

npm run build

Start the server:

npm start

You should see output indicating the server is running and connected to Firestore.

Interacting with the Server

Live Server

You'll need an MCP client that supports the following capabilities:

  • OAuth2 (with dynamic client registration)
  • Tool notifications
  • Resource notifications

You can use the MCP Inspector, but it does not have Tool and Resource notifications so you have to manually refresh the tools and resources.

You use the the Portal One web client and find the server in the list of available MCP servers and click 'connect'.

See other clients that support dynamic MCP tools and resources (discovery) in the MCP SDK Example Clients.

Local

Make sure the server can be accessed by the client. If you're running the server locally, and using a web based client, you can use a tool like ngrok to expose the server to the internet:

ngrok http http://localhost:8083

If you're using a client on localhost, you can connect directly to http://localhost:8083/mcp.

Project Structure

src/
├── config/
│   └── index.ts                # Loads and exports environment variables
├── controllers/
│   └── mcp.controller.ts       # Manages session lifecycles and creates entities on-demand
├── game/
│   ├── commands/               # Command Pattern: Encapsulates user actions
│   │   ├── command.interface.ts
│   │   ├── give-up.command.ts
│   │   ├── guess-number.command.ts
│   │   └── start-game.command.ts
│   ├── core/
│   │   ├── game-context.ts       # Central game logic coordinator for a SINGLE session
│   │   ├── game-session-service.ts # Handles all Firestore interactions (get/set state)
│   │   ├── game-types.ts       # Core TypeScript interfaces for the game
│   │   ├── resource-factory.ts # (Not used in current setup, but available)
│   │   └── tool-factory.ts     # (Not used in current setup, but available)
│   ├── states/                 # State Pattern: Manages game flow (Lobby, Playing)
│   │   ├── game-state.interface.ts
│   │   ├── lobby.state.ts
│   │   └── playing.state.ts
│   └── utils/
│       └── game-constants.ts   # Shared game constants
├── index.ts                    # Main application entry point (Express server setup)
├── mcp_setup/
│   ├── index.ts                # Creates the single, global McpServer instance
│   ├── resources/              # Factory functions for creating MCP resources
│   │   ├── index.ts            # Barrel file for exporting all resource setups
│   │   └── ... (setup-banner-image-resource.ts, etc.)
│   └── tools/                  # Factory functions for creating MCP tools
│       ├── index.ts            # Barrel file for exporting all tool setups
│       └── ... (setup-guess-number-tool.ts, etc.)
├── routes/
│   └── mcp.routes.ts           # Defines the Express routes for /mcp
└── services/
    └── firestore.service.ts    # Initializes the global Firestore client

Key Concepts Demonstrated

  • Dynamic, Session-Scoped MCP: The core of this architecture. Tools and resources are not global; they are created and destroyed for each user session.
  • Lifecycle Management: Using transport hooks (onsessioninitialized, onclose) to manage the setup and teardown of session resources.
  • Stateful Services over HTTP: Implementing persistent, isolated user sessions over a stateless protocol.
  • State Pattern: Managing complex state transitions for each user's game flow.
  • Firestore for State Persistence: Decoupling the server's runtime from the game state, allowing for horizontal scaling and resilience.
  • TypeScript Best Practices: Using types for robust code in a real-world, scalable application structure.

Contributing

Contributions are welcome! If you have ideas for improvements, new features, or find any bugs, please feel free to open an issue or a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Install configuration

Are you the maintainer?

Claim this server with your GitHub account to request manual ownership verification.

README Embed Badge
Markdown

Link to the catalog listing for Number Guessing Game MCP Server from your README. This badge does not certify ownership, compatibility or security.

[![MCP catalog listing](https://img.shields.io/badge/MCP-awesome--mcp-orange?style=flat-square)](https://awesome-mcp.com/servers/number-guessing-game-mcp-server)

REPOSITORY STATS

GitHub StarsUnavailable
ForksUnavailable

Public repository statistics could not be verified. Check the configured source address; unavailable counts are not zero.

Downloads and pulls

Separate sources, scopes and periods. Never combined or treated as installations, active users or security reviews.

No reviewed package or image identity; download statistics are not listed yet.

Related ai agents-models MCP Servers

Alternative and complementary servers in the same category

View all in ai agents-models →
Knowledge Graph Memory
@modelcontextprotocol/server-memory•Model Context Protocol

Store and retrieve entities, relations and observations in a persistent local knowledge graph.

create_entitiescreate_relationsadd_observations+6 more
92K
AI & Multi-Agent
Sequential Thinking
@modelcontextprotocol/server-sequential-thinking•Model Context Protocol

Organize problem solving into revisable, branching thought steps through an MCP tool.

sequential_thinking
92K
AI & Multi-Agent

Query-aware context compression with an MCP plugin for coding agents, plus Python and HTTP interfaces for reducing the context sent to a language model.

146
AI & Multi-Agent