groundmail-mcp 0.16.1 → 0.16.2

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.
Files changed (2) hide show
  1. package/dist/index.js +32 -6
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -77,6 +77,7 @@ import { createServer } from "http";
77
77
  import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
78
78
 
79
79
  // src/server.ts
80
+ import { AsyncLocalStorage } from "async_hooks";
80
81
  import { Server } from "@modelcontextprotocol/sdk/server/index.js";
81
82
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
82
83
  import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
@@ -1815,7 +1816,7 @@ function resolveApiKey() {
1815
1816
  }
1816
1817
 
1817
1818
  // src/server.ts
1818
- var MCP_SERVER_VERSION = "0.15.1";
1819
+ var MCP_SERVER_VERSION = "0.16.2";
1819
1820
  var MCP_SERVER_INSTRUCTIONS = [
1820
1821
  "Groundmail sends transactional email from domains the user has verified.",
1821
1822
  'To test before a domain is verified, call send_email with from "noreply@mail.groundmail.dev" and to set to the Groundmail account email; sandbox sends to any other address are rejected.',
@@ -1823,10 +1824,30 @@ var MCP_SERVER_INSTRUCTIONS = [
1823
1824
  "Confirm with the user before sending email to anyone other than themselves.",
1824
1825
  "Errors include a stable code and a link to https://docs.groundmail.dev/errors#<code> that says how to fix them."
1825
1826
  ].join(" ");
1827
+ var currentTool = new AsyncLocalStorage();
1828
+ function agentToken(name) {
1829
+ const token = name?.trim().split(/[\s/]/)[0]?.replace(/[^\w.-]/g, "").slice(0, 60);
1830
+ return token || null;
1831
+ }
1832
+ function mcpUserAgent(agent) {
1833
+ const token = agentToken(agent);
1834
+ return `groundmail-mcp/${MCP_SERVER_VERSION}${token ? ` (agent ${token})` : ""} node/${process.versions.node}`;
1835
+ }
1836
+ function mcpFetch(getAgent) {
1837
+ return (input, init) => {
1838
+ const headers = new Headers(init?.headers);
1839
+ headers.set("User-Agent", mcpUserAgent(getAgent()));
1840
+ const tool = currentTool.getStore();
1841
+ if (tool) headers.set("X-Groundmail-Mcp-Tool", tool);
1842
+ return fetch(input, { ...init, headers });
1843
+ };
1844
+ }
1826
1845
  function createMcpServer(apiKey, baseUrl, options = {}) {
1827
1846
  const excluded = options.http ? HTTP_EXCLUDED_TOOLS : /* @__PURE__ */ new Set();
1828
- const client = new Groundmail(apiKey, baseUrl ? { baseUrl } : {});
1829
- const server = new Server(
1847
+ let server = null;
1848
+ const fetchImpl = mcpFetch(() => options.agent ?? server?.getClientVersion()?.name ?? null);
1849
+ const client = new Groundmail(apiKey, baseUrl ? { baseUrl, fetch: fetchImpl } : { fetch: fetchImpl });
1850
+ server = new Server(
1830
1851
  { name: "groundmail-mcp", title: "Groundmail", version: MCP_SERVER_VERSION },
1831
1852
  { capabilities: { tools: {} }, instructions: MCP_SERVER_INSTRUCTIONS }
1832
1853
  );
@@ -1842,8 +1863,10 @@ function createMcpServer(apiKey, baseUrl, options = {}) {
1842
1863
  }));
1843
1864
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
1844
1865
  if (excluded.has(request.params.name)) return textResult(HTTP_EXCLUDED_TOOL_MESSAGE, true);
1845
- const result = await callMcpTool(client, request.params.name, request.params.arguments ?? {});
1846
- return result;
1866
+ return currentTool.run(
1867
+ request.params.name,
1868
+ () => callMcpTool(client, request.params.name, request.params.arguments ?? {})
1869
+ );
1847
1870
  });
1848
1871
  return server;
1849
1872
  }
@@ -2004,7 +2027,10 @@ async function handleHttpRequest(req, res, options = {}) {
2004
2027
  );
2005
2028
  return;
2006
2029
  }
2007
- const server = createMcpServer(apiKey, options.baseUrl, { http: true });
2030
+ const server = createMcpServer(apiKey, options.baseUrl, {
2031
+ http: true,
2032
+ agent: typeof req.headers["user-agent"] === "string" ? req.headers["user-agent"] : null
2033
+ });
2008
2034
  const transport = new StreamableHTTPServerTransport({
2009
2035
  sessionIdGenerator: void 0
2010
2036
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "groundmail-mcp",
3
- "version": "0.16.1",
3
+ "version": "0.16.2",
4
4
  "mcpName": "io.github.Groundmail/groundmail",
5
5
  "description": "Groundmail MCP server: send transactional email, manage domains, templates, webhooks and suppressions from Claude, Cursor, ChatGPT and other MCP clients",
6
6
  "license": "MIT",