toolcraft 0.0.8 → 0.0.10

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/dist/cli.js CHANGED
@@ -714,20 +714,36 @@ function formatSecretDescription(secret) {
714
714
  }
715
715
  return secret.optional === true ? "Optional secret" : "Required secret";
716
716
  }
717
- function formatCommandRowName(node, depth) {
718
- const name = node.aliases.length === 0 ? node.name : `${node.name} (${node.aliases.join(", ")})`;
717
+ function wrapOptionalCommandParameterToken(token, optional) {
718
+ return optional ? `[${token}]` : token;
719
+ }
720
+ function formatCommandDynamicParameterTokens(field, casing) {
721
+ const optional = field.optional || field.hasDefault;
722
+ return formatDynamicHelpFields(field, casing).map((row) => wrapOptionalCommandParameterToken(row.flags, optional));
723
+ }
724
+ function formatCommandParameterTokens(command, casing, globalLongOptionFlags) {
725
+ const collected = collectFields(command.params, casing, globalLongOptionFlags);
726
+ const fields = assignPositionals(collected.fields, command.positional);
727
+ return fields
728
+ .map((field) => wrapOptionalCommandParameterToken(formatHelpFieldFlags(field, globalLongOptionFlags), field.positionalIndex === undefined && (field.optional || field.hasDefault)))
729
+ .concat(collected.dynamicFields.flatMap((field) => formatCommandDynamicParameterTokens(field, casing)));
730
+ }
731
+ function formatCommandRowName(node, depth, casing, globalLongOptionFlags) {
732
+ const baseName = node.aliases.length === 0 ? node.name : `${node.name} (${node.aliases.join(", ")})`;
733
+ const parameterTokens = node.kind === "command" ? formatCommandParameterTokens(node, casing, globalLongOptionFlags) : [];
734
+ const name = parameterTokens.length === 0 ? baseName : `${baseName} ${parameterTokens.join(" ")}`;
719
735
  return `${" ".repeat(depth)}${name}`;
720
736
  }
721
- function formatCommandRows(group, scope, depth = 0) {
737
+ function formatCommandRows(group, scope, casing, globalLongOptionFlags, depth = 0) {
722
738
  return getVisibleChildren(group, scope).flatMap((child) => {
723
739
  const row = {
724
- name: formatCommandRowName(child, depth),
740
+ name: formatCommandRowName(child, depth, casing, globalLongOptionFlags),
725
741
  description: child.description ?? "",
726
742
  };
727
743
  if (child.kind === "command") {
728
744
  return [row];
729
745
  }
730
- return [row, ...formatCommandRows(child, scope, depth + 1)];
746
+ return [row, ...formatCommandRows(child, scope, casing, globalLongOptionFlags, depth + 1)];
731
747
  });
732
748
  }
733
749
  function formatGlobalOptionRows(showVersion, presetsEnabled) {
@@ -766,9 +782,10 @@ function buildUsageLine(breadcrumb, rootUsageName, suffix) {
766
782
  const subPath = breadcrumb.slice(1).join(" ");
767
783
  return subPath ? `${rootUsageName} ${subPath} ${suffix}` : `${rootUsageName} ${suffix}`;
768
784
  }
769
- function renderGroupHelp(group, breadcrumb, scope, showVersion, presetsEnabled, rootUsageName) {
785
+ function renderGroupHelp(group, breadcrumb, scope, casing, showVersion, presetsEnabled, rootUsageName) {
770
786
  const sections = [];
771
- const commandRows = formatCommandRows(group, scope);
787
+ const globalLongOptionFlags = getGlobalLongOptionFlags(presetsEnabled);
788
+ const commandRows = formatCommandRows(group, scope, casing, globalLongOptionFlags);
772
789
  if (commandRows.length > 0) {
773
790
  sections.push(`${text.section("Commands:")}\n${formatCommandList(commandRows)}`);
774
791
  }
@@ -833,7 +850,7 @@ async function renderGeneratedHelp(root, argv, options) {
833
850
  const casing = options.casing ?? "kebab";
834
851
  await withOutputFormat(output, async () => {
835
852
  const rendered = target.node.kind === "group"
836
- ? renderGroupHelp(target.node, target.breadcrumb, "cli", options.version !== undefined, options.presets === true, options.rootUsageName)
853
+ ? renderGroupHelp(target.node, target.breadcrumb, "cli", casing, options.version !== undefined, options.presets === true, options.rootUsageName)
837
854
  : renderLeafHelp(target.node, target.breadcrumb, casing, options.presets === true, options.rootUsageName);
838
855
  process.stdout.write(rendered);
839
856
  });
@@ -1,3 +1,6 @@
1
+ npm warn Unknown project config "link-workspace-packages". This will stop working in the next major version of npm. See `npm help npmrc` for supported config options.
2
+ npm warn Unknown project config "package-manager-strict". This will stop working in the next major version of npm. See `npm help npmrc` for supported config options.
3
+ npm warn Unknown project config "prefer-workspace-packages". This will stop working in the next major version of npm. See `npm help npmrc` for supported config options.
1
4
 
2
5
  > tiny-mcp-client@0.1.0 build
3
6
  > tsc
@@ -0,0 +1,97 @@
1
+ # tiny-mcp-client
2
+
3
+ `tiny-mcp-client` is a lightweight Model Context Protocol client used by tests, fixtures, and package integrations. It supports stdio transports, streamable HTTP transports, in-memory test pairs, JSON-RPC helpers, and OAuth metadata discovery for OAuth-protected MCP HTTP servers.
4
+
5
+ ## Usage
6
+
7
+ ```ts
8
+ import { HttpTransport, McpClient } from "tiny-mcp-client";
9
+
10
+ const client = new McpClient({
11
+ clientInfo: { name: "demo", version: "0.1.0" },
12
+ });
13
+
14
+ await client.connect(new HttpTransport({ url: "http://127.0.0.1:3000/mcp" }));
15
+ const tools = await client.listTools();
16
+ console.log(tools);
17
+ await client.close();
18
+ ```
19
+
20
+ ## Transports
21
+
22
+ | Transport | Description |
23
+ |-----------|-------------|
24
+ | `StdioTransport` | Spawns an MCP server process and communicates over stdio. |
25
+ | `HttpTransport` | Connects to streamable HTTP MCP endpoints, including session IDs, SSE GET streams, and session termination. |
26
+ | `createInMemoryTransportPair()` | Creates paired streams for in-process tests. |
27
+
28
+ ## OAuth HTTP support
29
+
30
+ `HttpTransport` accepts `oauth` options from `mcp-oauth`. When a protected server returns a Bearer `WWW-Authenticate` challenge, the transport discovers protected-resource metadata, loads authorization-server metadata, lets the OAuth provider handle authorization, and retries the request when credentials are available.
31
+
32
+ ```ts
33
+ import { HttpTransport, createDefaultOAuthClientProvider } from "tiny-mcp-client";
34
+
35
+ const transport = new HttpTransport({
36
+ url: "https://mcp.example.com/mcp",
37
+ oauth: {
38
+ provider: createDefaultOAuthClientProvider({
39
+ client: {
40
+ mode: "dynamic",
41
+ metadata: {
42
+ clientName: "tiny-client",
43
+ },
44
+ },
45
+ browser: {
46
+ openBrowser: async (url) => {
47
+ console.log(`Open ${url}`);
48
+ },
49
+ },
50
+ }),
51
+ },
52
+ });
53
+ ```
54
+
55
+ You can also call `discoverOAuthMetadata(resourceUrl, options)` directly, or instantiate `OAuthMetadataDiscovery` with a custom `fetch` implementation and shared cache.
56
+
57
+ ## Testing helpers
58
+
59
+ - `createTestPair()` and `createSdkTestPair()` create paired client/server fixtures.
60
+ - `createInMemoryTransportPair()` is useful for fast unit tests without opening sockets or spawning processes.
61
+ - JSON-RPC error constants are exported for assertions: `ERROR_PARSE`, `ERROR_INVALID_REQUEST`, `ERROR_METHOD_NOT_FOUND`, `ERROR_INVALID_PARAMS`, and `ERROR_INTERNAL`.
62
+
63
+ ## Config options
64
+
65
+ ### `McpClientOptions`
66
+
67
+ | Option | Type | Description |
68
+ |--------|------|-------------|
69
+ | `clientInfo` | `{ name: string; version: string }` | Required client identity sent during initialize. |
70
+ | `capabilities` | `ClientCapabilities` | Optional MCP client capabilities. |
71
+ | `onToolsChanged`, `onResourcesChanged`, `onPromptsChanged` | callbacks | Optional notification handlers. |
72
+ | `onResourceUpdated`, `onLog`, `onProgress` | callbacks | Optional resource/log/progress handlers. |
73
+ | `onSamplingRequest`, `onRootsList` | callbacks | Optional server-to-client request handlers. |
74
+
75
+ ### `HttpTransportOptions`
76
+
77
+ | Option | Type | Description |
78
+ |--------|------|-------------|
79
+ | `url` | `string` | MCP HTTP endpoint URL. |
80
+ | `headers` | `HeadersInit` | Static headers added to requests. |
81
+ | `fetch` | `(input, init?) => Promise<Response>` | Custom fetch implementation. |
82
+ | `oauth` | `OAuthClientProviderOptions` | Enables OAuth authorization handling. |
83
+ | `oauthDiscoveryCache` | `OAuthDiscoveryCache` | Optional shared metadata cache. |
84
+
85
+ ### `StdioTransportOptions`
86
+
87
+ | Option | Type | Description |
88
+ |--------|------|-------------|
89
+ | `command` | `string` | Server executable. |
90
+ | `args` | `string[]` | Server args. |
91
+ | `cwd` | `string` | Server working directory. |
92
+ | `env` | `NodeJS.ProcessEnv` | Server environment. |
93
+ | `spawn` | `StdioSpawn` | Custom spawn function for tests. |
94
+
95
+ ## Environment variables
96
+
97
+ This package does not expose public environment variables. Pass process environment explicitly through `StdioTransportOptions.env` when a spawned MCP server needs it.
@@ -1,14 +1,14 @@
1
1
  import type { ChildProcessWithoutNullStreams, SpawnOptions } from "node:child_process";
2
2
  import type { Readable, Writable } from "node:stream";
3
3
  import type { JSONRPCMessage as SdkJsonRpcMessage } from "@modelcontextprotocol/sdk/types.js";
4
- import { type OAuthClientProviderOptions } from "mcp-oauth";
4
+ import { type OAuthClientProviderOptions } from "../../mcp-oauth/dist/index.js";
5
5
  import type { Server as TinyStdioMcpServer } from "tiny-stdio-mcp-server";
6
6
  import type { OAuthDiscoveryCache } from "./oauth-discovery.js";
7
7
  export { OAuthMetadataDiscovery, discoverOAuthMetadata, parseBearerWwwAuthenticateHeader, resolveAuthorizationServerMetadataUrl, resolveProtectedResourceMetadataUrl, } from "./oauth-discovery.js";
8
- export { createAuthStoreSessionStore, createDefaultOAuthClientProvider, } from "mcp-oauth";
8
+ export { createAuthStoreSessionStore, createDefaultOAuthClientProvider, } from "../../mcp-oauth/dist/index.js";
9
9
  export type { OAuthDiscoveryCache, } from "./oauth-discovery.js";
10
10
  export type { OAuthAuthorizationServerMetadata, OAuthDiscoveryResult, OAuthMetadataFetch, OAuthProtectedResourceMetadata, OAuthUnauthorizedChallenge } from "./oauth-discovery.js";
11
- export type { DefaultOAuthClientProviderOptions, OAuthClientProvider, OAuthClientProviderOptions, OAuthSessionStore, StoredOAuthSession, } from "mcp-oauth";
11
+ export type { DefaultOAuthClientProviderOptions, OAuthClientProvider, OAuthClientProviderOptions, OAuthSessionStore, StoredOAuthSession, } from "../../mcp-oauth/dist/index.js";
12
12
  export type RequestId = number | string;
13
13
  export interface Implementation {
14
14
  name: string;
@@ -1,9 +1,9 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import { PassThrough } from "node:stream";
3
- import { createOAuthClientProvider, OAuthError, } from "mcp-oauth";
3
+ import { createOAuthClientProvider, OAuthError, } from "../../mcp-oauth/dist/index.js";
4
4
  import { OAuthMetadataDiscovery, parseBearerWwwAuthenticateHeader, } from "./oauth-discovery.js";
5
5
  export { OAuthMetadataDiscovery, discoverOAuthMetadata, parseBearerWwwAuthenticateHeader, resolveAuthorizationServerMetadataUrl, resolveProtectedResourceMetadataUrl, } from "./oauth-discovery.js";
6
- export { createAuthStoreSessionStore, createDefaultOAuthClientProvider, } from "mcp-oauth";
6
+ export { createAuthStoreSessionStore, createDefaultOAuthClientProvider, } from "../../mcp-oauth/dist/index.js";
7
7
  const MCP_PROTOCOL_VERSION = "2025-03-26";
8
8
  export class McpClient {
9
9
  currentState = "disconnected";
@@ -1,4 +1,4 @@
1
- import type { OAuthAuthorizationServerMetadata, OAuthDiscoveryResult, OAuthMetadataFetch, OAuthProtectedResourceMetadata, OAuthUnauthorizedChallenge } from "mcp-oauth";
1
+ import type { OAuthAuthorizationServerMetadata, OAuthDiscoveryResult, OAuthMetadataFetch, OAuthProtectedResourceMetadata, OAuthUnauthorizedChallenge } from "../../mcp-oauth/dist/index.js";
2
2
  export type { OAuthAuthorizationServerMetadata, OAuthDiscoveryResult, OAuthMetadataFetch, OAuthProtectedResourceMetadata, OAuthUnauthorizedChallenge, };
3
3
  export interface OAuthDiscoveryCache {
4
4
  get(resourceUrl: string): OAuthDiscoveryResult | null | undefined | Promise<OAuthDiscoveryResult | null | undefined>;
@@ -1,4 +1,4 @@
1
- import { canonicalizeResourceIndicator } from "mcp-oauth";
1
+ import { canonicalizeResourceIndicator } from "../../mcp-oauth/dist/index.js";
2
2
  function defaultOAuthMetadataFetch(input, init) {
3
3
  return fetch(input, init);
4
4
  }
@@ -4,7 +4,7 @@ import {
4
4
  OAuthError,
5
5
  type OAuthSessionStore,
6
6
  type StoredOAuthSession,
7
- } from "mcp-oauth";
7
+ } from "../../mcp-oauth/dist/index.js";
8
8
  import { nodeFetch } from "tiny-http-mcp-server/testing";
9
9
  import {
10
10
  createMcpOAuthTestServer,
@@ -86,7 +86,12 @@ function cloneResponse(response: Response, body: string): Response {
86
86
  });
87
87
  }
88
88
 
89
- async function reservePort(hostname: string): Promise<number> {
89
+ interface BoundLoopbackServerFactory {
90
+ createServer(): http.Server;
91
+ port: number;
92
+ }
93
+
94
+ async function createBoundLoopbackServerFactory(hostname: string): Promise<BoundLoopbackServerFactory> {
90
95
  const server = http.createServer();
91
96
 
92
97
  await new Promise<void>((resolve, reject) => {
@@ -106,43 +111,23 @@ async function reservePort(hostname: string): Promise<number> {
106
111
  resolve();
107
112
  });
108
113
  });
109
- throw new Error("Expected temporary port reservation to bind to a TCP port");
114
+ throw new Error("Expected loopback test server to bind to a TCP port");
110
115
  }
111
116
 
112
- const port = address.port;
113
- await new Promise<void>((resolve, reject) => {
114
- server.close((error) => {
115
- if (error !== undefined) {
116
- reject(error);
117
- return;
118
- }
119
-
120
- resolve();
121
- });
122
- });
123
- return port;
124
- }
125
-
126
- function createFixedPortServerFactory(port: number): () => http.Server {
127
- return () => {
128
- const server = http.createServer();
129
- const originalListen = server.listen.bind(server);
130
-
131
- server.listen = ((...args: unknown[]) => {
132
- let callback: (() => void) | undefined;
133
-
134
- for (let index = args.length - 1; index >= 0; index -= 1) {
135
- const value = args[index];
136
- if (typeof value === "function") {
137
- callback = value as () => void;
138
- break;
139
- }
140
- }
141
-
142
- return originalListen(port, "127.0.0.1", callback);
143
- }) as typeof server.listen;
117
+ server.listen = ((...args: Parameters<http.Server["listen"]>) => {
118
+ const callback = [...args].reverse().find((value) => typeof value === "function");
119
+ if (typeof callback === "function") {
120
+ queueMicrotask(() => callback());
121
+ }
144
122
 
145
123
  return server;
124
+ }) as typeof server.listen;
125
+
126
+ return {
127
+ createServer(): http.Server {
128
+ return server;
129
+ },
130
+ port: address.port,
146
131
  };
147
132
  }
148
133
 
@@ -557,10 +542,10 @@ describe("HttpTransport OAuth integration", () => {
557
542
  });
558
543
 
559
544
  it("skips DCR for a configured static client and still completes the PKCE flow", async () => {
560
- const redirectPort = await reservePort("127.0.0.1");
561
- const redirectUri = `http://127.0.0.1:${redirectPort}/callback`;
545
+ const loopbackServer = await createBoundLoopbackServerFactory("127.0.0.1");
546
+ const redirectUri = `http://127.0.0.1:${loopbackServer.port}/callback`;
562
547
  const harness = await createHarness({
563
- createServer: createFixedPortServerFactory(redirectPort),
548
+ createServer: loopbackServer.createServer,
564
549
  oauthClient: {
565
550
  mode: "static",
566
551
  clientId: "static-client",
@@ -8,7 +8,7 @@ import {
8
8
  OAuthError,
9
9
  type OAuthClientProvider,
10
10
  type OAuthClientProviderOptions,
11
- } from "mcp-oauth";
11
+ } from "../../mcp-oauth/dist/index.js";
12
12
  import type { Server as TinyStdioMcpServer } from "tiny-stdio-mcp-server";
13
13
  import {
14
14
  OAuthMetadataDiscovery,
@@ -28,7 +28,7 @@ export {
28
28
  export {
29
29
  createAuthStoreSessionStore,
30
30
  createDefaultOAuthClientProvider,
31
- } from "mcp-oauth";
31
+ } from "../../mcp-oauth/dist/index.js";
32
32
  export type {
33
33
  OAuthDiscoveryCache,
34
34
  } from "./oauth-discovery.js";
@@ -39,7 +39,7 @@ export type {
39
39
  OAuthClientProviderOptions,
40
40
  OAuthSessionStore,
41
41
  StoredOAuthSession,
42
- } from "mcp-oauth";
42
+ } from "../../mcp-oauth/dist/index.js";
43
43
 
44
44
  export type RequestId = number | string;
45
45
 
@@ -4,8 +4,8 @@ import type {
4
4
  OAuthMetadataFetch,
5
5
  OAuthProtectedResourceMetadata,
6
6
  OAuthUnauthorizedChallenge,
7
- } from "mcp-oauth";
8
- import { canonicalizeResourceIndicator } from "mcp-oauth";
7
+ } from "../../mcp-oauth/dist/index.js";
8
+ import { canonicalizeResourceIndicator } from "../../mcp-oauth/dist/index.js";
9
9
 
10
10
  export type {
11
11
  OAuthAuthorizationServerMetadata,
@@ -0,0 +1,25 @@
1
+ import { execFile } from "node:child_process";
2
+ import { pathToFileURL } from "node:url";
3
+ import { promisify } from "node:util";
4
+ import { describe, expect, it } from "vitest";
5
+
6
+ const execFileAsync = promisify(execFile);
7
+
8
+ describe("tiny-mcp-client runtime imports", () => {
9
+ it("loads the source entrypoint in a clean Node process", async () => {
10
+ const moduleUrl = pathToFileURL(new URL("./index.ts", import.meta.url).pathname).href;
11
+
12
+ const result = await execFileAsync(process.execPath, [
13
+ "--import",
14
+ "tsx",
15
+ "--input-type=module",
16
+ "--eval",
17
+ `await import(${JSON.stringify(moduleUrl)});`,
18
+ ], {
19
+ cwd: new URL("../../..", import.meta.url),
20
+ });
21
+
22
+ expect(result.stdout).toBe("");
23
+ expect(result.stderr).not.toContain("SyntaxError");
24
+ });
25
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolcraft",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -45,7 +45,7 @@
45
45
  "commander": "^14.0.3",
46
46
  "console-table-printer": "^2.15.0",
47
47
  "tiny-stdio-mcp-server": "^0.1.0",
48
- "toolcraft-schema": "^0.0.8"
48
+ "toolcraft-schema": "^0.0.10"
49
49
  },
50
50
  "files": [
51
51
  "dist"