@hasna/contacts 0.6.17 → 0.6.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ export declare const DEFAULT_MCP_HTTP_PORT = 8809;
3
+ export declare const MCP_HTTP_HOST = "127.0.0.1";
4
+ export declare const MCP_SERVICE_NAME = "contacts";
5
+ export declare function isHttpMode(args: string[]): boolean;
6
+ export declare function resolveMcpHttpPort(args: string[]): number;
7
+ export declare function healthPayload(name?: string): {
8
+ status: string;
9
+ name: string;
10
+ };
11
+ export declare function handleMcpRequest(req: Request, buildServer: () => McpServer): Promise<Response>;
12
+ export declare function startMcpHttpServer(options: {
13
+ name: string;
14
+ port: number;
15
+ buildServer: () => McpServer;
16
+ }): ReturnType<typeof Bun.serve>;
17
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/mcp/http.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEzE,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAC1C,eAAO,MAAM,aAAa,cAAc,CAAC;AACzC,eAAO,MAAM,gBAAgB,aAAa,CAAC;AAE3C,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAElD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAQzD;AAED,wBAAgB,aAAa,CAAC,IAAI,GAAE,MAAyB,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAE/F;AAED,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,OAAO,EACZ,WAAW,EAAE,MAAM,SAAS,GAC3B,OAAO,CAAC,QAAQ,CAAC,CAOnB;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,SAAS,CAAC;CAC9B,GAAG,UAAU,CAAC,OAAO,GAAG,CAAC,KAAK,CAAC,CAoB/B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=http.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.test.d.ts","sourceRoot":"","sources":["../../src/mcp/http.test.ts"],"names":[],"mappings":""}
@@ -1,3 +1,4 @@
1
1
  #!/usr/bin/env bun
2
- export {};
2
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
+ export declare function buildServer(): McpServer;
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAgBpE,wBAAgB,WAAW,IAAI,SAAS,CAKvC"}
package/dist/mcp/index.js CHANGED
@@ -21931,6 +21931,55 @@ function registerContactsTools(server) {
21931
21931
  }
21932
21932
  }
21933
21933
 
21934
+ // src/mcp/http.ts
21935
+ import { WebStandardStreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";
21936
+ var DEFAULT_MCP_HTTP_PORT = 8809;
21937
+ var MCP_HTTP_HOST = "127.0.0.1";
21938
+ var MCP_SERVICE_NAME = "contacts";
21939
+ function isHttpMode(args) {
21940
+ return args.includes("--http") || process.env.MCP_HTTP === "1";
21941
+ }
21942
+ function resolveMcpHttpPort(args) {
21943
+ const portIdx = args.indexOf("--port");
21944
+ if (portIdx >= 0 && args[portIdx + 1]) {
21945
+ return Number(args[portIdx + 1]);
21946
+ }
21947
+ const envPort = process.env.MCP_HTTP_PORT;
21948
+ if (envPort)
21949
+ return Number(envPort);
21950
+ return DEFAULT_MCP_HTTP_PORT;
21951
+ }
21952
+ function healthPayload(name = MCP_SERVICE_NAME) {
21953
+ return { status: "ok", name };
21954
+ }
21955
+ async function handleMcpRequest(req, buildServer) {
21956
+ const transport = new WebStandardStreamableHTTPServerTransport({
21957
+ sessionIdGenerator: undefined
21958
+ });
21959
+ const server = buildServer();
21960
+ await server.connect(transport);
21961
+ return transport.handleRequest(req);
21962
+ }
21963
+ function startMcpHttpServer(options) {
21964
+ const { name, port, buildServer } = options;
21965
+ const server = Bun.serve({
21966
+ hostname: MCP_HTTP_HOST,
21967
+ port,
21968
+ async fetch(req) {
21969
+ const url = new URL(req.url);
21970
+ if (url.pathname === "/health" && req.method === "GET") {
21971
+ return Response.json(healthPayload(name));
21972
+ }
21973
+ if (url.pathname === "/mcp") {
21974
+ return handleMcpRequest(req, buildServer);
21975
+ }
21976
+ return new Response("Not Found", { status: 404 });
21977
+ }
21978
+ });
21979
+ console.error(`${name}-mcp HTTP listening on http://${MCP_HTTP_HOST}:${port}/mcp`);
21980
+ return server;
21981
+ }
21982
+
21934
21983
  // src/mcp/index.ts
21935
21984
  function getServerVersion() {
21936
21985
  try {
@@ -21941,15 +21990,33 @@ function getServerVersion() {
21941
21990
  return "0.0.0";
21942
21991
  }
21943
21992
  }
21944
- var server = new McpServer({ name: "contacts", version: getServerVersion() });
21945
- registerContactsTools(server);
21993
+ function buildServer() {
21994
+ const server = new McpServer({ name: "contacts", version: getServerVersion() });
21995
+ registerContactsTools(server);
21996
+ registerCloudTools(server, "contacts");
21997
+ return server;
21998
+ }
21946
21999
  async function main() {
22000
+ const args = process.argv.slice(2);
22001
+ if (isHttpMode(args)) {
22002
+ startMcpHttpServer({
22003
+ name: "contacts",
22004
+ port: resolveMcpHttpPort(args),
22005
+ buildServer
22006
+ });
22007
+ return;
22008
+ }
21947
22009
  const transport = new StdioServerTransport;
21948
- registerCloudTools(server, "contacts");
21949
- await server.connect(transport);
22010
+ await buildServer().connect(transport);
21950
22011
  console.error("Contacts MCP server running on stdio");
21951
22012
  }
21952
- main().catch((err) => {
21953
- console.error("Fatal error:", err);
21954
- process.exit(1);
21955
- });
22013
+ var isDirectRun = import.meta.url === `file://${process.argv[1]}` || process.argv[1]?.endsWith("mcp/index.ts") || process.argv[1]?.endsWith("mcp/index.js");
22014
+ if (isDirectRun) {
22015
+ main().catch((err) => {
22016
+ console.error("Fatal error:", err);
22017
+ process.exit(1);
22018
+ });
22019
+ }
22020
+ export {
22021
+ buildServer
22022
+ };