<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: galaxy</title>
    <description>The latest articles on DEV Community by galaxy (@galaxy_7b6ad9933a659ac9cd).</description>
    <link>https://dev.to/galaxy_7b6ad9933a659ac9cd</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4247316%2F372c9d8b-ad05-4aef-8e20-f626e7c3ab03.png</url>
      <title>DEV Community: galaxy</title>
      <link>https://dev.to/galaxy_7b6ad9933a659ac9cd</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/galaxy_7b6ad9933a659ac9cd"/>
    <language>en</language>
    <item>
      <title>Building a Dual-Transport MCP Server for 1,000+ Lateral Thinking Puzzles (Stdio + Streamable HTTP)</title>
      <dc:creator>galaxy</dc:creator>
      <pubDate>Mon, 16 Nov 2026 09:01:45 +0000</pubDate>
      <link>https://dev.to/galaxy_7b6ad9933a659ac9cd/building-a-dual-transport-mcp-server-for-1000-lateral-thinking-puzzles-stdio-streamable-http-4de4</link>
      <guid>https://dev.to/galaxy_7b6ad9933a659ac9cd/building-a-dual-transport-mcp-server-for-1000-lateral-thinking-puzzles-stdio-streamable-http-4de4</guid>
      <description>&lt;p&gt;We just shipped the open-source MCP server for &lt;strong&gt;&lt;a href="https://lateralthinkingpuzzles.org" rel="noopener noreferrer"&gt;YesNoMystery&lt;/a&gt;&lt;/strong&gt; (Lateral Thinking Puzzles / &lt;em&gt;Turtle Soup&lt;/em&gt; / &lt;em&gt;Black Stories&lt;/em&gt;):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub&lt;/strong&gt;: &lt;a href="https://github.com/yesnomystery/yes-no-mystery-mcp" rel="noopener noreferrer"&gt;yesnomystery/yes-no-mystery-mcp&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;npm&lt;/strong&gt;: &lt;a href="https://www.npmjs.com/package/yes-no-mystery-mcp" rel="noopener noreferrer"&gt;&lt;code&gt;yes-no-mystery-mcp&lt;/code&gt;&lt;/a&gt; (and CLI alias &lt;a href="https://www.npmjs.com/package/lateral-thinking-puzzles-mcp" rel="noopener noreferrer"&gt;&lt;code&gt;lateral-thinking-puzzles-mcp&lt;/code&gt;&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Remote Streamable HTTP&lt;/strong&gt;: &lt;code&gt;https://lateralthinkingpuzzles.org/api/mcp&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Official MCP Registry&lt;/strong&gt;: &lt;code&gt;io.github.yesnomystery/yes-no-mystery-mcp&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is how we designed one shared TypeScript backend to power both remote Streamable HTTP and local &lt;code&gt;stdio&lt;/code&gt;, along with three production bugs we caught before opening it up to MCP clients.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Lateral Thinking Puzzles Fit MCP
&lt;/h2&gt;

&lt;p&gt;In a lateral thinking puzzle ("Turtle Soup"), the host gives players a brief, paradoxical scenario. Players ask yes/no questions to reconstruct the hidden backstory until they solve the mystery.&lt;/p&gt;

&lt;p&gt;Mapping this loop onto Model Context Protocol (MCP) tools turns any AI client (Claude Desktop, Cursor, VS Code, Claude Code) into either:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;A solo detective&lt;/strong&gt;: the LLM searches mysteries by language, difficulty, category, or tags, asks yes/no questions step by step, and unlocks clues on a 0–120 mastery scale.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;An interactive host&lt;/strong&gt;: you pick a puzzle together and ask questions directly inside your editor or chat app.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We kept the tool surface to four focused primitives:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;ynm_search_puzzles&lt;/code&gt; — filter 1,000+ official puzzles and password-free public community (UGC) puzzles across 12 languages (&lt;code&gt;en&lt;/code&gt;, &lt;code&gt;zh&lt;/code&gt;, &lt;code&gt;zh-TW&lt;/code&gt;, &lt;code&gt;ja&lt;/code&gt;, &lt;code&gt;ko&lt;/code&gt;, &lt;code&gt;de&lt;/code&gt;, &lt;code&gt;es&lt;/code&gt;, &lt;code&gt;fr&lt;/code&gt;, &lt;code&gt;it&lt;/code&gt;, &lt;code&gt;pt&lt;/code&gt;, &lt;code&gt;ru&lt;/code&gt;, &lt;code&gt;th&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ynm_get_puzzle&lt;/code&gt; — fetch a puzzle's scenario, target questions, unlocked clues so far, progress (0–120), and current answer reveal cost.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ynm_ask_question&lt;/code&gt; — ask a yes/no deduction question (&lt;code&gt;yes&lt;/code&gt;, &lt;code&gt;no&lt;/code&gt;, &lt;code&gt;unknown&lt;/code&gt;, &lt;code&gt;partial_ok&lt;/code&gt;, &lt;code&gt;irrelevant&lt;/code&gt;, &lt;code&gt;needs_rephrase&lt;/code&gt;). Supports both stateful Q&amp;amp;A history (default, up to 20 turns cached per puzzle in the CLI wrapper) and stateless standalone evaluation (&lt;code&gt;include_history: false&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ynm_reveal_solution&lt;/code&gt; — reveal the full solution and all clues using the same dynamic pricing as the website: 20/30/40 credits at 0 progress, dropping linearly down to 1 credit at 80+ progress, and &lt;strong&gt;0 credits (free)&lt;/strong&gt; once progress hits 100.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Search and detail endpoints strip &lt;code&gt;solution&lt;/code&gt; and locked clues completely—there is no accidental spoiler in tool responses.&lt;/p&gt;




&lt;h2&gt;
  
  
  Architecture: One Backend Service for Two Transports
&lt;/h2&gt;

&lt;p&gt;Rather than duplicating puzzle resolution, quota accounting, or AI prompting in a separate daemon, all logic lives inside our Next.js App Router codebase (&lt;code&gt;src/lib/mcp/*&lt;/code&gt;) and exposes two entrypoints over the same service layer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Remote clients ──▶ POST/GET/DELETE /api/mcp (Streamable HTTP via @modelcontextprotocol/server)
Local stdio    ──▶ npx -y yes-no-mystery-mcp
                     └─ GET  /api/mcp/puzzles
                     └─ POST /api/mcp/ask
                     └─ POST /api/mcp/reveal
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;yes-no-mystery-mcp&lt;/code&gt; npm package stays under 10 KB compressed: it validates schemas with &lt;code&gt;zod&lt;/code&gt;, keeps optional local Q&amp;amp;A history in memory for &lt;code&gt;stdio&lt;/code&gt; sessions, and talks to those thin JSON routes with explicit timeouts and &lt;code&gt;X-MCP-Client-Id&lt;/code&gt; headers.&lt;/p&gt;




&lt;h2&gt;
  
  
  Three Production Gotchas We Ran Into
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Cookie Isolation &amp;amp; Zero-Token Anti-Abuse Preflight
&lt;/h3&gt;

&lt;p&gt;On our website, logged-in users spend account credits and browser users have SameSite cookies. If &lt;code&gt;/api/mcp/*&lt;/code&gt; reused the same &lt;code&gt;getOptionalAuth&lt;/code&gt; helper as browser routes, a third-party page or misconfigured client making cross-origin calls could burn a logged-in user's paid credits.&lt;/p&gt;

&lt;p&gt;Fix:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;/api/mcp/*&lt;/code&gt; &lt;strong&gt;ignores browser &lt;code&gt;Cookie&lt;/code&gt; headers completely&lt;/strong&gt; and never sets &lt;code&gt;Access-Control-Allow-Credentials&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Instead, the server derives an isolated &lt;code&gt;mcp_&amp;lt;24hex&amp;gt;&lt;/code&gt; anonymous actor ID via HMAC-SHA256 from the trusted request IP fingerprint and &lt;code&gt;X-MCP-Client-Id&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Before touching any LLM provider, a lightweight Postgres check verifies both credit balance and our existing 1-hour / 24-hour IP+UA trial rate limits. Rate-limited or exhausted callers get a clean &lt;code&gt;402&lt;/code&gt;/&lt;code&gt;429&lt;/code&gt; JSON response and burn &lt;strong&gt;0 AI tokens&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. HTTP &lt;code&gt;301&lt;/code&gt; Silently Turns &lt;code&gt;POST&lt;/code&gt; into &lt;code&gt;GET&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Our reverse proxy enforces canonical domain redirects (&lt;code&gt;www.lateralthinkingpuzzles.org&lt;/code&gt; -&amp;gt; &lt;code&gt;301&lt;/code&gt; -&amp;gt; &lt;code&gt;lateralthinkingpuzzles.org&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;That works invisibly for browser &lt;code&gt;GET&lt;/code&gt; page views. For MCP over HTTP, standard &lt;code&gt;fetch()&lt;/code&gt; converts a &lt;code&gt;POST&lt;/code&gt; request into a &lt;code&gt;GET&lt;/code&gt; when it follows a &lt;code&gt;301&lt;/code&gt; redirect and drops the JSON body—breaking &lt;code&gt;POST /api/mcp&lt;/code&gt; and &lt;code&gt;POST /api/mcp/ask&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Testing against the live edge caught this right before &lt;code&gt;npm publish&lt;/code&gt;. Aligning &lt;code&gt;DEFAULT_API_BASE_URL&lt;/code&gt;, &lt;code&gt;server.json&lt;/code&gt; (&lt;code&gt;remotes[0].url&lt;/code&gt;), and client docs to the apex URL &lt;code&gt;https://lateralthinkingpuzzles.org/api/mcp&lt;/code&gt; removed the redirect completely.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Official MCP Registry Namespace &amp;amp; Schema Checks
&lt;/h3&gt;

&lt;p&gt;When publishing &lt;code&gt;io.github.yesnomystery/yes-no-mystery-mcp&lt;/code&gt; to the Official MCP Registry (&lt;code&gt;registry.modelcontextprotocol.io&lt;/code&gt;), two constraints tripped us up at first:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;2025-12-11&lt;/code&gt; &lt;code&gt;server.schema.json&lt;/code&gt; enforces &lt;code&gt;description&lt;/code&gt; &lt;code&gt;maxLength: 100&lt;/code&gt; (while our initial draft was 129 chars).&lt;/li&gt;
&lt;li&gt;Interactive &lt;code&gt;mcp-publisher login github&lt;/code&gt; device OAuth cannot read organization memberships (#1468), so publishing under a GitHub Organization namespace (&lt;code&gt;io.github.yesnomystery/*&lt;/code&gt;) requires GitHub Actions OIDC (&lt;code&gt;./mcp-publisher login github-oidc&lt;/code&gt;) with &lt;code&gt;id-token: write&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Adding Sigstore verification of &lt;code&gt;mcp-publisher&lt;/code&gt; inside a minimal workflow let us publish directly from the org repo with zero long-lived tokens.&lt;/p&gt;




&lt;h2&gt;
  
  
  Try It in 10 Seconds
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Option A: Remote Streamable HTTP (Zero Install)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"mcpServers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"yes-no-mystery"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://lateralthinkingpuzzles.org/api/mcp"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Option B: Local &lt;code&gt;npx&lt;/code&gt; (&lt;code&gt;stdio&lt;/code&gt;)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"mcpServers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"yes-no-mystery"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"npx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"args"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"-y"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"yes-no-mystery-mcp"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each anonymous client starts with &lt;strong&gt;50 free trial credits&lt;/strong&gt; (25 AI questions), and reaching 100/120 progress unlocks the full solution for free.&lt;/p&gt;

&lt;p&gt;Play on the web anytime in &lt;a href="https://lateralthinkingpuzzles.org/puzzle" rel="noopener noreferrer"&gt;English&lt;/a&gt;, &lt;a href="https://lateralthinkingpuzzles.org/zh" rel="noopener noreferrer"&gt;简体中文&lt;/a&gt;, or &lt;a href="https://lateralthinkingpuzzles.org/ja" rel="noopener noreferrer"&gt;日本語&lt;/a&gt;, or check out the source on &lt;a href="https://github.com/yesnomystery/yes-no-mystery-mcp" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>mcp</category>
      <category>ai</category>
      <category>typescript</category>
      <category>nextjs</category>
    </item>
  </channel>
</rss>
