无状态 MCP 重新引起了我的兴趣

Stateless MCP has recaptured my interest

西蒙·威利森 Simon Willison · 2026-07-31 · Simon Willison's Weblog ↗

打开互动全文版(逐段中英对照 + 针对本篇提问)→

摘要 · Abstract

赞助方:AWS——利用覆盖技术栈每一层的 ISV 资源,从 SaaS 迈向 Agentic SaaS。探索面向 ISV 的 AI 如何将愿景转化为成果。

Sponsored by: AWS — Move from SaaS to Agentic SaaS with resources for ISVs at every layer of the stack. Explore how AI for ISVs turns vision into results

核心贡献 · Key contributions

局限 · Limitations

章节 · Sections(共 6)

全文 · Full text(逐段中英对照)

无状态 MCP 重新点燃了我的兴趣(并催生了 mcp-explorer 与 datasette-mcp) Stateless MCP has recaptured my interest (and inspired mcp-explorer and datasette-mcp)

周二是“无状态 MCP 日”——MCP 2.0 正式发布,若用更正式却更难记的名字,则是 2026-07-28 Model Context Protocol 规范。这是 MCP 规范自首次发布以来最重大的变更,也重新点燃了我个人对这一协议的兴趣。

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.

背景介绍:MCP 即 Model Context Protocol(模型上下文协议),它描述了一种将新工具暴露给由 LLM 驱动的智能体框架的标准方式。它由 Anthropic 于 2024 年 11 月推出,在 2025 年的大部分时间里经历了**巨大**的关注度飙升,随后在人们逐渐意识到——一个能访问终端和 curl 的智能体运行框架(agent harness)可以以更灵活的方式完成 MCP 的大部分功能——之后,某种程度上被 Skills(Anthropic 的另一项发明)所盖过。我在我的 2025 年回顾中写过这一点。

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.

如今我又重新转向 MCP。给智能体一个可访问互联网的 shell 环境充满风险,并且需要一个足够强大的模型才能有效驾驭这样的环境。MCP 工具更易于审计和控制,而且足够简单,以至于在笔记本电脑上运行的小模型也能相当好地驱动它们。

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.

新的无状态 MCP 规范还大幅降低了为该协议实现客户端和服务端的复杂度。这周我就构建了三个!

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!

无状态 MCP 的便利之处 What’s easier with stateless MCP

有状态与无状态 MCP 之间差异的最佳演示,出现在 5 月 21 日介绍新规范候选发布版(RC)的博客文章中。该文章包含了一个清晰的改进前后对比示例。

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.

较旧的有状态 MCP(我将称之为“传统 MCP”)需要两个 HTTP 请求——第一个用于初始化会话并获取 Mcp-Session-Id,第二个用于实际调用工具:

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:

新的无状态方式使用单个 HTTP 请求,如下所示:

The new stateless way uses a single HTTP request which looks like this:

从客户端和服务端的实现角度来看,这要简洁得多。它也更适合构建可扩展的 Web 应用程序,因为现在你不需要维护服务器端状态来跟踪那些会话 ID,也不必担心将同一会话路由到同一台后端机器。

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.

mcp-explorer mcp-explorer

我找不到一个理想的 CLI 工具来交互式地探查 MCP 服务器,于是让 Codex 帮我构建了一个自己的工具。

I couldn't find a great CLI tool for interactively probing an MCP server, so I had Codex help build my own.

mcp-explorer 就是这一成果。它是一个无状态的 Python CLI 工具,因此你甚至无需安装即可试用——它可以像下面这样通过 uvx 运行:

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:

uvx mcp-explorer list https://agentic-mermaid.dev/mcp

uvx mcp-explorer list https://agentic-mermaid.dev/mcp

这条命令查询的是 Ade Oshineye 的 agentic-mermaid.dev 演示 MCP。上述命令会返回以下工具列表:

This queries Ade Oshineye's agentic-mermaid.dev demo MCP. The above command returns the following list of tools:

execute(code: string, timeoutMs?: integer) - 执行 Mermaid SDK 代码

execute(code: string, timeoutMs?: integer) - Execute Mermaid SDK code

在隔离沙箱中运行 JavaScript;返回一个值。

Run JavaScript in an isolated sandbox; return a value.

describe_sdk(family: string, detail?: string) - 描述 Mermaid SDK 操作

describe_sdk(family: string, detail?: string) - Describe Mermaid SDK operations

返回针对某一图表族、与版本匹配的变更操作。

Return version-matched mutation operations for one diagram family.

render_svg(source: string, options?: object) - 将 Mermaid 渲染为 SVG

render_svg(source: string, options?: object) - Render Mermaid as SVG

将 Mermaid 源字符串渲染为可主题化的 SVG。返回 { ok, svg }。

Render a Mermaid source string to themeable SVG. Returns { ok, svg }.

render_ascii(source: string, useAscii?: boolean, targetWidth?: integer, options?: object)——将 Mermaid 渲染为文本

render_ascii(source: string, useAscii?: boolean, targetWidth?: integer, options?: object) - Render Mermaid as text

将 Mermaid 源字符串渲染为文本。返回 { ok, text }。

Render a Mermaid source string to text. Returns { ok, text }.

render_png(source: string, scale?: number, background?: string, fitTo?: object, options?: object)——将 Mermaid 渲染为 PNG

render_png(source: string, scale?: number, background?: string, fitTo?: object, options?: object) - Render Mermaid as PNG

将 Mermaid 源字符串栅格化为 PNG。返回 { ok, png_base64 }。

Rasterize a Mermaid source string to PNG. Returns { ok, png_base64 }.

这会输出大量信息,包括输入和输出的 JSON schema。

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:

{"ok":true,"svg":"<svg xmlns=\"http://www.w3.org/2000/svg\" width=...

{"ok":true,"svg":"<svg xmlns=\"http://www.w3.org/2000/svg\" width=...

要只获取原始 SVG,可尝试在该命令后加上 \(| jq .svg -r\)。我得到了这张图片:

To get just the raw SVG, try adding \(| jq .svg -r\) to that command. I got back this image:

datasette-mcp datasette-mcp

第二个项目是 datasette-mcp,这是一个 Datasette 插件,可为任意 Datasette 实例添加一个 /-/mcp 端点。

The second project is datasette-mcp, a Datasette plugin which adds a /-/mcp endpoint to any Datasette instance.

这大概是我第四次尝试构建这个插件,但得益于新的无状态 MCP 规范,我终于有了一个感觉可以放心发布的版本。

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.

它只提供三个工具:list_databases()、get_database_schema(database_name)和 execute_sql(database_name, sql)。它们的行为完全符合你的预期——不过 execute_sql() 目前是只读的。

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.

将这些工具接入一个智能体,或像 ChatGPT、Claude 这样的聊天工具,它们就能对你托管的 Datasette 实例执行 SQL 查询。

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.

目前我把它运行在我博客的 Datasette 镜像上,地址是 datasette.simonwillison.net/-/mcp。把它接入 ChatGPT 和 Claude 花了我一番折腾,但最终我还是搞定了。这里有一篇新的 TIL,详细展示了具体做法。

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.

以下是我向它提问的一个共享 Claude 会话:

Here's a shared Claude session where I asked it:

列出 simonwillison.net 中的表

list tables in simonwillison.net

Simon 最近关于 MCP 说了什么?

what has Simon said recently about MCP?

它运行了 7 条独立的 SQL 查询来得出答案。

It ran 7 separate SQL queries to figure out the answer.

LLM MCP 客户端 llm-mcp-client

我的 LLM 工具早就该有官方的 MCP 集成了。新的 alpha 版 llm-mcp-client 插件正是我为此所做的尝试:

My LLM tool is long overdue for an official MCP integration. The new alpha llm-mcp-client plugin is my attempt at exactly that:

llm -T 'MCP("https://datasette.simonwillison.net/-/mcp")' 'count the notes'

llm -T 'MCP("https://datasette.simonwillison.net/-/mcp")' 'count the notes'

以下是输出(包含推理轨迹,我使用的是 LLM 0.32rc2):

Here's the output (including reasoning trace, I'm using LLM 0.32rc2):

_考虑笔记数量_

_Considering note count_

_我看到问题“count the notes”很可能是在要求我统计博客笔记的数量。它也可能指已发布的笔记或草稿,因此这里存在一些歧义。我需要弄清楚笔记的总数,可能是通过分别查询已发布笔记和草稿的数量来得到一个清晰的答案。让我们执行这个统计吧!_

_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!_

共有 151 条笔记。

There are 151 notes.

以及该提示对应的 llm 日志输出。

And the output of llm logs for that prompt.

一旦这一功能完全成熟,我考虑将其直接并入 LLM 核心。我也很期待在 Datasette Agent 和 llm-coding-agent 中试验 MCP。

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.

MCP 是构建智能体更安全的方式 MCP is a safer way to build with agents

在 MCP 首次发布几个月后,我写了《Model Context Protocol 存在提示注入安全问题》一文,其中指出:让最终用户自行混搭工具的模式,把避免数据外泄攻击的责任推给了用户自己。当时我还没有提出“致命三要素”(Lethal Trifecta)这一说法,但那绝对就是我所考虑的问题。

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.

后来,具备任意 shell 和 curl 访问权限的通用智能体出现了,而要让这类智能体保持安全就难得多!

Then general agents with arbitrary shell and curl access came along, and that's so much harder to keep secure!

我逐渐认识到 MCP 的一个优点:与在开放网络环境中执行任意命令(这是当今大多数通用智能体和编程智能体工具的默认方式)相比,借助 MCP 更容易推理智能体的能力以及可能出现的问题。

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.

当我在 LLM 之上构建敏感应用时,我打算更多地依赖 MCP。

I plan to lean into MCP a whole lot more when I'm building sensitive applications on top of LLMs.

互动版:针对本篇提问 →

接着读 · Read next