mcp
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSpacetimeDB over MCP
通过 MCP 使用 SpacetimeDB
A SpacetimeDB host speaks MCP, so an MCP-aware client can operate a live database with tool calls
instead of shell commands. If the client exposes tools, use them for anything that
reads or changes a running database.
spacetimedbCheck the tool list before deciding they are missing. The tools are passive: they appear as
, , , , and
, and nothing announces them.
spacetimedb.list_databasesspacetimedb.get_schemaspacetimedb.sqlspacetimedb.callspacetimedb.pingSpacetimeDB 主机支持 MCP,因此支持 MCP 的客户端可以通过工具调用而非 shell 命令来操作实时数据库。如果客户端公开了 工具,对于任何读取或修改正在运行的数据库的操作,都应使用这些工具。
spacetimedb在判断这些工具是否缺失之前,请先检查工具列表。这些工具是被动提供的:它们以 、、、 和 的形式出现,不会主动通知其存在。
spacetimedb.list_databasesspacetimedb.get_schemaspacetimedb.sqlspacetimedb.callspacetimedb.pingWhich to reach for
该使用哪种方式
| Task | Use |
|---|---|
| List databases, read a schema, run SQL, call a reducer | MCP tools |
| init, build, publish, generate, start, logs | |
The MCP tools only operate a database that already exists. They cannot scaffold a project, compile a
module, publish, or generate bindings, so the two are complementary rather than alternatives. Prefer
the tools when they are present: they are typed, they return JSON, and the client can gate the
destructive ones. When no MCP client is attached, the equivalent CLI commands are correct.
| 任务 | 使用方式 |
|---|---|
| 列出数据库、读取 schema、执行 SQL、调用 reducer | MCP 工具 |
| init、build、publish、generate、start、logs | |
MCP 工具只能操作已经存在的数据库。它们无法创建项目脚手架、编译 module、publish 或生成 bindings,因此两者是互补关系,而不是替代关系。如果存在这些工具,应优先使用:它们的类型明确、返回 JSON,并且客户端可以对破坏性工具设置访问限制。未连接 MCP 客户端时,使用对应的 CLI 命令才是正确做法。
The tools
工具
| Tool | Arguments | Returns |
|---|---|---|
| none | the databases you own, with identity and names |
| | tables and reducers as JSON |
| | rows as JSON |
| | the reducer outcome |
| optional | a health check |
list_databases| 工具 | 参数 | 返回值 |
|---|---|---|
| 无 | 你拥有的数据库,包含身份和名称 |
| | 以 JSON 形式返回表和 reducer |
| | 以 JSON 形式返回数据行 |
| | reducer 的执行结果 |
| 可选的 | 健康检查结果 |
list_databasesTwo shapes, so read tools/list
first
tools/list两种模式,因此先读取 tools/list
tools/listA server is either host-wide or scoped to one database. Do not assume which:
Host-wide ( with no database, or ). Every data tool takes a required
argument, a name or an identity, and is offered:
spacetime mcpPOST /v1/mcpdatabaselist_databasesjson
{ "name": "sql", "arguments": { "database": "mydb", "sql": "SELECT * FROM message" } }Scoped (, or ). The connection fixes the
database, so there is no argument and no :
spacetime mcp <database>POST /v1/database/<db>/mcpdatabaselist_databasesjson
{ "name": "sql", "arguments": { "sql": "SELECT * FROM message" } }When runs inside a project with a that has a single unambiguous
, it uses that server unless or is passed. It does not infer a
database from the config; omitting the database argument still means host-wide mode.
spacetime mcpspacetime.jsonserver--server--no-config服务器可以是主机级(host-wide),也可以限定到单个数据库(scoped)。不要假设服务器属于哪一种:
主机级(host-wide)(使用不带数据库的 ,或 )。每个数据工具都需要必填的 参数,该参数可以是名称或 identity,并且会提供 :
spacetime mcpPOST /v1/mcpdatabaselist_databasesjson
{ "name": "sql", "arguments": { "database": "mydb", "sql": "SELECT * FROM message" } }限定到单个数据库(scoped)(使用 ,或 )。连接已经确定了数据库,因此不需要 参数,也不会提供 :
spacetime mcp <database>POST /v1/database/<db>/mcpdatabaselist_databasesjson
{ "name": "sql", "arguments": { "sql": "SELECT * FROM message" } }如果在包含 的项目中运行 ,并且配置中只有一个明确无歧义的 ,那么它会使用该 server,除非传入 或 。它不会根据配置推断数据库;省略数据库参数仍然表示主机级模式。
spacetime.jsonspacetime mcpserver--server--no-configRules that do not change
始终不变的规则
The tools run with your identity, exactly as the HTTP API does. The model is the same as everywhere
else, so the skill still governs:
concepts- Reducers are the write path. Use to change data. It runs in a transaction that either fully commits or fully rolls back.
call - SQL writes require ownership. reads public tables; writing through it needs you to own the database. Prefer
sql.call - Private tables are not client-readable. still shows a private table's declaration, so a
get_schemaerror fromno such tableusually means the table is private rather than missing. Access depends on your identity, so do not assume a private table is readable.sql - Tool errors come back in band. A failed reducer or a bad query returns a result with
and the message as text, not a transport failure. Read the text before retrying.
isError: true
这些工具使用你的身份运行,与 HTTP API 完全一致。这里的模型与其他地方使用的模型相同,因此仍由 skill 负责约束:
concepts- Reducer 是写入路径。 使用 修改数据。它在事务中运行,事务要么完全提交,要么完全回滚。
call - 通过 SQL 写入需要数据库所有权。 可以读取 public 表,但通过它写入需要你拥有该数据库。优先使用
sql。call - 私有表对客户端不可读。 仍会显示私有表的声明,因此
get_schema返回sql错误通常意味着该表是私有的,而不是不存在。访问权限取决于你的身份,因此不要假设私有表可读。no such table - 工具错误会带内返回。 reducer 执行失败或查询无效时,返回的是一个包含 且以文本形式提供消息的结果,而不是传输层失败。重试前应先读取文本消息。
isError: true
Inspecting a database
检查数据库
list_databases {}
get_schema { "database": "mydb" }
sql { "database": "mydb", "sql": "SELECT * FROM message" }
call { "database": "mydb", "reducer": "send_message", "args": ["hello"] }Pass to to wait for a durably confirmed read.
"confirmed": truesqllist_databases {}
get_schema { "database": "mydb" }
sql { "database": "mydb", "sql": "SELECT * FROM message" }
call { "database": "mydb", "reducer": "send_message", "args": ["hello"] }向 传入 ,即可等待获得持久化确认的读取结果。
sql"confirmed": trueTroubleshooting
故障排查
| Message | Meaning |
|---|---|
| The server is host-wide and you omitted |
| The server is scoped to one database already |
| No such database on this server, or a name where an identity was meant |
| The table is private, or you are querying the wrong database |
No | No MCP server is connected. Use the CLI instead ( |
spacetime mcpcliReference: https://spacetimedb.com/docs
| 消息 | 含义 |
|---|---|
| 服务器为主机级模式,但你省略了 |
| 服务器已经限定到单个数据库 |
| 此服务器上不存在该数据库,或者应使用 identity 的地方使用了名称 |
| 该表是私有表,或者你查询了错误的数据库 |
完全没有 | 未连接 MCP 服务器。请改用 CLI( |
spacetime mcpcli