<?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: Chandan h</title>
    <description>The latest articles on DEV Community by Chandan h (@chandan_h).</description>
    <link>https://dev.to/chandan_h</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%2F1555459%2F339dec24-520f-431c-b94b-b25f6e198402.png</url>
      <title>DEV Community: Chandan h</title>
      <link>https://dev.to/chandan_h</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/chandan_h"/>
    <language>en</language>
    <item>
      <title>[Boost]</title>
      <dc:creator>Chandan h</dc:creator>
      <pubDate>Thu, 26 Nov 2026 05:34:03 +0000</pubDate>
      <link>https://dev.to/chandan_h/-o6j</link>
      <guid>https://dev.to/chandan_h/-o6j</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/chandan_h/how-to-scale-an-mcp-server-from-5-tools-to-5000-19k1" class="crayons-story__hidden-navigation-link"&gt;How to scale an MCP server, from 5 tools to 5,000&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/chandan_h" class="crayons-avatar  crayons-avatar--l  "&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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1555459%2F339dec24-520f-431c-b94b-b25f6e198402.png" alt="chandan_h profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/chandan_h" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Chandan h
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Chandan h
                
                
              
              &lt;div id="story-author-preview-content-5121546" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/chandan_h" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1555459%2F339dec24-520f-431c-b94b-b25f6e198402.png" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Chandan h&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/chandan_h/how-to-scale-an-mcp-server-from-5-tools-to-5000-19k1" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Nov 26&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/chandan_h/how-to-scale-an-mcp-server-from-5-tools-to-5000-19k1" id="article-link-5121546"&gt;
          How to scale an MCP server, from 5 tools to 5,000
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/mcp"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;mcp&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/ai"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;ai&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/architecture"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;architecture&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/webdev"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;webdev&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/chandan_h/how-to-scale-an-mcp-server-from-5-tools-to-5000-19k1" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/multi-unicorn-b44d6f8c23cdd00964192bedc38af3e82463978aa611b4365bd33a0f1f4f3e97.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;1&lt;span class="hidden s:inline"&gt;&amp;nbsp;reaction&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/chandan_h/how-to-scale-an-mcp-server-from-5-tools-to-5000-19k1#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              1&lt;span class="hidden s:inline"&gt;&amp;nbsp;comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            11 min read
          &lt;/small&gt;
          
          &lt;div class="only-sidebar-menu-item trusted-visible-block print-hidden align-center"&gt;
                
                    
                
          &lt;/div&gt;

        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;/div&gt;


</description>
    </item>
    <item>
      <title>How to scale an MCP server, from 5 tools to 5,000</title>
      <dc:creator>Chandan h</dc:creator>
      <pubDate>Thu, 26 Nov 2026 05:33:40 +0000</pubDate>
      <link>https://dev.to/chandan_h/how-to-scale-an-mcp-server-from-5-tools-to-5000-19k1</link>
      <guid>https://dev.to/chandan_h/how-to-scale-an-mcp-server-from-5-tools-to-5000-19k1</guid>
      <description>&lt;p&gt;Most MCP servers start the same way. You write eight or ten tools, connect Claude, and it works on the first try. Nothing in that first week tells you what the server will be like at 100 tools, or at 1,000.&lt;/p&gt;

&lt;p&gt;What happens is that it gets worse in ways that are hard to see from the inside. Answers take longer and cost more, and every so often the model calls the wrong tool. The advice you find first is to put a search layer in front of everything. That is the right design for a server with 2,000 tools and a waste of effort for one with 40.&lt;/p&gt;

&lt;p&gt;The right fix depends on how big the server is. This post follows one server as it grows, an invoicing app that starts with a handful of tools and ends with thousands. It covers what holds at every size first, then what to change at each one, with what the teams running the biggest servers report.&lt;/p&gt;

&lt;h2&gt;
  
  
  The tool list is what grows
&lt;/h2&gt;

&lt;p&gt;When a client connects, it asks the server which tools it has. For every tool it gets back a name, a description and a schema for the inputs. In most clients all of that text goes into the model's context before the user has typed anything, and it is sent again with every request.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqk63s3zl4ww0l9qea00r.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqk63s3zl4ww0l9qea00r.webp" alt="Four bars showing the share of the model's context taken by the tool list: 4% at 10 tools, 19% at 50, 75% at 200, and 188% at 500, which does not fit" width="800" height="286"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At ten tools nobody notices. At about 750 tokens a tool, 50 tools take a fifth of a 200,000 token window, 200 tools take three quarters of it, and 500 do not fit at all.&lt;/p&gt;

&lt;p&gt;A long list costs more than tokens. The more tools a model has to choose from, the more often it picks the wrong one. When that tool only reads, the user sees something they did not ask for. When it writes, an invoice is created or a refund goes out that nobody asked for, and neither can be taken back.&lt;/p&gt;

&lt;p&gt;So scaling is two jobs. One is keeping the list short. The other is making sure a wrong call cannot do damage. The safety work comes first here, because it is the same at 5 tools and at 5,000.&lt;/p&gt;

&lt;h2&gt;
  
  
  The MCP server holds no tools
&lt;/h2&gt;

&lt;p&gt;The easy path is to write the tools inside the MCP server. It works until the product gets its own assistant, which needs the same tools and cannot reach them there. So they get written a second time in the backend. Two copies drift, and one day the same invoice comes to one total in the app and a different one in Claude.&lt;/p&gt;

&lt;p&gt;The fix is to define each tool once, in the backend you already have, in one catalogue. The MCP server becomes a thin layer. It checks the login, asks the backend which tools exist and forwards each call.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fyl8mh120uvt9kgqmt4nl.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fyl8mh120uvt9kgqmt4nl.webp" alt="An isometric diagram. MCP clients send a call and a token to a thin MCP server with 0 tools, which passes the same call to the backend. The backend holds all 43 tools. The in-app assistant reaches the same catalogue directly. A key marks each place the token is checked." width="800" height="482"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That costs one extra hop, and it buys three things. A new tool reaches every client without a deploy of the MCP server. A tool does the same thing wherever it is called, so an invoice comes to the same total everywhere. And the MCP server has no business logic, no database and no service credential in it.&lt;/p&gt;

&lt;p&gt;The last one matters for security. The user's token arrives at the MCP server, is checked there and is passed to the backend unchanged. The backend checks it again from scratch and never trusts the MCP server to say who the user is. That makes two independent checks on one credential, and nothing in the MCP server worth stealing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Every tool says whether it can change things
&lt;/h2&gt;

&lt;p&gt;A client has to decide when to ask the user for permission. If a server tells it nothing, MCP &lt;a href="https://modelcontextprotocol.io/specification/2026-07-28/schema" rel="noopener noreferrer"&gt;treats every tool as destructive&lt;/a&gt;, and a careful client asks before each call, lookups included. People who are asked about everything stop reading and click Allow.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbeyuo44kc6g253mo024p.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbeyuo44kc6g253mo024p.webp" alt="Without annotations every call asks for approval. With them, lookups run and only the write asks." width="800" height="308"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The protocol has hints for this, and the server sets them per tool. A lookup such as &lt;code&gt;find_client&lt;/code&gt; gets &lt;code&gt;readOnlyHint: true&lt;/code&gt;, so it runs without a prompt. A write such as &lt;code&gt;create_invoice&lt;/code&gt; gets &lt;code&gt;destructiveHint: true&lt;/code&gt; and &lt;code&gt;idempotentHint: false&lt;/code&gt;. The first makes a client ask before the call. The second stops it retrying a call that already went through.&lt;/p&gt;

&lt;p&gt;These are hints, and a client is free to ignore them. They make the experience better. Safety comes from the next step.&lt;/p&gt;

&lt;h2&gt;
  
  
  A write never saves on the first call
&lt;/h2&gt;

&lt;p&gt;Suppose the model misreads the user and builds an invoice for the wrong amount. No annotation catches that, because the call itself is allowed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuxiem02ooh5691de7yis.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuxiem02ooh5691de7yis.webp" alt="Left: preview, yes, saved. Right: the amount changes after the yes, so nothing is saved." width="799" height="390"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What catches it is a second call. The first call to a write tool saves nothing. It builds a preview for the user to read and returns a token with it. The token is a signature of the exact details, made with a secret that stays on the server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="no"&gt;SECRET&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="s2"&gt;"change-me"&lt;/span&gt;          &lt;span class="c1"&gt;# a server-side secret, never sent to the model&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;token_for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;details&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;details&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sort_keys&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&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;hmac&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="no"&gt;SECRET&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hashlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sha256&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hexdigest&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="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="nd"&gt;@mcp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;tool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;annotations&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;WRITE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_invoice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;client_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;confirm_token&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="s2"&gt;"""Call once to get a preview and a confirm_token. Call again with the same details plus the token to save."""&lt;/span&gt;
    &lt;span class="n"&gt;details&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"client_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;client_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"amount"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;confirm_token&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="nf"&gt;token_for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;details&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"preview"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"preview"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Invoice for {client_id}: {amount:,.2f}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="s2"&gt;"confirm_token"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;token_for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;details&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"saved"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"invoice_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;save_invoice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;details&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;The save call sends the same details again, with the token. If the model changes the amount after the user said yes, the signature no longer matches and the call turns back into a preview.&lt;/p&gt;

&lt;p&gt;The server also has nothing to remember between the two calls. Every call starts from an empty state, which matters once you run more than one copy of the server. The protocol has gone the same way: the &lt;a href="https://modelcontextprotocol.io/specification/2026-07-28/changelog" rel="noopener noreferrer"&gt;2026-07-28 MCP specification&lt;/a&gt; removed sessions.&lt;/p&gt;

&lt;h2&gt;
  
  
  An error tells the model what to fix
&lt;/h2&gt;

&lt;p&gt;Models make small mistakes with arguments all the time. They send text where a number was expected, or misspell a field. What they do next depends on what comes back. A thrown error reaches the model as a transport failure, and a bare "invalid input" gives it nothing to go on, so it usually sends the same call again.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftsc7vk8nhs7xidm07v9g.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftsc7vk8nhs7xidm07v9g.webp" alt="A bare error makes the model repeat itself. A clear error lets it send the right call next." width="800" height="383"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The fix is to check every call against the tool's schema before the tool runs, and to answer with one line per problem. A call that sends &lt;code&gt;order_id&lt;/code&gt; as a number and misspells &lt;code&gt;amount&lt;/code&gt; comes back with three lines: the type that was expected, the field that is missing, and the field the tool does not take.&lt;/p&gt;

&lt;p&gt;The model reads those lines and repairs the call on its next try. The user is asked only when there is a real choice to make, such as a value outside a fixed list. The MCP specification asks for the same thing, errors that &lt;a href="https://modelcontextprotocol.io/specification/2026-07-28/server/tools" rel="noopener noreferrer"&gt;"contain actionable feedback"&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The tool list is fetched once every five minutes
&lt;/h2&gt;

&lt;p&gt;The MCP server gets the tool list from the backend, and that list only changes when the backend is deployed. Fetching it on every connection is a backend call that almost never learns anything. It also ties the two services together: if the backend is down at that moment, the user sees a connector with nothing in it.&lt;/p&gt;

&lt;p&gt;So the list is held in memory for a few minutes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="no"&gt;TTL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;                 &lt;span class="c1"&gt;# seconds&lt;/span&gt;
&lt;span class="n"&gt;_cached&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;            &lt;span class="c1"&gt;# (tools, fetched_at)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;tools&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;global&lt;/span&gt; &lt;span class="n"&gt;_cached&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;_cached&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="nf"&gt;now&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="n"&gt;_cached&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="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;TTL&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;_cached&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="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;_cached&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;fetch_tools_from_backend&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;now&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;except&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;_cached&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt;             &lt;span class="c1"&gt;# nothing to fall back on&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;_cached&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="c1"&gt;# fresh, or a few minutes stale&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The branch to notice is the failure one. A refresh that fails serves the previous list, because a list that is five minutes stale still works and an empty one makes the whole connector look broken. The price is that a new tool can take five minutes to appear.&lt;/p&gt;

&lt;p&gt;Return the tools in the same order every time as well. Model providers cache tool definitions, and on the Claude API changing any of them &lt;a href="https://platform.claude.com/docs/en/build-with-claude/prompt-caching" rel="noopener noreferrer"&gt;"invalidates the entire cache"&lt;/a&gt;. The 2026-07-28 specification adds a &lt;a href="https://modelcontextprotocol.io/specification/2026-07-28/server/utilities/caching" rel="noopener noreferrer"&gt;&lt;code&gt;ttlMs&lt;/code&gt; hint&lt;/a&gt; to list results, so a client can hold the list too.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to change as the list grows
&lt;/h2&gt;

&lt;p&gt;Everything above holds at any size. What follows depends on how many tools you have.&lt;/p&gt;

&lt;h3&gt;
  
  
  Under 50 tools, shrink what each tool costs
&lt;/h3&gt;

&lt;p&gt;Say the invoicing server has reached about 40 tools. The list is short enough to send whole, so the work is to cut what each tool costs. Start with the schemas. Frameworks generate them from function signatures and pad them with things the model has no use for: a &lt;code&gt;title&lt;/code&gt; that repeats the input's name, a &lt;code&gt;default: null&lt;/code&gt;, and an &lt;code&gt;anyOf&lt;/code&gt; wrapper around every optional input.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="no"&gt;NAMED&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"properties"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"$defs"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;     &lt;span class="c1"&gt;# their keys are input names, never schema words&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;slim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;isinstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;slim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="nb"&gt;isinstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;)&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;node&lt;/span&gt;
    &lt;span class="n"&gt;out&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="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&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;if&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"title"&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"default"&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;continue&lt;/span&gt;
        &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;key&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;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;slim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&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;v&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&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;if&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;NAMED&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="nb"&gt;isinstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="nf"&gt;slim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;out&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;"anyOf"&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="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"null"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="s2"&gt;"anyOf"&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&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;del&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"anyOf"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;options&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="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;out&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;out&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On three sample tools this took the schemas from 982 characters to 457, a little under half, and that saving is repeated on every model call.&lt;/p&gt;

&lt;p&gt;Then look at the list itself. Most servers that feel too big have one tool per API endpoint, and many of those are the same action pointed at different things. Block did this to its Linear server and went from more than 30 tools to 2 (&lt;a href="https://engineering.block.xyz/blog/blocks-playbook-for-designing-mcp-servers" rel="noopener noreferrer"&gt;source&lt;/a&gt;). The one rule is to keep a tool separate when its risk is different. Looking up an invoice and refunding one should not share a tool.&lt;/p&gt;

&lt;h3&gt;
  
  
  Past 50 tools, load them in groups
&lt;/h3&gt;

&lt;p&gt;Past about 50 tools, merging runs out. The server now covers invoices, clients, payments and reports, and nobody uses all of it at once. A support agent needs two of those four areas.&lt;/p&gt;

&lt;p&gt;So every tool goes in a group, and only the groups a user needs are loaded. Tools that are not loaded cost nothing and cannot be called by mistake. GitHub's MCP server works this way, with toolsets and a read-only switch (&lt;a href="https://github.com/github/github-mcp-server" rel="noopener noreferrer"&gt;source&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Choose the groups when the server is set up, or from what the user is allowed to do. Do not let the model switch groups on in the middle of a conversation. The current specification rules that out: the tool list &lt;a href="https://modelcontextprotocol.io/specification/2026-07-28/server/tools" rel="noopener noreferrer"&gt;"MUST NOT vary per-connection"&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Past 200 tools, put search in front
&lt;/h3&gt;

&lt;p&gt;At a few hundred tools even one group is too long. This is where the search layer makes sense. The model stops seeing your tools. It sees three or four fixed ones that search the catalogue, describe one tool and call it, and everything else stays on the server.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fiuhdj4svxepj3f8jw7b9.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fiuhdj4svxepj3f8jw7b9.webp" alt="The model sees four tools while 2,000 stay on the server. Below, one refund request goes through search, describe and call." width="800" height="469"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Block's Square server puts more than 200 API endpoints behind 3 tools this way (&lt;a href="https://engineering.block.xyz/blog/build-mcp-tools-like-ogres-with-layers" rel="noopener noreferrer"&gt;source&lt;/a&gt;). Cloudflare's API has over 2,500 endpoints, and its server exposes two tools, &lt;code&gt;search()&lt;/code&gt; and &lt;code&gt;execute()&lt;/code&gt;. Cloudflare says an equivalent plain server "would consume 1.17 million tokens", against "around 1,000 tokens" for this one (&lt;a href="https://blog.cloudflare.com/code-mode-mcp/" rel="noopener noreferrer"&gt;source&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;A gateway has costs, and they are the reason to wait this long. Every action takes two or three calls where it used to take one. Speakeasy measured 2 to 3 times more tool calls with its own gateway (&lt;a href="https://www.speakeasy.com/blog/how-we-reduced-token-usage-by-100x-dynamic-toolsets-v2" rel="noopener noreferrer"&gt;source&lt;/a&gt;). The client can no longer check arguments, because all it sees is a generic call tool, so the server has to, and the clear errors from earlier stop being optional. A single call tool would also hide the difference between a lookup and a refund, so keep a read version and a write version.&lt;/p&gt;

&lt;h2&gt;
  
  
  Measure before you build
&lt;/h2&gt;

&lt;p&gt;You do not have to guess which size you are. Connect your server in Claude Code and run &lt;code&gt;/context&lt;/code&gt;. It shows how many tokens your tools take, and the MCP docs suggest keeping that within 1% to 5% of the model's context window (&lt;a href="https://modelcontextprotocol.io/docs/2026-07-28/develop/clients/client-best-practices" rel="noopener noreferrer"&gt;source&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;If you are inside that range, the base is all you need: tools in the backend, reads and writes marked, saves in two calls, errors the model can act on, and a cached list. If you are over it, take the one step for your size and measure again.&lt;/p&gt;

&lt;p&gt;A related post walks through a small agent app that runs on free model tiers: &lt;a href="https://dev.to/portfolio-agents/"&gt;A portfolio run by 12 agents on free model tiers&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  How many tools can an MCP server have?
&lt;/h3&gt;

&lt;p&gt;As many as fit. The limit that bites first is the model's context window, because every tool's name, description and schema is loaded before the conversation starts. At about 750 tokens a tool, 50 tools take a fifth of a 200,000 token window and 200 tools take three quarters of it.&lt;/p&gt;

&lt;h3&gt;
  
  
  How do I reduce the tokens my MCP tools use?
&lt;/h3&gt;

&lt;p&gt;Trim the generated schemas first, then merge tools that do the same action on different things. Past about 50 tools, load them in groups so each user gets only the groups they need. Past about 200, put a search gateway in front so the model sees three or four tools.&lt;/p&gt;

&lt;h3&gt;
  
  
  When does an MCP server need tool search?
&lt;/h3&gt;

&lt;p&gt;At a few hundred tools, when even one group of tools is too long to send whole. Below that a search gateway costs more than it saves, because every action takes two or three calls where it used to take one.&lt;/p&gt;

&lt;h3&gt;
  
  
  Should MCP tools live in the MCP server or in the backend?
&lt;/h3&gt;

&lt;p&gt;In the backend. The MCP server then only checks the login and forwards each call, so a new tool reaches every client without a deploy of the MCP server, and the product's own assistant can use the same tools.&lt;/p&gt;

&lt;h3&gt;
  
  
  How do I stop an MCP tool from saving the wrong thing?
&lt;/h3&gt;

&lt;p&gt;Make every write take two calls. The first call saves nothing and returns a preview with a token that is a signature of the exact details. The second call saves only if the details still match that token.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://blog.chandan.studio/scaling-mcp-servers/" rel="noopener noreferrer"&gt;blog.chandan.studio&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>mcp</category>
      <category>ai</category>
      <category>architecture</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Building a Scalable and Robust Application with AWS</title>
      <dc:creator>Chandan h</dc:creator>
      <pubDate>Fri, 31 May 2024 17:05:08 +0000</pubDate>
      <link>https://dev.to/chandan_h/building-a-scalable-and-robust-application-with-aws-ojc</link>
      <guid>https://dev.to/chandan_h/building-a-scalable-and-robust-application-with-aws-ojc</guid>
      <description>&lt;p&gt;In this blog, I'll walk you through the architecture and implementation of a scalable and robust application using various AWS services. This project demonstrates how can integrate multiple services to create a resilient solution. Working &lt;a href="https://d1kw9qj8xa4cyp.cloudfront.net/"&gt;app link&lt;/a&gt; May be down because of cost&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Architecture Overview&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Key AWS Services Used&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Amazon S3: To host the React application built with Vite.&lt;/li&gt;
&lt;li&gt;Amazon CloudFront: For content delivery and caching to enhance performance.&lt;/li&gt;
&lt;li&gt;Amazon API Gateway: To manage API requests and route them to the appropriate backend services.&lt;/li&gt;
&lt;li&gt;Amazon Route 53: For domain name system (DNS) web services and routing user requests.&lt;/li&gt;
&lt;li&gt;Elastic Load Balancer (ELB): To distribute incoming application traffic across multiple EC2 instances.&lt;/li&gt;
&lt;li&gt;Amazon EC2: To run the backend servers.&lt;/li&gt;
&lt;li&gt;Amazon SQS: For message queuing and handling asynchronous requests.&lt;/li&gt;
&lt;li&gt;Amazon DynamoDB: To store execution results and manage state.&lt;/li&gt;
&lt;li&gt;AWS Cloud9: For development, debugging, and monitoring logs and sqs (we will be scaling worker nodes based on sqs length).&lt;/li&gt;
&lt;li&gt;AWS Certificate Manager: For managing SSL/TLS certificates to secure traffic.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Detailed Architecture Breakdown&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Front-end&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyknas6z8qghyjn52myoo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyknas6z8qghyjn52myoo.png" alt="Frontend aws diagram" width="800" height="405"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hosting the React Application&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Amazon S3: The React application built with Vite is hosted on an S3 bucket, which serves the static files.&lt;/p&gt;

&lt;p&gt;Amazon CloudFront: CloudFront is configured to deliver the application content with low latency and high transfer speeds.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Routing and Domain Management&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Amazon Route 53: Route 53 handles DNS management, routing user requests to the appropriate resources.&lt;/p&gt;

&lt;p&gt;AWS Certificate Manager: Manages SSL/TLS certificates to ensure secure communication between the user and the application.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Back-end&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxuhpbli905gxgynvgaj2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxuhpbli905gxgynvgaj2.png" alt="Backend aws diagram" width="800" height="386"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;API Gateway and Load Balancer&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Amazon API Gateway: API Gateway serves as the entry point for all API requests. It routes incoming requests to the backend services.&lt;/p&gt;

&lt;p&gt;Elastic Load Balancer: The load balancer distributes incoming API requests across two EC2 instances in a round-robin fashion, ensuring even load distribution.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Primary Backend servers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Amazon EC2: Two EC2 instances act as servers backend servers. They process incoming requests and interact with other AWS services.&lt;/p&gt;

&lt;p&gt;Amazon SQS: The backend servers place incoming requests into an SQS queue for asynchronous processing.&lt;/p&gt;

&lt;p&gt;Worker Nodes: Worker nodes monitor the SQS queue, processing messages as they arrive. The number of worker nodes scales up or down based on the queue length, managed by an Auto Scaling group.&lt;/p&gt;

&lt;p&gt;Amazon DynamoDB: Execution results are stored in DynamoDB. The backend servers periodically check the database to determine if a task has been completed.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Monitoring and Scaling&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Amazon CloudWatch: CloudWatch monitors the application and triggers scaling actions based on SQS metrics. It ensures that the application scales in and out based on demand.&lt;/p&gt;

&lt;p&gt;Auto Scaling Group: Manages the worker nodes, launching or terminating instances based on the queue length and CloudWatch metrics.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementation Details&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Frontend: React Application&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The frontend of the application is a simple React app built with Vite. It allows users to submit JavaScript code, which is then processed by the backend. The frontend interacts with the backend via API Gateway.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useRef, useState } from "react";
import axios from "axios";
import Editor, { Monaco } from "@monaco-editor/react";
import { editor as monacoEditor } from "monaco-editor";
import { Button } from "./components/ui/button";
import "./App.css";

function App() {
  const editorRef = useRef&amp;lt;monacoEditor.IStandaloneCodeEditor | null&amp;gt;(null);
  const [output, setOutput] = useState("");

  function handleEditorDidMount(
    editor: monacoEditor.IStandaloneCodeEditor,
    monaco: Monaco
  ) {
    editorRef.current = editor;
  }

  async function showValue() {
    if (editorRef.current) {
      const code = editorRef.current.getValue();
      try {
        const response = await axios.post(
          "https://api..primarybacked.com/submit-code",
          { code }
        );
        const { executionId } = response.data;

        const checkStatus = async () =&amp;gt; {
          const statusResponse = await axios.get(
            `https://api..primarybacked.com/check-status/${executionId}`
          );
          const { status, result } = statusResponse.data;
          if (status === "Executed") {
            setOutput(result);
          } else {
            setTimeout(checkStatus, 5000); // Polling every 5 seconds
          }
        };

        checkStatus();
      } catch (error) {
        console.error("Error submitting code:", error);
        setOutput("Error submitting code");
      }
    }
  }

  return (
    &amp;lt;div className="flex h-screen w-full flex-col bg-gray-950 text-gray-50"&amp;gt;
      &amp;lt;header className="flex items-center justify-between border-b border-gray-800 px-4 py-4 sm:px-6"&amp;gt;
        &amp;lt;div className="flex items-center gap-4"&amp;gt;
          &amp;lt;span className="text-xl font-semibold"&amp;gt;Code Playground&amp;lt;/span&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;Button onClick={showValue}&amp;gt;Run&amp;lt;/Button&amp;gt;
      &amp;lt;/header&amp;gt;
      &amp;lt;div className="flex-1 overflow-hidden"&amp;gt;
        &amp;lt;div className="grid h-full grid-cols-1 gap-6 p-4 sm:grid-cols-[1fr_400px] sm:p-6"&amp;gt;
          &amp;lt;div className="flex h-full flex-col gap-6 overflow-hidden rounded-lg border border-gray-800 bg-gray-900"&amp;gt;
            &amp;lt;div className="flex-1 overflow-auto p-4"&amp;gt;
              &amp;lt;Editor
                defaultLanguage="javascript"
                theme="vs-dark"
                defaultValue="console.log('Hello, world!');"
                onMount={handleEditorDidMount}
                options={{}}
              /&amp;gt;
            &amp;lt;/div&amp;gt;
          &amp;lt;/div&amp;gt;
          &amp;lt;div className="flex h-full flex-col gap-6 overflow-hidden rounded-lg border border-gray-800 bg-gray-900"&amp;gt;
            &amp;lt;div className="flex-1 overflow-auto p-4"&amp;gt;
              &amp;lt;pre className="whitespace-pre-wrap break-words font-mono text-sm"&amp;gt;
                {output}
              &amp;lt;/pre&amp;gt;
            &amp;lt;/div&amp;gt;
          &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export default App;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Primary Backend: Processing Requests&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The primary backend is built using EC2 instances, SQS, and DynamoDB.They forward the submitted code to the SQS, and forward the output to the users&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require('express');
const { DynamoDBClient, PutItemCommand, GetItemCommand } = require("@aws-sdk/client-dynamodb");
const { v4: uuidv4 } = require('uuid');
const { SQSClient, SendMessageCommand ,ReceiveMessageCommand} = require("@aws-sdk/client-sqs");
const cors = require('cors');
const app = express();
app.use(express.json());
require('dotenv').config();


app.use(cors({
    origin: '*',
    methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
}))

const config = {
    region: "eu-north-1",
    credentials: {
        accessKeyId: process.env.AWS_ACCESS_KEY_ID,
        secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
    }
};
const DBclient = new DynamoDBClient(config);
const sqsClient = new SQSClient(config);

app.post('/submit-code', async (req, res) =&amp;gt; {
    console.log(req.body)
    const executionId = uuidv4();
    const { code } = req.body;

    const input = {
        TableName: 'code',
        Item: {
            executionId: { S: executionId },
            code: { S: code },
            status: { S: 'pending' },
            result: { S: '' },
        },
    };

    try {
        await DBclient.send(new PutItemCommand(input));

        const sqsParams = {
            QueueUrl: process.env.QUEUE_URL,
            MessageBody: JSON.stringify({ executionId }),
            MessageDeduplicationId: executionId,
            MessageGroupId: "CodeSubmissionGroup",
        };

        await sqsClient.send(new SendMessageCommand(sqsParams));

        res.json({ executionId, message: "Code submitted successfully" });

    } catch (error) {
        console.error("Error submitting code:", error);
        res.status(500).json({ error: "Failed to submit code" });
    }
});


app.get('/check-status/:executionId', async (req, res) =&amp;gt; {
    const { executionId } = req.params;

    const params = {
        QueueUrl: process.env.QUEUE_URL,
        MaxNumberOfMessages: 10,
        WaitTimeSeconds: 0,
        VisibilityTimeout: 0,
    };

    try {
        const data = await sqsClient.send(new ReceiveMessageCommand(params));

        let found = false;
        if (data.Messages) {
            for (const message of data.Messages) {
                const body = JSON.parse(message.Body);
                if (body.executionId === executionId) {
                    found = true;
                    break;
                }
            }
        }

        if (found) {
            res.json({ status: 'pending', result: '' });
        } else {
            const dbParams = {
                TableName: 'code',
                Key: {
                    executionId: { S: executionId },
                },
            };
            const dbData = await DBclient.send(new GetItemCommand(dbParams));
            if (dbData.Item) {
                const status = dbData.Item.status.S;
                const result = dbData.Item.result.S;
                res.json({ status, result });
            } else {
                res.status(404).json({ error: "Execution ID not found" });
            }
        }
    } catch (error) {
        console.error("Error checking status:", error);
        res.status(500).json({ error: "Failed to check status" });
    }
});

app.listen(3000, () =&amp;gt; {
    console.log('primary backend listening on port 3000!')
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Worker node: Processing code&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The Worker node is built using EC2 instances,They process the submitted code, and store the results in DynamoDB.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require('express');
const safeEval = require('safe-eval');
const { DynamoDBClient, UpdateItemCommand, GetItemCommand } = require("@aws-sdk/client-dynamodb");
const { SQSClient, ReceiveMessageCommand, DeleteMessageCommand } = require("@aws-sdk/client-sqs");
require('dotenv').config();
const app = express();
app.use(express.json());
require('dotenv').config();

const config = {
    region: "eu-north-1",
    credentials: {
        accessKeyId: process.env.AWS_ACCESS_KEY_ID,
        secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
    }
};

const DBclient = new DynamoDBClient(config);
const sqsClient = new SQSClient(config);


const processMessage = async (message) =&amp;gt; {
    try {
        const { executionId } = JSON.parse(message.Body);

        const { Item } = await DBclient.send(new GetItemCommand({
            TableName: 'code',
            Key: {
                executionId: { S: executionId },
            },
        }));

        if (!Item) {
            console.log("Item not found for executionId:", executionId);
            return;
        }


        const { code } = Item;
        let outputString = '';

        try {
            const output = await safeEval(code.S);
            outputString = output != null || output != undefined ? output.toString() : 'Code did not return any output';
        } catch (error) {
            outputString = "this code cant be executed";
        }


        const input = {
            TableName: 'code',
            Key: {
                executionId: { S: executionId },
            },
            UpdateExpression: 'SET #status = :status, #result = :result',
            ExpressionAttributeNames: {
                '#status': 'status',
                '#result': 'result'
            },
            ExpressionAttributeValues: {
                ':status': { S: 'Executed' },
                ':result': { S: outputString },
            },
        };

        await DBclient.send(new UpdateItemCommand(input));

        await sqsClient.send(new DeleteMessageCommand({
            QueueUrl: process.env.QUEUE_URL,
            ReceiptHandle: message.ReceiptHandle,
        }));

    } catch (error) {
        console.error("Error processing message:", error);
    }
};


const processMessages = async () =&amp;gt; {
    while (true) {
        try {
            const { Messages } = await sqsClient.send(new ReceiveMessageCommand({
                QueueUrl: process.env.QUEUE_URL,
                WaitTimeSeconds: 10,
            }));

            if (Messages &amp;amp;&amp;amp; Messages.length &amp;gt; 0) {
                for (const message of Messages) {
                    await processMessage(message);
                }
            }
        } catch (error) {
            console.error("Error receiving messages:", error);
        }

        await new Promise(resolve =&amp;gt; setTimeout(resolve, 10000));
    }
};

processMessages();

const port = 4000;
app.listen(port, () =&amp;gt; {
    console.log(`Primary backend listening on port ${port}!`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is the complete architecture diagram&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F02xhwsn7l8oygd6ro0mn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F02xhwsn7l8oygd6ro0mn.png" alt="Aws architecture diagram" width="800" height="221"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This project shows how to use different AWS services to build an app that can handle lots of users and work efficiently. By combining services like S3, CloudFront, API Gateway, Route 53, ELB, EC2, SQS, DynamoDB, and Cloud9, do tasks without waiting, and adjust to how many people are using it. This setup makes sure the app is always available, reliable, and works fast.&lt;/p&gt;

&lt;p&gt;See you next time 👋&lt;/p&gt;

</description>
      <category>aws</category>
      <category>ec2</category>
      <category>sqs</category>
      <category>node</category>
    </item>
  </channel>
</rss>
