Skip to content

Commit e6f6815

Browse files
authored
Merge pull request #18 from metatool-ai/use-docker-host
Use docker host
2 parents 252cb4b + c1f78d3 commit e6f6815

File tree

6 files changed

+40
-7
lines changed

6 files changed

+40
-7
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ mcp-server-metamcp --metamcp-api-key <your-api-key> --transport sse --port 12006
6161

6262
With the SSE transport option, the server will start an Express.js web server that listens for SSE connections on the `/sse` endpoint and accepts messages on the `/messages` endpoint.
6363

64+
### Using with Docker
65+
66+
When running the server inside a Docker container and connecting to services on the host machine, use the `--use-docker-host` option to automatically transform localhost URLs:
67+
68+
```bash
69+
mcp-server-metamcp --metamcp-api-key <your-api-key> --transport sse --port 12006 --use-docker-host
70+
```
71+
72+
This will transform any localhost or 127.0.0.1 URLs to `host.docker.internal`, allowing the container to properly connect to services running on the host.
73+
6474
### Command Line Options
6575

6676
```
@@ -70,13 +80,16 @@ Options:
7080
--report Fetch all MCPs, initialize clients, and report tools to MetaMCP API
7181
--transport <type> Transport type to use (stdio or sse) (default: "stdio")
7282
--port <port> Port to use for SSE transport (default: "12006")
83+
--require-api-auth Require API key in SSE URL path
84+
--use-docker-host Transform localhost URLs to use host.docker.internal (can also be set via USE_DOCKER_HOST env var)
7385
-h, --help display help for command
7486
```
7587

7688
## Environment Variables
7789

7890
- `METAMCP_API_KEY`: API key for MetaMCP
7991
- `METAMCP_API_BASE_URL`: Base URL for MetaMCP API
92+
- `USE_DOCKER_HOST`: When set to "true", transforms localhost URLs to host.docker.internal for Docker compatibility
8093

8194
## Development
8295

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@metamcp/mcp-server-metamcp",
3-
"version": "0.4.6",
3+
"version": "0.5.0",
44
"description": "MCP Server MetaMCP manages all your other MCPs in one MCP.",
55
"scripts": {
66
"build": "tsc && shx chmod +x dist/*.js",

src/client.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ export interface ConnectedClient {
1414
cleanup: () => Promise<void>;
1515
}
1616

17+
/**
18+
* Transforms localhost URLs to use host.docker.internal when running inside Docker
19+
*/
20+
const transformDockerUrl = (url: string): string => {
21+
if (process.env.USE_DOCKER_HOST === "true") {
22+
return url.replace(/localhost|127\.0\.0\.1/g, "host.docker.internal");
23+
}
24+
return url;
25+
};
26+
1727
export const createMetaMcpClient = (
1828
serverParams: ServerParameters
1929
): { client: Client | undefined; transport: Transport | undefined } => {
@@ -30,14 +40,17 @@ export const createMetaMcpClient = (
3040
};
3141
transport = new StdioClientTransport(stdioParams);
3242
} else if (serverParams.type === "SSE" && serverParams.url) {
43+
// Transform the URL if USE_DOCKER_HOST is set to "true"
44+
const transformedUrl = transformDockerUrl(serverParams.url);
45+
3346
if (!serverParams.oauth_tokens) {
34-
transport = new SSEClientTransport(new URL(serverParams.url));
47+
transport = new SSEClientTransport(new URL(transformedUrl));
3548
} else {
3649
const headers: HeadersInit = {};
3750
headers[
3851
"Authorization"
3952
] = `Bearer ${serverParams.oauth_tokens.access_token}`;
40-
transport = new SSEClientTransport(new URL(serverParams.url), {
53+
transport = new SSEClientTransport(new URL(transformedUrl), {
4154
requestInit: {
4255
headers,
4356
},
@@ -54,7 +67,7 @@ export const createMetaMcpClient = (
5467
const client = new Client(
5568
{
5669
name: "MetaMCP",
57-
version: "0.4.6",
70+
version: "0.5.0",
5871
},
5972
{
6073
capabilities: {

src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ program
2727
.option("--transport <type>", "Transport type to use (stdio or sse)", "stdio")
2828
.option("--port <port>", "Port to use for SSE transport", "3001")
2929
.option("--require-api-auth", "Require API key in SSE URL path")
30+
.option(
31+
"--use-docker-host",
32+
"Transform localhost URLs to use host.docker.internal (can also be set via USE_DOCKER_HOST env var)"
33+
)
3034
.parse(process.argv);
3135

3236
const options = program.opts();
@@ -38,6 +42,9 @@ if (options.metamcpApiKey) {
3842
if (options.metamcpApiBaseUrl) {
3943
process.env.METAMCP_API_BASE_URL = options.metamcpApiBaseUrl;
4044
}
45+
if (options.useDockerHost) {
46+
process.env.USE_DOCKER_HOST = "true";
47+
}
4148

4249
async function main() {
4350
// If --report flag is set, run the reporting function instead of starting the server

src/mcp-proxy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const createServer = async () => {
4040
const server = new Server(
4141
{
4242
name: "MetaMCP",
43-
version: "0.4.6",
43+
version: "0.5.0",
4444
},
4545
{
4646
capabilities: {

0 commit comments

Comments
 (0)