Stateless MCP has recaptured my interest (and inspired mcp-explorer and datasette-mcp)
https://simonwillison.net/2026/Jul/31/stateless-mcp/📌 【MCP 2.0 規格更新】從 Stateful 轉向 Stateless,開發者為何重新看好 Model Context Protocol?
TL;DR:MCP 2.0 透過無狀態(Stateless)設計簡化開發流程,並在安全性與效能上優於直接給予 Agent 終端機權限。
隨著 Agent 技術不斷演進,如何安全且高效地讓 LLM 使用外部工具(Tools)一直是核心議題。儘管先前有人認為「給予 Agent 終端機與 curl 權限」更具靈活性,但 Simon Willison 指出,這種做法隱含極高的安全風險,且需要極強的模型能力才能穩定操作。相比之下,Model Context Protocol (MCP) 提供了更易於稽核與控制的標準化方式,讓即便是在筆電上運行的輕量化模型也能流暢驅動工具。
🧩 從兩次請求縮減至一次:Stateless MCP 的技術優勢
MCP 2.0(正式名稱為 2026-07-28 Model Context Protocol specification)最重大的改變在於從「有狀態」(Stateful)轉向「無狀態」(Stateless)的架構設計。
- Legacy MCP (Stateful): 實作複雜,開發者必須處理會話狀態。
- Step 1:發送第一個 HTTP 請求以初始化會話並取得
Mcp-Session-Id。 - Step 2:發送第二個 HTTP 請求來實際呼叫工具。
- Step 1:發送第一個 HTTP 請求以初始化會話並取得
- New MCP (Stateless): 流程極簡,僅需單一 HTTP 請求即可完成呼叫。
這種設計對工程師而言有兩大好處:首先,大幅降低了客戶端(Client)與伺服器端(Server)的實作複雜度;其次,由於不再需要維護伺服器端的 Session ID,這對於需要高擴展性的 Web 應用程式來說,是更理想的架構,開發者不再需要擔心路由問題或 Session 狀態同步。
📊 實踐成果:從 CLI 工具到資料庫插件
為了驗證新規格的易用性,作者在短時間內開發了多個專案:
- mcp-explorer:一個無狀態的 Python CLI 工具,用於互動式探測 MCP 伺服器。
- 透過
uvx即可直接執行,無需安裝。 - 能回傳完整的 JSON Schema(包含輸入與輸出定義)。
- 透過
- datasette-mcp:為 Datasette 實例新增
/-/mcp端點的插件。- 提供
list_databases()、get_database_schema()與execute_sql()三種工具。 - 目前
execute_sql()僅支援唯讀操作。 - 透過整合,LLM 可以透過執行多次 SQL 查詢來回答複雜問題(例如:查詢某人最近關於 MCP 的言論)。
- 提供
💡 安全性思考:為何 MCP 比 Shell 環境更安全?
在開發 Agent 時,安全性是首要考量。讓 Agent 在開放網路環境中執行任意命令(Command Execution)是非常危險的,這會將數據外洩的風險直接推給終端用戶。
作者認為,與「給予 Agent 終端機與網路存取權限」相比,使用 MCP 能讓開發者更容易理解與推理 Agent 的能力範圍,並能更精準地控制其權限,這對於構建敏感的應用程式至關重要。
🎯 實務啟示
如果你正在開發基於 Agent 的應用程式,且需要模型與外部資料或工具互動,MCP 2.0 的無狀態特性提供了一個更輕量、更易於擴展且更安全的標準方案。對於需要高度控制權的生產環境,比起開放 Shell 權限,使用結構化的 MCP 工具集是更穩健的選擇。
🔗 來源
- 標題:Stateless MCP has recaptured my interest (and inspired mcp-explorer and datasette-mcp)
- 作者/機構:Simon Willison
- 連結:https://simonwillison.net/2026/Jul/31/stateless-mcp/
#MCP #LLM #Agent #MachineLearning #SoftwareEngineering #Anthropic #Stateless #API #Python #DeveloperTools
原始資料 Simon Willison · 收集於 2026-08-09
摘要原文
Tuesday was Stateless MCP day —the rollout of MCP 2.0, or the 2026-07-28 Model Context Protocol specification to use the more formal but less memorable name. This is the most significant change to the MCP spec since it first launched, and has also served to reignite my personal interest in the protocol. For background: MCP is the Model Context Protocol, which describes a standard way to expose new tools to LLM-powered agent frameworks. It was introduced by Anthropic back in November 2024 , had a huge spike of interest through much of 2025, and then became somewhat eclipsed by Skills (another Anthropic invention) when it became apparent that an agent harness with access to a terminal and curl could do most of what MCP did in a more flexible way. I wrote about that in my review of 2025 . I’m coming back around to MCP now. Giving an agent a shell environment with the ability to access the internet is fraught with risk , and requires a strong model that is capable of effectively driving such an environment. MCP tools are easier to audit and control, and simple enough that smaller models that run on a laptop can still drive them reasonably well. The new stateless MCP specification also greatly decreases the complexity of implementing both clients and servers for the protocol. I built three of those this week! The best demonstration of the difference between stateful and stateless MCP is in this May 21st blog post that introduced the RC for the new specification. It included a clear before-and-after example. The older stateful MCP (I’m going to call it “legacy MCP”) required two HTTP requests—the first to initialize a session and obtain a Mcp-Session-Id , and the second to actually call the tool: The new stateless way uses a single HTTP request which looks like this: This is so much cleaner from both a client- and server-side implementation perspective. It’s also a better fit for building scalable web applications, since now you don’t need to maintain server-side state to keep track of those session IDs, or worry about routing the same session to the same backend machine. I couldn’t find a great CLI tool for interactively probing an MCP server, so I had Codex help build my own. mcp-explorer is the result. It’s a stateless Python CLI tool, so you don’t even need to install it to try it out—it works with uvx like this: This queries Ade Oshineye’s agentic-mermaid.dev demo MCP. The above command returns the following list of tools: This outputs a whole bunch of information, including the JSON schema of the inputs and outputs. To call that tool and pass arguments to it: To get just the raw SVG try adding | jq .svg -r to that command. I got back this image : There are a few more commands in the README, but you get the general idea. I find building CLI tools like this to be a really productive way to get familiar with a specification, even if an agent writes most of the actual code. The second project is datasette-mcp , a Datasette plugin which adds a /-/mcp endpoint to any Datasette instance. This is probably the fourth time I’ve tried building this plugin, but thanks to the new stateless MCP specification I finally have a version that feels good to release. It provides just three tools: list_databases() , get_database_schema(database_name) , and execute_sql(database_name, sql) . They do exactly what you would expect them to do—though execute_sql() is read-only for the moment. Wire these into an agent, or a chat tool like ChatGPT or Claude, and they’ll gain the ability to run SQL queries against your hosted Datasette instance. So far I’m running it on the Datasette mirror of my blog, at datasette.simonwillison.net/-/mcp . It took a bit of fiddling to figure out how to attach that to ChatGPT and Claude, but I got there in the end. Here’s a new TIL showing exactly how to do that. Here’s a shared Claude session where I asked it: list tables in simonwillison.net what has Simon said recently about MCP? It ran 7 separate SQL queries to figure out the answer. My LLM tool is long overdue for an official MCP integration. The new alpha llm-mcp-client plugin is my attempt at exactly that: Here’s the output (including reasoning trace, I’m using LLM 0.32rc2 ): I see the question “count the notes” is probably asking me to tally up blog notes. It could also mean published notes or drafts, so there’s some ambiguity there. I’ll need to figure out the total number of notes, likely by querying the count for both published notes and drafts to get a clear answer. Let’s execute that count! And the output of llm logs for that prompt. Once this is fully baked, I’m considering bringing it directly into LLM core. I’m excited to experiment with MCP in Datasette Agent and llm-coding-agent as well. A few months after MCP was first released, I wrote Model Context Protocol has prompt injection security problems , where I noted that the pattern of having end users mix and match tools pushed responsibility for avoiding data exfiltration attacks out to the users themselves. I hadn’t coined the Lethal Trifecta yet, but that was absolutely what I had in mind. Then general agents with arbitrary shell and curl access came along, and that’s so much harder to keep secure! Something I’ve come to appreciate about MCP is that it’s much easier to reason about agent capabilities and what might go wrong than with arbitrary command execution in an open network environment—the default for most of today’s general and coding agent tools. I plan to lean into MCP a whole lot more when I’m building sensitive applications on top of LLMs. This is Stateless MCP has recaptured my interest (and inspired mcp-explorer and datasette-mcp) by Simon Willison, posted on 31st July 2026 . Next: New release of LLM adds support for reasoning traces, OpenAI Responses, server-side tools, and smarter logging Previous: OpenAI’s accidental cyberattack against Hugging Face is science fiction that happened Sponsor me for $10/month and get a curated email digest of the month's most important LLM developments.
由 tencent/hy3:free 自動生成