Skip to content

Commit bf1a06c

Browse files
committed
stateless tests added
1 parent f37d85b commit bf1a06c

File tree

1 file changed

+15
-36
lines changed

1 file changed

+15
-36
lines changed

mock-client/http-client.ts

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,12 @@ async function parseResponse (response: any) {
2121
// Simple HTTP client for testing MCP server in HTTP mode
2222
async function testHTTPMode () {
2323
const baseUrl = (process.env['MCP_URL'] || 'http://localhost:3000').replace(/\/$/, '') // Remove trailing slash
24-
const sessionId = `test-session-${Date.now()}`
2524

2625
console.log('Testing Socket MCP in HTTP mode...')
2726
console.log(`Server URL: ${baseUrl}`)
28-
console.log(`Session ID: ${sessionId}`)
2927

3028
try {
31-
// 1. Initialize connection
29+
// 1. Initialize connection (stateless)
3230
console.log('\n1. Initializing connection...')
3331
const initRequest = {
3432
jsonrpc: '2.0',
@@ -48,6 +46,7 @@ async function testHTTPMode () {
4846
method: 'POST',
4947
headers: {
5048
'Content-Type': 'application/json',
49+
// SDK requires Accept to include both types even if server returns JSON
5150
Accept: 'application/json, text/event-stream',
5251
'User-Agent': 'socket-mcp-debug-client/1.0.0'
5352
},
@@ -57,10 +56,7 @@ async function testHTTPMode () {
5756
const initResult = await parseResponse(initResponse)
5857
console.log('Initialize response:', JSON.stringify(initResult, null, 2))
5958

60-
// Extract session ID from response headers
61-
const serverSessionId = initResponse.headers.get('mcp-session-id')
62-
const actualSessionId = serverSessionId || sessionId
63-
console.log('Session ID:', actualSessionId)
59+
console.log('Initialized (stateless)')
6460

6561
// 2. List tools
6662
console.log('\n2. Listing available tools...')
@@ -75,14 +71,22 @@ async function testHTTPMode () {
7571
method: 'POST',
7672
headers: {
7773
'Content-Type': 'application/json',
78-
Accept: 'application/json, text/event-stream',
79-
'mcp-session-id': actualSessionId
74+
Accept: 'application/json, text/event-stream'
8075
},
8176
body: JSON.stringify(toolsRequest)
8277
})
8378

8479
const toolsResult = await parseResponse(toolsResponse)
8580
console.log('Available tools:', JSON.stringify(toolsResult, null, 2))
81+
// Assert that the 'depscore' tool exists in the toolsResult
82+
if (
83+
!toolsResult ||
84+
!toolsResult.result ||
85+
!Array.isArray(toolsResult.result.tools) ||
86+
!toolsResult.result.tools.some((tool: any) => tool.name === 'depscore')
87+
) {
88+
throw new Error('depscore tool not found in available tools')
89+
}
8690

8791
// 3. Call depscore
8892
console.log('\n3. Calling depscore tool...')
@@ -106,40 +110,15 @@ async function testHTTPMode () {
106110
method: 'POST',
107111
headers: {
108112
'Content-Type': 'application/json',
109-
Accept: 'application/json, text/event-stream',
110-
'mcp-session-id': actualSessionId
113+
Accept: 'application/json, text/event-stream'
111114
},
112115
body: JSON.stringify(depscoreRequest)
113116
})
114117

115118
const depscoreResult = await parseResponse(depscoreResponse)
116119
console.log('Depscore result:', JSON.stringify(depscoreResult, null, 2))
117120

118-
// 4. Test SSE stream (optional)
119-
console.log('\n4. Testing SSE stream connection...')
120-
const sseResponse = await fetch(`${baseUrl}/`, {
121-
method: 'GET',
122-
headers: {
123-
'mcp-session-id': actualSessionId,
124-
Accept: 'text/event-stream'
125-
}
126-
})
127-
128-
if (sseResponse.ok) {
129-
console.log('SSE stream connected successfully')
130-
// Note: In a real implementation, you'd parse the SSE stream
131-
}
132-
133-
// 5. Clean up session
134-
console.log('\n5. Cleaning up session...')
135-
const cleanupResponse = await fetch(`${baseUrl}/`, {
136-
method: 'DELETE',
137-
headers: {
138-
'mcp-session-id': actualSessionId
139-
}
140-
})
141-
142-
console.log('Session cleanup:', cleanupResponse.status === 200 ? 'Success' : 'Failed')
121+
console.log('\n4. HTTP mode test complete (no sessions)')
143122
} catch (error) {
144123
console.error('Error:', error)
145124
}

0 commit comments

Comments
 (0)