@toolgrain/node 0.1.0 → 0.1.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,33 @@
1
+ # @toolgrain/node
2
+
3
+ ## 0.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - da94c47: Document the public API with JSDoc for exported types, members, options, and functions. Preserve field documentation in auth accessor return types and protocol constant hovers.
8
+ - f199707: Point package homepages and README documentation links to the live Toolgrain documentation site.
9
+ - d0c10ac: Use matching stable Toolgrain packages in installation instructions instead of
10
+ embedding outdated release pins.
11
+ - Updated dependencies [da94c47]
12
+ - Updated dependencies [f199707]
13
+ - Updated dependencies [d0c10ac]
14
+ - @toolgrain/http@0.1.2
15
+ - @toolgrain/mcp@0.1.2
16
+ - @toolgrain/protocol@0.1.2
17
+
18
+ ## 0.1.1
19
+
20
+ ### Patch Changes
21
+
22
+ - 16752a8: Refresh package READMEs with Toolgrain branding, clearer package roles, and direct
23
+ links to the tool, transport, and authorization guides. Clarify the supported Zod
24
+ version in installation commands and explicitly load Node types when compiling
25
+ the Node examples with current TypeScript.
26
+ - Updated dependencies [16752a8]
27
+ - @toolgrain/mcp@0.1.1
28
+ - @toolgrain/http@0.1.1
29
+ - @toolgrain/protocol@0.1.1
30
+
31
+ ## 0.1.0
32
+
33
+ Initial stable release. See the [0.1.0 release notes](https://github.com/keshavkatwe/toolgrain/releases/tag/v0.1.0) for installation instructions and known limitations.
package/README.md CHANGED
@@ -1,15 +1,29 @@
1
+ <a href="https://github.com/keshavkatwe/toolgrain#readme">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/keshavkatwe/toolgrain/main/brand/logo-dark.svg">
4
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/keshavkatwe/toolgrain/main/brand/logo-light.svg">
5
+ <img src="https://raw.githubusercontent.com/keshavkatwe/toolgrain/main/brand/logo-light.svg" alt="Toolgrain" width="200" height="48">
6
+ </picture>
7
+ </a>
8
+
1
9
  # @toolgrain/node
2
10
 
3
- Node.js stdio and HTTP transports for Toolgrain MCP servers. Tools and server
4
- composition live in
5
- [@toolgrain/mcp](https://github.com/keshavkatwe/toolgrain/tree/main/packages/mcp#readme).
11
+ **Choose stdio or HTTP. Keep your tools.**
12
+
13
+ Node.js transports for Toolgrain: process stdio, a managed HTTP listener, and
14
+ handlers for an existing Node application.
15
+
16
+ [Documentation](https://toolgrain.mintlify.site/transports/overview) ·
17
+ [Examples](https://toolgrain.mintlify.site/examples) ·
18
+ [npm](https://www.npmjs.com/package/@toolgrain/node)
6
19
 
7
20
  ## Installation
8
21
 
9
- Install the same `0.1.0` version across Toolgrain libraries.
22
+ Install matching stable versions across Toolgrain libraries. These commands
23
+ resolve npm's `latest` tag.
10
24
 
11
25
  ```sh
12
- npm install @toolgrain/node@0.1.0 @toolgrain/mcp@0.1.0 zod
26
+ npm install @toolgrain/node @toolgrain/mcp zod@^4.6.6
13
27
  npm install --save-dev typescript @types/node
14
28
  ```
15
29
 
@@ -46,7 +60,7 @@ for (const signal of ["SIGINT", "SIGTERM"] as const) {
46
60
  ```
47
61
 
48
62
  Save as `server.mts`, compile with TypeScript using
49
- `--strict --module NodeNext --target ES2022`, and run `node server.mjs`.
63
+ `--strict --module NodeNext --target ES2022 --types node`, and run `node server.mjs`.
50
64
  The endpoint defaults to `http://127.0.0.1:3000/mcp`. `server.close()` closes the
51
65
  owned listener. Toolgrain installs no process signal handlers; the example adds
52
66
  its own shutdown handling.
@@ -74,7 +88,7 @@ default to loopback on any port. Set production hosts explicitly. Applications
74
88
  own CORS, TLS, and trusted proxy normalization. Forwarded headers are ignored.
75
89
 
76
90
  Auth-configured servers require HTTP. See the
77
- [authorization guide](https://github.com/keshavkatwe/toolgrain/blob/main/docs/authorization.md).
91
+ [authorization guide](https://toolgrain.mintlify.site/guides/authorization).
78
92
 
79
93
  ## Requirements and protocol support
80
94
 
@@ -82,8 +96,8 @@ ESM only. Node.js `^24.20.0` or Bun `>=1.4.4 <2`; Zod `^4.6.6` through MCP;
82
96
  TypeScript 5.5.4 or later with `strict` enabled. Both MCP `2026-07-28` and
83
97
  `2025-06-18` are supported over stdio and independent HTTP POSTs with JSON
84
98
  responses. See the
85
- [support policy](https://github.com/keshavkatwe/toolgrain/blob/main/docs/support-policy.md)
86
- and [client compatibility notes](https://github.com/keshavkatwe/toolgrain/blob/main/docs/compatibility.md).
99
+ [support policy](https://toolgrain.mintlify.site/project/support-policy)
100
+ and [client compatibility notes](https://toolgrain.mintlify.site/compatibility/protocol).
87
101
 
88
102
  ## License
89
103
 
@@ -1,15 +1,27 @@
1
1
  import type { AddressInfo } from "node:net";
2
2
  import type { HttpOptions } from "@toolgrain/http";
3
3
  import type { RequestTransport } from "@toolgrain/mcp";
4
+ /** Managed listener settings plus the shared HTTP endpoint and validation options. */
4
5
  export interface HttpTransportOptions extends HttpOptions {
5
6
  /** Defaults to 3000. Use 0 to let the operating system choose a port. */
6
7
  port?: number;
7
8
  /** Bind address; defaults to 127.0.0.1. This is separate from allowedHosts. */
8
9
  hostname?: string;
9
10
  }
11
+ /** Single-use Node HTTP listener owned by the MCP server to which it is attached. */
10
12
  export interface HttpTransport extends RequestTransport {
11
13
  /** A copied bound address, or undefined before startup and after closing. */
12
14
  address(): AddressInfo | undefined;
13
15
  }
14
- /** Own a Node HTTP listener with combined MCP routing and local host defaults. */
16
+ /**
17
+ * Create a managed Node HTTP transport for independent MCP POSTs with JSON responses.
18
+ * `server.listen()` starts its listener and public auth metadata routes when configured.
19
+ * Default accepted hosts are loopback authorities on the actual listening port;
20
+ * `hostname` controls binding separately from the `allowedHosts` request policy.
21
+ *
22
+ * @param options - Listener settings, exact endpoint path, allowlists, and body limit.
23
+ * @returns A single-use request transport with a copied bound-address accessor.
24
+ * Closing through the server aborts active requests and closes listener connections.
25
+ * @throws For an invalid port or bind hostname; listener startup errors reject `listen()`.
26
+ */
15
27
  export declare function http(options?: HttpTransportOptions): HttpTransport;
@@ -1,6 +1,16 @@
1
1
  import { createServer as createHttpServer, } from "node:http";
2
2
  import { createNodeHttpHandler } from "./http.js";
3
- /** Own a Node HTTP listener with combined MCP routing and local host defaults. */
3
+ /**
4
+ * Create a managed Node HTTP transport for independent MCP POSTs with JSON responses.
5
+ * `server.listen()` starts its listener and public auth metadata routes when configured.
6
+ * Default accepted hosts are loopback authorities on the actual listening port;
7
+ * `hostname` controls binding separately from the `allowedHosts` request policy.
8
+ *
9
+ * @param options - Listener settings, exact endpoint path, allowlists, and body limit.
10
+ * @returns A single-use request transport with a copied bound-address accessor.
11
+ * Closing through the server aborts active requests and closes listener connections.
12
+ * @throws For an invalid port or bind hostname; listener startup errors reject `listen()`.
13
+ */
4
14
  export function http(options = {}) {
5
15
  const port = options.port ?? 3000;
6
16
  const hostname = options.hostname ?? "127.0.0.1";
package/dist/http.d.ts CHANGED
@@ -1,5 +1,26 @@
1
1
  import { type HttpOptions } from "@toolgrain/http";
2
2
  import type { Server } from "@toolgrain/mcp";
3
- /** Mount at the root before body parsing. Delegates unmatched paths when next is supplied. */
3
+ /**
4
+ * Create a Node handler combining MCP and public protected-resource metadata routes.
5
+ * Mount it at the application root before body parsing. Owned routes validate hosts
6
+ * before authentication or body work; forwarded headers are ignored.
7
+ *
8
+ * @param server - Server that authorizes and dispatches each independent request.
9
+ * @param options - Endpoint, host/origin allowlists, and request-body limit.
10
+ * @returns An async `(input, output, next?)` handler for Node requests/responses.
11
+ * Unmatched paths call `next()` when supplied; otherwise they return 404.
12
+ * The application owns its listener, TLS, CORS, and trusted proxy normalization.
13
+ * @throws For invalid HTTP configuration when constructing the handler.
14
+ */
4
15
  export declare function createNodeHttpHandler(server: Server, options?: HttpOptions): (input: import("http").IncomingMessage, output: import("http").ServerResponse, next?: () => void) => Promise<void>;
16
+ /**
17
+ * Create a public GET/HEAD handler for an auth-configured server's well-known metadata route.
18
+ * Register it separately when a framework requires explicit route registration.
19
+ * Hosts are checked before metadata work; unmatched metadata paths return 404.
20
+ *
21
+ * @param server - Auth-configured MCP server whose public resource metadata is advertised.
22
+ * @param options - Host allowlist; defaults to loopback hosts on any port.
23
+ * @returns An async handler accepting a Node request and response; it does not own a listener.
24
+ * @throws If authorization is not configured or the host allowlist is invalid.
25
+ */
5
26
  export declare function createNodeProtectedResourceMetadataHandler(server: Server, options?: Pick<HttpOptions, "allowedHosts">): (input: import("http").IncomingMessage, output: import("http").ServerResponse, next?: () => void) => Promise<void>;
package/dist/http.js CHANGED
@@ -1,10 +1,31 @@
1
1
  import { createHttpHandler, createProtectedResourceMetadataHandler, } from "@toolgrain/http";
2
2
  import { nodeHttpHandler } from "./http-handler.js";
3
- /** Mount at the root before body parsing. Delegates unmatched paths when next is supplied. */
3
+ /**
4
+ * Create a Node handler combining MCP and public protected-resource metadata routes.
5
+ * Mount it at the application root before body parsing. Owned routes validate hosts
6
+ * before authentication or body work; forwarded headers are ignored.
7
+ *
8
+ * @param server - Server that authorizes and dispatches each independent request.
9
+ * @param options - Endpoint, host/origin allowlists, and request-body limit.
10
+ * @returns An async `(input, output, next?)` handler for Node requests/responses.
11
+ * Unmatched paths call `next()` when supplied; otherwise they return 404.
12
+ * The application owns its listener, TLS, CORS, and trusted proxy normalization.
13
+ * @throws For invalid HTTP configuration when constructing the handler.
14
+ */
4
15
  export function createNodeHttpHandler(server, options) {
5
16
  const handle = createHttpHandler(server, options);
6
17
  return nodeHttpHandler(handle, handle.matches);
7
18
  }
19
+ /**
20
+ * Create a public GET/HEAD handler for an auth-configured server's well-known metadata route.
21
+ * Register it separately when a framework requires explicit route registration.
22
+ * Hosts are checked before metadata work; unmatched metadata paths return 404.
23
+ *
24
+ * @param server - Auth-configured MCP server whose public resource metadata is advertised.
25
+ * @param options - Host allowlist; defaults to loopback hosts on any port.
26
+ * @returns An async handler accepting a Node request and response; it does not own a listener.
27
+ * @throws If authorization is not configured or the host allowlist is invalid.
28
+ */
8
29
  export function createNodeProtectedResourceMetadataHandler(server, options) {
9
30
  return nodeHttpHandler(createProtectedResourceMetadataHandler(server, options));
10
31
  }
package/dist/stdio.d.ts CHANGED
@@ -1,10 +1,21 @@
1
1
  import type { Readable, Writable } from "node:stream";
2
2
  import type { Transport } from "@toolgrain/mcp";
3
+ /** Streams and framing limit for a single-use, newline-delimited JSON transport. */
3
4
  export interface StdioOptions {
5
+ /** Incoming UTF-8 JSON stream; defaults to process stdin and remains application-owned. */
4
6
  input?: Readable;
7
+ /** Outgoing MCP response stream; defaults to process stdout and must not contain application logs. */
5
8
  output?: Writable;
6
9
  /** Maximum UTF-8 bytes per incoming message, excluding its newline. Default: 1 MiB. */
7
10
  maxMessageBytes?: number;
8
11
  }
9
- /** A single-use transport; supplied streams remain owned by the caller. */
12
+ /**
13
+ * Create a single-use stdio transport with newline framing and write backpressure.
14
+ * Attach it through `server.listen()`. Closing detaches listeners and pauses input;
15
+ * supplied streams remain application-owned and are not ended or destroyed.
16
+ *
17
+ * @param options - Input/output streams and a positive incoming-message byte limit.
18
+ * @returns A transport that can be attached once and cannot restart after closing.
19
+ * @throws `RangeError` if `maxMessageBytes` is not a positive safe integer.
20
+ */
10
21
  export declare function stdio(options?: StdioOptions): Transport;
package/dist/stdio.js CHANGED
@@ -1,7 +1,15 @@
1
1
  import { stdin, stdout } from "node:process";
2
2
  import { createMessageDecoder } from "./framing.js";
3
3
  import { writeLine } from "./write.js";
4
- /** A single-use transport; supplied streams remain owned by the caller. */
4
+ /**
5
+ * Create a single-use stdio transport with newline framing and write backpressure.
6
+ * Attach it through `server.listen()`. Closing detaches listeners and pauses input;
7
+ * supplied streams remain application-owned and are not ended or destroyed.
8
+ *
9
+ * @param options - Input/output streams and a positive incoming-message byte limit.
10
+ * @returns A transport that can be attached once and cannot restart after closing.
11
+ * @throws `RangeError` if `maxMessageBytes` is not a positive safe integer.
12
+ */
5
13
  export function stdio(options = {}) {
6
14
  return new StdioTransport(options);
7
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toolgrain/node",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Node.js stdio and HTTP transports for Toolgrain MCP servers.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -8,7 +8,7 @@
8
8
  "url": "git+https://github.com/keshavkatwe/toolgrain.git",
9
9
  "directory": "packages/node"
10
10
  },
11
- "homepage": "https://github.com/keshavkatwe/toolgrain/tree/main/packages/node#readme",
11
+ "homepage": "https://toolgrain.mintlify.site/reference/node",
12
12
  "bugs": {
13
13
  "url": "https://github.com/keshavkatwe/toolgrain/issues"
14
14
  },
@@ -33,6 +33,7 @@
33
33
  }
34
34
  },
35
35
  "files": [
36
+ "CHANGELOG.md",
36
37
  "dist"
37
38
  ],
38
39
  "scripts": {
@@ -52,9 +53,9 @@
52
53
  "@toolgrain/repo-tools": "0.0.0"
53
54
  },
54
55
  "dependencies": {
55
- "@toolgrain/mcp": "0.1.0",
56
- "@toolgrain/protocol": "0.1.0",
57
- "@toolgrain/http": "0.1.0"
56
+ "@toolgrain/mcp": "0.1.2",
57
+ "@toolgrain/protocol": "0.1.2",
58
+ "@toolgrain/http": "0.1.2"
58
59
  },
59
60
  "engines": {
60
61
  "node": "^24.20.0",