@jangmanj/mcp-client 0.1.1 → 0.3.0
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/README.md +72 -0
- package/dist/core/schema/types.d.ts +11 -6
- package/dist/core/schema/types.js +1 -1
- package/dist/ext-events/push.js +1 -1
- package/extensions/bridge.ts +574 -0
- package/extensions/config.ts +330 -0
- package/extensions/content.ts +78 -0
- package/extensions/index.ts +162 -0
- package/extensions/oauth.ts +159 -0
- package/extensions/pi-api.ts +130 -0
- package/package.json +20 -3
package/README.md
CHANGED
|
@@ -8,6 +8,34 @@ MCP 2026-07-28 client library: core protocol/lifecycle, stdio and HTTP transport
|
|
|
8
8
|
npm install @jangmanj/mcp-client
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
## Quickstart
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { McpClient } from "@jangmanj/mcp-client";
|
|
15
|
+
import { createOps } from "@jangmanj/mcp-client/ops";
|
|
16
|
+
import { StdioTransport } from "@jangmanj/mcp-client/transport-stdio";
|
|
17
|
+
|
|
18
|
+
const client = new McpClient({
|
|
19
|
+
transport: new StdioTransport({ command: "npx", args: ["-y", "@modelcontextprotocol/server-filesystem", "."] }),
|
|
20
|
+
server: { key: "filesystem" },
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const ops = createOps(client);
|
|
24
|
+
const tools = await ops.tools.listAll();
|
|
25
|
+
if (tools.kind === "ok") {
|
|
26
|
+
console.log(tools.value.items.map((t) => t.name));
|
|
27
|
+
const result = await ops.tools.call("list_allowed_directories");
|
|
28
|
+
if (result.kind === "ok") console.log(result.value.content);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
await client.close();
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Every call returns a discriminated `Outcome` (`ok` / `jsonrpc-error` / `transport-failure` /
|
|
35
|
+
`mrtr-interim` / …) instead of throwing — pattern-match on `kind`. HTTP servers use
|
|
36
|
+
`HttpTransport` from `/transport-http`; OAuth, bearer, and client-credentials live in
|
|
37
|
+
`/auth` (`OAuthAuthorization`, `ConfiguredBearer`, `ClientCredentialsAuth`).
|
|
38
|
+
|
|
11
39
|
## Subpath exports
|
|
12
40
|
|
|
13
41
|
- `@jangmanj/mcp-client` (re-exports `./core`)
|
|
@@ -27,9 +55,53 @@ npm install @jangmanj/mcp-client
|
|
|
27
55
|
- Use `"moduleResolution": "NodeNext"` (or `"Bundler"`) in your consumer `tsconfig.json` so subpath exports resolve cleanly.
|
|
28
56
|
- If your consumer `tsconfig.json` overrides `"lib"` without `"DOM"` (for example `"lib": ["ES2023"]`), install `@types/node` and include `"types": ["node"]` so standard Web/Node globals (`AbortSignal`, `URL`, `Response`, `CryptoKey`) are typed.
|
|
29
57
|
|
|
58
|
+
## Pi extension
|
|
59
|
+
|
|
60
|
+
This package doubles as a [Pi](https://pi.dev) package: installing it registers an
|
|
61
|
+
extension that replaces Pi's built-in MCP session support with a bridge built on
|
|
62
|
+
this library (transports, lifecycle, ops, MRTR) and exposes each server's tools to
|
|
63
|
+
Pi as `mcp__<server>__<tool>`.
|
|
64
|
+
|
|
65
|
+
```sh
|
|
66
|
+
pi install npm:@jangmanj/mcp-client
|
|
67
|
+
# or from a checkout / git ref:
|
|
68
|
+
pi install ./path/to/mcp-client
|
|
69
|
+
pi install git:github.com/JangMan-J/mcp-client@v0.1.1
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The extension reads the same `mcp.json` files as built-in MCP
|
|
73
|
+
(`$PI_CODING_AGENT_DIR/mcp.json` or `~/.pi/agent/mcp.json`, plus `.pi/mcp.json` in
|
|
74
|
+
trusted projects) with the same merge, interpolation (`${VAR}`, `!command`), and
|
|
75
|
+
exposure rules (`codemode` default, `direct`/`deferred`/`hidden`, `toolExposure`
|
|
76
|
+
patterns). `/mcp` lists server states; `/mcp reconnect <name>` restarts one.
|
|
77
|
+
Servers registered by other extensions via `pi.registerMcpServer()` are connected
|
|
78
|
+
too, with file configuration taking precedence.
|
|
79
|
+
|
|
80
|
+
Not supported yet: MCP prompts/resources exposure to Pi (servers offering only prompts or
|
|
81
|
+
resources connect but register nothing), elicitation UI (consent prompts decline by
|
|
82
|
+
default), task-based tool calls, and OAuth options `callbackPort`/`callbackUrl`/
|
|
83
|
+
`scope`/`authServerMetadataUrl` (the bridge uses an ephemeral loopback redirect and the
|
|
84
|
+
advertised scopes).
|
|
85
|
+
|
|
86
|
+
OAuth works out of the box for HTTP servers without a static `Authorization` header: the
|
|
87
|
+
first 401 marks the server "needs sign-in" in `/mcp`, and `/mcp login <name>` runs the
|
|
88
|
+
authorization-code + PKCE flow with CIMD/DCR registration through the system browser.
|
|
89
|
+
Credentials persist in `$PI_CODING_AGENT_DIR/mcp-client-oauth.json` (issuer-keyed);
|
|
90
|
+
`/mcp logout <name>` deletes them. Static clients can be set with
|
|
91
|
+
`"oauth": { "clientId": "...", "clientSecret": "${SECRET}", "clientName": "..." }`.
|
|
92
|
+
|
|
93
|
+
A running Pi session picks the extension up on `/reload`; fresh starts load it
|
|
94
|
+
automatically.
|
|
95
|
+
|
|
30
96
|
## Development
|
|
31
97
|
|
|
32
98
|
```sh
|
|
33
99
|
npm run check
|
|
34
100
|
npm run smoke:pack
|
|
101
|
+
npm run gen:spec-matrix # regenerate SPEC.md (requirement ID -> source -> tests)
|
|
102
|
+
npm run check:spec-drift # compare the vendored schema + spec prose against upstream
|
|
35
103
|
```
|
|
104
|
+
|
|
105
|
+
SPEC.md is the generated traceability matrix; CI fails when it is stale or a source
|
|
106
|
+
requirement ID is cited by no test and not exempted. `spec-drift.yml` (daily cron)
|
|
107
|
+
opens an issue when the upstream MCP 2026-07-28 schema or spec prose moves.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* AUTO-GENERATED from packages/core/src/schema/schema.json (MCP 2026-07-28, tag
|
|
2
|
+
* AUTO-GENERATED from packages/core/src/schema/schema.json (MCP 2026-07-28, tag 2bbace55).
|
|
3
3
|
* Do not edit manually; regenerate with `npm run gen:schema`.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
@@ -49,8 +49,8 @@ export type InputRequest = CreateMessageRequest | ListRootsRequest | ElicitReque
|
|
|
49
49
|
*/
|
|
50
50
|
export type ElicitRequestParams = ElicitRequestFormParams | ElicitRequestURLParams;
|
|
51
51
|
/**
|
|
52
|
-
* Restricted schema definitions
|
|
53
|
-
* without nested objects
|
|
52
|
+
* Restricted schema definitions for strings, numbers, booleans, and enums,
|
|
53
|
+
* without nested objects. The only arrays allowed are multi-select enums.
|
|
54
54
|
*
|
|
55
55
|
* This interface was referenced by `McpSchema20260728`'s JSON-Schema
|
|
56
56
|
* via the `definition` "PrimitiveSchemaDefinition".
|
|
@@ -1523,6 +1523,11 @@ export interface Tool {
|
|
|
1523
1523
|
* (`if`/`then`/`else`), reference keywords (`$ref`, `$defs`, `$anchor`), and any other
|
|
1524
1524
|
* standard validation or annotation keywords.
|
|
1525
1525
|
*
|
|
1526
|
+
* When using composition keywords, declare `properties` at the schema root and keep the
|
|
1527
|
+
* branches to presence assertions such as `required`. A subschema that fails on a type
|
|
1528
|
+
* error is indistinguishable from one that does not apply, so type constraints placed
|
|
1529
|
+
* inside `oneOf` branches are not enforced for whichever branch does not match.
|
|
1530
|
+
*
|
|
1526
1531
|
* Property schemas may carry an `x-mcp-header` annotation to mirror the
|
|
1527
1532
|
* argument value into an HTTP header on the Streamable HTTP transport. See
|
|
1528
1533
|
* the Streamable HTTP transport specification for the validity and
|
|
@@ -2727,12 +2732,12 @@ export interface InternalError {
|
|
|
2727
2732
|
*
|
|
2728
2733
|
* In MCP, this error is returned in various contexts when request parameters fail validation:
|
|
2729
2734
|
*
|
|
2730
|
-
* - **Tools**: Unknown tool name or
|
|
2735
|
+
* - **Tools**: Unknown tool name, or a request that does not satisfy the `CallToolRequest` schema. Invalid tool arguments are instead reported as tool execution errors, with `isError` set to true
|
|
2731
2736
|
* - **Prompts**: Unknown prompt name or missing required arguments
|
|
2732
2737
|
* - **Pagination**: Invalid or expired cursor values
|
|
2733
|
-
* - **Logging
|
|
2738
|
+
* - **Logging** (deprecated): Invalid log level
|
|
2734
2739
|
* - **Elicitation**: Server requests an elicitation mode not declared in client capabilities
|
|
2735
|
-
* - **Sampling
|
|
2740
|
+
* - **Sampling** (deprecated): Missing tool result or tool results mixed with other content
|
|
2736
2741
|
*
|
|
2737
2742
|
* This interface was referenced by `McpSchema20260728`'s JSON-Schema
|
|
2738
2743
|
* via the `definition` "InvalidParamsError".
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
2
|
/**
|
|
3
|
-
* AUTO-GENERATED from packages/core/src/schema/schema.json (MCP 2026-07-28, tag
|
|
3
|
+
* AUTO-GENERATED from packages/core/src/schema/schema.json (MCP 2026-07-28, tag 2bbace55).
|
|
4
4
|
* Do not edit manually; regenerate with `npm run gen:schema`.
|
|
5
5
|
*/
|
|
6
6
|
export {};
|
package/dist/ext-events/push.js
CHANGED
|
@@ -34,7 +34,7 @@ export function watchStream(open, clock, jitter, advance, accept, deliver) {
|
|
|
34
34
|
let heartbeat = 0;
|
|
35
35
|
const arm = () => {
|
|
36
36
|
timer?.();
|
|
37
|
-
timer = clock.setTimeout(reconnect, heartbeat);
|
|
37
|
+
timer = clock.setTimeout(reconnect, heartbeat * 2);
|
|
38
38
|
};
|
|
39
39
|
void stream.done.then(reconnect, reconnect);
|
|
40
40
|
void (async () => {
|