@yaks/mcp-client 0.0.0-stage → 0.2.36
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/LICENSE +202 -0
- package/README.md +174 -2
- package/_dist/mod.d.ts +90 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/oauth.d.ts +46 -0
- package/_dist/oauth.d.ts.map +1 -0
- package/_dist/servers.d.ts +11 -0
- package/_dist/servers.d.ts.map +1 -0
- package/_dist/vocab.d.ts +6 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/deno.json +1 -0
- package/mod.js +371 -0
- package/mod.js.map +1 -0
- package/mod.ts +492 -0
- package/oauth.js +95 -0
- package/oauth.js.map +1 -0
- package/oauth.ts +140 -0
- package/package.json +30 -4
- package/servers.js +94 -0
- package/servers.js.map +1 -0
- package/servers.ts +93 -0
- package/vocab.js +16 -0
- package/vocab.js.map +1 -0
- package/vocab.json +81 -0
- package/vocab.ts +17 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Jeff Peterson
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,175 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @yaks/mcp-client
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@yaks/mcp-client` connects to remote Model Context Protocol (MCP) servers over
|
|
4
|
+
Streamable HTTP and exposes their tools as portable `@yaks/graph.Tool`
|
|
5
|
+
definitions. It uses the installed MCP TypeScript SDK for protocol negotiation
|
|
6
|
+
and requires no session daemon, harness, graph, or local MCP server.
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
deno add jsr:@yaks/mcp-client
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Entry points:
|
|
13
|
+
|
|
14
|
+
- `@yaks/mcp-client`: connections, discovery, calls, naming, and error types.
|
|
15
|
+
- `@yaks/mcp-client/oauth`: where a server signs in, as data.
|
|
16
|
+
- `@yaks/mcp-client/servers`: optional graph-backed server configuration.
|
|
17
|
+
- `@yaks/mcp-client/vocab`: the graph vocabulary document alone.
|
|
18
|
+
|
|
19
|
+
This example talks to a server over the network, so it is not run as a test:
|
|
20
|
+
|
|
21
|
+
```ts ignore
|
|
22
|
+
import { connect } from '@yaks/mcp-client'
|
|
23
|
+
|
|
24
|
+
const remote = connect({ name: 'design', url: 'https://example.com/mcp' }, {
|
|
25
|
+
token: async () => credentialFromYourHost(),
|
|
26
|
+
})
|
|
27
|
+
try {
|
|
28
|
+
const tools = await remote.list()
|
|
29
|
+
// This example server is assumed to advertise render_html with an html argument.
|
|
30
|
+
console.log(tools.map((tool) => tool.name))
|
|
31
|
+
const result = await remote.call('render_html', {
|
|
32
|
+
html: '<h1>Example</h1>',
|
|
33
|
+
})
|
|
34
|
+
console.log(result)
|
|
35
|
+
} finally {
|
|
36
|
+
await remote.close()
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`credentialFromYourHost` is application code that returns the credential for
|
|
41
|
+
this server. The application supplies credentials; the package does not search
|
|
42
|
+
config files. The token callback runs for every HTTP request. Credentials
|
|
43
|
+
require HTTPS except on loopback hosts and are never forwarded across origins.
|
|
44
|
+
Redirects are refused.
|
|
45
|
+
|
|
46
|
+
A failed call is never replayed, because a lost response does not prove that a
|
|
47
|
+
remote mutation failed. Recreate the connection after a connection failure.
|
|
48
|
+
|
|
49
|
+
## Graph and CLI use
|
|
50
|
+
|
|
51
|
+
`remote.tools()` returns `@yaks/graph.Tool[]`. Each definition contains the
|
|
52
|
+
remote JSON Schema `inputSchema`, MCP annotations, connection metadata, and a
|
|
53
|
+
`run` handler. Existing graph, CLI, and model adapters can execute these tools;
|
|
54
|
+
this package adds no invocation or result components.
|
|
55
|
+
|
|
56
|
+
A **bundle** is one entity's components represented as a JSON object. A tool's
|
|
57
|
+
`run` method returns bundles containing its text blocks, or its structured
|
|
58
|
+
output when it wrote no text: a model reads one form, never both. Call
|
|
59
|
+
`remote.call()` when the application needs the complete MCP result, including
|
|
60
|
+
non-text content blocks.
|
|
61
|
+
|
|
62
|
+
Remote protocol names remain unchanged in `tools/call`. Exposed local names
|
|
63
|
+
combine a normalized namespace with the exact remote name: `yaks.app` and
|
|
64
|
+
`app_list` become `yaks_app__app_list`. Duplicate normalized namespaces or
|
|
65
|
+
exposed names are rejected. Invalid remote characters and names longer than 64
|
|
66
|
+
characters produce errors. Set `Server.namespace` to choose a shorter local
|
|
67
|
+
namespace and `label` to change descriptions. `meta.server` and
|
|
68
|
+
`meta.remoteName` preserve connection identity and the protocol name.
|
|
69
|
+
|
|
70
|
+
Remote schemas and annotations are preserved. The client does not infer CLI
|
|
71
|
+
nouns or verbs, convert schemas, or validate call arguments. The remote server
|
|
72
|
+
remains responsible for runtime argument validation.
|
|
73
|
+
|
|
74
|
+
`clients(servers, options)` combines several connections. Server names and
|
|
75
|
+
normalized namespaces must be unique. A server's optional `allow` array limits
|
|
76
|
+
discovery and calls to exact remote names. Tool lists are cached until a
|
|
77
|
+
`notifications/tools/list_changed` notification arrives or `refresh()`
|
|
78
|
+
invalidates one connection. Discovery is limited to 1,000 tools.
|
|
79
|
+
|
|
80
|
+
A CLI can add explicit noun and verb metadata, mapping each of `remote.tools()`
|
|
81
|
+
to `{ ...tool, noun: 'mockup', verb: 'publish' }`. Choose a unique pair for
|
|
82
|
+
every tool. The `@yaks/cli/structured` adapter can execute
|
|
83
|
+
`tool.run(args, context)`; the definitions remain usable by adapters that do not
|
|
84
|
+
use CLI names.
|
|
85
|
+
|
|
86
|
+
## Results and lifecycle
|
|
87
|
+
|
|
88
|
+
`call` returns the MCP result unchanged, including `isError`,
|
|
89
|
+
`structuredContent`, and content blocks. Protocol and transport failures throw
|
|
90
|
+
`MCPError`; an MCP reply with `isError` is still a successful protocol reply.
|
|
91
|
+
Applications should store large or base64 content blocks outside a model prompt,
|
|
92
|
+
for example in `@yaks/blob`, and return artifact references.
|
|
93
|
+
|
|
94
|
+
Requests default to a 60-second deadline. `call` accepts an `AbortSignal`.
|
|
95
|
+
Cancellation is best-effort and does not prove that a remote side effect was
|
|
96
|
+
undone. `close()` attempts to terminate the protocol session and closes the SDK
|
|
97
|
+
transport. Let accepted calls finish before orderly shutdown.
|
|
98
|
+
|
|
99
|
+
This version supports tools over Streamable HTTP. It does not support stdio,
|
|
100
|
+
legacy HTTP+SSE fallback, prompt or resource browsing, sampling, elicitation,
|
|
101
|
+
automatic reconnect, mutation retries, or task-based remote tools. Tools may
|
|
102
|
+
still return embedded resource content and links. The SDK buffers response
|
|
103
|
+
bodies in memory.
|
|
104
|
+
|
|
105
|
+
## Where a server signs in
|
|
106
|
+
|
|
107
|
+
`@yaks/mcp-client/oauth` exports `discover(url, challenge?, fetch?)`. It finds
|
|
108
|
+
where an MCP server signs in the way the MCP spec says: the server's
|
|
109
|
+
protected-resource metadata (RFC 9728, or the URL a 401 challenge names) points
|
|
110
|
+
at the authorization server, whose metadata (RFC 8414) names the endpoints. It
|
|
111
|
+
answers data, not a flow (and, asking a server, is not run as a test):
|
|
112
|
+
|
|
113
|
+
```ts ignore
|
|
114
|
+
import { discover } from '@yaks/mcp-client/oauth'
|
|
115
|
+
|
|
116
|
+
const { integration, register } = await discover('https://example.com/mcp')
|
|
117
|
+
// integration: { name, authorize, token, scopes?, resource, issuer?, hosts }
|
|
118
|
+
const client = await register('http://127.0.0.1:8765/oauth/callback')
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
`integration` is an integration as [@yaks/connections](../connections) takes it:
|
|
122
|
+
the grant is for the server (RFC 8707 `resource`), the server's host is the only
|
|
123
|
+
one its tokens go to, and a server that says it names its issuer on a return
|
|
124
|
+
(RFC 9207) has every return checked for it. `register(redirect)` answers the id
|
|
125
|
+
of a public client there: the URL of the host's own client metadata document
|
|
126
|
+
where `discover` was given one (its fourth argument) and the server takes Client
|
|
127
|
+
ID Metadata Documents, as ElevenLabs' does, else one registered now (RFC 7591).
|
|
128
|
+
`client(id, redirect)` is that document, which the host serves at `id`; yaks.app
|
|
129
|
+
serves it at `/connections/client.json`. Signing in, keeping the tokens and
|
|
130
|
+
refreshing them is @yaks/connections' and @yaks/oauth's.
|
|
131
|
+
|
|
132
|
+
Discovery and registration use bounded deadlines, refuse redirects, and require
|
|
133
|
+
HTTPS except on loopback addresses. Configure only trusted MCP servers.
|
|
134
|
+
|
|
135
|
+
## Graph server definitions
|
|
136
|
+
|
|
137
|
+
`@yaks/mcp-client/servers` is an optional adapter. It exports `serverOf` and
|
|
138
|
+
`graphToolName`; the `mcp_server` component is `mcpDoc`, from
|
|
139
|
+
`@yaks/mcp-client/vocab`.
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
import { graph } from '@yaks/graph'
|
|
143
|
+
import { ram } from '@yaks/ram'
|
|
144
|
+
import { loadVocab } from '@yaks/vocab'
|
|
145
|
+
import { mcpDoc } from '@yaks/mcp-client/vocab'
|
|
146
|
+
|
|
147
|
+
let vocab = loadVocab([mcpDoc])
|
|
148
|
+
let g = graph({ storage: ram(vocab), vocab })
|
|
149
|
+
await g.apply([{
|
|
150
|
+
entity: { eid: '$server' },
|
|
151
|
+
mcp_server: { name: 'Example', url: 'https://example.org/mcp' },
|
|
152
|
+
}])
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
`serverOf(bundle)` validates an enabled `mcp_server` component and returns its
|
|
156
|
+
label, entity ID, and portable `Server` configuration. The `$server` alias asks
|
|
157
|
+
the graph to generate a UUID. `enabled: false` disables the definition. `allow`
|
|
158
|
+
contains JSON text for an array of exact remote names. OAuth fields are
|
|
159
|
+
`redirect_url`, `client_id`, `client_metadata_url`, and `scope`.
|
|
160
|
+
|
|
161
|
+
A definition with `machine` is a server on a machine behind a tunnel: `machine`
|
|
162
|
+
is the entity whose tunnel reaches it, and `url` is the server's path there
|
|
163
|
+
(`/mcp`). Its `Server` stands at `MACHINE` with that path. Only a host holding
|
|
164
|
+
the tunnel can ask it, so `connect` refuses such a server without the host's
|
|
165
|
+
`fetch`, and a 401 from it asks for no sign-in.
|
|
166
|
+
|
|
167
|
+
`graphToolName` creates the displayed tool name, which is also the tool's
|
|
168
|
+
identity in a graph: a `tool` entity's id is derived from its name. Renaming the
|
|
169
|
+
label changes future exposed tool names.
|
|
170
|
+
|
|
171
|
+
Low-level `connect` and `clients` work without a graph. Consumer adapters may
|
|
172
|
+
validate tool input. The MCP SDK's output validation uses the shared
|
|
173
|
+
`@yaks/vocab/tools` validator. Draft-07, 2019-09, and 2020-12 are supported;
|
|
174
|
+
undeclared schemas default to 2020-12. Unsupported dialects fail explicitly, and
|
|
175
|
+
external schema references are not fetched.
|
package/_dist/mod.d.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { CallToolResult, Tool as RemoteTool } from "@modelcontextprotocol/sdk/types";
|
|
2
|
+
import type { Tool, ToolId } from "@yaks/graph";
|
|
3
|
+
/**
|
|
4
|
+
* A reply's structured content as the text a model reads, when the reply has
|
|
5
|
+
* no text of its own. A server sends its answer twice, as text for a reader
|
|
6
|
+
* and as `structuredContent` for a parser, and a model reads one of them: the
|
|
7
|
+
* text, which the spec has carry the structured content's JSON and which is
|
|
8
|
+
* all a client that reads only text sees. A reply that wrote no text is read
|
|
9
|
+
* as its structured content.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { assertEquals } from '@std/assert'
|
|
13
|
+
* let text = { type: 'text', text: 'https://example.test/mockup/1' }
|
|
14
|
+
* let structuredContent = { saved: '<h1>mockup</h1>' }
|
|
15
|
+
* assertEquals(unsaid({ content: [text], structuredContent }), undefined)
|
|
16
|
+
* assertEquals(
|
|
17
|
+
* unsaid({ content: [], structuredContent }),
|
|
18
|
+
* '{"saved":"<h1>mockup</h1>"}',
|
|
19
|
+
* )
|
|
20
|
+
* ```
|
|
21
|
+
*/ export declare const unsaid: (reply: {
|
|
22
|
+
content?: unknown[];
|
|
23
|
+
structuredContent?: unknown;
|
|
24
|
+
}) => string | undefined;
|
|
25
|
+
/** A trusted server's configuration, shared across the application.
|
|
26
|
+
* Credentials are resolved separately. */ export type Server = {
|
|
27
|
+
name: string;
|
|
28
|
+
/** Friendly display label; defaults to name. */ label?: string;
|
|
29
|
+
/** Local namespace for public tool names; defaults to name. */ namespace?: string;
|
|
30
|
+
url: string;
|
|
31
|
+
/** The entity whose tunnel reaches the machine this server runs on. Its
|
|
32
|
+
* `url` then stands at {@link MACHINE} and only its path is meant, and only
|
|
33
|
+
* a host holding that tunnel can ask it, through the `fetch` it gives
|
|
34
|
+
* `connect`. */ machine?: string;
|
|
35
|
+
/** Exact remote names; omission exposes all discovered tools. */ allow?: string[];
|
|
36
|
+
/** The header a credential is sent in, as it is kept; omission sends it
|
|
37
|
+
* as `Authorization: Bearer`. */ header?: string;
|
|
38
|
+
/** Explicit OAuth settings; tokens stay in the application's own storage. */ oauth?: {
|
|
39
|
+
redirectUrl?: string;
|
|
40
|
+
clientId?: string;
|
|
41
|
+
clientMetadataUrl?: string;
|
|
42
|
+
scope?: string;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
export type Options = {
|
|
46
|
+
token?: (server: Server) => string | null | Promise<string | null>;
|
|
47
|
+
fetch?: typeof fetch;
|
|
48
|
+
timeout?: number;
|
|
49
|
+
};
|
|
50
|
+
export declare class MCPError extends Error {
|
|
51
|
+
readonly server: string;
|
|
52
|
+
constructor(message: string, server: string);
|
|
53
|
+
}
|
|
54
|
+
export declare class MCPAuthorizationRequired extends MCPError {
|
|
55
|
+
readonly challenge: {
|
|
56
|
+
resourceMetadataUrl?: string;
|
|
57
|
+
scope?: string;
|
|
58
|
+
};
|
|
59
|
+
constructor(server: string, challenge?: {
|
|
60
|
+
resourceMetadataUrl?: string;
|
|
61
|
+
scope?: string;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/** Where a server on a machine stands: a tunnel reaches one machine whatever
|
|
65
|
+
* host a request names, so its address is this origin and the server's path. */ export declare const MACHINE: 'http://machine';
|
|
66
|
+
/** Normalize only the local namespace, never the server's opaque tool name. */ export declare const namespaceOf: (name: string) => string;
|
|
67
|
+
/** A provider-safe name with the exact remote name retained after the separator. */ export declare const nameOf: (server: string, name: string) => string;
|
|
68
|
+
/** Refuse normalized namespace collisions rather than hiding them behind hashes. */ export declare const checkNamespaces: (servers: readonly Server[]) => void;
|
|
69
|
+
/** Separators in opaque remote names can also create a cross-server collision. */ export declare const checkToolNames: (tools: readonly ToolId[]) => void;
|
|
70
|
+
export type Connection = {
|
|
71
|
+
list: () => Promise<RemoteTool[]>;
|
|
72
|
+
/** What the server said to read before its tools, in its answer to
|
|
73
|
+
* `initialize` (the protocol's `instructions`), or nothing where it said
|
|
74
|
+
* none. It is the server's own text, as trusted as the server is. */ instructions: () => Promise<string | undefined>;
|
|
75
|
+
/** What the server calls itself in its answer to `initialize` (the
|
|
76
|
+
* protocol's `serverInfo`): its `title` where it gave one, else its `name`;
|
|
77
|
+
* nothing where it gave neither. */ about: () => Promise<string | undefined>;
|
|
78
|
+
call: (name: string, args: Record<string, unknown>, signal?: AbortSignal) => Promise<CallToolResult>;
|
|
79
|
+
refresh: () => void;
|
|
80
|
+
tools: () => Promise<Tool[]>;
|
|
81
|
+
close: () => Promise<void>;
|
|
82
|
+
};
|
|
83
|
+
export type Clients = {
|
|
84
|
+
tools: () => Promise<Tool[]>;
|
|
85
|
+
close: () => Promise<void>;
|
|
86
|
+
};
|
|
87
|
+
/** One owned connection. connect/list are lazy; calls are never automatically replayed. */ export declare const connect: (server: Server, options?: Options) => Connection;
|
|
88
|
+
/** Several configured connections at once, usable from a CLI, from graph
|
|
89
|
+
* tools, or from anywhere else. */ export declare const clients: (servers: readonly Server[], options?: Options) => Clients;
|
|
90
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sources":["../mod.ts"],"names":[],"mappings":"AAMA,cACE,cAAc,EACd,QAAQ,UAAU,0CACgC;AACpD,cAAc,IAAI,EAAE,MAAM,2BAAgC;AA8D1D;;;;;;;;;;;;;;;;;;CAkBC,GACD,OAAO,cAAM,SACX;EAAS,UAAU,OAAO;EAAI,oBAAoB,OAAO;MACxD,MAAM,GAAG,SAAS,CAMwB;AAE7C;wCACwC,GACxC,YAAY;EACV,MAAM,MAAM;EACZ,8CAA8C,GAC9C,QAAQ,MAAM;EACd,6DAA6D,GAC7D,YAAY,MAAM;EAClB,KAAK,MAAM;EACX;;;gBAGc,GACd,UAAU,MAAM;EAChB,+DAA+D,GAC/D,QAAQ,MAAM;EACd;iCAC+B,GAC/B,SAAS,MAAM;EACf,2EAA2E,GAC3E;IACE,cAAc,MAAM;IACpB,WAAW,MAAM;IACjB,oBAAoB,MAAM;IAC1B,QAAQ,MAAM;;;AAGlB,YAAY;EACV,SAAS,QAAQ,WAAW,MAAM,GAAG,IAAI,GAAG,QAAQ,MAAM,GAAG,IAAI;EACjE,eAAe;EACf,UAAU,MAAM;;AAElB,OAAO,cAAM,iBAAiB;WACiB,QAAQ,MAAM;EAA3D,YAAY,SAAS,MAAM,EAAE,AAAgB,QAAQ,MAAM;AAG7D;AACA,OAAO,cAAM,iCAAiC;WAG1B;IACd,sBAAsB,MAAM;IAC5B,QAAQ,MAAM;;EAJlB,YACE,QAAQ,MAAM,EACd,AAAgB;IACd,sBAAsB,MAAM;IAC5B,QAAQ,MAAM;GACV;AAIV;AACA;8EAC8E,GAC9E,OAAO,cAAM,SAAU,iBAAgB;AAEvC,6EAA6E,GAC7E,OAAO,cAAM,cAAe,MAAM,MAAM,KAAG,MAAM,CAMhD;AAED,kFAAkF,GAClF,OAAO,cAAM,SAAU,QAAQ,MAAM,EAAE,MAAM,MAAM,KAAG,MAAM,CAe3D;AAED,kFAAkF,GAClF,OAAO,cAAM,kBAAmB,kBAAkB,aAAW,IAAI,CAShE;AAED,gFAAgF,GAChF,OAAO,cAAM,iBAAkB,gBAAgB,aAAW,IAAI,CAQ7D;AAED,YAAY;EACV,YAAY,QAAQ;EACpB;;qEAEmE,GACnE,oBAAoB,QAAQ,MAAM,GAAG,SAAS;EAC9C;;oCAEkC,GAClC,aAAa,QAAQ,MAAM,GAAG,SAAS;EACvC,OACE,MAAM,MAAM,EACZ,MAAM,OAAO,MAAM,EAAE,OAAO,GAC5B,SAAS,gBACN,QAAQ;EACb,eAAe,IAAI;EACnB,aAAa,QAAQ;EACrB,aAAa,QAAQ,IAAI;;AAE3B,YAAY;EACV,aAAa,QAAQ;EACrB,aAAa,QAAQ,IAAI;;AAG3B,yFAAyF,GACzF,OAAO,cAAM,UAAW,QAAQ,QAAQ,UAAS,YAAe,WA4O/D;AAED;iCACiC,GACjC,OAAO,cAAM,UACX,kBAAkB,UAClB,UAAS,YACR,QAoBF"}
|
package/_dist/oauth.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export type AuthorizationChallenge = {
|
|
2
|
+
resourceMetadataUrl?: string;
|
|
3
|
+
scope?: string;
|
|
4
|
+
};
|
|
5
|
+
/** An MCP server's sign-in, as data, and how to register a client with it. */ export type Found = {
|
|
6
|
+
integration: {
|
|
7
|
+
name: string;
|
|
8
|
+
authorize: string;
|
|
9
|
+
token: string;
|
|
10
|
+
userinfo?: string;
|
|
11
|
+
scopes?: string[];
|
|
12
|
+
resource: string;
|
|
13
|
+
issuer?: string;
|
|
14
|
+
hosts: string[];
|
|
15
|
+
};
|
|
16
|
+
/** a public client for `redirect`: the host's metadata document where the
|
|
17
|
+
* server takes one, else one registered now; its id */ register: (redirect: string) => Promise<string>;
|
|
18
|
+
};
|
|
19
|
+
/** A public client's metadata (RFC 7591), and its id where it is a
|
|
20
|
+
* document's URL. */ export type ClientDocument = {
|
|
21
|
+
client_id?: string;
|
|
22
|
+
client_name: string;
|
|
23
|
+
redirect_uris: string[];
|
|
24
|
+
grant_types: string[];
|
|
25
|
+
response_types: string[];
|
|
26
|
+
token_endpoint_auth_method: string;
|
|
27
|
+
};
|
|
28
|
+
/** What the host's public client says of itself, returning to `redirect`:
|
|
29
|
+
* what it registers with (RFC 7591), and its metadata document, served at
|
|
30
|
+
* `id`, the URL that is its id where a server takes one.
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { assertEquals } from '@std/assert'
|
|
34
|
+
* let doc = client('https://h.test/oauth/client.json', 'https://h.test/cb')
|
|
35
|
+
* assertEquals([doc.client_id, doc.redirect_uris], [
|
|
36
|
+
* 'https://h.test/oauth/client.json', ['https://h.test/cb'],
|
|
37
|
+
* ])
|
|
38
|
+
* ```
|
|
39
|
+
*/ export declare const client: (id: string | undefined, redirect: string) => ClientDocument;
|
|
40
|
+
export declare class AuthorizationError extends Error {
|
|
41
|
+
}
|
|
42
|
+
/** Find where the server at `url` signs in. The integration is named for the
|
|
43
|
+
* server, sends its tokens to the server's host alone, and asks for the grant
|
|
44
|
+
* to be for the server (RFC 8707). `document` is the URL the host serves its
|
|
45
|
+
* client's metadata document at ({@link client}), where it serves one. */ export declare const discover: (url: string, challenge?: AuthorizationChallenge, fetch?: typeof globalThis.fetch, document?: string) => Promise<Found>;
|
|
46
|
+
//# sourceMappingURL=oauth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth.d.ts","sources":["../oauth.ts"],"names":[],"mappings":"AAgBA,YAAY;EACV,sBAAsB,MAAM;EAC5B,QAAQ,MAAM;;AAGhB,4EAA4E,GAC5E,YAAY;EACV;IACE,MAAM,MAAM;IACZ,WAAW,MAAM;IACjB,OAAO,MAAM;IACb,WAAW,MAAM;IACjB,SAAS,MAAM;IACf,UAAU,MAAM;IAChB,SAAS,MAAM;IACf,OAAO,MAAM;;EAEf;uDACqD,GACrD,WAAW,UAAU,MAAM,KAAK,QAAQ,MAAM;;AAGhD;mBACmB,GACnB,YAAY;EACV,YAAY,MAAM;EAClB,aAAa,MAAM;EACnB,eAAe,MAAM;EACrB,aAAa,MAAM;EACnB,gBAAgB,MAAM;EACtB,4BAA4B,MAAM;;AAGpC;;;;;;;;;;;CAWC,GACD,OAAO,cAAM,SACX,IAAI,MAAM,GAAG,SAAS,EACtB,UAAU,MAAM,KACf,eAOD;AAEF,OAAO,cAAM,2BAA2B;AAAO;AAc/C;;;wEAGwE,GACxE,OAAO,cAAM,WACX,KAAK,MAAM,EACX,YAAW,wBACX,eAAc,WAAW,OACzB,WAAW,MAAM,KAChB,QAAQ,OA2CV"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Persisted MCP server definitions. Connections and credentials are not graph data. */ import type { Bundle } from "@yaks/graph";
|
|
2
|
+
import { type Server } from "./mod.js";
|
|
3
|
+
export type GraphServer = {
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
server: Server;
|
|
7
|
+
};
|
|
8
|
+
/** Whether a credential may be sent in the header `name`. */ export declare const credentialHeader: (name: string) => boolean;
|
|
9
|
+
/** Validate one definition before connecting. Invalid rows need not block other servers. */ export declare const serverOf: (row: Bundle) => GraphServer | undefined;
|
|
10
|
+
/** Public names are readable; identity and connection revisions are separate. */ export declare const graphToolName: (_id: string, server: Server, remote: string) => string;
|
|
11
|
+
//# sourceMappingURL=servers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"servers.d.ts","sources":["../servers.ts"],"names":[],"mappings":"AAAA,sFAAsF,GACtF,cAAc,MAAM,2BAAsC;AAC1D,SAAuC,KAAK,MAAM,mBAAkB;AAEpE,YAAY;EAAgB,IAAI,MAAM;EAAE,OAAO,MAAM;EAAE,QAAQ;;AAiB/D,2DAA2D,GAC3D,OAAO,cAAM,mBAAoB,MAAM,MAAM,KAAG,OAAO,CACS;AAEhE,0FAA0F,GAC1F,OAAO,cAAM,WAAY,KAAK,WAAS,cAAc,SAAS,CA2D7D;AAED,+EAA+E,GAC/E,OAAO,cAAM,gBACX,KAAK,MAAM,EACX,QAAQ,QACR,QAAQ,MAAM,KACb,MAAM,CAAmD"}
|
package/_dist/vocab.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { VocabDoc } from "@yaks/vocab";
|
|
2
|
+
/** The `mcp_server` component: a server definition, persisted. */ export declare let mcpDoc: VocabDoc;
|
|
3
|
+
/** What this package is: its manifest's description, the one place it is
|
|
4
|
+
* written, which a host stamps on each document here. */ export declare let description: string;
|
|
5
|
+
/** Every document this plugin declares. */ export declare let docs: VocabDoc[];
|
|
6
|
+
//# sourceMappingURL=vocab.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vocab.d.ts","sources":["../vocab.ts"],"names":[],"mappings":"AAIA,cAAc,QAAQ,2BAAgC;AAItD,gEAAgE,GAChE,OAAO,YAAI,QAAQ,SAAc;AAEjC;uDACuD,GACvD,OAAO,YAAI,aAAa,MAAM,CAAuB;AAErD,yCAAyC,GACzC,OAAO,YAAI,MAAM,WAAqB"}
|
package/deno.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"compilerOptions":{"lib":["deno.ns","dom","esnext"]},"publish":{"exclude":["**/*_test.ts","testing.ts"]},"name":"@yaks/mcp-client","version":"0.2.36","license":"Apache-2.0","description":"Consume remote MCP tools as portable graph Tool definitions over Streamable HTTP.","exports":{".":"./mod.ts","./oauth":"./oauth.ts","./servers":"./servers.ts","./vocab":"./vocab.ts"},"imports":{"@yaks/mcp-client":"./mod.ts","@yaks/mcp-client/oauth":"./oauth.ts","@yaks/mcp-client/servers":"./servers.ts","@yaks/mcp-client/vocab":"./vocab.ts"}}
|