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,簡化 LLM 工具調用的實作門檻
TL;DR:MCP 2.0 引入無狀態(Stateless)規範,將兩次 HTTP 請求簡化為一次,大幅降低開發複雜度。
隨著 AI Agent 框架日益成熟,如何讓大型語言模型(LLM)安全且高效地存取外部工具,已成為工程師關注的核心。2026 年 7 月 28 日,Model Context Protocol (MCP) 發布了 2.0 規範,這項由 Anthropic 推出的標準,旨在定義一種標準化的方式,讓 Agent 框架能輕鬆擴充新工具。
🤔 從複雜的 Session 管理,進化到單次請求的簡潔
在舊版的「有狀態(Stateful)」MCP 規範(作者稱之為 Legacy MCP)中,開發者必須處理複雜的會話狀態。一個典型的工具調用需要兩次 HTTP 請求:
- 第一次:初始化會話並取得
Mcp-Session-Id。 - 第二次:使用該 ID 來實際呼叫工具。
而在全新的「無狀態(Stateless)」MCP 2.0 規範中,整個流程被簡化為單次 HTTP 請求。這對工程師而言有兩大好處:
- 實作更簡單:無論是客戶端還是伺服器端,程式碼邏輯都變得更乾淨。
- 更適合擴展 Web 應用:開發者不再需要維護伺服器端的 Session ID,也不用擔心路由問題(例如確保同一個會話必須連到同一個後端機器)。
🧩 更安全且低門檻的工具調用方式
雖然讓 Agent 直接擁有終端機(Shell)與 curl 的權限看起來更靈活,但這也帶來了極高的安全風險,且需要極強的模型能力才能穩定操作。
相比之下,使用 MCP 規範的優勢在於:
- 易於審核與控制:比起隨機的指令執行,MCP 工具的行為更容易預期。
- 對小模型友善:由於介面簡單,即便是在筆電上運行的輕量化模型,也能夠流暢地驅動 MCP 工具。
📊 實踐成果:從 CLI 工具到資料庫插件
作者透過這次規範更新,快速開發了三個實用的工具來驗證新規範的威力:
-
mcp-explorer 這是一個無狀態的 Python CLI 工具,讓開發者可以互動式地探測 MCP 伺服器。開發者可以直接使用
uvx執行,無需安裝,即可查詢工具列表、JSON Schema 以及輸出結果(例如直接取得 SVG 圖片)。 -
datasette-mcp 這是一個 Datasette 插件,為任何 Datasette 實例增加
/mcp端點。它提供三個核心工具:list_databases()、get_database_schema()以及execute_sql()(目前僅限唯讀)。這讓 LLM 能直接對託管的資料庫進行 SQL 查詢。 -
llm-mcp-client 作者嘗試將 MCP 直接整合進
llm工具中,讓模型在執行任務時,能透過推理過程(Reasoning trace)來決定並執行相關的 SQL 查詢。
🎯 實務啟示
對於正在構建 AI Agent 的工程師來說,MCP 2.0 的無狀態化標誌著「工具化」標準的成熟。當工具調用變得像單純的 API 請求一樣簡單時,我們應該更專注於如何定義更精準的工具介面,並利用其安全性優勢,將 LLM 應用於處理更敏感的業務邏輯。
🔗 來源
- 標題:Stateless MCP has recaptured my interest (and inspired mcp-explorer and datasette-mcp)
- 作者/機構:Simon Willison
- 連結:simonwillison.net/2026/Jul/31/stateless-mcp/
#AI #MCP #LLM #Anthropic #AgenticWorkflow #SoftwareEngineering #Python #DataScience #API #MachineLearning
原始資料 Simon Willison · 收集於 2026-08-01
摘要原文
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 . 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 自動生成