Skip to main content
Glama
basementstudio

MCP DOS - Classic DOS Gaming Server

open-dos

Read-onlyIdempotent

Launch and play classic DOS games like DOOM, Super Mario, and Tetris directly from your AI assistant using js-dos emulation.

Instructions

Open and play a DOS game using js-dos. Use list to see the exact key you need to use and the available games.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
gameYesDOS game slug to play (e.g., 'doom', 'doom2').

Implementation Reference

  • The main handler function for the 'open-dos' tool. It validates the game slug, starts an Express server if needed, generates an HTML page with js-dos for the game, opens it in Chrome, and returns success or error messages.
    export default async function openDos({ game }: InferSchema<typeof schema>) {
      try {
        const result = await suppressStdioAsync(async () => {
          const gameSlug = game.toLowerCase();
    
          // Check if game exists
          if (!DOS_GAMES[gameSlug]) {
            return {
              content: [
                { type: "text", text: `Game "${game}" not found` },
                { type: "text", text: `Available games: ${Object.keys(DOS_GAMES).join(', ')}` }
              ],
              isError: true,
            };
          }
    
          // Start server if not already running
          const port = await startServer();
    
          // Build URLs for both local and CDN options
          const localUrl = `http://localhost:${port}/${encodeURIComponent(gameSlug)}`;
          const cdnUrl = `http://localhost:${port}/${encodeURIComponent(gameSlug)}?cdn=true`;
          const gameInfo = DOS_GAMES[gameSlug];
    
          // Try to open with CDN first if available, otherwise use local
          const useUrl = gameInfo.cdnFile ? cdnUrl : localUrl;
    
          // Open URL in Chrome
          await open(useUrl, { app: { name: 'google chrome' } });
    
          const response = {
            content: [
              { type: "text", text: `Started ${gameInfo.title}` },
              { type: "text", text: `Game URL: ${useUrl}` },
              { type: "text", text: `Controls: ${JSON.stringify(gameInfo.keys, null, 2)}` },
            ],
          };
    
          if (port > 5555) {
            response.content.push({ type: "text", text: `Game servers start from port 5555. If you see that the game started on ports above 5555, it means you have older servers running. You can use the \`close-app\` tool to close them.` });
          }
    
          return response;
        });
    
        return result;
      } catch (error) {
        return {
          content: [{ type: "text", text: `Error starting game: ${error}` }],
          isError: true,
        };
      }
    } 
  • Input schema definition using Zod for the 'game' parameter.
    export const schema = {
      game: z.string().describe("DOS game slug to play (e.g., 'doom', 'doom2')."),
    };
  • Tool metadata including name, description, and annotations, used for registration in the MCP toolset.
    export const metadata = {
      name: "open-dos",
      description: "Open and play a DOS game using js-dos. Use `list` to see the exact key you need to use and the available games.",
      annotations: {
        title: "Play DOS game",
        readOnlyHint: true,
        destructiveHint: false,
        idempotentHint: true,
      },
    };
  • Helper function to start the Express server that serves the DOS game HTML pages, finds available port starting from 5555, and sets up routes for games and API.
    async function startServer(): Promise<number> {
      const server = getGlobalServer();
      const p = getGlobalServerPort();
      if (server && p) {
        return p;
      }
    
      const app = express();
      const port = await findAvailablePort();
    
      app.get('/close', (req, res) => {
        getGlobalServer()?.close();
        res.send('Server closed');
      });
    
      app.post('/close', (req, res) => {
        getGlobalServer()?.close();
        res.send('Server closed');
      });
    
      // Game route: /:gameSlug with optional CDN parameter
      app.get('/:gameSlug', (req, res) => {
        const gameSlug = req.params.gameSlug;
        const useCDN = req.query.cdn === 'true';
        res.send(createGameHTML(gameSlug, useCDN));
      });
    
      // API to list available games
      app.get('/api/games', (req, res) => {
        res.json({
          games: Object.keys(DOS_GAMES),
          count: Object.keys(DOS_GAMES).length,
          gameDetails: DOS_GAMES,
          usage: {
            local: "http://localhost:PORT/GAME_SLUG",
            cdn: "http://localhost:PORT/GAME_SLUG?cdn=true"
          }
        });
      });
    
      // Start server
      setGlobalServer(app.listen(port, () => { }));
      setGlobalServerPort(port);
    
      return port;
    }
  • Helper function that generates the HTML page for embedding js-dos, including game file, executable, key mappings, and styles.
    function createGameHTML(gameSlug: string, useCDN: boolean = false): string {
      const game = DOS_GAMES[gameSlug];
      if (!game) {
        return `<!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Game Not Found</title>
    </head>
    <body>
        <h1>Game "${gameSlug}" not found</h1>
        <p>Available games: ${Object.keys(DOS_GAMES).join(', ')}</p>
    </body>
    </html>`;
      }
    
      // Use CDN file if requested and available, otherwise use local file
      const gameFile = useCDN && game.cdnFile ? game.cdnFile : game.file;
    
      // Generate key mappings display
      const keyMappingsHTML = game.keys
        .filter(k => k.code !== -1)
        .map(k => `<div class="key-mapping"><kbd>${k.key}</kbd> - ${k.text || k.key}</div>`)
        .join('');
    
      return `<!doctype html>
    <html lang="en-us">
      <head>
        <meta charset="utf-8">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>${game.title}</title>
        <style type="text/css">
          body { margin: 0; padding: 0; }
          .dosbox-container { width: 100vw; height: 100vh; }
          .dosbox-canvas { width: 100%; height: 100%; }
          .dosbox-container > .dosbox-overlay {
            background: url(https://js-dos.com/cdn/${gameSlug.toUpperCase()}.png);
            background-size: contain;
            background-repeat: no-repeat;
            background-position: center;
          }
          .dosbox-start {
            background: rgba(0, 0, 0, 0.5);
            color: #0f0;
            font-family: monospace;
            font-size: 16px;
            padding: 10px;
            border: none;
            cursor: pointer;
          }
          body { margin: 0; padding: 20px; background: #000; color: #0f0; font-family: monospace; }
          button { background: #0f0; color: #000; border: none; padding: 10px 20px; margin: 10px 0; cursor: pointer; font-family: monospace; }
          button:hover { background: #0a0; }
          .info { background: #333; padding: 10px; margin: 10px 0; border-radius: 5px; }
          .dosbox-fullscreen {
            position: absolute;
            top: 10px;
            right: 10px;
            background: #0f0;
            color: #000;
            border: none;
            padding: 10px 20px;
            margin: 10px 0;
            cursor: pointer;
          }
          .controls {
            position: absolute;
            top: 10px;
            left: 10px;
            background: rgba(0, 0, 0, 0.8);
            padding: 15px;
            border-radius: 5px;
            font-size: 12px;
            max-width: 250px;
          }
          .key-mapping {
            margin: 5px 0;
          }
          kbd {
            background: #0f0;
            color: #000;
            padding: 2px 6px;
            border-radius: 3px;
            font-family: monospace;
            font-size: 11px;
          }
          .controls h4 {
            margin: 0 0 10px 0;
            color: #0f0;
          }
        </style>
      </head>
      <body>
        <div id="dosbox"></div>
        <button class="dosbox-fullscreen" onclick="dosbox.requestFullScreen();">Fullscreen</button>
        <div class="controls">
          <h4>Controls:</h4>
          ${keyMappingsHTML}
        </div>
        <script type="text/javascript" src="https://js-dos.com/cdn/js-dos-api.js"></script>
        <script type="text/javascript">
          const keyMappings = ${JSON.stringify(game.keys)};
          
          var dosbox = new Dosbox({
            id: "dosbox",
            onload: function (dosbox) {
              dosbox.run("${gameFile}", "${game.executable}");
            },
            onrun: function (dosbox, app) {
              console.log("App '" + app + "' is running");
              
              // Configure key mappings
              if (dosbox.setKeyMapping) {
                keyMappings.forEach(function(mapping) {
                  if (mapping.code !== -1) {
                    dosbox.setKeyMapping(mapping.key, mapping.code);
                  }
                });
              }
            }
          });
        </script>
      </body>
    </html>`;
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description adds valuable context beyond annotations by explaining that users need to check available games first and mentioning 'js-dos' as the implementation technology. While annotations already declare this as a safe, read-only, idempotent operation, the description provides useful practical guidance without contradicting the annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is perfectly concise with two sentences that each earn their place - the first states the purpose, the second provides critical usage guidance. No wasted words, perfectly front-loaded with the core functionality.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the simple single-parameter tool with excellent annotations (readOnlyHint, idempotentHint, destructiveHint) and no output schema needed, the description provides sufficient context. It could potentially mention what happens when the tool is invoked (e.g., opens a game interface), but the annotations cover safety concerns adequately.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 100% schema description coverage, the schema already fully documents the single 'game' parameter. The description adds minimal value beyond the schema by mentioning 'exact key' and referring to the list tool, but doesn't provide additional parameter semantics beyond what's already in the structured data.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Open and play') and resource ('a DOS game using js-dos'), distinguishing it from sibling tools like 'close-app' and 'List DOS Games'. It provides a concrete example of what the tool does rather than just restating the name.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly states when to use this tool ('to see the exact key you need to use and the available games') and provides a clear alternative ('Use `list`'), giving perfect guidance on when to use this tool versus its sibling.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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/basementstudio/mcp-dos'

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