Skip to content

Commit b4d51d4

Browse files
committed
update HTTP client endpoints to use root path
1 parent e2081b9 commit b4d51d4

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

mock-client/http-client.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async function testHTTPMode() {
4444
}
4545
};
4646

47-
const initResponse = await fetch(`${baseUrl}/mcp`, {
47+
const initResponse = await fetch(`${baseUrl}/`, {
4848
method: 'POST',
4949
headers: {
5050
'Content-Type': 'application/json',
@@ -71,7 +71,7 @@ async function testHTTPMode() {
7171
params: {}
7272
};
7373

74-
const toolsResponse = await fetch(`${baseUrl}/mcp`, {
74+
const toolsResponse = await fetch(`${baseUrl}/`, {
7575
method: 'POST',
7676
headers: {
7777
'Content-Type': 'application/json',
@@ -102,7 +102,7 @@ async function testHTTPMode() {
102102
}
103103
};
104104

105-
const depscoreResponse = await fetch(`${baseUrl}/mcp`, {
105+
const depscoreResponse = await fetch(`${baseUrl}/`, {
106106
method: 'POST',
107107
headers: {
108108
'Content-Type': 'application/json',
@@ -117,7 +117,7 @@ async function testHTTPMode() {
117117

118118
// 4. Test SSE stream (optional)
119119
console.log('\n4. Testing SSE stream connection...');
120-
const sseResponse = await fetch(`${baseUrl}/mcp`, {
120+
const sseResponse = await fetch(`${baseUrl}/`, {
121121
method: 'GET',
122122
headers: {
123123
'mcp-session-id': actualSessionId,
@@ -132,7 +132,7 @@ async function testHTTPMode() {
132132

133133
// 5. Clean up session
134134
console.log('\n5. Cleaning up session...');
135-
const cleanupResponse = await fetch(`${baseUrl}/mcp`, {
135+
const cleanupResponse = await fetch(`${baseUrl}/`, {
136136
method: 'DELETE',
137137
headers: {
138138
'mcp-session-id': actualSessionId

src/index.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ server.tool(
9696
async ({ packages }) => {
9797
logger.info(`Received request for ${packages.length} packages`);
9898

99+
const SOCKET_HEADERS = {
100+
"user-agent": `socket-mcp/${VERSION}`,
101+
"accept": "application/x-ndjson",
102+
"content-type": "application/json",
103+
"authorization": `Bearer ${SOCKET_API_KEY}`
104+
};
105+
99106
// Build components array for the API request
100107
const components = packages.map(pkg => {
101108
const cleanedVersion = pkg.version.replace(/[\^~]/g, ''); // Remove ^ and ~ from version
@@ -124,14 +131,14 @@ server.tool(
124131
logger.error(errorMsg);
125132
return {
126133
content: [{ type: "text", text: errorMsg }],
127-
isError: false
134+
isError: true
128135
};
129136
} else if (!responseText.trim()) {
130137
const errorMsg = `No packages were found.`;
131138
logger.error(errorMsg);
132139
return {
133140
content: [{ type: "text", text: errorMsg }],
134-
isError: false
141+
isError: true
135142
};
136143
}
137144

@@ -230,14 +237,6 @@ if (!SOCKET_API_KEY) {
230237
}
231238
}
232239

233-
// Now that we have the API key, set up the headers
234-
const SOCKET_HEADERS = {
235-
"user-agent": `socket-mcp/${VERSION}`,
236-
"accept": "application/x-ndjson",
237-
"content-type": "application/json",
238-
"authorization": `Bearer ${SOCKET_API_KEY}`
239-
};
240-
241240
if (useHttp) {
242241
// HTTP mode with Server-Sent Events
243242
logger.info(`Starting HTTP server on port ${port}`);
@@ -268,7 +267,7 @@ if (useHttp) {
268267
return;
269268
}
270269

271-
if (url.pathname === '/mcp') {
270+
if (url.pathname === '/') {
272271
if (req.method === 'POST') {
273272
// Handle JSON-RPC messages
274273
let body = '';
@@ -366,7 +365,7 @@ if (useHttp) {
366365

367366
httpServer.listen(port, () => {
368367
logger.info(`Socket MCP HTTP server version ${VERSION} started successfully on port ${port}`);
369-
logger.info(`Connect to: http://localhost:${port}/mcp`);
368+
logger.info(`Connect to: http://localhost:${port}/`);
370369
});
371370

372371
} else {

0 commit comments

Comments
 (0)