Skip to content

Commit c2ad42e

Browse files
authored
fix(mcp-http-server): default host to 127.0.0.1, not all interfaces (#1918)
1 parent e9f3387 commit c2ad42e

7 files changed

Lines changed: 13 additions & 13 deletions

File tree

packages/agent-infra/mcp-http-server/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ await startSseAndStreamableHttpMcpServer({
4040
| Parameter | Type | Description |
4141
|-----------|------|-------------|
4242
| `port` | `number` | Port to listen on (default: 8080) |
43-
| `host` | `string` | Host to bind to (default: '::') |
43+
| `host` | `string` | Host to bind to (default: '127.0.0.1') |
4444
| `stateless` | `boolean` | Enable stateless mode for streamable HTTP (default: true) |
4545
| `middlewares` | `MiddlewareFunction[]` | Custom Express middlewares |
4646
| `routes` | `RoutesConfig` | Custom route configuration |

packages/agent-infra/mcp-http-server/src/startServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export async function startSseAndStreamableHttpMcpServer(
259259
},
260260
);
261261

262-
const HOST = host || '::';
262+
const HOST = host || '127.0.0.1';
263263
const PORT = Number(port || process.env.PORT || 8080);
264264

265265
return new Promise((resolve, reject) => {

packages/agent-infra/mcp-http-server/tests/startServer-server.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ describe('MCP Server HTTP Server Tests', () => {
148148
);
149149

150150
const transport = new SSEClientTransport(
151-
new URL(`http://localhost:${port}/sse`),
151+
new URL(`http://127.0.0.1:${port}/sse`),
152152
);
153153

154154
await client.connect(transport);
@@ -371,7 +371,7 @@ describe('MCP Server HTTP Server Tests', () => {
371371

372372
it('should handle health check endpoint via custom middleware', async () => {
373373
const response = await fetch(
374-
`http://localhost:${customMiddlewarePort}/health`,
374+
`http://127.0.0.1:${customMiddlewarePort}/health`,
375375
);
376376

377377
expect(response.status).toBe(200);
@@ -440,7 +440,7 @@ describe('MCP Server HTTP Server Tests', () => {
440440
});
441441

442442
try {
443-
const response = await fetch(`http://localhost:${middlewarePort}/mcp`, {
443+
const response = await fetch(`http://127.0.0.1:${middlewarePort}/mcp`, {
444444
method: 'POST',
445445
headers: { 'Content-Type': 'application/json' },
446446
body: JSON.stringify({
@@ -530,7 +530,7 @@ describe('MCP Server HTTP Server Tests', () => {
530530

531531
try {
532532
const response = await fetch(
533-
`http://localhost:${statefulTestPort}/mcp`,
533+
`http://127.0.0.1:${statefulTestPort}/mcp`,
534534
{
535535
method: 'POST',
536536
headers: {

packages/agent-infra/mcp-servers/browser/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ program
6868
.option('--headless', 'run browser in headless mode, headed by default')
6969
.option(
7070
'--host <host>',
71-
'host to bind server to. Default is localhost. Use 0.0.0.0 to bind to all interfaces.',
71+
'host to bind server to. Default is 127.0.0.1 (loopback). Use 0.0.0.0 to bind to all interfaces.',
7272
)
7373
// .option('--ignore-https-errors', 'ignore https errors')
7474
// .option(

packages/agent-infra/mcp-servers/commands/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ npx @agent-infra/mcp-server-commands --port 8089
120120
```
121121

122122
You can use one of the two MCP Server remote endpoint:
123-
- Streamable HTTP(Recommended): `http://127.0.0.1::8089/mcp`
124-
- SSE: `http://127.0.0.1::8089/sse`
123+
- Streamable HTTP(Recommended): `http://127.0.0.1:8089/mcp`
124+
- SSE: `http://127.0.0.1:8089/sse`
125125

126126

127127
And then in MCP client config, set the `url` to the SSE endpoint:
@@ -130,7 +130,7 @@ And then in MCP client config, set the `url` to the SSE endpoint:
130130
{
131131
"mcpServers": {
132132
"commands": {
133-
"url": "http://127.0.0.1::8089/sse"
133+
"url": "http://127.0.0.1:8089/sse"
134134
}
135135
}
136136
}
@@ -143,7 +143,7 @@ And then in MCP client config, set the `url` to the SSE endpoint:
143143
"mcpServers": {
144144
"commands": {
145145
"type": "streamable-http", // If there is MCP Client support
146-
"url": "http://127.0.0.1::8089/mcp"
146+
"url": "http://127.0.0.1:8089/mcp"
147147
}
148148
}
149149
}

packages/agent-infra/mcp-servers/commands/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ program
2020
.option('--cwd <cwd>', 'current working directory')
2121
.option(
2222
'--host <host>',
23-
'host to bind server to. Default is localhost. Use 0.0.0.0 to bind to all interfaces.',
23+
'host to bind server to. Default is 127.0.0.1 (loopback). Use 0.0.0.0 to bind to all interfaces.',
2424
)
2525
.option('--port <port>', 'port to listen on for SSE and HTTP transport.')
2626
.action(async (options) => {

packages/agent-infra/mcp-servers/filesystem/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ program
2525
)
2626
.option(
2727
'--host <host>',
28-
'host to bind server to. Default is localhost. Use 0.0.0.0 to bind to all interfaces.',
28+
'host to bind server to. Default is 127.0.0.1 (loopback). Use 0.0.0.0 to bind to all interfaces.',
2929
)
3030
.option('--port <port>', 'port to listen on for SSE and HTTP transport.')
3131
.action(async (options) => {

0 commit comments

Comments
 (0)