Skip to content

Commit dbe8bb0

Browse files
committed
feat: storacha/client + agent tracking + log cleanup
1 parent 70ad572 commit dbe8bb0

File tree

21 files changed

+257
-212
lines changed

21 files changed

+257
-212
lines changed

docs/spec.md

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ An MCP server provides a standardized way for AI applications to discover and us
1919
```mermaid
2020
flowchart LR
2121
A[AI Application] -->|Request| B[Storacha MCP Server]
22-
B -->|Upload| C[w3up-client]
22+
B -->|Upload| C[storacha-client]
2323
B -->|Retrieve| E[HTTP Gateway]
2424
C -->|Store| D[(Decentralized Storage)]
2525
D -->|Content-addressed Data| E
2626
C -->|Response| B
2727
E -->|Response| B
2828
B -->|Response| A
29-
29+
3030
classDef client fill:#d4f1f9,stroke:#0078d7,stroke-width:2px
3131
classDef server fill:#ffe6cc,stroke:#d79b00,stroke-width:2px
3232
classDef storage fill:#d5e8d4,stroke:#82b366,stroke-width:2px
3333
classDef gateway fill:#fff2cc,stroke:#d6b656,stroke-width:2px
34-
34+
3535
class A client
3636
class B server
3737
class C,D storage
@@ -107,7 +107,7 @@ The Storacha MCP server requires the following configuration:
107107
- **MCP_CONNECTION_TIMEOUT**: Connection timeout in milliseconds (default: 30000)
108108
- **MCP_TRANSPORT_MODE**: Transport mode to use (stdio or sse) (default: stdio)
109109
- **SHARED_ACCESS_TOKEN**: Optional access token used to authenticate upload operations (if not set, authentication is disabled)
110-
- **PRIVATE_KEY**: Required - Agent private key for w3up-client (for default delegation)
110+
- **PRIVATE_KEY**: Required - Agent private key for storacha-client (for default delegation)
111111
- **DELEGATION**: Required - The base64 encoded delegation that authorizes the Agent owner of the private key to upload files
112112
- **GATEWAY_URL**: Custom gateway URL for file retrieval (default: 'https://storacha.link')
113113
- **MAX_FILE_SIZE**: Maximum file size in bytes (default: 104857600 - 100MB)
@@ -116,51 +116,55 @@ The Storacha MCP server requires the following configuration:
116116

117117
The server needs to interface with Storacha storage via:
118118

119-
1. **w3up-client/storacha-client**: For uploading files to the Storacha Network and managing spaces
119+
1. **@storacha/client**: For uploading files to the Storacha Network and managing spaces
120120
2. **HTTP Trustless Gateway**: For retrieving files by CID
121121

122122
### MCP Transport Options
123123

124124
The Model Context Protocol (MCP) is transport-agnostic, meaning it can operate over different communication channels. The Storacha MCP server supports two transport modes:
125125

126126
1. **Server-Sent Events (SSE)**: One-way, server-to-client streaming
127-
- Pros:
127+
128+
- Pros:
128129
- Real-time updates for file operation status
129130
- Lower latency for status notifications
130131
- Compatible with web browsers and HTTP clients
131-
- Cons:
132+
- Cons:
132133
- One-way communication only
133134
- Requires HTTP server setup
134-
- Best for:
135+
- Best for:
135136
- Web-based integrations
136137
- Real-time status updates
137138
- Browser-based clients
138139

139140
2. **Standard I/O (stdio)**: Communication through process streams
140-
- Pros:
141+
- Pros:
141142
- No network setup required
142143
- Simple for local tools and CLI applications
143144
- Direct process-to-process communication
144-
- Cons:
145+
- Cons:
145146
- Limited to local machine
146147
- No network access
147-
- Best for:
148+
- Best for:
148149
- CLI tools
149150
- Local development
150151
- Process integration
151152

152153
The server can be configured to use either transport mode via the `MCP_TRANSPORT_MODE` environment variable:
154+
153155
- `sse`: Uses Express with SSE for HTTP-based communication
154156
- `stdio`: Uses standard I/O streams for local communication
155157

156158
The SSE implementation includes:
159+
157160
- Express server for HTTP handling
158161
- CORS configuration for web access
159162
- Temporary session-based message routing
160163
- Connection timeout management
161164
- Health check endpoint
162165

163166
The stdio implementation provides:
167+
164168
- Direct process communication
165169
- Simple message passing
166170
- No network dependencies
@@ -175,34 +179,34 @@ The Storacha MCP server utilizes the latest [MCP TypeScript SDK](https://github.
175179
The SSE server implementation consists of the following components:
176180

177181
1. **Server Configuration**
182+
178183
- Express application for HTTP server functionality
179184
- CORS enabled with appropriate headers for web access
180185
- OPTIONS request handling for preflight requests
181186
- Connection timeout configuration (default: 30 seconds)
182187
- Configurable via `MCP_CONNECTION_TIMEOUT` environment variable
183188

184189
2. **Connection Management**
190+
185191
- Maintains an in memory Map of active connections using session IDs
186192
- Each connection is associated with a unique SSEServerTransport instance
187193
- Automatic cleanup of closed connections
188194
- Idle connections are terminated after timeout period
189195

190196
3. **Endpoints**
197+
191198
- `/sse`: Establishes SSE connections
192199
- Sets appropriate SSE headers (Content-Type, Cache-Control, Connection)
193200
- Creates and stores new transport instance
194201
- Handles connection closure
195202
- Connects transport to MCP server
196-
197203
- `/messages`: Handles client-to-server communication
198204
- Routes messages to appropriate transport based on session ID
199205
- Processes messages through the connected transport
200-
201206
- `/health`: Provides server status information
202207
- Reports server initialization state
203208
- Shows active connection count
204209
- Lists connected session IDs
205-
206210
- `/`: Root endpoint with basic server information
207211
- Server name and version
208212
- Available endpoints
@@ -219,20 +223,23 @@ The SSE server implementation consists of the following components:
219223
The stdio server implementation consists of the following components:
220224

221225
1. **Server Configuration**
226+
222227
- Direct process-to-process communication using standard I/O streams
223228
- No network dependencies or HTTP server required
224229
- Simple message passing interface
225230
- Connection timeout configuration (default: 30 seconds)
226231
- Configurable via `MCP_CONNECTION_TIMEOUT` environment variable
227232

228233
2. **Connection Management**
234+
229235
- Single persistent connection through stdin/stdout
230236
- No need for session tracking or connection cleanup
231237
- Direct message routing to MCP server
232238
- Process-level communication
233239
- Idle connections are terminated after timeout period
234240

235241
3. **Message Handling**
242+
236243
- Reads JSON-RPC messages from stdin
237244
- Processes messages through MCP server
238245
- Writes responses to stdout
@@ -253,9 +260,9 @@ The MCP SDK uses a standardized error handling approach with the following forma
253260
```typescript
254261
// Error response format
255262
{
256-
content: [{
257-
type: "text",
258-
text: "Error message here"
263+
content: [{
264+
type: "text",
265+
text: "Error message here"
259266
}],
260267
isError: true
261268
}
@@ -277,12 +284,14 @@ All errors are consistently formatted to follow the MCP specification, including
277284
The server implements the following mechanisms to handle large file uploads:
278285

279286
1. **File Size Limits**
287+
280288
- Default maximum file size: 100MB (104857600 bytes)
281289
- Configurable via `MAX_FILE_SIZE` environment variable
282290
- Size validation occurs before processing to prevent server overload
283291
- Returns standardized MCP error format when size limit is exceeded
284292

285293
2. **Connection Timeouts**
294+
286295
- Default connection timeout: 30 seconds
287296
- Configurable via `MCP_CONNECTION_TIMEOUT` environment variable
288297
- Applies to both SSE and stdio transports
@@ -295,6 +304,7 @@ The server implements the following mechanisms to handle large file uploads:
295304
- Graceful handling of connection timeouts
296305

297306
Note: The following features are planned for future implementation:
307+
298308
- Stream-based processing for large files
299309
- Chunked upload support
300310
- Memory management optimizations
@@ -320,10 +330,12 @@ Regardless of the approach, integration typically follows these steps:
320330
1. **Client Initialization**: Configure the client with the Storacha MCP server URL and authentication if required.
321331

322332
2. **Transport Selection**: Choose the appropriate transport mode:
333+
323334
- For web-based clients: Use SSE transport with `/sse` and `/messages` endpoints
324335
- For local tools: Use stdio transport for direct process communication
325336

326337
3. **Operation Invocation**: Call the upload or retrieve operations with appropriate parameters:
338+
327339
- For SSE transport: Send JSON-RPC messages to `/messages` endpoint
328340
- For stdio transport: Send JSON-RPC messages through stdin
329341

@@ -347,11 +359,13 @@ The Storacha MCP server can be deployed using various approaches:
347359
The Storacha MCP server implements these security measures:
348360

349361
1. **Authentication**
362+
350363
- Private key authentication for storage operations
351364
- Delegation proof validation for storage access
352365
- Optional shared access token for API access
353366

354367
2. **Delegation Requirements**
368+
355369
- A delegation proof is required for all upload operations
356370
- Delegation can be provided in two ways:
357371
- Via the `DELEGATION` environment variable (server-wide setting)

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"test:watch": "vitest watch",
2020
"test:coverage": "pnpm typecheck && vitest run --coverage",
2121
"test": "pnpm typecheck && vitest run",
22-
"test:integration": "pnpm typecheck && vitest run test/integration/**.test.ts",
22+
"test:integration": "pnpm build && pnpm typecheck && vitest run test/integration/**.test.ts",
2323
"inspect": "pnpm build && npx @modelcontextprotocol/inspector node dist/index.js",
2424
"inspect:sse": "MCP_TRANSPORT_MODE=sse pnpm inspect",
2525
"inspect:stdio": "MCP_TRANSPORT_MODE=stdio pnpm inspect",
@@ -43,10 +43,10 @@
4343
"dependencies": {
4444
"@ipld/car": "^5.4.0",
4545
"@modelcontextprotocol/sdk": "^1.7.0",
46+
"@storacha/client": "^1.2.5",
4647
"@ucanto/core": "^10.3.1",
4748
"@ucanto/interface": "^10.2.0",
4849
"@ucanto/principal": "^9.0.2",
49-
"@web3-storage/w3up-client": "^17.2.0",
5050
"cors": "^2.8.5",
5151
"dotenv": "^16.4.7",
5252
"express": "^4.21.2",

0 commit comments

Comments
 (0)