Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![npm version](https://img.shields.io/npm/v/ipgeolocation-io-mcp?logo=npm&label=npm&color=CB3837)](https://www.npmjs.com/package/ipgeolocation-io-mcp)
[![GitHub release](https://img.shields.io/github/v/release/IPGeolocation/ipgeolocation-io-mcp?logo=github&label=release&color=181717)](https://github.com/IPGeolocation/ipgeolocation-io-mcp/releases)
[![MCP Registry](https://img.shields.io/badge/MCP%20Registry-live-0A7CFF?logo=modelcontextprotocol&logoColor=white)](https://registry.modelcontextprotocol.io/?q=ipgeolocation)
[![Glama](https://glama.ai/mcp/servers/IPGeolocation/ipgeolocation-io-mcp/badges/score.svg)](https://glama.ai/mcp/servers/IPGeolocation/ipgeolocation-io-mcp)
[![Glama](https://img.shields.io/badge/Glama-listed-0A7CFF)](https://glama.ai/mcp/servers/IPGeolocation/ipgeolocation-io-mcp)
[![Node.js](https://img.shields.io/badge/node-%3E%3D18-5FA04E?logo=node.js&logoColor=white)](https://nodejs.org/)
[![License](https://img.shields.io/badge/license-MIT-16A34A)](https://github.com/IPGeolocation/ipgeolocation-io-mcp/blob/main/LICENSE)

Expand Down
22 changes: 12 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@
},
"overrides": {
"@hono/node-server": "1.19.14",
"express-rate-limit": "8.2.2",
"hono": "4.12.15",
"express-rate-limit": "8.5.1",
"hono": "4.12.18",
"path-to-regexp": "8.4.2"
},
"devDependencies": {
Expand Down
17 changes: 17 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { z } from "zod";
import { registerGeolocationTools } from "./tools/geolocation.js";
import { registerSecurityTools } from "./tools/security.js";
Expand Down Expand Up @@ -104,3 +106,18 @@ export async function startStdioServer(): Promise<void> {
process.exit(0);
});
}

function isDirectEntrypoint(): boolean {
if (!process.argv[1]) {
return false;
}

return path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
}

if (isDirectEntrypoint()) {
startStdioServer().catch((error) => {
console.error(error);
process.exit(1);
});
}
29 changes: 29 additions & 0 deletions tests/mcp.protocol.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import { fileURLToPath } from "node:url";
import path from "node:path";
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";

const repoRoot = path.resolve(fileURLToPath(new URL("..", import.meta.url)));

Expand Down Expand Up @@ -86,6 +88,33 @@ test("server entrypoint exports Smithery-compatible config without auto-starting
assert.ok(entrypoint.default({ config: { apiKey: "test-key" } }));
});

test("package main can run as a stdio server for generic hosts", async () => {
const packageJson = JSON.parse(await readRepoFile("package.json"));
const transport = new StdioClientTransport({
command: process.execPath,
args: [path.join(repoRoot, "dist/index.js")],
cwd: repoRoot,
env: {
IPGEOLOCATION_API_KEY: "test-key",
},
stderr: "pipe",
});
const client = new Client({
name: "entrypoint-test",
version: "1.0.0",
});

try {
await client.connect(transport, { timeout: 5000 });
assert.deepEqual(client.getServerVersion(), {
name: "ipgeolocation-io-mcp",
version: packageJson.version,
});
} finally {
await client.close();
}
});

test("Dockerfile starts the stdio CLI entrypoint", async () => {
const dockerfile = await readRepoFile("Dockerfile");

Expand Down
Loading