<?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: Shaher Shamroukh</title>
    <description>The latest articles on DEV Community by Shaher Shamroukh (@shahershamroukh).</description>
    <link>https://dev.to/shahershamroukh</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%2F508938%2F7b59ffb1-d88a-405f-8dbe-46996a2aa250.png</url>
      <title>DEV Community: Shaher Shamroukh</title>
      <link>https://dev.to/shahershamroukh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shahershamroukh"/>
    <language>en</language>
    <item>
      <title>I Added an MCP Server to My Rails SaaS. Now AI Agents Create 54% of Our Posts</title>
      <dc:creator>Shaher Shamroukh</dc:creator>
      <pubDate>Thu, 26 Nov 2026 11:28:56 +0000</pubDate>
      <link>https://dev.to/shahershamroukh/i-added-an-mcp-server-to-my-rails-saas-now-ai-agents-create-54-of-our-posts-13ed</link>
      <guid>https://dev.to/shahershamroukh/i-added-an-mcp-server-to-my-rails-saas-now-ai-agents-create-54-of-our-posts-13ed</guid>
      <description>&lt;p&gt;I run &lt;a href="https://robinreach.com" rel="noopener noreferrer"&gt;RobinReach&lt;/a&gt;, a social media scheduling SaaS built on Rails. A while back I added an MCP server so people could manage their social accounts from Claude or ChatGPT.&lt;/p&gt;

&lt;p&gt;I thought of it as a side feature for a few technical users. Then I ran a quick query on our posts table for the last three months:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="nc"&gt;Post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;created_at&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;months&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ago&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;span class="nf"&gt;group&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:creation_source&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result: &lt;strong&gt;54.1%&lt;/strong&gt; of all posts were created through MCP. Our REST API was 13.7%. The web app and built-in automations together were 32.2%.&lt;/p&gt;

&lt;p&gt;So AI agents now create more content on our platform than our own dashboard does. Here's how the MCP server is built, and the five things I'd tell any Rails dev about to build one.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I built
&lt;/h2&gt;

&lt;p&gt;Nothing exotic. It's a regular Rails endpoint that speaks MCP's JSON-RPC, sitting on top of the same app that powers the dashboard and the REST API.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Claude / ChatGPT
      |  JSON-RPC over HTTP (tools/list, tools/call)
      v
Mcp::V1::MessagesController     &amp;lt;- auth: API key or OAuth token
      |
      v
Mcp::RobinreachToolRegistry     &amp;lt;- one schema per tool
      |
      v
Existing service objects        &amp;lt;- same code the dashboard and API use
      |
      v
Sidekiq jobs                    &amp;lt;- publishing, media, analytics
      |
      v
Facebook, Instagram, LinkedIn, X, TikTok, YouTube, Threads, Bluesky...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The stack is boring on purpose: Rails, Postgres, Sidekiq on Redis, Doorkeeper for OAuth. The interesting part is all in the decisions, so let's get into those.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lesson 1: Don't build a second app
&lt;/h2&gt;

&lt;p&gt;The biggest mistake you can make is writing "MCP versions" of your features. Every MCP tool in RobinReach is a thin adapter over a service object that already exists: the same &lt;code&gt;PostCreator&lt;/code&gt;, the same validators, the same publish jobs the dashboard uses.&lt;/p&gt;

&lt;p&gt;This paid off more than I expected:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fixes land everywhere.&lt;/strong&gt; When I fixed a TikTok or Instagram publishing bug, MCP users got the fix the same minute dashboard users did.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Validation is consistent.&lt;/strong&gt; An agent can't create a post the UI would reject, because it hits the exact same rules.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Refactors are safer.&lt;/strong&gt; When I moved media delivery behind a CDN, I only had to check one path. &lt;code&gt;PostCreator&lt;/code&gt; matches attached media by storage key, not by URL, so tool responses could switch to CDN URLs without breaking anything downstream.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If your controllers are fat and your logic lives in them, fix that first. An MCP server is a great excuse to finally extract service objects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lesson 2: Tool design is product design
&lt;/h2&gt;

&lt;p&gt;My first version had a few big tools with an &lt;code&gt;action&lt;/code&gt; parameter that switched behavior. It worked, but models picked the wrong action, sent the wrong fields, and got confused by giant schemas. Splitting it into many small tools, each with its own focused schema, made agents noticeably more reliable.&lt;/p&gt;

&lt;p&gt;Here's the shape of it, simplified:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Simplified for the article, not production code&lt;/span&gt;
&lt;span class="k"&gt;module&lt;/span&gt; &lt;span class="nc"&gt;Mcp&lt;/span&gt;
  &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ToolRegistry&lt;/span&gt;
    &lt;span class="no"&gt;TOOLS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="s2"&gt;"posts_create"&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Create and schedule a post on one or more social profiles. "&lt;/span&gt; \
                     &lt;span class="s2"&gt;"Call account_profiles first to get valid profile ids. "&lt;/span&gt; \
                     &lt;span class="s2"&gt;"Omit publish_time to save as a draft."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;input_schema&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"object"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="n"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;      &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"string"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;profile_ids&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"array"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"string"&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="n"&gt;publish_time&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"string"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ISO 8601 with timezone"&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="n"&gt;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt; &lt;span class="n"&gt;profile_ids&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="n"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;brand&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;PostCreator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;brand&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;call&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="c1"&gt;# ...dozens more&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;freeze&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;list&lt;/span&gt;
      &lt;span class="no"&gt;TOOLS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tool&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;tool&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:description&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;inputSchema&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;tool&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:input_schema&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="k"&gt;end&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;brand&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="n"&gt;tool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;TOOLS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nb"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;UnknownToolError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="n"&gt;tool&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:handler&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;brand&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A few rules I now follow:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Descriptions are your docs.&lt;/strong&gt; The model reads them, not your help center. Say when to call the tool, what to call first, and what happens if a field is missing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Name tools by noun then verb.&lt;/strong&gt; &lt;code&gt;posts_create&lt;/code&gt;, &lt;code&gt;posts_reschedule&lt;/code&gt;, &lt;code&gt;analytics_top_posts&lt;/code&gt;. Related tools group together and models find them faster.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Return errors an agent can act on.&lt;/strong&gt; "profile_ids contains a Pinterest profile, but no board_id was given" gets fixed on the next call. "Validation failed" gets you a confused user.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Give agents a dry run.&lt;/strong&gt; A &lt;code&gt;posts_validate&lt;/code&gt; tool lets the model check a post before creating it, which cuts down on half-created content.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Lesson 3: Start with API keys, but plan for OAuth
&lt;/h2&gt;

&lt;p&gt;The first version authenticated with the same API keys as our REST API. That's the fastest way to ship, and it's fine for developers pasting a key into a config file.&lt;/p&gt;

&lt;p&gt;But normal users don't paste keys. To show up as a proper connector in ChatGPT and Claude, you need OAuth. I added it with Doorkeeper, alongside the existing key auth, so nothing broke for people already connected.&lt;/p&gt;

&lt;p&gt;The part worth copying is the consent screen. When someone connects, they choose to give the assistant their whole account or a single brand. For agencies that's huge: you can let an assistant work on one client without it ever seeing the others. We do the same with API keys, where each brand can have its own key scoped to that brand only.&lt;/p&gt;

&lt;p&gt;The design rule behind it: &lt;strong&gt;resolve scope once, at the auth layer.&lt;/strong&gt; By the time a tool runs, it receives a brand it's allowed to touch, and it never has to check permissions itself. Fewer places to get it wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lesson 4: Text is easy, media is the hard part
&lt;/h2&gt;

&lt;p&gt;Getting an agent to schedule a text post was quick. Getting it to attach the right image was a long tail of edge cases.&lt;/p&gt;

&lt;p&gt;The core problem: the agent's files don't live where your server can reach them. A customer told me ChatGPT could schedule their posts fine, but couldn't attach the images it had just generated in the chat. Those images had no public URL, and my tools only accepted URLs.&lt;/p&gt;

&lt;p&gt;So media ended up with several ways in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Public URL:&lt;/strong&gt; the agent passes a link, a background job downloads it, and a status tool lets the agent poll until it's ready.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;From the chat:&lt;/strong&gt; a dedicated tool that accepts the assistant's own file references, so images generated or uploaded in ChatGPT can go straight into a post.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Direct upload:&lt;/strong&gt; a signed upload URL for local files, created and finalized in two steps.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Generated or found in-app:&lt;/strong&gt; AI image generation and stock photo search as tools of their own.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then the platforms add their own fun. Instagram, for example, sometimes fails to fetch an image that was uploaded to a CDN a second earlier, then succeeds a minute later with the exact same URL. The fix was retrying that specific error with exponential backoff inside each Instagram service class, not retrying the whole job.&lt;/p&gt;

&lt;p&gt;The general lesson: &lt;strong&gt;any media step that can take more than a couple of seconds should be a background job with a status tool.&lt;/strong&gt; Agents are fine with polling. They're not fine with timeouts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lesson 5: Agents are your most demanding power users
&lt;/h2&gt;

&lt;p&gt;A human schedules a few posts, looks around, goes for coffee. An agent asked to "plan next month for all my brands" fires off a burst of calls in seconds. Your app needs to be ready for that.&lt;/p&gt;

&lt;p&gt;Things that bit me or almost did:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Synchronous uploads.&lt;/strong&gt; One upload endpoint stored files inline on the request thread. A single upload was fine. A burst of them from one agent tied up Puma threads and caused timeouts that cleared on their own minutes later. Classic "works on my machine" bug that only appears under agent traffic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rate limits.&lt;/strong&gt; You need them, and you need to document them correctly. Agents read your docs literally.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Batch tools.&lt;/strong&gt; Instead of making the model call &lt;code&gt;posts_create&lt;/code&gt; twenty times, a bulk tool that takes up to 20 posts per call is faster for everyone and easier on your server.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Queue priorities.&lt;/strong&gt; Publishing has to stay fast no matter how many analytics or media jobs agents kick off. Give publishing its own Sidekiq queue and keep heavy work like video processing in a separate container.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cost controls on expensive tools.&lt;/strong&gt; Anything that calls a paid AI API (image generation, video edits) needs per-plan limits, or one enthusiastic agent will show up on your bill.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why this matters if you run a SaaS
&lt;/h2&gt;

&lt;p&gt;MCP isn't a niche experiment anymore. OpenAI, Google and Microsoft all support it, it's governed by the Linux Foundation's Agentic AI Foundation, and the official MCP Registry listed over 47,000 active servers in October 2026 (&lt;a href="https://www.digitalapplied.com/blog/mcp-adoption-statistics-2026-model-context-protocol" rel="noopener noreferrer"&gt;Digital Applied&lt;/a&gt;). For Rails folks, the official Ruby SDK is one of the project's Tier 1 SDKs.&lt;/p&gt;

&lt;p&gt;My takeaway from our numbers: &lt;strong&gt;your users already spend their day in an AI assistant.&lt;/strong&gt; If your product isn't reachable from there, they'll either copy and paste between tabs or find a tool that is.&lt;/p&gt;

&lt;p&gt;If you're starting out:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Track the source of everything from day one.&lt;/strong&gt; A simple &lt;code&gt;creation_source&lt;/code&gt; column is how I found out any of this. Without it, I'd still think MCP was a side feature.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Start with read tools plus one write tool.&lt;/strong&gt; "List my stuff" and "create one thing" covers a surprising amount of real use.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Wrap your existing services.&lt;/strong&gt; No new business logic in the MCP layer.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ship API keys first, OAuth second.&lt;/strong&gt; Then get listed in the Claude and ChatGPT connector directories, because that's where non-technical users find you.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Watch your logs, not just your metrics.&lt;/strong&gt; The tool calls agents make tell you exactly which tools are confusing and which ones are missing.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Wrapping up
&lt;/h2&gt;

&lt;p&gt;I put a lot of work into our dashboard. Then more than half of our content started arriving through a JSON-RPC endpoint I almost didn't build.&lt;/p&gt;

&lt;p&gt;The dashboard still matters. People use it to review, approve and check results. But the daily work is moving into the chat, and the products that make that easy are going to win.&lt;/p&gt;

&lt;p&gt;We published the full breakdown, with methodology and what it means for marketers, on the RobinReach blog: &lt;a href="https://robinreach.com/articles/ai-agents-now-create-54-of-our-social-media" rel="noopener noreferrer"&gt;https://robinreach.com/articles/ai-agents-now-create-54-of-our-social-media&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you're building an MCP server in Rails and get stuck on any of this, drop a comment. Happy to share more.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>saas</category>
      <category>webdev</category>
      <category>mcp</category>
    </item>
    <item>
      <title>I gave my AI agent eyes so it could design carousels</title>
      <dc:creator>Shaher Shamroukh</dc:creator>
      <pubDate>Mon, 23 Nov 2026 18:54:57 +0000</pubDate>
      <link>https://dev.to/shahershamroukh/i-gave-my-ai-agent-eyes-so-it-could-design-carousels-2pci</link>
      <guid>https://dev.to/shahershamroukh/i-gave-my-ai-agent-eyes-so-it-could-design-carousels-2pci</guid>
      <description>&lt;p&gt;The first time I asked Claude to make a carousel through our MCP server, it wrote seven solid slides. Then it had to tell me the honest truth: it had no idea what they looked like.&lt;/p&gt;

&lt;p&gt;Fair enough. It had written text into a JSON blob. Somewhere else, a browser would turn that into images. The agent had no browser, so it was designing blind.&lt;/p&gt;

&lt;p&gt;This post is about fixing that: rendering HTML slides on the server so an AI agent can look at its own work, catch its own mistakes, and only then schedule the post. The stack is Rails, Sidekiq and a headless Chromium container, but the ideas work anywhere.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem: the renderer lived in the browser
&lt;/h2&gt;

&lt;p&gt;Our carousel studio draws every slide as plain HTML and CSS: 1080 by 1350 pixels, one design system, around 80 themes. When a person clicks Export, the browser turns each slide into a JPEG with an html-to-image library and uploads it.&lt;/p&gt;

&lt;p&gt;That works great for humans. It's useless for an agent. An MCP tool call runs on the server. There is no tab, no DOM, no click. So the agent could create and edit carousels, but every image it handed back was either missing or stale.&lt;/p&gt;

&lt;p&gt;I had three options:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Rewrite the renderer for the server (canvas, Satori, something else).&lt;/li&gt;
&lt;li&gt;Ask the user to open the editor and export.&lt;/li&gt;
&lt;li&gt;Run the exact same renderer on the server, in a real browser.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Option 1 means two renderers that drift apart forever. Option 2 defeats the point of an agent. So, option 3.&lt;/p&gt;

&lt;h2&gt;
  
  
  Same renderer, real Chromium, its own box
&lt;/h2&gt;

&lt;p&gt;I didn't want Chromium inside the Rails image. It's big, it eats memory, and if it crashes I don't want it taking a web worker with it. So it runs as its own container: &lt;a href="https://gotenberg.dev" rel="noopener noreferrer"&gt;Gotenberg&lt;/a&gt;, which wraps headless Chromium in a small HTTP API.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;renderer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;gotenberg/gotenberg:8.39.0-chromium&lt;/span&gt;
  &lt;span class="na"&gt;command&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;gotenberg&lt;/span&gt;
    &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;--api-timeout=60s&lt;/span&gt;
    &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;--chromium-restart-after=50&lt;/span&gt;
    &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;--chromium-allow-list=^file:///tmp/.*|^https://fonts\.(googleapis|gstatic)\.com/.*&lt;/span&gt;
  &lt;span class="na"&gt;mem_limit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;1g&lt;/span&gt;
  &lt;span class="na"&gt;cpus&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No published ports, a memory cap, a restart every 50 renders to keep Chromium fresh, and an allow-list so the page can only load its own files and Google Fonts. Nothing else on the internet.&lt;/p&gt;

&lt;p&gt;The flow for one render:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The agent calls a tool like &lt;code&gt;carousels_render&lt;/code&gt;. Rails answers right away with a job id.&lt;/li&gt;
&lt;li&gt;A Sidekiq job builds one self-contained HTML page: the same renderer JavaScript the browser uses, the same CSS, the slide data as JSON, and every image as a local file.&lt;/li&gt;
&lt;li&gt;The job posts that page to Gotenberg and gets one PNG back.&lt;/li&gt;
&lt;li&gt;ImageMagick cuts it into slides, and the job saves them as JPEGs.&lt;/li&gt;
&lt;li&gt;The agent polls the job id and gets image URLs back.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The render jobs run on their own Sidekiq queue, so a slow render never delays someone's scheduled post.&lt;/p&gt;

&lt;h2&gt;
  
  
  One screenshot, many slides
&lt;/h2&gt;

&lt;p&gt;The naive version takes one screenshot per slide. With 7 slides that's 7 Chromium page loads, 7 font downloads and 7 chances to time out.&lt;/p&gt;

&lt;p&gt;Instead, the page stacks every slide on top of each other, with no gaps:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1080px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.slide&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1080px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1350px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;overflow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;hidden&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;Then Gotenberg takes a single screenshot of the whole page, 1080 pixels wide and 1350 times the slide count tall. One page load, fonts fetched once, and every slide rendered in the same browser state.&lt;/p&gt;

&lt;p&gt;Cutting it back into slides is one ImageMagick command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;magick page.png -crop 1080x1350 +repage -quality 92 slide_%02d.jpg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same trick made a second feature almost free. The agent can ask to see one slide in four different designs before choosing. That's just four copies of the same slide, each with a different theme, stacked on one page. One render, four previews, a few seconds.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three bugs that cost me hours
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Every image came back blank.&lt;/strong&gt; In the browser export, images get &lt;code&gt;crossOrigin = "anonymous"&lt;/code&gt; so html-to-image can read their pixels. On the server the page loads from &lt;code&gt;file://&lt;/code&gt;, and Chromium treats a cross-origin request from a file page as a failure. Photos, logos, all gone, with no error. The fix was a one-liner: the server page is the screenshot, so it doesn't need to read pixels, so no &lt;code&gt;crossOrigin&lt;/code&gt; there.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. A missing image hung the render for a full minute.&lt;/strong&gt; Gotenberg waits until an expression is true (&lt;code&gt;window.renderReady === true&lt;/code&gt;) before taking the screenshot. When an image failed, my code threw an error before setting the flag, so Gotenberg sat there until its 60 second timeout. Now the page sets the flag first, then throws. With &lt;code&gt;failOnConsoleExceptions&lt;/code&gt; on, Gotenberg answers with an error right away, and the agent gets "this image can't be used" in a second instead of a vague timeout.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. A job released someone else's lock.&lt;/strong&gt; Generation takes a Redis lock per account so nobody runs two at once. If a job ran longer than the lock's TTL, a second job could take the lock, and then the first job's &lt;code&gt;DEL&lt;/code&gt; at the end would delete the second job's lock. The fix is to delete only if the value is still yours, atomically:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lua"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"get"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;KEYS&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="no"&gt;ARGV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"del"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;KEYS&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;None of these showed up in my own testing. A teammate's code review caught all three before any customer did, which is a good argument for code review.&lt;/p&gt;

&lt;h2&gt;
  
  
  Giving the agent eyes
&lt;/h2&gt;

&lt;p&gt;Rendering images is only half of it. The agent has to actually look at them. A few things made the difference:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Return the images, not just URLs.&lt;/strong&gt; MCP tool results can carry images. When the agent asks for a preview of four designs, it gets four small images back in the tool result, each labelled with the design's name, so it can compare them like a person would.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tell it to look before it posts.&lt;/strong&gt; The tool's answer includes a plain next step: look at every slide before showing or scheduling them, and fix anything that's off. Agents follow instructions in tool results surprisingly well. With the images in front of it, Claude can spot a crowded slide or a cover where the title fights the background, edit it and render again.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hand it the boring fields.&lt;/strong&gt; When a carousel is ready, the tool also returns a LinkedIn document title and alt text for every slide, built from the slides' own text. Before, the agent had to write these itself or skip them. Now they're just there, ready to pass along.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keep status calls read-only.&lt;/strong&gt; My first version of the status tool started a render if the images were missing. Helpful, I thought. In practice an agent polling every few seconds kicked off renders nobody asked for. A status call now only reports; starting work is always its own explicit tool.&lt;/p&gt;

&lt;h2&gt;
  
  
  The writing problem
&lt;/h2&gt;

&lt;p&gt;Once the slides looked right, the next complaint was the words. A teammate tried it end to end and the first carousel opened with "Unlock the Power of AI in Coding!" Every slide had an exclamation mark. Two slides said the same thing.&lt;/p&gt;

&lt;p&gt;A better prompt helped, but prompts are suggestions. So after the first draft, a small Ruby check looks for the things a reader notices first:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;exclamation marks on slides&lt;/li&gt;
&lt;li&gt;a list of hype phrases (unlock, game changer, supercharge, level up, and friends)&lt;/li&gt;
&lt;li&gt;two slides making the same point&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The repeat check is simple word overlap between slides:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;words&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;slides&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;downcase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;scan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;\&lt;span class="nb"&gt;p&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;L&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;uniq&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;shared&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;words&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;words&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;b&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="n"&gt;size&lt;/span&gt;
&lt;span class="n"&gt;all&lt;/span&gt;    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;words&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;words&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;b&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="n"&gt;size&lt;/span&gt;
&lt;span class="n"&gt;repeat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;all&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;shared&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fdiv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;all&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the draft has problems, the AI gets exactly one revision, with the list of problems. The important part is what happens next: the revision is only kept if it has &lt;strong&gt;no more problems than the draft and at least as many usable slides&lt;/strong&gt;. If the revision call fails, times out, or comes back broken, the user gets the first draft. The check can make a carousel better. It can never make one worse, and it can never fail the whole job.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd tell anyone building tools for agents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;One renderer, two places.&lt;/strong&gt; Running the browser's code in a headless browser beat writing a second renderer by a mile. The slides an agent makes look exactly like the ones a person exports.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Let the agent check its own work.&lt;/strong&gt; The biggest quality jump didn't come from a better model or prompt. It came from giving the agent the finished images and asking it to look.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fail fast and say why.&lt;/strong&gt; "This image can't be used" in one second is worth more than a timeout after sixty. Agents recover well from clear errors and badly from vague ones.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Make the AI's second try safe.&lt;/strong&gt; Automatic revisions are great until one comes back worse. Only keep it when it's measurably better, and fall back to the first draft on any error.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Isolate the heavy stuff.&lt;/strong&gt; Chromium in its own container with a memory cap, render jobs on their own queue, and a kill switch in an env var. When something goes wrong, nothing else notices.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Where this lives
&lt;/h2&gt;

&lt;p&gt;All of this runs in &lt;a href="https://robinreach.com" rel="noopener noreferrer"&gt;RobinReach&lt;/a&gt;, the social media scheduler I build. If you use Claude or ChatGPT, you can &lt;a href="https://robinreach.com/mcp" rel="noopener noreferrer"&gt;connect it over MCP&lt;/a&gt; and ask for a carousel in plain words. It writes it, renders it, looks at it, fixes it, and schedules it once you say yes.&lt;/p&gt;

&lt;p&gt;The pattern isn't specific to carousels, though. Any time an agent makes something visual (a chart, a thumbnail, an email, a landing page), the same move works: render it the way a human would see it, and hand the agent the picture.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>productivity</category>
      <category>rails</category>
      <category>socialmedia</category>
    </item>
    <item>
      <title>Giving an AI Agent Write Access to Your App: Guardrails We Built for RobinReach's MCP Tools</title>
      <dc:creator>Shaher Shamroukh</dc:creator>
      <pubDate>Mon, 15 Jun 2026 21:04:23 +0000</pubDate>
      <link>https://dev.to/shahershamroukh/giving-an-ai-agent-write-access-to-your-app-guardrails-we-built-for-robinreachs-mcp-tools-5h8</link>
      <guid>https://dev.to/shahershamroukh/giving-an-ai-agent-write-access-to-your-app-guardrails-we-built-for-robinreachs-mcp-tools-5h8</guid>
      <description>&lt;p&gt;A few months ago I wrote about &lt;a href="https://dev.to/shahershamroukh/building-a-production-mcp-server-in-ruby-on-rails-lessons-from-robinreach-4f4c"&gt;building a production MCP server in Rails&lt;/a&gt;, the plumbing of exposing RobinReach's API as a set of MCP tools that Claude and other agents can call.&lt;/p&gt;

&lt;p&gt;That post was about connecting an AI agent to your app. This one is about the harder problem: what happens once it's connected and can actually do things, like publish to a client's Instagram, reply to a comment on their behalf, or schedule a week of content. The moment an agent has write access, "it works in the demo" stops being good enough.&lt;/p&gt;

&lt;p&gt;The single question every user (and every one of our customers' customers) eventually asks is some version of: "can this thing accidentally touch something it shouldn't?" Specifically, on a platform that manages multiple brands for multiple clients, can the AI agent working on Brand A ever see or post to Brand B?&lt;/p&gt;

&lt;p&gt;The answer is no, and the reason why is the part I want to focus on, because it's a different kind of guardrail than the usual "we told the AI not to" approach.&lt;/p&gt;

&lt;h2&gt;
  
  
  Brand isolation is not a rule the agent follows. It's a wall the agent can't see over.
&lt;/h2&gt;

&lt;p&gt;The easy way to build this would be: give the agent one set of credentials for the whole account, list every brand the user has access to, and then add an instruction like "always check which brand you're working on and never act on the wrong one."&lt;/p&gt;

&lt;p&gt;That approach technically works, right up until it doesn't. LLMs make mistakes. They mix up context across a long conversation, they reuse an ID from three messages ago, they occasionally just hallucinate. If the &lt;em&gt;only&lt;/em&gt; thing standing between "agent posts to Brand A" and "agent posts to Brand B" is a sentence in a prompt telling it to be careful, that's not a guardrail. That's a hope.&lt;/p&gt;

&lt;p&gt;So we built it differently. The connector that the agent talks to is scoped at the API/auth layer, not the prompt layer. When the integration is set up, the credentials issued for that connection are tied to a specific account and a specific set of brands the user actually has access to. Every tool call the agent makes gets validated against that scope on the server, before it ever touches a database row.&lt;/p&gt;

&lt;p&gt;What this means in practice:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The agent cannot list, read, or write to a brand that isn't in its scope. Not "is instructed not to," cannot. There is no code path where a request for a different brand's data returns anything other than an authorization error.&lt;/li&gt;
&lt;li&gt;If an account only has one brand, brand_id isn't even something the agent needs to think about, the scope handles it silently.&lt;/li&gt;
&lt;li&gt;If an account has multiple brands, the agent has to explicitly select and pass a brand_id on every write action, and that brand_id is checked against the connector's allowed scope on every single call, not just the first one.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The reason this matters so much is that it moves the guarantee from "the AI is well behaved" to "the infrastructure makes the bad outcome impossible." Those are very different sentences to say to a customer. One is a promise about behavior. The other is a statement about architecture. If you're building anything where an AI agent has access to multiple tenants, customers, or brands, this is the line I'd draw first, before writing a single line of prompt instructions.&lt;/p&gt;

&lt;h2&gt;
  
  
  The second layer: validating what the agent is about to do, not just where
&lt;/h2&gt;

&lt;p&gt;Scoping solves "is this the right brand." It doesn't solve "is this the right content." That's where validation comes in, and we treat it as a hard, separate step.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;validate_post&lt;/code&gt; is a required call that happens before &lt;code&gt;create_post&lt;/code&gt;, and the agent is instructed it must never skip it. We deliberately did not fold validation into the create step itself, even though that would be simpler. Splitting it forces a "draft, check, fix" loop instead of "fire and see what happens."&lt;/p&gt;

&lt;p&gt;What gets checked:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Character limits per platform (280 for Twitter, 500 for Threads, 2200 for Instagram, and so on), counting hashtags, emojis, line breaks, and unshortened URLs, because LLMs are notoriously bad at counting characters themselves.&lt;/li&gt;
&lt;li&gt;Required fields per platform, like a title for Pinterest or media for a Reel.&lt;/li&gt;
&lt;li&gt;Whether the content makes sense for the platforms it's being sent to at all.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If something fails, the agent gets a structured response back describing exactly what's wrong, and it can correct the content before anything goes near a real social account. In practice this catches the most common failure mode by a wide margin: an agent writing one great LinkedIn post and then naively reusing the same text as a tweet, which is both too long and the wrong tone.&lt;/p&gt;

&lt;h2&gt;
  
  
  The other guardrails, briefly
&lt;/h2&gt;

&lt;p&gt;A few more things worth a sentence each, because together they form the full picture:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Draft by default.&lt;/strong&gt; Anything the agent generates proactively lands as a draft, not scheduled or published. Scheduling or publishing only happens when the user actually asks for that outcome. This gives the agent a safe "here's what I made, take a look" state instead of a binary publish or don't.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Audience aware scheduling.&lt;/strong&gt; Before scheduling anything, the agent pulls the audience's actual best performing times for that brand and platform, rather than picking a "reasonable sounding" time itself. Left alone, an LLM tends to pick suspiciously round numbers like 9am or noon, because those are common in training data, not because that's when this brand's followers are online.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Voice learned from feedback.&lt;/strong&gt; Whenever a user edits or rejects generated content, that correction is saved and applied automatically next time. The agent is told to apply it silently, so the output just sounds like the brand without the user re-explaining preferences every session.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Comments are surfaced, not auto handled.&lt;/strong&gt; The agent can read and reply to comments, but it always shows the user who said what, on which post, and flags anything that looks like a complaint before drafting a response. Replying as the brand to a real customer is high stakes enough that a human stays in the loop.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;No raw API leaks into the conversation.&lt;/strong&gt; Tool names, JSON, internal IDs, none of that reaches the user. Everything is translated into plain language, like "your Facebook page Acme Co has 3 new comments" instead of a payload with internal identifiers. This sounds cosmetic but it's actually a trust guardrail. The moment a non technical user sees a raw error or an ID, the illusion that they're talking to "their social media manager" breaks, and they become more cautious about giving the tool any access at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  The pattern, if you're building something similar
&lt;/h2&gt;

&lt;p&gt;Across all of this, the theme is the same. Don't try to make the agent smarter. Make the wrong action structurally harder to take than the right one, and put the hardest boundaries where the cost of a mistake is highest.&lt;/p&gt;

&lt;p&gt;For us, that meant brand and tenant isolation enforced at the auth layer, where the agent has no technical ability to even ask for the wrong thing, and content validation enforced as a separate required step, where mistakes get caught before they go live. Everything else, voice, scheduling, comment handling, is built on top of those two foundations.&lt;/p&gt;

&lt;p&gt;MCP makes it trivially easy to hand an LLM the keys to your app. The interesting engineering work is making sure some of those keys don't open every door.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>mcp</category>
      <category>rails</category>
      <category>developer</category>
    </item>
    <item>
      <title>AWS vs DigitalOcean for SaaS: Why We Chose DigitalOcean for a Production Rails App</title>
      <dc:creator>Shaher Shamroukh</dc:creator>
      <pubDate>Wed, 20 May 2026 19:34:22 +0000</pubDate>
      <link>https://dev.to/shahershamroukh/aws-vs-digitalocean-for-saas-why-we-chose-digitalocean-for-a-production-rails-app-8oi</link>
      <guid>https://dev.to/shahershamroukh/aws-vs-digitalocean-for-saas-why-we-chose-digitalocean-for-a-production-rails-app-8oi</guid>
      <description>&lt;p&gt;There is a moment every SaaS founder hits early on.&lt;/p&gt;

&lt;p&gt;You open AWS, look at the console, and it feels like you have walked into an airport control tower.&lt;/p&gt;

&lt;p&gt;Everything is powerful. Everything is configurable. Everything is also overwhelming.&lt;/p&gt;

&lt;p&gt;Then you open DigitalOcean and think:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“This looks too simple to be serious.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We had the same reaction while building RobinReach, a Ruby on Rails SaaS handling social media scheduling, background jobs, API integrations, media processing, and multi-tenant data.&lt;/p&gt;

&lt;p&gt;And we still chose DigitalOcean.&lt;/p&gt;

&lt;p&gt;Not because AWS is worse.&lt;/p&gt;

&lt;p&gt;But because better infrastructure is not the same thing as a better decision for your stage.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Wrong Question Most Engineers Ask
&lt;/h1&gt;

&lt;p&gt;Most infrastructure debates start with:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Which is better, AWS or DigitalOcean?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But in real SaaS building, that is not the right question.&lt;/p&gt;

&lt;p&gt;The real question is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Which system lets us move faster without increasing operational complexity?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Because early-stage SaaS products do not fail due to lack of scalability.&lt;/p&gt;

&lt;p&gt;They fail due to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;slow iteration cycles
&lt;/li&gt;
&lt;li&gt;operational overhead
&lt;/li&gt;
&lt;li&gt;DevOps complexity
&lt;/li&gt;
&lt;li&gt;decision fatigue
&lt;/li&gt;
&lt;li&gt;fragile deployments
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Infrastructure is rarely the bottleneck early on.&lt;/p&gt;

&lt;p&gt;Complexity is.&lt;/p&gt;




&lt;h1&gt;
  
  
  What We Actually Needed for RobinReach
&lt;/h1&gt;

&lt;p&gt;RobinReach is not a simple CRUD app.&lt;/p&gt;

&lt;p&gt;It includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ruby on Rails API backend
&lt;/li&gt;
&lt;li&gt;Sidekiq background job processing
&lt;/li&gt;
&lt;li&gt;Redis queues
&lt;/li&gt;
&lt;li&gt;PostgreSQL database
&lt;/li&gt;
&lt;li&gt;Media processing for images and videos
&lt;/li&gt;
&lt;li&gt;OAuth integrations with multiple social platforms
&lt;/li&gt;
&lt;li&gt;Scheduled publishing across timezones
&lt;/li&gt;
&lt;li&gt;Multi-tenant architecture
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On paper, this sounds like AWS territory.&lt;/p&gt;

&lt;p&gt;But in reality, none of this requires AWS level infrastructure on day one.&lt;/p&gt;

&lt;p&gt;What it requires is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;stable compute
&lt;/li&gt;
&lt;li&gt;reliable background jobs
&lt;/li&gt;
&lt;li&gt;predictable deployments
&lt;/li&gt;
&lt;li&gt;simple observability
&lt;/li&gt;
&lt;li&gt;low operational friction
&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  AWS: What Looks Powerful vs What You Actually Feel
&lt;/h1&gt;

&lt;p&gt;AWS is undeniably powerful.&lt;/p&gt;

&lt;p&gt;You get:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;infinite scaling options
&lt;/li&gt;
&lt;li&gt;global infrastructure
&lt;/li&gt;
&lt;li&gt;deep service ecosystem like S3, ECS, Lambda
&lt;/li&gt;
&lt;li&gt;enterprise grade security
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But early-stage SaaS reality looks very different.&lt;/p&gt;

&lt;p&gt;What you actually feel:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;VPC design decisions before product market fit
&lt;/li&gt;
&lt;li&gt;IAM complexity from day one
&lt;/li&gt;
&lt;li&gt;service fragmentation
&lt;/li&gt;
&lt;li&gt;networking overhead
&lt;/li&gt;
&lt;li&gt;slower deployment workflows
&lt;/li&gt;
&lt;li&gt;DevOps dependency creeping in early
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;AWS is optimized for scale.&lt;/p&gt;

&lt;p&gt;But early-stage startups are not a scaling problem yet.&lt;/p&gt;

&lt;p&gt;They are a speed problem.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Hidden Cost of AWS: Cognitive Load
&lt;/h1&gt;

&lt;p&gt;The real cost of AWS is not money.&lt;/p&gt;

&lt;p&gt;It is cognitive overhead.&lt;/p&gt;

&lt;p&gt;Every small decision becomes a system design problem:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Which service should we use here
&lt;/li&gt;
&lt;li&gt;How should these services communicate
&lt;/li&gt;
&lt;li&gt;Why did this IAM role break production
&lt;/li&gt;
&lt;li&gt;Why is deployment slower than expected
&lt;/li&gt;
&lt;li&gt;Why do we need five services for something simple
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Individually, these problems are solvable.&lt;/p&gt;

&lt;p&gt;But together, they create friction.&lt;/p&gt;

&lt;p&gt;And friction slows iteration.&lt;/p&gt;

&lt;p&gt;In SaaS, iteration speed is everything.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why DigitalOcean Worked Better for Us
&lt;/h1&gt;

&lt;p&gt;DigitalOcean did not feel powerful.&lt;/p&gt;

&lt;p&gt;It felt predictable.&lt;/p&gt;

&lt;p&gt;And that predictability matters more than people think.&lt;/p&gt;

&lt;p&gt;With DigitalOcean, we could:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;deploy Rails apps quickly
&lt;/li&gt;
&lt;li&gt;run Sidekiq workers without orchestration complexity
&lt;/li&gt;
&lt;li&gt;manage PostgreSQL without infrastructure overhead
&lt;/li&gt;
&lt;li&gt;scale vertically in a controlled way
&lt;/li&gt;
&lt;li&gt;focus on product instead of infrastructure design
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Most importantly:&lt;/p&gt;

&lt;p&gt;We reduced the number of decisions we had to make outside of product work.&lt;/p&gt;

&lt;p&gt;That alone increased our shipping speed.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Real Decision Was Not Technical, It Was Strategic
&lt;/h1&gt;

&lt;p&gt;We did not choose DigitalOcean because it is simpler.&lt;/p&gt;

&lt;p&gt;We chose it because it reduced unnecessary system complexity at our current stage.&lt;/p&gt;

&lt;p&gt;At this stage of RobinReach, the most valuable resource is not infrastructure power.&lt;/p&gt;

&lt;p&gt;It is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;uninterrupted product iteration.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h1&gt;
  
  
  The Scaling Myth
&lt;/h1&gt;

&lt;p&gt;There is a common belief in engineering culture:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Start with AWS so you can scale later.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But in practice, most SaaS companies do not fail because they chose the wrong cloud provider.&lt;/p&gt;

&lt;p&gt;They fail because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;they over engineered too early
&lt;/li&gt;
&lt;li&gt;they slowed down before finding product market fit
&lt;/li&gt;
&lt;li&gt;they optimized systems they did not yet need
&lt;/li&gt;
&lt;li&gt;they lost iteration speed
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Scaling is not the first problem.&lt;/p&gt;

&lt;p&gt;Survival is.&lt;/p&gt;




&lt;h1&gt;
  
  
  When AWS Actually Makes Sense
&lt;/h1&gt;

&lt;p&gt;This is not an anti AWS argument.&lt;/p&gt;

&lt;p&gt;AWS becomes the right choice when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;traffic volume becomes consistently large
&lt;/li&gt;
&lt;li&gt;multi region deployment is required
&lt;/li&gt;
&lt;li&gt;enterprise compliance is mandatory
&lt;/li&gt;
&lt;li&gt;infrastructure specialization is needed
&lt;/li&gt;
&lt;li&gt;DevOps becomes a dedicated function, not a side task
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At that point, AWS is not overkill.&lt;/p&gt;

&lt;p&gt;It is necessary.&lt;/p&gt;

&lt;p&gt;But early on, it can easily become premature complexity.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Hidden Part Nobody Talks About: Billing Complexity
&lt;/h1&gt;

&lt;p&gt;One of the biggest reasons we chose DigitalOcean is not only infrastructure simplicity.&lt;/p&gt;

&lt;p&gt;It is billing clarity.&lt;/p&gt;

&lt;p&gt;Because in early SaaS, the real pain is not cost itself.&lt;/p&gt;

&lt;p&gt;It is unpredictable cost and unclear billing logic.&lt;/p&gt;




&lt;h2&gt;
  
  
  AWS: Powerful, but requires interpretation
&lt;/h2&gt;

&lt;p&gt;AWS billing is not a single number per server.&lt;/p&gt;

&lt;p&gt;It is a combination of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;EC2 compute usage
&lt;/li&gt;
&lt;li&gt;EBS storage
&lt;/li&gt;
&lt;li&gt;S3 storage and requests
&lt;/li&gt;
&lt;li&gt;data transfer in and out
&lt;/li&gt;
&lt;li&gt;load balancers
&lt;/li&gt;
&lt;li&gt;NAT gateways
&lt;/li&gt;
&lt;li&gt;logging and monitoring services
&lt;/li&gt;
&lt;li&gt;region based pricing differences
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The problem is not that AWS is expensive.&lt;/p&gt;

&lt;p&gt;The problem is:&lt;/p&gt;

&lt;p&gt;You often only understand your bill after you have already been charged.&lt;/p&gt;

&lt;p&gt;Even small changes in architecture can affect cost in non obvious ways.&lt;/p&gt;




&lt;h2&gt;
  
  
  DigitalOcean: simple, predictable, boring in a good way
&lt;/h2&gt;

&lt;p&gt;DigitalOcean takes a different approach:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;fixed monthly pricing for compute
&lt;/li&gt;
&lt;li&gt;clear pricing for databases
&lt;/li&gt;
&lt;li&gt;predictable bandwidth limits
&lt;/li&gt;
&lt;li&gt;simple storage pricing
&lt;/li&gt;
&lt;li&gt;no hidden service cross billing complexity
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You do not need to decode your bill.&lt;/p&gt;

&lt;p&gt;You already know what it will be.&lt;/p&gt;

&lt;p&gt;That predictability changes how you build.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why this matters more than people think
&lt;/h2&gt;

&lt;p&gt;At early stage SaaS, the biggest cost is not infrastructure.&lt;/p&gt;

&lt;p&gt;It is mental bandwidth.&lt;/p&gt;

&lt;p&gt;If you constantly need to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;explain your cloud bill
&lt;/li&gt;
&lt;li&gt;debug unexpected cost spikes
&lt;/li&gt;
&lt;li&gt;optimize infra before you have scale
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You are not building product.&lt;/p&gt;

&lt;p&gt;You are managing infrastructure uncertainty.&lt;/p&gt;




&lt;h2&gt;
  
  
  The simple rule we followed
&lt;/h2&gt;

&lt;p&gt;We asked ourselves:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Can we predict next month’s infrastructure cost within a reasonable range without analysis?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If the answer is no, complexity is too high for our stage.&lt;/p&gt;




&lt;h1&gt;
  
  
  Architecture Snapshot (What We Run on DigitalOcean)
&lt;/h1&gt;

&lt;p&gt;A simplified view of our setup:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rails application for API and web layer
&lt;/li&gt;
&lt;li&gt;Sidekiq workers for background processing
&lt;/li&gt;
&lt;li&gt;Redis for queues and caching
&lt;/li&gt;
&lt;li&gt;PostgreSQL as the primary datastore
&lt;/li&gt;
&lt;li&gt;Object storage for media assets
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This setup is intentionally simple.&lt;/p&gt;

&lt;p&gt;Not because we cannot handle complexity.&lt;/p&gt;

&lt;p&gt;But because we are optimizing for speed of iteration.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Real Lesson from Building RobinReach
&lt;/h1&gt;

&lt;p&gt;Infrastructure decisions are not about capability.&lt;/p&gt;

&lt;p&gt;They are about tradeoffs between:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;flexibility and simplicity
&lt;/li&gt;
&lt;li&gt;power and cognitive load
&lt;/li&gt;
&lt;li&gt;scalability and iteration speed
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And early-stage SaaS has one consistent truth:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The fastest team to iterate usually wins, not the one with the most complex infrastructure.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h1&gt;
  
  
  Final Thought
&lt;/h1&gt;

&lt;p&gt;AWS did not feel wrong.&lt;/p&gt;

&lt;p&gt;It just felt like solving problems we did not have yet.&lt;/p&gt;

&lt;p&gt;DigitalOcean did not feel impressive.&lt;/p&gt;

&lt;p&gt;It felt invisible.&lt;/p&gt;

&lt;p&gt;And in early-stage SaaS, invisible infrastructure is often exactly what you want.&lt;/p&gt;

&lt;p&gt;Because the less you think about infrastructure,&lt;/p&gt;

&lt;p&gt;the more you can think about building something people actually use.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>digitalocean</category>
      <category>rails</category>
      <category>devops</category>
    </item>
    <item>
      <title>Building a Production MCP Server in Ruby on Rails, Lessons from RobinReach</title>
      <dc:creator>Shaher Shamroukh</dc:creator>
      <pubDate>Thu, 30 Apr 2026 20:05:14 +0000</pubDate>
      <link>https://dev.to/shahershamroukh/building-a-production-mcp-server-in-ruby-on-rails-lessons-from-robinreach-4f4c</link>
      <guid>https://dev.to/shahershamroukh/building-a-production-mcp-server-in-ruby-on-rails-lessons-from-robinreach-4f4c</guid>
      <description>&lt;h1&gt;
  
  
  Building a Remote MCP Server in Ruby on Rails, A Production Guide
&lt;/h1&gt;

&lt;p&gt;Most MCP tutorials are Python or Node.js.&lt;/p&gt;

&lt;p&gt;This is the Rails version, built in production, serving real users, powering an AI agent inside a SaaS product.&lt;/p&gt;

&lt;p&gt;Here's the architecture, the key decisions, and the gotchas that cost us time.&lt;/p&gt;




&lt;h2&gt;
  
  
  What MCP Actually Is
&lt;/h2&gt;

&lt;p&gt;Model Context Protocol is a standard for connecting AI models to external tools and data sources.&lt;/p&gt;

&lt;p&gt;Before MCP, you'd give Claude a document and ask it questions. After MCP, Claude can call your API, read your database, take actions in your product, all from a conversation.&lt;/p&gt;

&lt;p&gt;The protocol is simple: JSON-RPC 2.0. Claude sends requests, your server responds. That's it.&lt;/p&gt;

&lt;p&gt;What makes it powerful is the standard — Claude knows how to discover, authenticate with, and call any MCP server that implements the spec correctly.&lt;/p&gt;




&lt;h2&gt;
  
  
  Local vs Remote, Why This Distinction Matters
&lt;/h2&gt;

&lt;p&gt;Most tutorials show &lt;strong&gt;local MCP servers&lt;/strong&gt; a process running on the user's machine, communicating via stdio.&lt;/p&gt;

&lt;p&gt;That works for developer tools. It doesn't work for SaaS.&lt;/p&gt;

&lt;p&gt;For a multi-tenant web application, you need a &lt;strong&gt;remote MCP server&lt;/strong&gt; an HTTP endpoint that authenticates each user and serves their specific data.&lt;/p&gt;

&lt;p&gt;This changes everything:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Local (stdio)&lt;/th&gt;
&lt;th&gt;Remote (HTTP)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Transport&lt;/td&gt;
&lt;td&gt;stdin/stdout&lt;/td&gt;
&lt;td&gt;HTTP + SSE&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Auth&lt;/td&gt;
&lt;td&gt;None needed&lt;/td&gt;
&lt;td&gt;OAuth 2.0 required&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Multi-user&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Deployment&lt;/td&gt;
&lt;td&gt;User's machine&lt;/td&gt;
&lt;td&gt;Your server&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Use case&lt;/td&gt;
&lt;td&gt;Dev tools, CLIs&lt;/td&gt;
&lt;td&gt;SaaS products&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Rails is perfect for remote MCP. It's already an HTTP server. It already has auth. You're just adding a new endpoint.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Architecture
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Claude (client)
      ↓  JSON-RPC 2.0 over HTTPS
POST /mcp/v1/messages
      ↓
ApplicationController (auth + plan gating)
      ↓
MCP Tool Handler
      ↓
Your existing Rails services
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No new infrastructure. No separate process. No Node.js. Just a new controller that speaks JSON-RPC.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 1 — The Routes
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# config/routes.rb&lt;/span&gt;
&lt;span class="c1"&gt;# These must be at root level — outside any scope or namespace&lt;/span&gt;

&lt;span class="c1"&gt;# OAuth Discovery — Claude hits these before anything else&lt;/span&gt;
&lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s2"&gt;"/.well-known/oauth-protected-resource"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="ss"&gt;to: &lt;/span&gt;&lt;span class="s2"&gt;"mcp/oauth#protected_resource"&lt;/span&gt;
&lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s2"&gt;"/.well-known/oauth-authorization-server"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;to: &lt;/span&gt;&lt;span class="s2"&gt;"mcp/oauth#authorization_server"&lt;/span&gt;

&lt;span class="c1"&gt;# OAuth Flow&lt;/span&gt;
&lt;span class="n"&gt;scope&lt;/span&gt; &lt;span class="s2"&gt;"/mcp/oauth"&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="s2"&gt;"register"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="ss"&gt;to: &lt;/span&gt;&lt;span class="s2"&gt;"mcp/oauth#register"&lt;/span&gt;
  &lt;span class="n"&gt;get&lt;/span&gt;  &lt;span class="s2"&gt;"authorize"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;to: &lt;/span&gt;&lt;span class="s2"&gt;"mcp/oauth#authorize"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;as: :mcp_oauth_authorize&lt;/span&gt;
  &lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="s2"&gt;"token"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;     &lt;span class="ss"&gt;to: &lt;/span&gt;&lt;span class="s2"&gt;"mcp/oauth#token"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;     &lt;span class="ss"&gt;as: :mcp_oauth_token&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="c1"&gt;# MCP Endpoint&lt;/span&gt;
&lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="s2"&gt;"mcp/v1/messages"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;to: &lt;/span&gt;&lt;span class="s2"&gt;"mcp/v1/messages#create"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;defaults: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;format: :json&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Critical:&lt;/strong&gt; The &lt;code&gt;.well-known&lt;/code&gt; routes must exist before you test anything with Claude.ai. When a user adds your integration, Claude hits these discovery endpoints first. Without them the connection silently fails and you'll spend a day wondering why.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 2 — Authentication
&lt;/h2&gt;

&lt;p&gt;For a SaaS product, you likely already have API keys. Use them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# app/controllers/mcp/v1/base_controller.rb&lt;/span&gt;
&lt;span class="k"&gt;module&lt;/span&gt; &lt;span class="nn"&gt;Mcp&lt;/span&gt;
  &lt;span class="k"&gt;module&lt;/span&gt; &lt;span class="nn"&gt;V1&lt;/span&gt;
    &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BaseController&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ActionController&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;API&lt;/span&gt;
      &lt;span class="n"&gt;before_action&lt;/span&gt; &lt;span class="ss"&gt;:authenticate!&lt;/span&gt;

      &lt;span class="kp"&gt;private&lt;/span&gt;

      &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;authenticate!&lt;/span&gt;
        &lt;span class="c1"&gt;# Accept token from header or query param&lt;/span&gt;
        &lt;span class="n"&gt;token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"Authorization"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                       &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_s&lt;/span&gt;
                       &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;delete_prefix&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Bearer "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                       &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;
        &lt;span class="n"&gt;token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:api_key&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;to_s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;blank?&lt;/span&gt;

        &lt;span class="vi"&gt;@api_key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;ApiKey&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find_by&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;key: &lt;/span&gt;&lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;unless&lt;/span&gt; &lt;span class="vi"&gt;@api_key&lt;/span&gt;
          &lt;span class="n"&gt;render&lt;/span&gt; &lt;span class="ss"&gt;json: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="ss"&gt;jsonrpc: &lt;/span&gt;&lt;span class="s2"&gt;"2.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="ss"&gt;error: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;code: &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;32_600&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;message: &lt;/span&gt;&lt;span class="s2"&gt;"Unauthorized"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
          &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="ss"&gt;status: :unauthorized&lt;/span&gt;
        &lt;span class="k"&gt;end&lt;/span&gt;

        &lt;span class="vi"&gt;@api_key&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;touch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:last_used_at&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="vi"&gt;@current_company&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="vi"&gt;@api_key&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;company&lt;/span&gt;
      &lt;span class="k"&gt;end&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice: we accept the token from both the &lt;code&gt;Authorization&lt;/code&gt; header and a query param. This matters because some MCP clients pass it differently, and it lets users connect via a simple URL with &lt;code&gt;?api_key=xxx&lt;/code&gt; during development.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 3 — The JSON-RPC Handler
&lt;/h2&gt;

&lt;p&gt;MCP uses JSON-RPC 2.0. Every request has a &lt;code&gt;method&lt;/code&gt;, optional &lt;code&gt;params&lt;/code&gt;, and an &lt;code&gt;id&lt;/code&gt;. Your response always includes the same &lt;code&gt;id&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# app/controllers/mcp/v1/messages_controller.rb&lt;/span&gt;
&lt;span class="k"&gt;module&lt;/span&gt; &lt;span class="nn"&gt;Mcp&lt;/span&gt;
  &lt;span class="k"&gt;module&lt;/span&gt; &lt;span class="nn"&gt;V1&lt;/span&gt;
    &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MessagesController&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;BaseController&lt;/span&gt;
      &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create&lt;/span&gt;
        &lt;span class="n"&gt;body&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;raw_post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nb"&gt;method&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"method"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="n"&gt;params&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"params"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
        &lt;span class="nb"&gt;id&lt;/span&gt;     &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

        &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;method&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;head&lt;/span&gt; &lt;span class="ss"&gt;:no_content&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="ss"&gt;:notification&lt;/span&gt;

        &lt;span class="n"&gt;render&lt;/span&gt; &lt;span class="ss"&gt;json: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;jsonrpc: &lt;/span&gt;&lt;span class="s2"&gt;"2.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;id: &lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;result: &lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

      &lt;span class="k"&gt;rescue&lt;/span&gt; &lt;span class="no"&gt;JSON&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;ParserError&lt;/span&gt;
        &lt;span class="n"&gt;render&lt;/span&gt; &lt;span class="ss"&gt;json: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;jsonrpc: &lt;/span&gt;&lt;span class="s2"&gt;"2.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;error: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;code: &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;32_700&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;message: &lt;/span&gt;&lt;span class="s2"&gt;"Parse error"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
               &lt;span class="ss"&gt;status: :bad_request&lt;/span&gt;
      &lt;span class="k"&gt;rescue&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;
        &lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"[MCP] &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;class&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;message&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;backtrace&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;first&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;render&lt;/span&gt; &lt;span class="ss"&gt;json: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;jsonrpc: &lt;/span&gt;&lt;span class="s2"&gt;"2.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;id: &lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;error: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;code: &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;32_603&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;message: &lt;/span&gt;&lt;span class="s2"&gt;"Internal error"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="k"&gt;end&lt;/span&gt;

      &lt;span class="kp"&gt;private&lt;/span&gt;

      &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;method&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nb"&gt;method&lt;/span&gt;
        &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="s2"&gt;"initialize"&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="ss"&gt;protocolVersion: &lt;/span&gt;&lt;span class="s2"&gt;"2024-11-05"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="ss"&gt;serverInfo: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;name: &lt;/span&gt;&lt;span class="s2"&gt;"your-app"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;version: &lt;/span&gt;&lt;span class="s2"&gt;"1.0.0"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="ss"&gt;capabilities: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;tools: &lt;/span&gt;&lt;span class="p"&gt;{}&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="ss"&gt;instructions: &lt;/span&gt;&lt;span class="n"&gt;system_prompt&lt;/span&gt;  &lt;span class="c1"&gt;# injected into Claude's context&lt;/span&gt;
          &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="s2"&gt;"tools/list"&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;tools: &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="no"&gt;YourMcpTool&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="s2"&gt;"tools/call"&lt;/span&gt;
          &lt;span class="n"&gt;call_tool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="sr"&gt;/\Anotifications\//&lt;/span&gt;
          &lt;span class="ss"&gt;:notification&lt;/span&gt;  &lt;span class="c1"&gt;# no response needed&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;
          &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="s2"&gt;"Method not found: &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="nb"&gt;method&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
        &lt;span class="k"&gt;end&lt;/span&gt;
      &lt;span class="k"&gt;end&lt;/span&gt;

      &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;call_tool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nb"&gt;name&lt;/span&gt;      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="n"&gt;arguments&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"arguments"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

        &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;YourMcpTool&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="vi"&gt;@current_company&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;content: &lt;/span&gt;&lt;span class="p"&gt;[{&lt;/span&gt; &lt;span class="ss"&gt;type: &lt;/span&gt;&lt;span class="s2"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;text: &lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_json&lt;/span&gt; &lt;span class="p"&gt;}]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="k"&gt;rescue&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="ss"&gt;content: &lt;/span&gt;&lt;span class="p"&gt;[{&lt;/span&gt; &lt;span class="ss"&gt;type: &lt;/span&gt;&lt;span class="s2"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;text: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;error: &lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;message&lt;/span&gt; &lt;span class="p"&gt;}.&lt;/span&gt;&lt;span class="nf"&gt;to_json&lt;/span&gt; &lt;span class="p"&gt;}],&lt;/span&gt;
          &lt;span class="ss"&gt;isError: &lt;/span&gt;&lt;span class="kp"&gt;true&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="k"&gt;end&lt;/span&gt;

      &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;system_prompt&lt;/span&gt;
        &lt;span class="c1"&gt;# This is injected into Claude's context at connect time.&lt;/span&gt;
        &lt;span class="c1"&gt;# Use it to tell Claude how to behave, what order to call things,&lt;/span&gt;
        &lt;span class="c1"&gt;# and any domain-specific rules your application has.&lt;/span&gt;
        &lt;span class="c1"&gt;# Keep it focused — Claude reads this on every connection.&lt;/span&gt;
        &lt;span class="no"&gt;YOUR_SYSTEM_PROMPT&lt;/span&gt;
      &lt;span class="k"&gt;end&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key point:&lt;/strong&gt; Errors from tool calls should return &lt;code&gt;isError: true&lt;/code&gt; with a message in the content, not an HTTP error status. Claude reads the response body, not the HTTP status code. A descriptive error message in JSON is far more useful than a 500 with no body.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 4 — The Tool Design Decision
&lt;/h2&gt;

&lt;p&gt;This is the most important architectural decision you'll make.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Option A — Many small tools:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;list_posts, create_post, delete_post,
get_analytics, search_media, generate_image...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Option B — One tool, many actions:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;your_app (action: "list_posts" | "create_post" | ...)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We went with Option B. Here's why.&lt;/p&gt;

&lt;p&gt;With many tools, Claude has to pick the right tool before starting. With one tool and an &lt;code&gt;action&lt;/code&gt; parameter, Claude can reason about what to do mid-conversation without switching tools.&lt;/p&gt;

&lt;p&gt;It also makes the integration cleaner from the user's perspective — they see one integration in their Claude settings, not a wall of tools.&lt;/p&gt;

&lt;p&gt;The schema looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nc"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;schema&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="ss"&gt;name: &lt;/span&gt;&lt;span class="s2"&gt;"your_app"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="ss"&gt;description: &lt;/span&gt;&lt;span class="s2"&gt;"Brief description of what this tool does and when to use it."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="ss"&gt;inputSchema: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="ss"&gt;type: &lt;/span&gt;&lt;span class="s2"&gt;"object"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="ss"&gt;properties: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="ss"&gt;action: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="ss"&gt;type: &lt;/span&gt;&lt;span class="s2"&gt;"string"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="ss"&gt;enum: &lt;/span&gt;&lt;span class="no"&gt;ACTIONS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="c1"&gt;# your list of supported actions&lt;/span&gt;
          &lt;span class="ss"&gt;description: &lt;/span&gt;&lt;span class="s2"&gt;"The action to perform"&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="c1"&gt;# ... your other parameters&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="ss"&gt;required: &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"action"&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="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 5 — OAuth Discovery
&lt;/h2&gt;

&lt;p&gt;For Claude.ai's "Connect" button to work, you need to implement OAuth discovery.&lt;/p&gt;

&lt;p&gt;The good news: you don't need a full OAuth server. You can use OAuth as a thin wrapper around your existing API keys.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# app/controllers/mcp/oauth_controller.rb&lt;/span&gt;
&lt;span class="k"&gt;module&lt;/span&gt; &lt;span class="nn"&gt;Mcp&lt;/span&gt;
  &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;OauthController&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ActionController&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;API&lt;/span&gt;

    &lt;span class="c1"&gt;# Tells Claude where your MCP server is&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;protected_resource&lt;/span&gt;
      &lt;span class="n"&gt;render&lt;/span&gt; &lt;span class="ss"&gt;json: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="ss"&gt;resource: &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;base_url&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/mcp/v1/messages"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="ss"&gt;authorization_servers: &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;base_url&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="ss"&gt;bearer_methods_supported: &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"header"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"query"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;

    &lt;span class="c1"&gt;# Tells Claude how to authenticate&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;authorization_server&lt;/span&gt;
      &lt;span class="n"&gt;render&lt;/span&gt; &lt;span class="ss"&gt;json: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="ss"&gt;issuer: &lt;/span&gt;&lt;span class="n"&gt;base_url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="ss"&gt;authorization_endpoint: &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;base_url&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/mcp/oauth/authorize"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="ss"&gt;token_endpoint: &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;base_url&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/mcp/oauth/token"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="ss"&gt;registration_endpoint: &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;base_url&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/mcp/oauth/register"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="ss"&gt;response_types_supported: &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"code"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="ss"&gt;grant_types_supported: &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"authorization_code"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="ss"&gt;code_challenge_methods_supported: &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"S256"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="ss"&gt;token_endpoint_auth_methods_supported: &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"none"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="ss"&gt;scopes_supported: &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"mcp"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;

    &lt;span class="c1"&gt;# Claude registers itself as a client&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;register&lt;/span&gt;
      &lt;span class="n"&gt;render&lt;/span&gt; &lt;span class="ss"&gt;json: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="ss"&gt;client_id:                    &lt;/span&gt;&lt;span class="s2"&gt;"claude_&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="no"&gt;SecureRandom&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="ss"&gt;client_secret:                &lt;/span&gt;&lt;span class="kp"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="ss"&gt;grant_types:                  &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"authorization_code"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="ss"&gt;token_endpoint_auth_method:   &lt;/span&gt;&lt;span class="s2"&gt;"none"&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="ss"&gt;status: :created&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;

    &lt;span class="c1"&gt;# User sees this page and approves the connection&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;authorize&lt;/span&gt;
      &lt;span class="c1"&gt;# Require the user to be logged in&lt;/span&gt;
      &lt;span class="k"&gt;unless&lt;/span&gt; &lt;span class="n"&gt;current_user_from_session&lt;/span&gt;
        &lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:oauth_return_to&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fullpath&lt;/span&gt;
        &lt;span class="n"&gt;redirect_to&lt;/span&gt; &lt;span class="n"&gt;login_path&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;
      &lt;span class="k"&gt;end&lt;/span&gt;

      &lt;span class="c1"&gt;# Generate short-lived authorization code&lt;/span&gt;
      &lt;span class="n"&gt;code&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;SecureRandom&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;32&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="no"&gt;REDIS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="s2"&gt;"mcp:oauth:code:&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;minutes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;current_user_from_session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;api_key&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;key&lt;/span&gt;
      &lt;span class="p"&gt;)&lt;/span&gt;

      &lt;span class="c1"&gt;# Redirect back to Claude with the code&lt;/span&gt;
      &lt;span class="n"&gt;redirect_to&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:redirect_uri&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;?code=&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;amp;state=&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:state&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                  &lt;span class="ss"&gt;allow_other_host: &lt;/span&gt;&lt;span class="kp"&gt;true&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;

    &lt;span class="c1"&gt;# Claude exchanges code for an access token&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;token&lt;/span&gt;
      &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;REDIS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"mcp:oauth:code:&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:code&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

      &lt;span class="k"&gt;unless&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;
        &lt;span class="n"&gt;render&lt;/span&gt; &lt;span class="ss"&gt;json: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;error: &lt;/span&gt;&lt;span class="s2"&gt;"invalid_grant"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="ss"&gt;status: :bad_request&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;
      &lt;span class="k"&gt;end&lt;/span&gt;

      &lt;span class="no"&gt;REDIS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;del&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"mcp:oauth:code:&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:code&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# single use&lt;/span&gt;

      &lt;span class="n"&gt;render&lt;/span&gt; &lt;span class="ss"&gt;json: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="ss"&gt;access_token: &lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="c1"&gt;# your existing API key becomes the token&lt;/span&gt;
        &lt;span class="ss"&gt;token_type:   &lt;/span&gt;&lt;span class="s2"&gt;"Bearer"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="ss"&gt;scope:        &lt;/span&gt;&lt;span class="s2"&gt;"mcp"&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;

    &lt;span class="kp"&gt;private&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;base_url&lt;/span&gt;
      &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;protocol&lt;/span&gt;&lt;span class="si"&gt;}#{&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;host_with_port&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;current_user_from_session&lt;/span&gt;
      &lt;span class="c1"&gt;# Hook into your existing session auth&lt;/span&gt;
      &lt;span class="c1"&gt;# For Devise: User.find_by(id: session["warden.user.user.key"]&amp;amp;.first&amp;amp;.first)&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The key insight: &lt;strong&gt;your existing API key becomes the OAuth access token.&lt;/strong&gt; You don't need a new token system. OAuth is just a wrapper around what you already have. The code is a short-lived Redis key that maps to the real API key. Claude exchanges it once, gets the API key, and uses it as a Bearer token forever after.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 6 — The System Prompt
&lt;/h2&gt;

&lt;p&gt;This is the part nobody writes about. The &lt;code&gt;instructions&lt;/code&gt; field in your &lt;code&gt;initialize&lt;/code&gt; response gets injected into Claude's context on every connection.&lt;/p&gt;

&lt;p&gt;Use it to teach Claude:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to behave in your domain&lt;/li&gt;
&lt;li&gt;What order to call actions in&lt;/li&gt;
&lt;li&gt;Rules specific to your application&lt;/li&gt;
&lt;li&gt;How to talk to users&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A few principles we learned:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tell Claude what to do first.&lt;/strong&gt; "Always call &lt;code&gt;get_account_status&lt;/code&gt; before anything else" — Claude follows this reliably.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Encode your validation rules.&lt;/strong&gt; If certain actions must happen before others, put it in the system prompt. "Always validate before creating. Never skip this step."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Make it dynamic.&lt;/strong&gt; We append user-specific context — their preferred language, brand tone, timezone — at connect time. Claude immediately writes in the right voice without the user having to explain anything.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keep it focused.&lt;/strong&gt; The system prompt should be under 500 words. Long prompts dilute Claude's attention. Every sentence should earn its place.&lt;/p&gt;




&lt;h2&gt;
  
  
  Testing
&lt;/h2&gt;

&lt;p&gt;Test with curl before testing with Claude. If curl works, Claude will work.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;BASE_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"https://yourapp.com"&lt;/span&gt;
&lt;span class="nv"&gt;API_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"your_api_key"&lt;/span&gt;

&lt;span class="c"&gt;# 1. Test the MCP handshake&lt;/span&gt;
curl &lt;span class="nt"&gt;-s&lt;/span&gt; &lt;span class="nt"&gt;-X&lt;/span&gt; POST &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$BASE_URL&lt;/span&gt;&lt;span class="s2"&gt;/mcp/v1/messages"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Authorization: Bearer &lt;/span&gt;&lt;span class="nv"&gt;$API_KEY&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;'{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}'&lt;/span&gt; | jq &lt;span class="nb"&gt;.&lt;/span&gt;

&lt;span class="c"&gt;# 2. List your tools&lt;/span&gt;
curl &lt;span class="nt"&gt;-s&lt;/span&gt; &lt;span class="nt"&gt;-X&lt;/span&gt; POST &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$BASE_URL&lt;/span&gt;&lt;span class="s2"&gt;/mcp/v1/messages"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Authorization: Bearer &lt;/span&gt;&lt;span class="nv"&gt;$API_KEY&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;'{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}'&lt;/span&gt; | jq &lt;span class="nb"&gt;.&lt;/span&gt;

&lt;span class="c"&gt;# 3. Call a tool&lt;/span&gt;
curl &lt;span class="nt"&gt;-s&lt;/span&gt; &lt;span class="nt"&gt;-X&lt;/span&gt; POST &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$BASE_URL&lt;/span&gt;&lt;span class="s2"&gt;/mcp/v1/messages"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Authorization: Bearer &lt;/span&gt;&lt;span class="nv"&gt;$API_KEY&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;'{
    "jsonrpc": "2.0",
    "id": 3,
    "method": "tools/call",
    "params": {
      "name": "your_app",
      "arguments": { "action": "get_account_status" }
    }
  }'&lt;/span&gt; | jq &lt;span class="nb"&gt;.&lt;/span&gt;

&lt;span class="c"&gt;# 4. Test OAuth discovery&lt;/span&gt;
curl &lt;span class="nt"&gt;-s&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$BASE_URL&lt;/span&gt;&lt;span class="s2"&gt;/.well-known/oauth-protected-resource"&lt;/span&gt; | jq &lt;span class="nb"&gt;.&lt;/span&gt;
curl &lt;span class="nt"&gt;-s&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$BASE_URL&lt;/span&gt;&lt;span class="s2"&gt;/.well-known/oauth-authorization-server"&lt;/span&gt; | jq &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run these in order. Each one confirms a layer of the stack is working before you move to the next.&lt;/p&gt;




&lt;h2&gt;
  
  
  Lessons Learned
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The &lt;code&gt;.well-known&lt;/code&gt; routes are not optional.&lt;/strong&gt;&lt;br&gt;
This cost us a full day. Add them first. Test them before anything else.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Errors belong in the response body, not HTTP status codes.&lt;/strong&gt;&lt;br&gt;
Claude reads JSON. Return &lt;code&gt;{ error: "descriptive message" }&lt;/code&gt; with &lt;code&gt;isError: true&lt;/code&gt;. A 500 with no body tells Claude nothing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The system prompt matters more than the tool schema.&lt;/strong&gt;&lt;br&gt;
We spent too long on the schema and not enough on the prompt. Claude's behavior improved more from prompt changes than from schema changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Redis for lightweight state.&lt;/strong&gt;&lt;br&gt;
User preferences, session data, short-lived codes — Redis handles all of it without schema migrations. Fast, simple, already in your stack.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sequential over parallel.&lt;/strong&gt;&lt;br&gt;
We considered letting Claude batch multiple actions. Don't. Claude reasons better when it processes one response before deciding what to do next.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test from the user's perspective weekly.&lt;/strong&gt;&lt;br&gt;
Connect to your own MCP server as a real user and have a real conversation. You'll find issues that unit tests miss — awkward response formats, actions that don't chain well, edge cases in your tool schema.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Result
&lt;/h2&gt;

&lt;p&gt;A production MCP server in Rails that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Authenticates via existing API keys&lt;/li&gt;
&lt;li&gt;Supports OAuth discovery for one-click connection in Claude.ai&lt;/li&gt;
&lt;li&gt;Serves multiple tenants from a single endpoint&lt;/li&gt;
&lt;li&gt;Reuses all existing Rails services&lt;/li&gt;
&lt;li&gt;Deploys exactly like any other Rails endpoint&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;No new infrastructure. No Node.js. No separate process.&lt;/p&gt;

&lt;p&gt;Just Rails doing what Rails does.&lt;/p&gt;




&lt;h2&gt;
  
  
  Try It
&lt;/h2&gt;

&lt;p&gt;We built this for RobinReach, a social media management platform where users manage their entire social presence through a conversation with Robin, our AI manager.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://robinreach.com" rel="noopener noreferrer"&gt;&lt;strong&gt;robinreach.com&lt;/strong&gt;&lt;/a&gt; → Settings → Connect Claude&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Questions? Drop a comment. Happy to go deeper on any part of this.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>rails</category>
      <category>mcp</category>
      <category>claude</category>
    </item>
    <item>
      <title>AI Can Write Code But It Still Can’t Think Like a Developer</title>
      <dc:creator>Shaher Shamroukh</dc:creator>
      <pubDate>Wed, 07 Jan 2026 17:32:16 +0000</pubDate>
      <link>https://dev.to/shahershamroukh/ai-can-write-code-but-it-still-cant-think-like-a-developer-18pb</link>
      <guid>https://dev.to/shahershamroukh/ai-can-write-code-but-it-still-cant-think-like-a-developer-18pb</guid>
      <description>&lt;p&gt;Everyone is talking about AI replacing developers. Some say junior devs won’t even find jobs in 2026. As someone running a dev team at RobinReach, I think this is overblown and here’s why.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Writing Code Is Not the Same as Solving Problems&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A lot of people think coding is just typing lines of code or building a simple website. Real software development is way more than that. You have to understand what a feature should actually do, how it should behave in tricky situations, track down bugs and find the root cause, design a system that is scalable and maintainable, and make decisions about trade-offs between speed, performance, security, and user experience.&lt;/p&gt;

&lt;p&gt;And when it comes to full web apps, it gets even more complex. You are not just writing HTML or CSS. You have databases, backend logic, routing, state management, APIs, integrations, and frontend frameworks. AI cannot grasp the full system in context or reason about how all the pieces interact.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Static Websites Versus Full Web Apps&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is where people get confused. A static website is something simple, like a landing page or portfolio. You can set up a WordPress site or a Wix page in a couple of hours without any AI. It’s straightforward and there is nothing revolutionary about AI doing the same thing a little faster.&lt;/p&gt;

&lt;p&gt;Full web apps are a different story. They have databases, backend logic, authentication, APIs, dynamic routing, state management, error handling, and scaling. Building and maintaining these apps requires problem-solving, debugging, and architectural thinking. AI is not ready to do that.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What Research Says&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A recent MIT CSAIL study reported by IBM Think confirms this. It says that AI can churn out code but cannot think like a software engineer. AI struggles with planning long-term code, understanding an entire codebase, and handling legacy systems or specialized libraries.&lt;/p&gt;

&lt;p&gt;Even the best AI does not remember previous prompts or understand how a project evolves over time. AI can write code but it cannot replace the reasoning, problem-solving, and judgment that real developers provide.&lt;/p&gt;

&lt;p&gt;You can read the full article here: &lt;a href="https://www.ibm.com/think/news/ai-write-code-can-beat-software-engineers" rel="noopener noreferrer"&gt;IBM Think – AI can write code, but can it beat software engineers?&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;My Experience at &lt;a href="https://robinreach.com/" rel="noopener noreferrer"&gt;RobinReach&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Even with AI tools, my junior developer drives the AI, not the other way around. They review suggestions, debug issues, validate fixes, and make architectural decisions. AI speeds up repetitive work but the thinking, problem-solving, and judgment are still fully human.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Future of Development&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The future is not AI replacing developers. It is humans working with AI. Developers who learn to use AI effectively will be faster and more productive. But understanding systems, reasoning through problems, and building robust software will always be human work.&lt;/p&gt;

&lt;p&gt;Are we overestimating AI, or is the future really about developers guiding AI to solve real software problems?&lt;/p&gt;

</description>
      <category>coding</category>
      <category>ai</category>
      <category>softwareengineering</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Managing Multiple Brands in Rails: Multi-Tenant Patterns from RobinReach</title>
      <dc:creator>Shaher Shamroukh</dc:creator>
      <pubDate>Mon, 22 Dec 2025 20:47:02 +0000</pubDate>
      <link>https://dev.to/shahershamroukh/managing-multiple-brands-in-rails-multi-tenant-patterns-from-robinreach-10ln</link>
      <guid>https://dev.to/shahershamroukh/managing-multiple-brands-in-rails-multi-tenant-patterns-from-robinreach-10ln</guid>
      <description>&lt;p&gt;Scaling a SaaS application is one thing; letting a single user manage multiple brands, each with its own isolated data, is another. &lt;br&gt;
At &lt;strong&gt;RobinReach&lt;/strong&gt;, we faced this challenge head-on: users needed to handle multiple workspaces, each with its own social profiles, posts, and team members, all while switching seamlessly between them. &lt;br&gt;
Here’s how we built it in Rails, and the lessons learned along the way.&lt;/p&gt;

&lt;p&gt;The Challenge: &lt;strong&gt;Multi-Brand Management&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Imagine a user managing three different companies on your platform. Each company has:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Its own social media profiles&lt;/li&gt;
&lt;li&gt;Scheduled posts&lt;/li&gt;
&lt;li&gt;Team members and roles&lt;/li&gt;
&lt;li&gt;Analytics and performance data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Without proper isolation, cross-tenant data leaks become a nightmare. &lt;br&gt;
Multi-tenancy is not just a database pattern, it’s a mindset for every layer of your application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Workspace-Based Multi-Tenancy&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At &lt;strong&gt;RobinReach&lt;/strong&gt;, we modeled each brand or workspace as a tenant. All core models—Posts, SocialProfiles, Members, are scoped to a tenant. We use a thread-safe Current object to hold the tenant context:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;class Current &amp;lt; ActiveSupport::CurrentAttributes&lt;br&gt;
  attribute :company&lt;br&gt;
end&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This allows all models to reference the current tenant easily:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;class Post &amp;lt; ApplicationRecord&lt;br&gt;
  belongs_to :company&lt;br&gt;
  default_scope { where(company_id: Current.company.id) }&lt;br&gt;
end&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
With this pattern, every query automatically respects tenant boundaries.&lt;/p&gt;

&lt;p&gt;Seamless Workspace Switching&lt;/p&gt;

&lt;p&gt;Users expect to switch between workspaces without logging out. We store the current workspace in the session:&lt;br&gt;
&lt;code&gt;def switch_workspace(company_id)&lt;br&gt;
  session[:current_company_id] = company_id&lt;br&gt;
  Current.company = Company.find(company_id)&lt;br&gt;
end&lt;/code&gt;&lt;br&gt;
This ensures that every action like viewing posts, scheduling content, or managing members, is scoped correctly to the selected workspace.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Background Jobs in a Multi-Tenant Environment&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Multi-tenancy isn’t just about database queries; background jobs must also respect tenant boundaries. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lessons Learned:&lt;/strong&gt;&lt;br&gt;
Always pass the tenant ID to background jobs.&lt;/p&gt;

&lt;p&gt;Make jobs idempotent to prevent cross-tenant side effects.&lt;/p&gt;

&lt;p&gt;Use Sidekiq queues strategically; high-volume tenants might need separate queues.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Best Practices for Workspace Multi-Tenancy&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enforce tenant isolation at all layers – models, services, jobs, and controllers.&lt;/li&gt;
&lt;li&gt;Use thread-safe context objects (Current) for tenant information.&lt;/li&gt;
&lt;li&gt;Design for fast workspace switching in the UI.&lt;/li&gt;
&lt;li&gt;Keep background jobs idempotent and tenant-aware.&lt;/li&gt;
&lt;li&gt;Cache per tenant when appropriate to reduce database load.&lt;/li&gt;
&lt;li&gt;Monitor performance per workspace to detect heavy tenants early.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Building a multi-brand SaaS in Rails isn’t just a technical challenge, it’s a design mindset.&lt;br&gt;
RobinReach demonstrates that with careful scoping, background job design, and workspace isolation, you can deliver a seamless multi-tenant experience.&lt;/p&gt;

&lt;p&gt;For Rails developers building SaaS platforms, these patterns can save you from future headaches and set your app up for scale.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>rails</category>
      <category>saas</category>
    </item>
    <item>
      <title>Building an AI Social Media Manager with Ruby on Rails: Architecture, Automation, and Lessons Learned</title>
      <dc:creator>Shaher Shamroukh</dc:creator>
      <pubDate>Thu, 23 Oct 2025 19:56:33 +0000</pubDate>
      <link>https://dev.to/shahershamroukh/building-an-ai-social-media-manager-with-ruby-on-rails-architecture-automation-and-lessons-3lpj</link>
      <guid>https://dev.to/shahershamroukh/building-an-ai-social-media-manager-with-ruby-on-rails-architecture-automation-and-lessons-3lpj</guid>
      <description>&lt;p&gt;Building an AI Social Media Manager with Ruby on Rails: Architecture, Automation, and Lessons Learned&lt;/p&gt;

&lt;p&gt;In a previous post, &lt;a href="https://dev.to/shahershamroukh/how-were-building-a-social-media-empire-with-rails-and-sidekiq-5p0"&gt;How We’re Building a Social Media Empire with Rails and Sidekiq&lt;/a&gt;, &lt;br&gt;
I shared how we scaled background jobs and task automation using Rails and Sidekiq. That article focused on how &lt;a href="https://robinreach.com/" rel="noopener noreferrer"&gt;RobinReach&lt;/a&gt;&lt;br&gt;
Our social media management platform handled large-scale post scheduling and media processing.&lt;/p&gt;

&lt;p&gt;This time, we’re taking a deeper dive into how we integrated AI into our architecture and how Ruby on Rails continues to be the backbone of everything we build.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Rails Still Works for AI SaaS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Even in 2025, Ruby on Rails remains a perfect fit for startups building fast, scalable, and flexible SaaS products. When we started building RobinReach, we needed to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Move fast with a clean architecture.&lt;/li&gt;
&lt;li&gt;Handle complex background automation.&lt;/li&gt;
&lt;li&gt;Support multi-tenant data isolation for agencies.&lt;/li&gt;
&lt;li&gt;Integrate AI models that evolve quickly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Rails gave us that foundation. With Hotwire and Tailwind CSS, we kept the frontend lean and responsive, no heavy SPAs needed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Our Service-Driven Architecture&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One of our early decisions was to adopt a service-driven architecture. Every core component from AI post generation to video rendering lives inside a dedicated service class.&lt;/p&gt;

&lt;p&gt;That means each domain (posts, media, analytics, automation) can evolve independently while staying testable and predictable.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Ai::ContentGeneratorService
 def initialize(post)
  @post = post
 end

 def call
  prompt = "Create a social media caption about #{@post.topic} in an engaging tone."
  response = RubyLLM::Client.new(model: "gpt-4o-    mini").complete(prompt)
 @post.update!(caption: response.text)
 end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By keeping logic inside services, we avoid bloated models and controllers, and it makes it easy to reuse across background jobs.&lt;/p&gt;

&lt;p&gt;Using AI for Content Refinement&lt;/p&gt;

&lt;p&gt;We started with the ruby-openai gem, but later switched to ruby-llm for its flexibility and broader model support.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Our AI layer powers features like:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;RobinGen → generates captions, hashtags, and text variations.&lt;/li&gt;
&lt;li&gt;RobinPilot → automates post creation from articles or ideas.&lt;/li&gt;
&lt;li&gt;Content refinement → rewrites existing drafts to fit platform tone (LinkedIn, Instagram, etc.).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The workflow is simple:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User drafts or uploads content.&lt;/li&gt;
&lt;li&gt;AI refines tone, grammar, or platform style.&lt;/li&gt;
&lt;li&gt;User reviews and approves before scheduling.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We use background jobs to handle API calls asynchronously, ensuring the dashboard stays responsive while posts are being “AI-polished.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Media Handling with MiniMagick and FFmpeg&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For visuals, we rely on MiniMagick for image resizing and Streamio-FFmpeg for short-form video generation. These two tools help us dynamically create social media content that looks like it was edited manually.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Multi-Tenant Design for Agencies and Brands&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;RobinReach was designed for both businesses and marketing agencies. Each company account can manage multiple brands, each brand having its own users, social profiles, posts, and analytics.&lt;/p&gt;

&lt;p&gt;We use a company context service to isolate data automatically:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Every query is scoped by company.&lt;/li&gt;
&lt;li&gt;Each background job inherits that context.&lt;/li&gt;
&lt;li&gt;Admins can switch between brands instantly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This approach ensures data security and scalability without introducing unnecessary complexity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lessons Learned Building RobinReach&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AI integration works best when it’s optional and assistive, not intrusive.&lt;/li&gt;
&lt;li&gt;Service objects keep Rails clean and maintainable as complexity grows.&lt;/li&gt;
&lt;li&gt;Multi-tenancy needs clear boundaries early, retrofitting it later is painful.&lt;/li&gt;
&lt;li&gt;Rails still excels when paired with modern, lightweight tools like Hotwire and Tailwind.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Closing Thoughts&lt;/p&gt;

&lt;p&gt;Building RobinReach has been a continuous learning process. We’ve learned that Rails is still one of the best frameworks for quickly turning complex ideas, like AI-driven automation, into production-ready features.&lt;/p&gt;

&lt;p&gt;Our next steps include making RobinReach’s AI even smarter, from better content understanding to predicting the best times to post.&lt;/p&gt;

&lt;p&gt;If you’d like to follow our journey or see how AI can simplify your social media workflow, you can check out RobinReach at &lt;a href="https://robinreach.com/en" rel="noopener noreferrer"&gt;https://robinreach.com/en&lt;/a&gt;&lt;br&gt;
.&lt;/p&gt;

</description>
      <category>rails</category>
      <category>ruby</category>
      <category>architecture</category>
      <category>ai</category>
    </item>
    <item>
      <title>How We’re Building a Social Media Empire with Rails and Sidekiq</title>
      <dc:creator>Shaher Shamroukh</dc:creator>
      <pubDate>Tue, 05 Aug 2025 21:23:22 +0000</pubDate>
      <link>https://dev.to/shahershamroukh/how-were-building-a-social-media-empire-with-rails-and-sidekiq-5p0</link>
      <guid>https://dev.to/shahershamroukh/how-were-building-a-social-media-empire-with-rails-and-sidekiq-5p0</guid>
      <description>&lt;p&gt;It’s been a minute since I last published a blog post, mostly because we’ve been busy building &lt;a href="https://robinreach.com/en" rel="noopener noreferrer"&gt;RobinReach&lt;/a&gt;, a modern social media management platform powered by Ruby on Rails.&lt;/p&gt;

&lt;p&gt;If you’ve ever tried building a tool that posts to multiple social platforms, handles different time zones, supports team approvals, automates publishing, and still provides clean analytics… you know it’s not a walk in the park.&lt;/p&gt;

&lt;p&gt;What could’ve easily turned into a tangled mess of conditionals, platform-specific logic, and fragile scheduling code became a clean, maintainable, and scalable system thanks to Rails' service-oriented design and Sidekiq for background job handling.&lt;/p&gt;

&lt;p&gt;The Stack That Powers RobinReach&lt;br&gt;
RobinReach runs on a streamlined and modern Rails stack:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ruby on Rails 7&lt;/li&gt;
&lt;li&gt;PostgreSQL&lt;/li&gt;
&lt;li&gt;Sidekiq + Redis for background jobs&lt;/li&gt;
&lt;li&gt;Hotwire + Stimulus for reactive UI&lt;/li&gt;
&lt;li&gt;TailwindCSS for styling&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We manage thousands of scheduled posts across platforms like Instagram, LinkedIn, TikTok, Twitter, and YouTube, all orchestrated through Sidekiq workers that handle everything from publishing to AI content generation.&lt;/p&gt;

&lt;p&gt;🧩 Why a Service-Oriented Architecture?&lt;br&gt;
Each social media platform comes with its own rules: different APIs, content requirements, authentication flows, error handling, rate limits, the list goes on.&lt;/p&gt;

&lt;p&gt;Instead of cluttering models or controllers with conditional logic, we split the logic by platform using dedicated service classes, like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module SocialMedia
  module InstagramDirect
    class Post &amp;lt; SocialMedia::ApplicationService
      def initialize(post, profile)
        # setup context
      end

      def call
        # 1. create media container
        # 2. wait for readiness
        # 3. publish
        # 4. return success or failure
      end
    end
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We use the same structure for:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;SocialMedia::Twitter::Service&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;code&gt;SocialMedia::LinkedIn::Service&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Each class is responsible for only one job: posting to its platform.&lt;/p&gt;

&lt;p&gt;What This Gives Us:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A clean interface: &lt;code&gt;PlatformService.new(post, profile).call&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Separation of concerns&lt;/li&gt;
&lt;li&gt;Platform-specific logging + error handling&lt;/li&gt;
&lt;li&gt;Easier testing, mocking, and maintenance&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;⏱ Why Sidekiq?&lt;/p&gt;

&lt;p&gt;Publishing a post isn’t instant:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It needs to go out at the scheduled time&lt;/li&gt;
&lt;li&gt;Some platforms require polling&lt;/li&gt;
&lt;li&gt;Others need multi-step media uploads&lt;/li&gt;
&lt;li&gt;You don’t want users waiting for any of that&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Welcome Sidekiq.&lt;/p&gt;

&lt;p&gt;We use Sidekiq to handle everything asynchronously and at scale.&lt;/p&gt;

&lt;p&gt;A Typical Flow:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;User schedules a post for a future time&lt;/li&gt;
&lt;li&gt;We enqueue the job like this:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;PostJob.perform_at(post.publish_time, post.id)&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The job runs, finds the post, and calls the right service object&lt;/li&gt;
&lt;li&gt;Everything happens in the background, with automatic retries if things fail.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;💡The Sweet Spot: Service + Sidekiq&lt;br&gt;
Here’s why the combination is so powerful:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔧 Service Objects&lt;/strong&gt;            &lt;strong&gt;⏱ Sidekiq&lt;/strong&gt;&lt;br&gt;
Encapsulate platform logic  Handles execution &amp;amp; timing&lt;br&gt;
Keep jobs thin                  Makes everything async&lt;br&gt;
Testable, predictable           Retryable, resilient&lt;br&gt;
Modular per platform            Scalable with queues&lt;/p&gt;

&lt;p&gt;We can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add new platforms without touching existing logic&lt;/li&gt;
&lt;li&gt;Retry failed posts automatically&lt;/li&gt;
&lt;li&gt;Track errors in logs or monitoring tools&lt;/li&gt;
&lt;li&gt;Move fast without fearing regression&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🧪 Testability Bonus&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Each service object is unit-tested on its own.&lt;/li&gt;
&lt;li&gt;Jobs are tested separately with inline Sidekiq workers.&lt;/li&gt;
&lt;li&gt;Because logic is separated, we can:&lt;/li&gt;
&lt;li&gt;Mock external API calls in services&lt;/li&gt;
&lt;li&gt;Simulate platform failures&lt;/li&gt;
&lt;li&gt;Write isolated tests for platform behaviors&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This would be a nightmare with fat models or controllers.&lt;/p&gt;

&lt;p&gt;Final Thoughts&lt;br&gt;
If you’re building a Rails app that interacts with third-party APIs, handles user actions asynchronously, or needs to scale beyond a weekend project…&lt;/p&gt;

&lt;p&gt;💡 Split logic into service objects&lt;br&gt;
🧠 Run tasks with Sidekiq&lt;/p&gt;

&lt;p&gt;That combo gave us:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A cleaner codebase&lt;/li&gt;
&lt;li&gt;Faster iteration cycles&lt;/li&gt;
&lt;li&gt;Fewer bugs&lt;/li&gt;
&lt;li&gt;Less stress&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Rails gives you the foundation. These two patterns help you build skyscrapers on top of it.&lt;/p&gt;

&lt;p&gt;Oh, and one more thing…&lt;br&gt;
Turns out we’re not the only social media management tool built with Rails,  shoutout to &lt;a href="https://publer.com/" rel="noopener noreferrer"&gt;Publer&lt;/a&gt;, whose product and UX has definitely inspired us along the way.&lt;/p&gt;

&lt;p&gt;Rails is alive and well. And with service objects + Sidekiq, it scales beautifully.&lt;/p&gt;

</description>
      <category>rails</category>
      <category>robinreach</category>
      <category>sidekiq</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to Integrate Your SaaS with AppSumo: A Step-by-Step Guide</title>
      <dc:creator>Shaher Shamroukh</dc:creator>
      <pubDate>Thu, 13 Mar 2025 16:23:53 +0000</pubDate>
      <link>https://dev.to/shahershamroukh/how-to-integrate-your-saas-with-appsumo-a-step-by-step-guide-288e</link>
      <guid>https://dev.to/shahershamroukh/how-to-integrate-your-saas-with-appsumo-a-step-by-step-guide-288e</guid>
      <description>&lt;p&gt;If you're launching your SaaS on AppSumo, integrating with their API is crucial for a smooth user experience. This guide walks you through the AppSumo authentication and license verification process, using a fully working Ruby on Rails example.&lt;/p&gt;

&lt;p&gt;This article was inspired by RobinReach’s AppSumo integration. &lt;br&gt;
Check out &lt;a href="https://robinreach.com/" rel="noopener noreferrer"&gt;RobinReach&lt;/a&gt; for automated social media management! 🎯&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F01yvhk5sfwhml7brruvt.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F01yvhk5sfwhml7brruvt.jpeg" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
Whether you're a founder or developer, this guide will help you integrate AppSumo seamlessly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Integrate with AppSumo?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;AppSumo offers lifetime deals (LTDs) to a large number of users. &lt;br&gt;
To streamline onboarding and license verification, they provide an OpenID-based authentication system. By integrating with AppSumo's API, you can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Verify purchases and activate licenses automatically&lt;/li&gt;
&lt;li&gt;Handle license upgrades/downgrades&lt;/li&gt;
&lt;li&gt;Respond to AppSumo webhook events&lt;/li&gt;
&lt;li&gt;Improve user onboarding&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Setting Up the Authentication Flow&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first step in the integration is to set up an authentication flow that allows users to sign in via AppSumo.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.1 Create an OAuth Redirect to AppSumo&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In &lt;code&gt;AppsumoAuthController&lt;/code&gt;, we define a method to generate the OAuth authorization URL and redirect users:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class AppsumoAuthController &amp;lt; ApplicationController
  skip_before_action :authenticate_user!
  skip_before_action :verify_authenticity_token

  CLIENT_ID = Rails.application.credentials.appsumo.client_id
  REDIRECT_URI = 'https://robinreach.com/appsumo/callback'

  def redirect
    auth_url = "https://appsumo.com/openid/authorize?client_id=#{CLIENT_ID}&amp;amp;response_type=code&amp;amp;redirect_uri=#{REDIRECT_URI}"
    redirect_to auth_url, allow_other_host: true
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This method constructs the OAuth authorization URL, allowing users to authenticate via AppSumo. Upon successful authentication, users are redirected to the specified callback URL.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.2 Handle the Callback and Exchange Code for an Access Token&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When users approve the authentication, AppSumo redirects them back with an authorization code. We exchange this code for an access token:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def callback
  code = params[:code]
  return redirect_to auth_url if code.blank?

  response = fetch_access_token(code)
  if response['access_token']
    session[:appsumo_access_token] = response['access_token']
    session[:appsumo_refresh_token] = response['refresh_token']
    redirect_to appsumo_license_path
  else
    render json: { error: response['error'] || 'Failed to authenticate' }, status: :unauthorized
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;fetch_access_token&lt;/code&gt; method sends a request to AppSumo to retrieve the access token:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def fetch_access_token(code)
  response = self.class.post('/token/', headers: { 'Content-Type' =&amp;gt; 'application/json' }, body: {
    client_id: CLIENT_ID,
    client_secret: Rails.application.credentials.appsumo.client_secret,
    code: code,
    redirect_uri: REDIRECT_URI,
    grant_type: 'authorization_code'
  }.to_json)

  response.parsed_response
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This step is essential for securely retrieving an access token, which will be used for further API requests.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Fetch and Validate the License Key&lt;/strong&gt;&lt;br&gt;
Once authenticated, we need to fetch the license key to check if the user has a valid AppSumo purchase&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def fetch_license
  access_token = session[:appsumo_access_token]
  if access_token
    response = self.class.get("/license_key/", query: { access_token: access_token })
    if response.success?
      license_key = response.parsed_response["license_key"]
      handle_license_verification(license_key)
    else
      refresh_access_token
    end
  else
    redirect_to new_user_session_path
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This method retrieves the license key and checks if it belongs to an existing Company. If not, the user is directed to sign up.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Handling Webhook Events&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;AppSumo sends webhooks for key events like purchases, upgrades, and deactivations. We need to process them accordingly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def webhook
  payload = JSON.parse(request.body.read)
  license_key = payload['license_key']
  event = payload['event']
  tier = payload['tier'].to_i

  case event
  when 'activate', 'purchase'
    REDIS.set(license_key, { license_key: license_key, tier: tier }.to_json, ex: 60 * 60 * 24 * 60)
    render json: { success: true, event: event }, status: :ok
  when 'upgrade', 'downgrade'
    update_license(license_key, payload['prev_license_key'], tier)
  when 'deactivate'
    deactivate_license(license_key)
  else
    render json: { success: false, error: 'Unknown event' }, status: :bad_request
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why Store in Redis?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We use Redis to temporarily store the license data for quick access. This reduces the number of database queries and speeds up license verification. The data is set to expire after 60 days, ensuring that stale licenses are not kept indefinitely.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Updating the Company Based on the Event&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For events like purchases or upgrades, we update the Company record to reflect the new subscription tier:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def update_company_license(license_key, tier)
  company = Company.find_by(license_key: license_key)
  if company
    company.update(plan_tier: tier)
  else
    Company.create(license_key: license_key, plan_tier: tier)
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This ensures that companies have the correct access level based on their AppSumo purchase.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Securing Webhooks with Signature Verification&lt;/strong&gt;&lt;br&gt;
Since webhooks can be exploited, we verify requests using HMAC-SHA256 signatures:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def verify_signature
  timestamp = request.headers['X-Appsumo-Timestamp']
  signature = request.headers['X-Appsumo-Signature']
  body = request.raw_post

  return render json: { success: false, error: 'Missing headers' }, status: :unauthorized unless timestamp &amp;amp;&amp;amp; signature &amp;amp;&amp;amp; body

  message = "#{timestamp}#{body}"
  calculated_signature = OpenSSL::HMAC.hexdigest('SHA256', API_KEY, message)

  unless ActiveSupport::SecurityUtils.secure_compare(signature, calculated_signature)
    render json: { success: false, error: 'Invalid signature' }, status: :unauthorized
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This prevents unauthorized requests and protects your system from fraudulent webhooks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final Thoughts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Integrating AppSumo’s API into your SaaS can automate user onboarding, license management etc.&lt;/p&gt;

&lt;p&gt;Key Takeaways:&lt;/p&gt;

&lt;p&gt;✅ Implement OAuth authentication for AppSumo users&lt;br&gt;
✅ Retrieve and validate AppSumo license keys&lt;br&gt;
✅ Handle webhook events for upgrades, downgrades, and deactivations&lt;br&gt;
✅ Secure webhooks using signature verification&lt;/p&gt;

&lt;p&gt;This integration ensures that your SaaS can handle AppSumo deals efficiently while providing a seamless experience to users.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔗 Next Steps:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Test OAuth flow and webhook processing.&lt;/li&gt;
&lt;li&gt;Monitor webhook logs for debugging.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For more details, refer to the AppSumo Licensing &lt;a href="https://docs.licensing.appsumo.com/#overview" rel="noopener noreferrer"&gt;Guide&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This guide is inspired by RobinReach’s integration with AppSumo. Discover how RobinReach simplifies social media management with automation and smart scheduling! 🚀&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Just Launched RobinReach: Multi-Channel Social Media Management 🚀</title>
      <dc:creator>Shaher Shamroukh</dc:creator>
      <pubDate>Wed, 18 Dec 2024 09:40:19 +0000</pubDate>
      <link>https://dev.to/shahershamroukh/just-launched-robinreach-multi-channel-social-media-management-pc1</link>
      <guid>https://dev.to/shahershamroukh/just-launched-robinreach-multi-channel-social-media-management-pc1</guid>
      <description>&lt;p&gt;Hey Everyone! 👋&lt;/p&gt;

&lt;p&gt;I’m excited to share that RobinReach, my social media management platform, is now live on &lt;a href="https://www.producthunt.com/posts/robinreach" rel="noopener noreferrer"&gt;Product Hunt&lt;/a&gt;! 🎉&lt;/p&gt;

&lt;p&gt;RobinReach is built with Ruby on Rails and designed for small businesses, teams, and agencies to simplify their social media workflows.&lt;/p&gt;

&lt;p&gt;Here’s what makes it stand out:&lt;/p&gt;

&lt;p&gt;🌍 Multi-channel support: Manage all your social media accounts (Instagram, LinkedIn, Facebook, Twitter, and more) in one place.&lt;/p&gt;

&lt;p&gt;✍️ Content creation: AI-assisted tools for generating and optimizing posts.&lt;/p&gt;

&lt;p&gt;🔁 Content repurposing: Easily reuse and adapt content for different platforms to maximize reach.&lt;/p&gt;

&lt;p&gt;📊 Analytics: Actionable insights to measure performance and improve engagement.&lt;/p&gt;

&lt;p&gt;Whether you're scheduling posts, repurposing old content, or reviewing metrics, RobinReach aims to save time and boost results.&lt;/p&gt;

&lt;p&gt;💡 Built primarily with Ruby on Rails, integrated with ChatGPT, FFmpeg, and Unsplash. It also supports features like TikTok/YouTube Shorts video generation and Canva image editing.&lt;/p&gt;

&lt;p&gt;👉 Check it out here: &lt;a href="https://www.producthunt.com/posts/robinreach" rel="noopener noreferrer"&gt;RobinReach on Product Hunt&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Would love to hear your thoughts on:&lt;br&gt;
1️⃣ The concept—does it fill a gap you see in social media management?&lt;br&gt;
2️⃣ The tech side—any feedback or tips on scaling multi-channel management features?&lt;br&gt;
3️⃣ Advice on making the most of a PH launch if you've done one before!&lt;/p&gt;

&lt;p&gt;Let’s chat—I'm happy to answer questions about the tech stack, challenges, or lessons learned. 🚀&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>automation</category>
      <category>ruby</category>
      <category>ai</category>
    </item>
    <item>
      <title>ActiveRecord Calculations</title>
      <dc:creator>Shaher Shamroukh</dc:creator>
      <pubDate>Tue, 29 Mar 2022 16:40:24 +0000</pubDate>
      <link>https://dev.to/shahershamroukh/activerecord-calculations-3fd0</link>
      <guid>https://dev.to/shahershamroukh/activerecord-calculations-3fd0</guid>
      <description>&lt;p&gt;Let's talk about some useful methods that are very handy when we need to do some calculations to our database records.&lt;/p&gt;

&lt;h4&gt;
  
  
  So what is activerecord calculations?
&lt;/h4&gt;

&lt;h5&gt;
  
  
  ActiveRecord Calculations provide methods for calculating values of columns in the ActiveRecord models.
&lt;/h5&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;count&lt;/code&gt; Method
&lt;/h3&gt;

&lt;p&gt;Let's start with a method that is widely knowing for simple count.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.count 
#returns the number of users.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keep in mind that count is not always the most performant with that being said &lt;br&gt;
this &lt;a href="https://longliveruby.com/articles/active-record-counting-records" rel="noopener noreferrer"&gt;article&lt;/a&gt; demonstrates the difference between &lt;code&gt;count&lt;/code&gt;, &lt;code&gt;size&lt;/code&gt;, &lt;code&gt;length&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;But &lt;code&gt;count&lt;/code&gt; has much more to offer 🔥 so let's see the different usage of count below 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.count(:address)
# returns the count of all users whose address exist in our db.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.distinct.count(:city)
# returns the count of different cities we have in our db.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.group(:city).count
# returns a hash with each city and it's count.
#{ 'Cairo' =&amp;gt; 5, 'Qina' =&amp;gt; 3 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can also do the above 👆 with multiple columns&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Post.group(:status, :category).count
# {["draft", "business"]=&amp;gt;10, ["published", "art"]=&amp;gt;5}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;maximum&lt;/code&gt; Method
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.maximum(:age)
# 98
# returns the maximum value on the given column.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;minimum&lt;/code&gt; Method
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.minimum(:age)
# 18
# returns the minimum value on the given column.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;average&lt;/code&gt; Method
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.average(:age)
# 27.5
# returns the average value on the given column.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;sum&lt;/code&gt; Method
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.sum(:age)
# 7845
# returns the sum of the values on the given column.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;ids&lt;/code&gt; Method
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.ids
# returns the users ids
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;Please check out &lt;a href="https://api.rubyonrails.org/v7.0.2.3/classes/ActiveRecord/Calculations.html" rel="noopener noreferrer"&gt;the documentation&lt;/a&gt; for reference.&lt;/p&gt;

&lt;p&gt;I hope you found the article useful and enjoyed reading as much as i enjoyed writing it 😃.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
