Skip to content

Commit b557f5e

Browse files
authored
Merge pull request #270 from deploystackio/feat/sdk-typescript
Feat/sdk typescript
2 parents 8197bc2 + 27db9d4 commit b557f5e

File tree

8 files changed

+992
-424
lines changed

8 files changed

+992
-424
lines changed

development/satellite/architecture.mdx

Lines changed: 55 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,29 @@ Satellites operate as edge workers similar to GitHub Actions runners, providing:
2424

2525
## Current Implementation Architecture
2626

27-
### Phase 1: MCP Transport Layer
27+
### MCP SDK Transport Layer
2828

29-
The current satellite implementation provides complete MCP client interface support:
29+
The satellite uses the official `@modelcontextprotocol/sdk` for all MCP client communication:
3030

3131
```
3232
┌─────────────────────────────────────────────────────────────────────────────────┐
33-
│ MCP Transport Implementation
33+
Official MCP SDK Implementation │
3434
│ │
35-
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────
36-
│ │ SSE Transport │ │ SSE Messaging │ Streamable HTTP │
37-
│ │
38-
│ │ • GET /sse │ │ • POST /message │ │ • GET/POST /mcp │
39-
│ │ • Session Mgmt │ │ • JSON-RPC 2.0 │ │ • Optional SSE │
40-
│ │ • 30min timeout │ │ • Session-based │ │ • CORS Support │
41-
│ └─────────────────┘ └─────────────────┘ └─────────────────
35+
│ ┌─────────────────────────────────────────────────────────────────────────┐
36+
│ │ MCP SDK Server
37+
│ │
38+
│ │ • StreamableHTTPServerTransport • Standard JSON-RPC handling
39+
│ │ • Automatic session management • Built-in error responses
40+
│ │ • Protocol 2025-03-26 compliance • SSE streaming support
41+
│ └─────────────────────────────────────────────────────────────────────────┘
4242
│ │
43-
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────
44-
│ │ Session Manager │ SSE Handler │ Streamable HTTP │
45-
│ │ Handler
46-
│ │ • 32-byte IDs │ │ • Connection │ │ • Dual Response │
47-
│ │ • Activity │ │ Management • Session Aware │
48-
│ │ • Auto Cleanup │ │ • Message Send │ │ • Error Handle │
49-
│ └─────────────────┘ └─────────────────┘ └─────────────────
43+
│ ┌─────────────────────────────────────────────────────────────────────────┐
44+
│ │ MCP Client Integration
45+
│ │
46+
│ │ • StreamableHTTPClientTransport • External server discovery
47+
│ │ • Automatic connection cleanup • Tool discovery caching │ │
48+
│ │ • Standard MCP method support • Process communication
49+
│ └─────────────────────────────────────────────────────────────────────────┘
5050
│ │
5151
│ ┌─────────────────────────────────────────────────────────────────────────┐ │
5252
│ │ Foundation Infrastructure │ │
@@ -59,66 +59,58 @@ The current satellite implementation provides complete MCP client interface supp
5959
└─────────────────────────────────────────────────────────────────────────────────┘
6060
```
6161

62-
### Current MCP Transport Endpoints
62+
### MCP Transport Endpoints
6363

64-
**Implemented Endpoints:**
65-
- `GET /sse` - Establish SSE connection with session management
66-
- `POST /message?session={id}` - Send JSON-RPC messages via SSE sessions
67-
- `GET /mcp` - Establish SSE stream for Streamable HTTP transport
68-
- `POST /mcp` - Send JSON-RPC messages via Streamable HTTP
69-
- `OPTIONS /mcp` - CORS preflight handling
64+
**Active Endpoints:**
65+
- `GET /mcp` - Establish SSE stream via MCP SDK
66+
- `POST /mcp` - Send JSON-RPC messages via MCP SDK
67+
- `DELETE /mcp` - Session termination via MCP SDK
7068

7169
**Transport Protocol Support:**
7270
```
73-
MCP Client Satellite
71+
MCP Client Satellite (MCP SDK)
7472
│ │
75-
│──── GET /sse ────────────▶│ (Establish SSE session)
73+
│──── POST /mcp ────────────▶│ (Initialize connection)
7674
│ │
77-
│◀─── Session URL ──────────│ (Return session endpoint)
75+
│◀─── Session headers ──────│ (Session established)
7876
│ │
79-
│──── POST /message ────────▶│ (Send JSON-RPC via session)
77+
│──── POST /mcp ────────────▶│ (JSON-RPC tools/list)
8078
│ │
81-
│◀─── Response via SSE ─────│ (Stream response back)
79+
│◀─── Tools response ───────│ (Cached tools returned)
8280
```
8381

84-
### Core Components
85-
86-
**Session Manager:**
87-
- Cryptographically secure 32-byte base64url session IDs
88-
- 30-minute session timeout with automatic cleanup
89-
- Activity tracking and session state management
90-
- Client info storage and MCP initialization tracking
82+
### Core SDK Components
9183

92-
**SSE Handler:**
93-
- Server-Sent Events connection establishment
94-
- Message sending with error handling
95-
- Heartbeat and endpoint event management
96-
- Connection lifecycle management
84+
**MCP Server Wrapper:**
85+
- Official SDK Server integration with Fastify
86+
- Standard MCP protocol method handlers
87+
- Automatic session and transport management
88+
- Integration with existing tool discovery and process management
9789

98-
**Streamable HTTP Handler:**
99-
- Dual response mode (JSON and SSE streaming)
100-
- Optional session-based communication
101-
- CORS preflight handling
102-
- Error counting and session management
90+
**Client Communication:**
91+
- StreamableHTTPClientTransport for external server communication
92+
- Automatic connection establishment and cleanup
93+
- Standard MCP method execution (listTools, callTool)
94+
- Built-in error handling and retry logic
10395

104-
### JSON-RPC 2.0 Protocol Implementation
96+
### MCP Protocol Implementation
10597

10698
**Supported MCP Methods:**
107-
- `initialize` - MCP session initialization
99+
- `initialize` - MCP session initialization (SDK automatic)
108100
- `notifications/initialized` - Client initialization complete
109-
- `tools/list` - List available tools from remote MCP servers
110-
- `tools/call` - Execute tools on remote MCP servers
101+
- `tools/list` - List cached tools from discovered servers
102+
- `tools/call` - Execute tools routed to appropriate servers
111103
- `resources/list` - List available resources (returns empty array)
112104
- `resources/templates/list` - List resource templates (returns empty array)
113105
- `prompts/list` - List available prompts (returns empty array)
114106

115107
For detailed information about tool discovery and execution, see [Tool Discovery Implementation](/development/satellite/tool-discovery).
116108

117109
**Error Handling:**
118-
- JSON-RPC 2.0 compliant error responses
119-
- HTTP status code mapping
120-
- Structured error logging
121-
- Session validation and error reporting
110+
- Standard JSON-RPC 2.0 compliant error responses via SDK
111+
- Automatic HTTP status code mapping
112+
- Structured error logging with operation tracking
113+
- Built-in session validation and error reporting
122114

123115
## Planned Full Architecture
124116

@@ -414,18 +406,18 @@ npm run dev
414406

415407
**Test MCP Transport:**
416408
```bash
417-
# Test SSE connection
418-
curl -N -H "Accept: text/event-stream" http://localhost:3001/sse
419-
420-
# Send JSON-RPC message (replace SESSION_ID)
421-
curl -X POST "http://localhost:3001/message?session=SESSION_ID" \
409+
# Test MCP connection
410+
curl -X POST "http://localhost:3001/mcp" \
422411
-H "Content-Type: application/json" \
423412
-d '{"jsonrpc":"2.0","id":"1","method":"initialize","params":{}}'
424413

425-
# Direct HTTP transport
426-
curl -X POST http://localhost:3001/mcp \
414+
# Test tool discovery
415+
curl -X POST "http://localhost:3001/mcp" \
427416
-H "Content-Type: application/json" \
428-
-d '{"jsonrpc":"2.0","id":"1","method":"tools/list","params":{}}'
417+
-d '{"jsonrpc":"2.0","id":"2","method":"tools/list","params":{}}'
418+
419+
# Test SSE streaming
420+
curl -N -H "Accept: text/event-stream" "http://localhost:3001/mcp"
429421
```
430422

431423
**MCP Client Configuration:**
@@ -436,7 +428,7 @@ curl -X POST http://localhost:3001/mcp \
436428
"command": "npx",
437429
"args": ["@modelcontextprotocol/server-fetch"],
438430
"env": {
439-
"MCP_SERVER_URL": "http://localhost:3001/sse"
431+
"MCP_SERVER_URL": "http://localhost:3001/mcp"
440432
}
441433
}
442434
}

development/satellite/mcp-transport.mdx

Lines changed: 43 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,41 @@
11
---
22
title: MCP Transport Protocols
3-
description: External communication endpoints for MCP client integration
3+
description: Official MCP SDK transport implementation for external client integration
44
---
55

66
# MCP Transport Protocols
77

8-
Satellite implements three MCP transport protocols for external client communication. Each protocol serves different use cases and client requirements.
8+
Satellite uses the official `@modelcontextprotocol/sdk` to provide MCP client communication. This ensures full protocol compliance and seamless compatibility with all MCP clients including VS Code, Claude, and MCP Inspector.
99

1010
## Transport Overview
1111

12-
| Protocol | Endpoint | Method | Use Case |
13-
|----------|----------|--------|---------|
14-
| SSE Transport | `/sse` | GET | Persistent connections with session management |
15-
| SSE Messaging | `/message` | POST | JSON-RPC message sending via established sessions |
16-
| Streamable HTTP | `/mcp` | GET/POST | Direct HTTP communication with optional streaming |
12+
| Protocol | Endpoint | Method | Use Case | Implementation |
13+
|----------|----------|--------|----------|---------------|
14+
| Streamable HTTP | `/mcp` | POST | Standard JSON-RPC communication | Official MCP SDK |
15+
| SSE Streaming | `/mcp` | GET | Server-sent events for real-time updates | Official MCP SDK |
16+
| Session Management | `/mcp` | DELETE | Session termination | Official MCP SDK |
1717

18-
## SSE Transport
18+
## MCP SDK Implementation
1919

20-
### Connection Establishment
20+
Satellite leverages the official MCP TypeScript SDK for all transport operations:
2121

22-
**Endpoint:** `GET /sse`
22+
```typescript
23+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
24+
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
2325

24-
**Headers:**
25-
- `Accept: text/event-stream` (required)
26-
- `Cache-Control: no-cache`
27-
- `Connection: keep-alive`
28-
29-
**Response:**
30-
- Content-Type: `text/event-stream`
31-
- Session ID and endpoint URL sent as SSE events
32-
- 30-minute session timeout with automatic cleanup
33-
34-
**Example:**
35-
```bash
36-
curl -N -H "Accept: text/event-stream" http://localhost:3001/sse
37-
```
38-
39-
**SSE Events:**
40-
```
41-
event: endpoint
42-
data: {"url": "http://localhost:3001/message?session=abc123..."}
43-
44-
event: heartbeat
45-
data: {"timestamp": "2025-01-09T13:30:00.000Z"}
26+
const server = new Server({
27+
name: 'deploystack-satellite',
28+
version: '1.0.0'
29+
});
4630
```
4731

4832
### Session Management
4933

50-
- **Session ID:** 32-byte cryptographically secure base64url identifier
51-
- **Timeout:** 30 minutes of inactivity
52-
- **Activity Tracking:** Updated on each message received
53-
- **Cleanup:** Automatic removal of expired sessions
54-
55-
## SSE Messaging
56-
57-
**Endpoint:** `POST /message?session={sessionId}`
58-
59-
**Headers:**
60-
- `Content-Type: application/json` (required)
61-
62-
**Request Body:** JSON-RPC 2.0 message
63-
```json
64-
{
65-
"jsonrpc": "2.0",
66-
"id": "req-1",
67-
"method": "initialize",
68-
"params": {
69-
"clientInfo": {
70-
"name": "my-client",
71-
"version": "1.0.0"
72-
}
73-
}
74-
}
75-
```
76-
77-
**Response:** Message processing status
78-
```json
79-
{
80-
"status": "sent",
81-
"messageId": "req-1"
82-
}
83-
```
84-
85-
**Status Codes:**
86-
- `200` - Message sent successfully
87-
- `202` - Message accepted (for notifications)
88-
- `400` - Invalid JSON-RPC or missing session
89-
- `404` - Session not found
90-
- `500` - Internal server error
34+
The SDK provides automatic session management with:
35+
- **Session ID:** Cryptographically secure identifiers
36+
- **Timeout:** Configurable session timeouts
37+
- **Activity Tracking:** Automatic session activity updates
38+
- **Cleanup:** Built-in session cleanup and resource management
9139

9240
## Streamable HTTP Transport
9341

@@ -167,33 +115,31 @@ For detailed information about tool discovery and execution, see [Tool Discovery
167115

168116
### MCP Client Configuration
169117

170-
**SSE Transport Example:**
118+
**Standard Configuration:**
171119
```json
172120
{
173121
"mcpServers": {
174122
"satellite": {
175123
"command": "npx",
176124
"args": ["@modelcontextprotocol/server-fetch"],
177125
"env": {
178-
"MCP_SERVER_URL": "http://localhost:3001/sse"
126+
"MCP_SERVER_URL": "http://localhost:3001/mcp"
179127
}
180128
}
181129
}
182130
}
183131
```
184132

185-
**Direct HTTP Example:**
133+
**VS Code Configuration:**
186134
```json
187135
{
188-
"mcpServers": {
189-
"satellite": {
190-
"command": "npx",
191-
"args": ["@modelcontextprotocol/server-fetch"],
192-
"env": {
193-
"MCP_SERVER_URL": "http://localhost:3001/mcp"
194-
}
136+
"servers": {
137+
"deploystack-satellite": {
138+
"url": "http://localhost:3001/mcp",
139+
"type": "http"
195140
}
196-
}
141+
},
142+
"inputs": []
197143
}
198144
```
199145

@@ -207,29 +153,27 @@ For detailed information about tool discovery and execution, see [Tool Discovery
207153
npm run dev
208154
```
209155

210-
2. **Test SSE Connection:**
156+
2. **Test MCP Connection:**
211157
```bash
212-
curl -N -H "Accept: text/event-stream" http://localhost:3001/sse
158+
curl -X POST "http://localhost:3001/mcp" \
159+
-H "Content-Type: application/json" \
160+
-d '{"jsonrpc":"2.0","id":"1","method":"initialize","params":{}}'
213161
```
214162

215-
3. **Send JSON-RPC Message:**
163+
3. **Test Tools Discovery:**
216164
```bash
217-
curl -X POST "http://localhost:3001/message?session=YOUR_SESSION_ID" \
165+
curl -X POST "http://localhost:3001/mcp" \
218166
-H "Content-Type: application/json" \
219-
-d '{"jsonrpc":"2.0","id":"1","method":"initialize","params":{}}'
167+
-d '{"jsonrpc":"2.0","id":"2","method":"tools/list","params":{}}'
220168
```
221169

222-
### Protocol Selection
223-
224-
**Use SSE Transport when:**
225-
- Long-lived connections needed
226-
- Session state management required
227-
- Real-time bidirectional communication
170+
### Protocol Features
228171

229-
**Use Streamable HTTP when:**
230-
- Stateless request/response patterns
231-
- Standard HTTP client libraries
232-
- Optional streaming responses
172+
The official MCP SDK provides:
173+
- **Automatic Session Management:** Sessions created and managed transparently
174+
- **Standard Protocol Compliance:** Full MCP specification 2025-03-26 support
175+
- **Flexible Transport Options:** JSON and SSE streaming responses
176+
- **Built-in Error Handling:** Standard JSON-RPC error responses
233177

234178
## Security Considerations
235179

docs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"group": "Essentials",
1818
"pages": [
1919
"index",
20+
"general/quick-start",
2021
"general/architecture",
2122
"general/teams",
2223
"general/roles",

0 commit comments

Comments
 (0)