<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Satyam Mishra on Medium]]></title>
        <description><![CDATA[Stories by Satyam Mishra on Medium]]></description>
        <link>https://medium.com/@satyammishraai?source=rss-18ebc39fb672------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*cXfGS--ywnkrJ9UFkvqq8Q.png</url>
            <title>Stories by Satyam Mishra on Medium</title>
            <link>https://medium.com/@satyammishraai?source=rss-18ebc39fb672------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 10:24:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@satyammishraai/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[What MCP actually means when you ship it]]></title>
            <link>https://satyammishraai.medium.com/what-mcp-actually-means-when-you-ship-it-1c5cd0a666f3?source=rss-18ebc39fb672------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c5cd0a666f3</guid>
            <category><![CDATA[model-context-protocol]]></category>
            <category><![CDATA[mcp-server]]></category>
            <category><![CDATA[agentic-ai]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Satyam Mishra]]></dc:creator>
            <pubDate>Fri, 24 Apr 2026 19:27:26 GMT</pubDate>
            <atom:updated>2026-04-24T19:27:26.590Z</atom:updated>
            <content:encoded><![CDATA[<p>I rewrote the same GitHub connector three times.</p><p>First time: a LangChain chatbot. Second time: a raw Claude API app. Third time: a FastAPI microservice calling the exact same GitHub endpoints. Same authentication, same API logic, three separate integration layers. The third time I was copy-pasting my own code from six months earlier, and I remember thinking: there has to be a better way to do this.</p><p>That’s the problem MCP fixes. And it does fix it. Mostly.</p><h3>The 30-second definition</h3><p>MCP is a client-server protocol that standardizes how LLM applications connect to external tools and data sources.</p><p>Your app is the client. Your data sources and tools are servers. Every server exposes its capabilities using the same message format. Clients discover those capabilities at runtime and route model requests through them.</p><p>The bet: build the tool server once, and any MCP-compatible client (your chatbot, Claude Desktop, someone else’s agent) can use it without any changes.</p><h3>What the textbook gets right</h3><p>The three-primitive model is clean.</p><p><strong>Tools</strong> handle anything with a side effect: search arXiv, write to a database, call an external API. The model decides when to call them. Your code executes the actual function. The model never directly runs anything.</p><p><strong>Resources</strong> expose read-only data as URIs. papers://topic/transformers fetches cached paper data. The client can pull this into context without the model ever asking for it. Think of it as a GET endpoint the client can browse and inject.</p><p><strong>Prompts</strong> are pre-engineered templates users can trigger with a slash command. Type /summarize topic=attention and get a structured research prompt injected automatically. No prompt engineering required on the user side.</p><p>The separation is also right. Servers are standalone programs. They don’t know or care what client is talking to them. A server you build today works with Claude Desktop, your custom chatbot, or an agent framework you haven’t written yet.</p><p>And the LSP analogy is genuinely apt. Before Microsoft’s Language Server Protocol in 2016, every IDE needed a custom plugin for every programming language. VS Code needed its own Python plugin, Go plugin, Rust plugin. After LSP, language servers were built once and every editor that spoke the protocol could use them. MCP applies the same logic to AI tool integrations.</p><h3>What shipping it actually looks like</h3><p>Here’s the minimal research server, start to finish:</p><pre>from mcp.server.fastmcp import FastMCP<br>import arxiv, json</pre><pre>mcp = FastMCP(&quot;ResearchServer&quot;)</pre><pre>@mcp.tool<br>def search_papers(topic: str, max_results: int = 5) -&gt; list[str]:<br>    &quot;&quot;&quot;Search arXiv for papers on a topic. Returns paper IDs.&quot;&quot;&quot;<br>    client = arxiv.Client()<br>    results = list(client.results(arxiv.Search(query=topic, max_results=max_results)))<br>    data = {r.entry_id: {&quot;title&quot;: r.title, &quot;summary&quot;: r.summary} for r in results}<br>    with open(&quot;papers.json&quot;, &quot;w&quot;) as f:<br>        json.dump(data, f)<br>    return list(data.keys())</pre><pre>@mcp.tool<br>def extract_info(paper_id: str) -&gt; dict:<br>    &quot;&quot;&quot;Get title and summary for a paper by ID.&quot;&quot;&quot;<br>    with open(&quot;papers.json&quot;) as f:<br>        return json.load(f).get(paper_id, {&quot;error&quot;: &quot;not found&quot;})</pre><pre>if __name__ == &quot;__main__&quot;:<br>    mcp.run()</pre><p>Run it: uv run research_server.py. That&#39;s it. No HTTP boilerplate. The @mcp.tool decorator reads your type hints, generates the JSON schema, registers the function for discovery, and handles incoming call routing.</p><p>The client side is where the interesting decisions live:</p><pre>import asyncio<br>from mcp import ClientSession, StdioServerParameters<br>from mcp.client.stdio import stdio_client<br>from anthropic import Anthropic</pre><pre>async def run():<br>    params = StdioServerParameters(command=&quot;uv&quot;, args=[&quot;run&quot;, &quot;research_server.py&quot;])<br>    async with stdio_client(params) as (read, write):<br>        async with ClientSession(read, write) as session:<br>            await session.initialize()<br>            <br>            # Tools are discovered at runtime, not hardcoded<br>            tools_response = await session.list_tools()<br>            tool_defs = [<br>                {&quot;name&quot;: t.name, &quot;description&quot;: t.description, &quot;input_schema&quot;: t.inputSchema}<br>                for t in tools_response.tools<br>            ]<br>            <br>            client = Anthropic()<br>            messages = [{&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;find papers on attention mechanisms&quot;}]<br>            <br>            while True:<br>                response = client.messages.create(<br>                    model=&quot;claude-sonnet-4-6&quot;, max_tokens=4096,<br>                    tools=tool_defs, messages=messages<br>                )<br>                if response.stop_reason != &quot;tool_use&quot;:<br>                    print(response.content[0].text)<br>                    break<br>                <br>                results = []<br>                for block in response.content:<br>                    if block.type == &quot;tool_use&quot;:<br>                        result = await session.call_tool(block.name, block.input)<br>                        results.append({<br>                            &quot;type&quot;: &quot;tool_result&quot;, &quot;tool_use_id&quot;: block.id,<br>                            &quot;content&quot;: result.content<br>                        })<br>                <br>                messages.extend([<br>                    {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: response.content},<br>                    {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: results}<br>                ])</pre><pre>asyncio.run(run())</pre><p>The difference from hand-rolled tool use: session.list_tools() instead of a hardcoded list. session.call_tool() instead of a local function call. The agentic loop is the same pattern you&#39;d write anyway.</p><p>And going remote is one line on the server:</p><pre>mcp.run(transport=&quot;sse&quot;)  # was: mcp.run()</pre><p>Deploy to Render, Fly.io, or any web host. The client points at the SSE endpoint instead of launching a subprocess. Your agentic loop doesn’t change at all.</p><h3>Three things that broke before I got it right</h3><p><strong>The async mismatch in notebooks.</strong> MCP’s client is async throughout. Jupyter already has a running event loop. Call asyncio.run() inside Jupyter and you get &quot;cannot run nested event loops.&quot; Fix: nest_asyncio.apply() at the top of the notebook. Not obvious from the docs. Cost me 40 minutes.</p><p><strong>Giving the model too many tools.</strong> First pass, I exposed 12 tools on one server. Tool routing quality dropped. The model called list_saved_papers when I wanted it to search for new ones. Kept confusing similar-sounding tools. The fix was brutal but necessary: cut to 7 tools, rewrote every description to make the routing decision unambiguous. &quot;Search arXiv for new papers on a topic, returns new paper IDs&quot; vs &quot;List papers you&#39;ve already saved.&quot; Different verbs, different framing.</p><p><strong>Treating stdio like it scales.</strong> It doesn’t. Stdio spins up a new subprocess for every connection. Fine for local development. Fine for Claude Desktop where one user connects once. Not fine for a web app where 50 users hit your server simultaneously. The moment you have concurrent users, switch to SSE transport. Render’s free tier handles the deployment.</p><h3>When NOT to use MCP</h3><p>If you’re writing a 100-line script that calls one API: just call the API. MCP is infrastructure. Infrastructure has setup cost. Don’t pay it for a script you’ll run twice.</p><p>If you control both client and server and they’ll never be used by anything else: direct function calls are simpler and faster. The protocol overhead is worth it when portability matters, not when you’re the only user of both sides.</p><p>If you need sub-50ms tool execution latency in a hot path: the subprocess model adds startup time, and SSE adds network round-trips. For latency-critical code, in-process function calls still win by a wide margin. MCP is not for microsecond-level performance requirements.</p><h3>What I’m watching for</h3><p>OAuth 2.1 support for remote servers is the missing piece for production multi-tenant apps. Right now, remote server auth is DIY. Once the Python SDK ships stable OAuth 2.1, you’ll be able to build servers that third parties can connect to with proper token-based auth, not just API keys in environment variables shared over Slack.</p><p>The registry is the bigger long-term bet. An NPM-style registry for verified MCP servers means you stop building GitHub integrations and start installing them. Agents that can query the registry, find the official server for a tool, install it, and add it to their active connections at runtime: that’s a meaningful step toward AI systems that can extend their own capabilities safely.</p><p>And the composability piece (clients that are also servers, agents that expose MCP upward while consuming MCP downward) is where multi-agent architectures get interesting without requiring a special framework. Just MCP connections all the way down.</p><p>MCP isn’t a model improvement. The model doesn’t get smarter because you added a protocol.</p><p>What changes is the infrastructure layer. The same way REST standardized how web services talk to each other, MCP standardizes how AI applications talk to tools. Once the handshake is standard, every server built by anyone works with every client built by anyone.</p><p>The connector rewrite problem I had three times? That’s the problem this solves.</p><p>If you’re still rebuilding the same integration per app, the cost is already there. It’s just invisible because you’ve internalized it as normal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*584v_3Ls3rdXootKtfpGbw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gOrUnfvgZhSm3tnFtk1-2Q.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c5cd0a666f3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[On-device AI went from MBs to GBs. Here’s the stack that did it.]]></title>
            <link>https://satyammishraai.medium.com/on-device-ai-went-from-mbs-to-gbs-heres-the-stack-that-did-it-19e4d4bd20ea?source=rss-18ebc39fb672------2</link>
            <guid isPermaLink="false">https://medium.com/p/19e4d4bd20ea</guid>
            <dc:creator><![CDATA[Satyam Mishra]]></dc:creator>
            <pubDate>Fri, 24 Apr 2026 19:14:43 GMT</pubDate>
            <atom:updated>2026-04-24T19:14:43.440Z</atom:updated>
            <content:encoded><![CDATA[<p>Three years ago, “AI on a phone” meant a 13 MB segmentation model running in 6 milliseconds. Today a Pixel 9 Pro runs a 4 billion parameter LLM in 2.5 GB of RAM with a 128K context window.</p><p>Same device class. Different universe.</p><p>The shift wasn’t about phones getting smarter. It was about the deployment stack finally catching up with what the hardware could already do. And the same four part playbook that shrank a segmentation model down to 13 MB is what now fits Gemma 4 into a phone that still has to send messages and play Spotify.</p><p>Here’s what changed, what still breaks, and why the model was never the bottleneck.</p><h4>The 30 second picture</h4><p>On-device AI means: the trained model artifact lives on the user’s device, and every inference call runs there. No network round trip. No API cost per token. No data leaves the device.</p><p>That’s the boring definition. Almost everyone gets it right on slide one.</p><p>What people get wrong is that “on-device” isn’t one thing. It’s a stack with four layers, and each layer has to cooperate for the whole thing to ship.</p><p>Graph capture turns Python into a static computation graph. A compiler targets that graph at a specific phone chip. A runtime loads the compiled binary and dispatches work to the right compute unit. A validator catches silent numerical drift between the cloud-trained model and what the phone actually computes.</p><p>Skip any one layer and you have a demo. Nail all four and you have a product.</p><h4><strong>The shift, in two numbers</strong></h4><p>13 MB. 2.5 GB.</p><p>That’s the ceiling jump. A W8A8 quantized FFNet segmentation model used to be the flashy thing you’d put on a phone. It ran at 6 ms on a Galaxy S23 NPU and held PSNR above 30 dB against the float version. Niche, but real.</p><p>Gemma 4 E4B now ships as a 4 billion parameter LLM in 2.5 GB of RAM. Not a demo. Not “someday.” Actually running on a Pixel, with a 128K context window.</p><p>The math that got there is the same math that shrank the CNN. Int4 weights. Int16 activations. Calibration on a few hundred samples. No retraining.</p><p>What changed isn’t the technique. It’s that NPUs, compilers, and runtimes finally converged on one workflow that works end to end.</p><p><strong>Why the NPU is suddenly the only unit that matters</strong></p><p>Every modern smartphone SoC has three engines: CPU, GPU, NPU.</p><p>The CPU runs anything, slowly. The GPU runs parallel float workloads. The NPU runs quantized integer matmul at roughly 10x CPU efficiency.</p><p>For neural network inference, that 10x decides whether your feature ships or tanks the user’s battery.</p><p>The production benchmark that burns this into your brain: same segmentation model, same Galaxy S23. <strong>800 ms on CPU. 22 ms on the NPU. 6 ms after int8 quantization.</strong></p><p>That’s not a paper number. That’s what a user feels.</p><p>For LLMs, the battery angle matters more than latency. A Pixel 9 Pro running Gemma 4 on the NPU drains far slower than the same model forced onto the CPU. Battery is the new latency. Users will tolerate a feature that’s a little slow. They won’t tolerate a feature that kills their phone by 3pm.</p><p>But the NPU only wins if every op lands on it. One unsupported op mid graph, and the tensor bounces back to CPU and back again. That bounce kills the 10x. More on that below.</p><h4>Quantization is the whole ballgame</h4><p>Quantization isn’t an optimization pass anymore. It’s the only reason any of this works.</p><p>Two default playbooks depending on what you’re shipping.</p><p><strong>W8A8 for CNNs.</strong> Int8 weights, int8 activations. Shrinks a 55 MB perception model to 13 MB. Speeds 22 ms NPU inference to 6 ms. PSNR holds at 33 dB, comfortably above the 30 dB shippability threshold. This is the boring, reliable, “use this first” recipe for perception tasks.</p><p><strong>W4A16 for LLMs.</strong> Int4 weights, int16 activations. 4x weight compression from BF16. This is how a 4B LLM fits in 2.5 GB of RAM. Activations stay in 16 bits because LLM attention is sensitive to activation precision in a way convnets aren’t.</p><p>The math is one line:</p><pre>q = round(x / scale)<br>dequant = q * scale</pre><p>Walk it through. Float weight x = 12.5. Learned scale = 2.35.</p><pre>q = round(12.5 / 2.35) = 5<br>dequant = 5 * 2.35 = 11.75<br>error = 0.75</pre><p>That error, multiplied across every weight, is the cost of the 4x compression. The whole game is keeping that error below the accuracy floor that matters for the task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*py4h1gY9lV3ESSV835asxg.png" /></figure><p>Two ways to calibrate the scales.</p><p><strong>Post-Training Quantization (PTQ).</strong> Feed a few hundred representative samples to the trained model. Learn scales per tensor or per channel. Done. No training loop. This covers 90% of CNN deployments and a surprising share of LLM deployments too.</p><p><strong>Quantization-Aware Training (QAT).</strong> Insert fake quant ops during training. The model’s weights adapt to integer rounding. Slower, needs training data and compute. Use when PTQ drops accuracy past your budget, which for LLMs happens more than you’d expect.</p><p>The failure mode you’ll hit first: per tensor scales get poisoned by outliers. One activation dimension carries way more magnitude than the median and hijacks the scale for the whole tensor. Fix: per channel scales on conv weights, mixed precision for the one stubborn layer.</p><p>The failure mode you’ll hit second: calibration set mismatch. You calibrated on ImageNet, production sees indoor phone photos. The scales are tuned to the wrong distribution. Always calibrate on production-like data.</p><h3>The deployment pipeline, if you haven’t shipped one</h3><p>Server-side model shipping you already know. Export to ONNX, run behind Triton on a GPU, pick a batch size, optimize throughput. You control the machine.</p><p>Device-side shipping inverts every assumption. You don’t control the machine. The user picks the device. The compiler runs somewhere else. You ship an artifact, not a service.</p><p>Four stages, every single time:</p><pre>import torch<br>import qai_hub as hub<br><br># 1. Graph capture: Python to static DAG<br>traced = torch.jit.trace(model, sample_input)<br><br># 2. Compile for a specific phone<br>compile_job = hub.submit_compile_job(<br>    model=traced,<br>    device=hub.Device(&quot;Samsung Galaxy S23&quot;),<br>    input_specs={&quot;image&quot;: (1, 3, 1024, 2048)},<br>)<br>device_binary = compile_job.get_target_model()<br><br># 3. Profile on the real phone<br>profile_job = hub.submit_profile_job(<br>    model=device_binary,<br>    device=hub.Device(&quot;Samsung Galaxy S23&quot;),<br>)<br>profile = profile_job.download_profile()<br><br># 4. Validate numerical parity vs the float source<br># PSNR(cloud_outputs, device_outputs) &gt; 30 dB means shippable</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s2pb1yCkYTzZ2FOJfp2mKg.png" /></figure><p>The profile is the thing you actually read. It tells you which compute unit each op landed on. The goal: every op on the NPU. If you see one CPU hop in the middle of the graph, that one op is eating your 10x advantage.</p><p>PSNR &gt; 30 dB between cloud and device outputs is the shippability gate for perception tasks. Run it per device. The 300+ phone matrix is the actual test set, not your laptop.</p><p>Pick the right runtime for the target. TFLite on Android. ONNX on Windows. QNN for fully embedded Qualcomm targets. Three formats, three toolchains, one artifact each. Don’t try to ship one universal binary. That’s the road to months of op-compatibility pain.</p><h3>What still breaks teams</h3><p>The model is not the problem. Say that three ways.</p><p><strong>A single CPU fallback op kills NPU throughput.</strong> The compiler assigns each op a compute unit. If one op isn’t supported on the NPU, it falls back to CPU, and the tensor has to bounce. One bounce in the middle of the graph means CPU to NPU to CPU to NPU. You just lost the speedup. The fix is either rewriting the op with a supported primitive, or accepting the performance cliff.</p><p>Most teams don’t even realize this is happening. The overall latency looks okay, the benchmark is “fast enough”, and the mystery is why the NPU utilization chart has a gap in the middle. The gap is the bounce.</p><p><strong>Preprocess on CPU turns 6 ms of inference into 300 ms of UX.</strong> Teams benchmark the model alone, hit 6 ms, and think they’re done. Then the production pipeline has a CPU-side YUV-to-RGB resize that takes 300 ms per frame and the app feels broken.</p><p>Move preprocess to the GPU. OpenCV’s GPU ops are the default answer. The same holds for postprocess: upsample, threshold, blur, alpha composite, all on the GPU, all on the same frame.</p><p><strong>Long contexts blow memory budgets phones don’t have.</strong> Gemma 4’s 128K context is a ceiling, not a floor. Attention memory scales with context length. A real phone has 6 to 12 GB of RAM, shared with the OS and every other app. Running a 4B LLM with a 128K fill is theoretical, not practical. Ship with shorter real-world context windows and accept that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JtGajXjFgW0bDkl6vAw1PA.png" /></figure><h3>When on-device is the wrong answer</h3><p>Not every workload belongs on the phone. Two cases where cloud still wins cleanly.</p><p>Workloads that need fresh data the device doesn’t have. A product search against a catalog that updates every minute is a cloud call. Trying to ship a daily-updated embedding index to every phone is a bad idea.</p><p>Workloads where the user already pays for latency. A document analysis that runs once, waits a second, returns a result. Users already swallowed the round trip. There’s no UX win for cramming it onto a phone, and on-device inference will cost you engineering weeks.</p><p>On-device earns its keep when latency is real-time, privacy is load-bearing, or per-request cost doesn’t amortize. Camera effects, keyboard prediction, audio denoise, conversational assistants on low-context tasks. Everything else is a calculation.</p><h3>The part nobody talks about</h3><p>On-device AI isn’t a model problem. It’s a pipeline problem.</p><p>The interesting work in 2026 isn’t making the model smaller. Gemma 4 is already small enough. The interesting work is the system around it: keeping every op on the NPU, keeping every preprocess on the GPU, keeping the context window short enough to avoid swap, keeping the profile green across 300 devices.</p><p>The teams that ship are the teams that treat the model as one node in a pipeline, not as the product.</p><p>That’s a reframe, and it matters. Most orgs staff an ML team and a mobile team and expect the handoff to work. It doesn’t. The people who understand quantization don’t own the camera pipeline. The people who own the camera pipeline don’t understand why the NPU falls back. The bug lives in the seam, and the seam has no owner.</p><p>The fix is organizational, not technical. One team owns the full pipeline from tensor input to pixel output. Anything less and you ship demos.</p><p>Phones didn’t get smarter. The deployment stack did. The real question now isn’t “can we run this model on a phone.” It’s “can we keep the pipeline green when three other apps are also running a model, the battery is at 20%, and the user is on a mid-range Xiaomi from 2022.”</p><p>That’s a systems question. And systems questions are how on-device AI becomes an actual product instead of a benchmark.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19e4d4bd20ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>