-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprotocol.html
More file actions
343 lines (320 loc) · 16.8 KB
/
protocol.html
File metadata and controls
343 lines (320 loc) · 16.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Protocol Design - S2SP Protocol</title>
<link rel="stylesheet" href="../css/style.css">
</head>
<body>
<nav class="nav">
<div class="nav-inner">
<a href="../index.html" class="nav-logo">
<img src="../images/s2sp_icon.png" class="logo-icon" alt="S2SP">
S2SP Protocol
</a>
<ul class="nav-links">
<li><a href="../index.html">Home</a></li>
<li><a href="introduction.html">Docs</a></li>
<li><a href="protocol.html" class="active">Protocol</a></li>
<li><a href="sdk.html">SDK</a></li>
<li><a href="demos.html">Examples</a>
</li>
</ul>
</div>
</nav>
<div class="doc-layout">
<aside class="sidebar">
<div class="sidebar-section">
<h4>Getting Started</h4>
<a href="introduction.html">Introduction</a>
<a href="introduction.html#quick-start">Quick Start</a>
</div>
<div class="sidebar-section">
<h4>Learn</h4>
<a href="protocol.html" class="active">Protocol Design</a>
<a href="#data-model" class="sub">Data Model</a>
<a href="#two-planes" class="sub">Two Planes</a>
<a href="#async-mode" class="sub">Async Mode</a>
<a href="#sync-mode" class="sub">Sync Mode</a>
<a href="#data-plane-endpoint" class="sub">Data Plane Endpoint</a>
<a href="#security" class="sub">Security</a>
</div>
<div class="sidebar-section">
<h4>Develop</h4>
<a href="sdk.html">Python SDK</a>
</div>
<div class="sidebar-section">
<h4>Examples</h4>
<a href="demos.html">Agent Development with S2SP</a>
<a href="tutorial.html">Use S2SP Servers in Claude</a>
</div>
</aside>
<main class="doc-content">
<h1>Protocol Design</h1>
<p>
S2SP divides data communication between an AI agent and MCP servers into a
<strong>control plane</strong> (what the LLM sees) and a <strong>data plane</strong>
(what flows between servers or through the agent's SDK without entering the LLM context).
</p>
<h2 id="data-model">Data Model</h2>
<p>
S2SP applies to MCP tools that return <strong>structured tabular data</strong> —
like a pandas DataFrame: <em>n</em> rows × <em>w</em> columns. Each row is a
data sample with several column fields.
</p>
<p>
The columns are divided into two groups at call time by the agent:
</p>
<ul>
<li><strong>Abstract domains</strong> (control plane): Columns the LLM needs for
reasoning and decision-making. These are returned to the agent.</li>
<li><strong>Body domains</strong> (data plane): Remaining columns. These bypass
the LLM — either cached on the resource server (async) or passed through
the agent's SDK layer (sync) without entering the LLM context.</li>
</ul>
<p>
Every row gets an auto-generated <code>_row_id</code> (integer index: 0, 1, 2, ...),
used to reconcile abstract and body when merging later.
</p>
<div class="code-block">
<pre><span class="comment"># A tool returns 30 columns per row. Agent requests only 4:</span>
get_alerts(area=<span class="string">"CA"</span>, abstract_domains=<span class="string">"event,severity,urgency,status"</span>)
<span class="comment"># Response (control plane):</span>
{
<span class="string">"total_rows"</span>: 14,
<span class="string">"abstract_domains"</span>: [<span class="string">"event"</span>, <span class="string">"severity"</span>, <span class="string">"urgency"</span>, <span class="string">"status"</span>],
<span class="string">"body_domains"</span>: [<span class="string">"description"</span>, <span class="string">"instruction"</span>, ... <span class="comment">26 more</span>],
<span class="string">"abstract"</span>: [
{<span class="string">"_row_id"</span>: 0, <span class="string">"event"</span>: <span class="string">"Wind Advisory"</span>, <span class="string">"severity"</span>: <span class="string">"Moderate"</span>, ...},
{<span class="string">"_row_id"</span>: 1, <span class="string">"event"</span>: <span class="string">"Flood Watch"</span>, <span class="string">"severity"</span>: <span class="string">"Minor"</span>, ...},
...
],
<span class="string">"resource_url"</span>: <span class="string">"http://host:port/s2sp/data/dK7x_..."</span> <span class="comment">// async mode only (presigned URL)</span>
}</pre>
</div>
<h2 id="two-planes">Two Planes</h2>
<h3>Control Plane</h3>
<p>
The control plane uses standard MCP tool calls. The agent calls an
<code>@s2sp_resource_tool()</code>-decorated tool with <code>abstract_domains</code> to
specify which columns it needs. The response contains only those columns +
<code>_row_id</code>. The agent uses this lightweight data to filter, reason,
and decide which rows matter — then tells a consumer server what to do.
</p>
<h3>Data Plane</h3>
<p>
The data plane carries body domains. It operates differently depending on the mode:
</p>
<ul>
<li><strong>Async mode</strong> — Direct HTTP between servers. Body data is
cached on the resource server. A consumer server fetches it via
a <code>POST</code> request to the presigned <code>resource_url</code>. The agent has no visibility into
this channel. Data flows server-to-server only.</li>
<li><strong>Sync mode</strong> — Data channel through the agent. Body data
is returned inline alongside the abstract in a single tool response. The body
passes through the agent's SDK layer but is <em>not</em> sent to the LLM —
only the abstract enters the LLM context. No server-to-server fetch needed.</li>
</ul>
<h2 id="async-mode">Async Mode (default)</h2>
<p>
Body data is cached on the resource server. The response includes
<code>resource_url</code> but no body.
</p>
<ol>
<li>Agent calls <code>get_alerts(area="CA", abstract_domains="event,severity", mode="async")</code></li>
<li>Resource server fetches all data, assigns <code>_row_id</code> to each row, caches full data</li>
<li>Returns abstract rows + <code>resource_url</code> (no body)</li>
<li>Agent filters on abstract, selects rows, passes abstract + resource ref to consumer</li>
<li>Consumer calls <code>POST /s2sp/data/{resource_url}</code> on resource server with <code>{"row_ids": [...]}</code></li>
<li>Source returns full data for selected rows. Agent never saw it.</li>
</ol>
<div class="code-block">
<pre><span class="comment">Agent Resource Server Consumer Server</span>
| | |
| <span class="keyword">get_alerts</span>(abstract_ | |
| domains="event,..") | |
|────────────────────────▶| |
| | cache full data |
| ◀─ abstract + resource | assign _row_id |
| _id + _url | |
| | |
| <span class="func">filter</span>: pick wind rows | |
| | |
| <span class="keyword">draw_chart</span>(abstract, | |
| resource_url, _url) | |
|────────────────────────────────────────────────────▶|
| | |
| | <span class="string">POST <resource_url></span> |
| |◀─────────────────────────|
| | {"row_ids": [0,2,5]} |
| | |
| |──────────────────────────▶|
| | full body data |
| | |
| ◀─ chart result | <span class="func">merge + chart</span></pre>
</div>
<h2 id="sync-mode">Sync Mode</h2>
<p>
Body data returned inline. No <code>resource_url</code>.
No server-to-server fetch.
</p>
<ol>
<li>Agent calls <code>get_alerts(area="CA", abstract_domains="event,severity", mode="sync")</code></li>
<li>Source returns abstract + body inline (both as lists of dicts with <code>_row_id</code>)</li>
<li>Agent's SDK layer separates: abstract → LLM, body → data buffer</li>
<li>Agent filters on abstract, passes matching abstract + body rows to consumer</li>
<li>Consumer merges by <code>_row_id</code>, processes data. No HTTP fetch needed.</li>
</ol>
<div class="code-block">
<pre><span class="comment">Agent Resource Server</span>
| |
| <span class="keyword">get_alerts</span>(mode="sync", |
| abstract_domains="..") |
|─────────────────────────────▶|
| |
| ◀─ abstract + body inline |
| (no resource_url) |
| |
| SDK: abstract → LLM |
| body → data buffer |
| |
| LLM: <span class="func">filter</span> by event |
| |
| pass abstract + body |
| to consumer (no fetch) |</pre>
</div>
<h2>When to Use Each Mode</h2>
<table>
<thead>
<tr>
<th></th>
<th>Async Mode</th>
<th>Sync Mode</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>Body location</strong></td>
<td>Cached on resource server</td>
<td>Returned inline to agent</td>
</tr>
<tr>
<td><strong>Data plane</strong></td>
<td>Direct HTTP between servers</td>
<td>Through agent SDK (not LLM)</td>
</tr>
<tr>
<td><strong>resource_url</strong></td>
<td>Yes</td>
<td>No</td>
</tr>
<tr>
<td><strong>Server-to-server fetch</strong></td>
<td>Yes (<code>POST /s2sp/data/</code>)</td>
<td>No</td>
</tr>
<tr>
<td><strong>Best for</strong></td>
<td>Multi-server pipelines, large data</td>
<td>Single-agent setups, small data</td>
</tr>
<tr>
<td><strong>Body through agent process</strong></td>
<td>No</td>
<td>Yes (SDK layer, not LLM)</td>
</tr>
</tbody>
</table>
<h2 id="data-plane-endpoint">Data Plane Endpoint</h2>
<p>
Every S2SP server exposes an HTTP endpoint for data-plane access:
</p>
<div class="code-block">
<pre><span class="keyword">POST</span> <span class="string"><resource_url></span>
Content-Type: application/json
{
<span class="string">"row_ids"</span>: [0, 2, 5], <span class="comment">// optional: select rows by _row_id</span>
<span class="string">"columns"</span>: [<span class="string">"description"</span>] <span class="comment">// optional: select body columns</span>
}
<span class="comment">Response:</span>
{
<span class="string">"body"</span>: [
{<span class="string">"_row_id"</span>: 0, <span class="string">"description"</span>: <span class="string">"North winds 25-35 mph..."</span>, ...},
{<span class="string">"_row_id"</span>: 2, <span class="string">"description"</span>: <span class="string">"Gusts up to 55 mph..."</span>, ...},
...
],
<span class="string">"total_rows"</span>: 3,
<span class="string">"columns_returned"</span>: [<span class="string">"_row_id"</span>, <span class="string">"description"</span>]
}</pre>
</div>
<ul>
<li>If <code>row_ids</code> is omitted or empty: all cached rows are returned.</li>
<li>If <code>columns</code> is omitted or empty: all columns are returned.</li>
<li><code>_row_id</code> is always included in the response for reconciliation.</li>
</ul>
<h2 id="security">Security Model</h2>
<p>
S2SP uses 256-bit cryptographic <code>resource_url</code> values as capability
tokens. Each <code>resource_url</code> is single-use and expires after a 10-minute
TTL. In async mode, only parties who received the <code>resource_url</code> from the
agent (via the control plane) can fetch data from the resource server's data plane.
</p>
<h3>Three-Way Trust</h3>
<ol>
<li><strong>The Agent</strong> decides which servers exchange data and which
<code>resource_url</code> to share with which consumer.</li>
<li><strong>The Source</strong> caches data and serves it only to requests
with a valid <code>resource_url</code>.</li>
<li><strong>The Consumer</strong> can only access data the agent explicitly
authorized by sharing the <code>resource_url</code>.</li>
</ol>
<h3>Token Expiry</h3>
<p>
Cached data and <code>resource_url</code> references are single-use and expire
after a 10-minute TTL. After expiry, the data is removed from the resource server
server's cache and the <code>resource_url</code> becomes invalid.
</p>
<h2>MCP Compatibility</h2>
<p>
Both resource and consumer tools are fully backward-compatible with MCP:
</p>
<h3>Resource Tool (<code>@s2sp_resource_tool()</code>)</h3>
<ul>
<li><strong>Without <code>abstract_domains</code></strong>: The tool behaves
exactly like a standard MCP tool — returns all data as
<code>list[dict]</code>. No caching, no <code>resource_url</code>,
no <code>_row_id</code>.</li>
<li><strong>With <code>abstract_domains</code></strong>: The S2SP layer
activates — filters columns, adds <code>_row_id</code>, caches body,
returns <code>resource_url</code>.</li>
<li>Agents that don't know about S2SP simply omit
<code>abstract_domains</code> and get normal MCP behavior.</li>
</ul>
<h3>Consumer Tool (<code>@s2sp_consumer_tool()</code>)</h3>
<ul>
<li>Appears as a standard MCP tool with four string parameters:
<code>abstract_data</code>, <code>resource_url</code>,
<code>body_data</code>, <code>column_mapping</code>.</li>
<li>Any MCP agent can call it — it's just a regular tool that accepts
JSON strings. No special S2SP client required.</li>
<li>The consumer server handles fetching and merging internally — the
agent just passes the parameters from the resource tool response.</li>
</ul>
<h3>General</h3>
<ul>
<li><strong>MCP Inspector</strong>: Every S2SP server works with
<code>mcp dev</code> for debugging. All tools, resources, and prompts
are visible and callable.</li>
<li><strong>No spec changes</strong>: S2SP uses standard MCP tool parameters
and JSON responses. No modifications to the MCP protocol are required.</li>
<li><strong>Claude Desktop / OpenAI / Anthropic</strong>: Tested with all
major MCP-compatible clients.</li>
</ul>
</main>
</div>
<footer class="footer">
<p>S2SP Protocol — An open extension for MCP.</p>
</footer>
</body>
</html>