@corbits/mcp 0.1.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/LICENSE +176 -0
- package/README.md +81 -0
- package/dist/client.d.ts +39 -0
- package/dist/client.js +143 -0
- package/dist/hub/discover.d.ts +41 -0
- package/dist/hub/discover.js +100 -0
- package/dist/hub/index.d.ts +1 -0
- package/dist/hub/index.js +4 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/naming.d.ts +10 -0
- package/dist/naming.js +26 -0
- package/dist/sidecar-bundle.d.ts +48 -0
- package/dist/sidecar-bundle.js +176 -0
- package/dist/tool.d.ts +39 -0
- package/dist/tool.js +96 -0
- package/dist/url.d.ts +6 -0
- package/dist/url.js +22 -0
- package/package.json +88 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
|
|
3
|
+
Version 2.1, February 1999
|
|
4
|
+
|
|
5
|
+
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
|
6
|
+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
7
|
+
|
|
8
|
+
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
|
9
|
+
|
|
10
|
+
[This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.]
|
|
11
|
+
|
|
12
|
+
Preamble
|
|
13
|
+
|
|
14
|
+
The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users.
|
|
15
|
+
|
|
16
|
+
This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below.
|
|
17
|
+
|
|
18
|
+
When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things.
|
|
19
|
+
|
|
20
|
+
To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it.
|
|
21
|
+
|
|
22
|
+
For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights.
|
|
23
|
+
|
|
24
|
+
We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library.
|
|
25
|
+
|
|
26
|
+
To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others.
|
|
27
|
+
|
|
28
|
+
Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license.
|
|
29
|
+
|
|
30
|
+
Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs.
|
|
31
|
+
|
|
32
|
+
When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library.
|
|
33
|
+
|
|
34
|
+
We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances.
|
|
35
|
+
|
|
36
|
+
For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License.
|
|
37
|
+
|
|
38
|
+
In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system.
|
|
39
|
+
|
|
40
|
+
Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library.
|
|
41
|
+
|
|
42
|
+
The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run.
|
|
43
|
+
|
|
44
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
45
|
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
|
46
|
+
|
|
47
|
+
0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you".
|
|
48
|
+
|
|
49
|
+
A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables.
|
|
50
|
+
|
|
51
|
+
The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".)
|
|
52
|
+
|
|
53
|
+
"Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library.
|
|
54
|
+
|
|
55
|
+
Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does.
|
|
56
|
+
|
|
57
|
+
1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library.
|
|
58
|
+
|
|
59
|
+
You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
|
|
60
|
+
|
|
61
|
+
2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
|
|
62
|
+
|
|
63
|
+
a) The modified work must itself be a software library.
|
|
64
|
+
|
|
65
|
+
b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change.
|
|
66
|
+
|
|
67
|
+
c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License.
|
|
68
|
+
|
|
69
|
+
d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful.
|
|
70
|
+
|
|
71
|
+
(For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.)
|
|
72
|
+
|
|
73
|
+
These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.
|
|
74
|
+
|
|
75
|
+
Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library.
|
|
76
|
+
|
|
77
|
+
In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
|
|
78
|
+
|
|
79
|
+
3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices.
|
|
80
|
+
|
|
81
|
+
Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy.
|
|
82
|
+
|
|
83
|
+
This option is useful when you wish to copy part of the code of the Library into a program that is not a library.
|
|
84
|
+
|
|
85
|
+
4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange.
|
|
86
|
+
|
|
87
|
+
If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code.
|
|
88
|
+
|
|
89
|
+
5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License.
|
|
90
|
+
|
|
91
|
+
However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables.
|
|
92
|
+
|
|
93
|
+
When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law.
|
|
94
|
+
|
|
95
|
+
If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.)
|
|
96
|
+
|
|
97
|
+
Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself.
|
|
98
|
+
|
|
99
|
+
6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications.
|
|
100
|
+
|
|
101
|
+
You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things:
|
|
102
|
+
|
|
103
|
+
a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.)
|
|
104
|
+
|
|
105
|
+
b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with.
|
|
106
|
+
|
|
107
|
+
c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution.
|
|
108
|
+
|
|
109
|
+
d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place.
|
|
110
|
+
|
|
111
|
+
e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy.
|
|
112
|
+
|
|
113
|
+
For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.
|
|
114
|
+
|
|
115
|
+
It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute.
|
|
116
|
+
|
|
117
|
+
7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things:
|
|
118
|
+
|
|
119
|
+
a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above.
|
|
120
|
+
|
|
121
|
+
b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.
|
|
122
|
+
|
|
123
|
+
8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.
|
|
124
|
+
|
|
125
|
+
9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it.
|
|
126
|
+
|
|
127
|
+
10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License.
|
|
128
|
+
|
|
129
|
+
11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library.
|
|
130
|
+
|
|
131
|
+
If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances.
|
|
132
|
+
|
|
133
|
+
It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
|
|
134
|
+
|
|
135
|
+
This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
|
|
136
|
+
|
|
137
|
+
12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.
|
|
138
|
+
|
|
139
|
+
13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
|
|
140
|
+
|
|
141
|
+
Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation.
|
|
142
|
+
|
|
143
|
+
14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.
|
|
144
|
+
|
|
145
|
+
NO WARRANTY
|
|
146
|
+
|
|
147
|
+
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
|
148
|
+
|
|
149
|
+
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
|
150
|
+
|
|
151
|
+
END OF TERMS AND CONDITIONS
|
|
152
|
+
|
|
153
|
+
How to Apply These Terms to Your New Libraries
|
|
154
|
+
|
|
155
|
+
If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License).
|
|
156
|
+
|
|
157
|
+
To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
|
|
158
|
+
|
|
159
|
+
one line to give the library's name and an idea of what it does.
|
|
160
|
+
Copyright (C) year name of author
|
|
161
|
+
|
|
162
|
+
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
|
163
|
+
|
|
164
|
+
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
|
165
|
+
|
|
166
|
+
You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail.
|
|
167
|
+
|
|
168
|
+
You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names:
|
|
169
|
+
|
|
170
|
+
Yoyodyne, Inc., hereby disclaims all copyright interest in
|
|
171
|
+
the library `Frob' (a library for tweaking knobs) written
|
|
172
|
+
by James Random Hacker.
|
|
173
|
+
|
|
174
|
+
signature of Ty Coon, 1 April 1990
|
|
175
|
+
Ty Coon, President of Vice
|
|
176
|
+
That's all there is to it!
|
package/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# @corbits/mcp
|
|
2
|
+
|
|
3
|
+
An MCP client for Interchange: streamable HTTP transport (2025-03-26 spec),
|
|
4
|
+
one `@intx/agent` tool per remote tool, and no gate of its own -- native
|
|
5
|
+
per-tool grants check the whole surface.
|
|
6
|
+
|
|
7
|
+
## Shape
|
|
8
|
+
|
|
9
|
+
Discovery and calling are split, because a deployed agent's tool factories
|
|
10
|
+
are evaluated synchronously when the agent is constructed and the agent must
|
|
11
|
+
never hold a server's bearer.
|
|
12
|
+
|
|
13
|
+
1. **The deployer discovers the catalog once**, server-side, through the hub
|
|
14
|
+
route this package mounts. The browser never holds an MCP token, so this
|
|
15
|
+
is the only way an OAuth-protected server's `tools/list` can be read.
|
|
16
|
+
2. **The catalog is stored** with the rest of the agent's deploy config.
|
|
17
|
+
3. **`mcpServers` turns it into tools.** It is synchronous and does no
|
|
18
|
+
network work at construction: the names and the `ask` marks come from the
|
|
19
|
+
stored catalog.
|
|
20
|
+
4. **At run time the agent only ever sees a mediated handle.** Each server's
|
|
21
|
+
credential resolves to an `http` handle -- a fetch pinned to that server's
|
|
22
|
+
origin that injects the bearer per request -- so the token never reaches
|
|
23
|
+
agent code, and a relative path is all the bundle ever asks for.
|
|
24
|
+
|
|
25
|
+
### Hub
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { mountMcpDiscovery } from "@corbits/mcp/hub";
|
|
29
|
+
|
|
30
|
+
const api = new Hono<TenantEnv>();
|
|
31
|
+
mountMcpDiscovery(api, { db, cipher, requireGrant });
|
|
32
|
+
app.route("/api/tenants/:tenantId", api);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`POST /api/tenants/:tenantId/mcp/discover` with `{ url, credentialId? }`
|
|
36
|
+
answers `{ data: { serverInfo, tools } }`. `url` must be https (http only on
|
|
37
|
+
loopback); `credentialId` names a tenant credential whose secret is sent as a
|
|
38
|
+
bearer, and the keyless sentinel sends no `authorization` header at all. The
|
|
39
|
+
outbound fetch is origin-pinned and refuses a 3xx, so the secret never leaves
|
|
40
|
+
the server's own origin.
|
|
41
|
+
|
|
42
|
+
### Sidecar bundle
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { mcpServers } from "@corbits/mcp/sidecar-bundle";
|
|
46
|
+
|
|
47
|
+
export const tools = mcpServers({
|
|
48
|
+
servers: [
|
|
49
|
+
{
|
|
50
|
+
handle: "linear",
|
|
51
|
+
url: "https://mcp.linear.app/mcp",
|
|
52
|
+
tools: storedCatalog,
|
|
53
|
+
allowWithoutAsk: ["linear.list_issues"],
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Each catalog entry becomes a tool named `<handle>.<tool>`, with the remote
|
|
60
|
+
`inputSchema` passed through verbatim and its call proxied to `tools/call`. A
|
|
61
|
+
result's text content comes back as text and anything else as JSON; `isError`
|
|
62
|
+
passes through. A handle that will not resolve, or a server that fails
|
|
63
|
+
`initialize`, fails only that server's calls.
|
|
64
|
+
|
|
65
|
+
`mcpTools` (the root export) is the author-time equivalent, for code that can
|
|
66
|
+
await discovery itself.
|
|
67
|
+
|
|
68
|
+
## Grants
|
|
69
|
+
|
|
70
|
+
Every call is checked as resource `tool:<name>`, most specific match wins,
|
|
71
|
+
`deny` beats `ask` beats `allow`. Because each remote tool is its own agent
|
|
72
|
+
tool, `tool:<handle>.<tool>` is grantable individually and `tool:<handle>.*`
|
|
73
|
+
covers a whole server.
|
|
74
|
+
|
|
75
|
+
Every generated tool starts `ask`-marked. Listing `"<handle>.<tool>"` in
|
|
76
|
+
`allowWithoutAsk` is the only way to lower that mark, and it is ignored for
|
|
77
|
+
any remote tool the server flags `destructiveHint: true`.
|
|
78
|
+
|
|
79
|
+
## License
|
|
80
|
+
|
|
81
|
+
LGPL-2.1-only.
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export declare const McpToolSchema: import("arktype/internal/variants/object.ts").ObjectType<{
|
|
2
|
+
name: string;
|
|
3
|
+
inputSchema: Record<string, unknown>;
|
|
4
|
+
description?: string;
|
|
5
|
+
annotations?: {
|
|
6
|
+
readOnlyHint?: boolean;
|
|
7
|
+
destructiveHint?: boolean;
|
|
8
|
+
idempotentHint?: boolean;
|
|
9
|
+
openWorldHint?: boolean;
|
|
10
|
+
};
|
|
11
|
+
}, {}>;
|
|
12
|
+
export type McpTool = typeof McpToolSchema.infer;
|
|
13
|
+
export interface McpToolResult {
|
|
14
|
+
content: unknown;
|
|
15
|
+
isError?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export type FetchLike = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
18
|
+
export interface McpClientOptions {
|
|
19
|
+
/** Injectable `fetch` for tests and mediated-credential handles. */
|
|
20
|
+
fetch?: FetchLike;
|
|
21
|
+
}
|
|
22
|
+
export declare class McpError extends Error {
|
|
23
|
+
constructor(message: string);
|
|
24
|
+
}
|
|
25
|
+
declare const InitializeResult: import("arktype/internal/variants/object.ts").ObjectType<{
|
|
26
|
+
protocolVersion?: string;
|
|
27
|
+
serverInfo?: {
|
|
28
|
+
name: string;
|
|
29
|
+
version?: string;
|
|
30
|
+
};
|
|
31
|
+
}, {}>;
|
|
32
|
+
export type McpServerInfo = typeof InitializeResult.infer;
|
|
33
|
+
/** `initialize` handshake. The server's own identification is returned for a
|
|
34
|
+
* caller that shows it; nothing here depends on it. */
|
|
35
|
+
export declare function mcpInitialize(url: string, opts?: McpClientOptions): Promise<McpServerInfo>;
|
|
36
|
+
/** `tools/list`: the remote server's tool catalog. */
|
|
37
|
+
export declare function mcpListTools(url: string, opts?: McpClientOptions): Promise<McpTool[]>;
|
|
38
|
+
export declare function mcpCallTool(url: string, name: string, toolArguments: Record<string, unknown>, opts?: McpClientOptions): Promise<McpToolResult>;
|
|
39
|
+
export {};
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// MCP streamable-HTTP transport client (2025-03-26 spec): no session id or
|
|
2
|
+
// resumption because this client only ever sends one request and awaits
|
|
3
|
+
// its one reply, which is all initialize/tools-list/tools-call need.
|
|
4
|
+
import { type } from "arktype";
|
|
5
|
+
export const McpToolSchema = type({
|
|
6
|
+
name: "string",
|
|
7
|
+
"description?": "string",
|
|
8
|
+
inputSchema: "Record<string, unknown>",
|
|
9
|
+
"annotations?": {
|
|
10
|
+
"readOnlyHint?": "boolean",
|
|
11
|
+
"destructiveHint?": "boolean",
|
|
12
|
+
"idempotentHint?": "boolean",
|
|
13
|
+
"openWorldHint?": "boolean",
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
const JsonRpcResponse = type({
|
|
17
|
+
jsonrpc: "'2.0'",
|
|
18
|
+
id: "string | number",
|
|
19
|
+
"result?": "unknown",
|
|
20
|
+
"error?": { code: "number", message: "string", "data?": "unknown" },
|
|
21
|
+
});
|
|
22
|
+
export class McpError extends Error {
|
|
23
|
+
constructor(message) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.name = "McpError";
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
let nextId = 1;
|
|
29
|
+
/**
|
|
30
|
+
* Send one JSON-RPC request over streamable HTTP and return its `result`.
|
|
31
|
+
* Handles both response shapes the spec allows: a direct `application/json`
|
|
32
|
+
* body, and a `text/event-stream` whose `data:` frames each carry a
|
|
33
|
+
* JSON-RPC message -- the first one matching this request's id wins.
|
|
34
|
+
*/
|
|
35
|
+
async function sendRequest(url, method, params, opts) {
|
|
36
|
+
const fetchImpl = opts.fetch ?? fetch;
|
|
37
|
+
const id = nextId++;
|
|
38
|
+
const response = await fetchImpl(url, {
|
|
39
|
+
method: "POST",
|
|
40
|
+
headers: {
|
|
41
|
+
"content-type": "application/json",
|
|
42
|
+
accept: "application/json, text/event-stream",
|
|
43
|
+
},
|
|
44
|
+
body: JSON.stringify({
|
|
45
|
+
jsonrpc: "2.0",
|
|
46
|
+
id,
|
|
47
|
+
method,
|
|
48
|
+
...(params !== undefined ? { params } : {}),
|
|
49
|
+
}),
|
|
50
|
+
});
|
|
51
|
+
if (!response.ok) {
|
|
52
|
+
throw new McpError(`MCP server ${url} responded ${response.status} to ${method}`);
|
|
53
|
+
}
|
|
54
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
55
|
+
const message = contentType.includes("text/event-stream")
|
|
56
|
+
? await readSseJsonRpc(response, id)
|
|
57
|
+
: await response.json();
|
|
58
|
+
const parsed = JsonRpcResponse(message);
|
|
59
|
+
if (parsed instanceof type.errors) {
|
|
60
|
+
throw new McpError(`MCP server ${url} sent a malformed response to ${method}: ${parsed.summary}`);
|
|
61
|
+
}
|
|
62
|
+
if (parsed.error !== undefined) {
|
|
63
|
+
throw new McpError(`MCP server ${url} rejected ${method}: ${parsed.error.message}`);
|
|
64
|
+
}
|
|
65
|
+
return parsed.result;
|
|
66
|
+
}
|
|
67
|
+
/** Read an SSE body and return the first JSON-RPC message whose id matches. */
|
|
68
|
+
async function readSseJsonRpc(response, id) {
|
|
69
|
+
const body = response.body;
|
|
70
|
+
if (body === null) {
|
|
71
|
+
throw new McpError("MCP server sent an event-stream response with no body");
|
|
72
|
+
}
|
|
73
|
+
const reader = body.getReader();
|
|
74
|
+
const decoder = new TextDecoder();
|
|
75
|
+
let buffer = "";
|
|
76
|
+
try {
|
|
77
|
+
for (;;) {
|
|
78
|
+
const { done, value } = await reader.read();
|
|
79
|
+
if (done)
|
|
80
|
+
break;
|
|
81
|
+
buffer += decoder.decode(value, { stream: true });
|
|
82
|
+
const frames = buffer.split("\n\n");
|
|
83
|
+
buffer = frames.pop() ?? "";
|
|
84
|
+
for (const frame of frames) {
|
|
85
|
+
const dataLines = frame
|
|
86
|
+
.split("\n")
|
|
87
|
+
.filter((line) => line.startsWith("data:"))
|
|
88
|
+
.map((line) => line.slice(5).trim());
|
|
89
|
+
if (dataLines.length === 0)
|
|
90
|
+
continue;
|
|
91
|
+
const candidate = JSON.parse(dataLines.join("\n"));
|
|
92
|
+
if (typeof candidate === "object" &&
|
|
93
|
+
candidate !== null &&
|
|
94
|
+
"id" in candidate &&
|
|
95
|
+
candidate.id === id) {
|
|
96
|
+
return candidate;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
reader.releaseLock();
|
|
103
|
+
}
|
|
104
|
+
throw new McpError("MCP server closed the event stream without a matching response");
|
|
105
|
+
}
|
|
106
|
+
const InitializeResult = type({
|
|
107
|
+
"protocolVersion?": "string",
|
|
108
|
+
"serverInfo?": { name: "string", "version?": "string" },
|
|
109
|
+
});
|
|
110
|
+
/** `initialize` handshake. The server's own identification is returned for a
|
|
111
|
+
* caller that shows it; nothing here depends on it. */
|
|
112
|
+
export async function mcpInitialize(url, opts = {}) {
|
|
113
|
+
const result = await sendRequest(url, "initialize", {
|
|
114
|
+
protocolVersion: "2025-03-26",
|
|
115
|
+
capabilities: {},
|
|
116
|
+
clientInfo: { name: "@corbits/mcp", version: "0.1.0" },
|
|
117
|
+
}, opts);
|
|
118
|
+
const parsed = InitializeResult(result);
|
|
119
|
+
return parsed instanceof type.errors ? {} : parsed;
|
|
120
|
+
}
|
|
121
|
+
const ToolsListResult = type({ tools: McpToolSchema.array() });
|
|
122
|
+
/** `tools/list`: the remote server's tool catalog. */
|
|
123
|
+
export async function mcpListTools(url, opts = {}) {
|
|
124
|
+
const result = await sendRequest(url, "tools/list", undefined, opts);
|
|
125
|
+
const parsed = ToolsListResult(result);
|
|
126
|
+
if (parsed instanceof type.errors) {
|
|
127
|
+
throw new McpError(`MCP server ${url} sent a malformed tools/list result: ${parsed.summary}`);
|
|
128
|
+
}
|
|
129
|
+
return parsed.tools;
|
|
130
|
+
}
|
|
131
|
+
/** `tools/call`: invoke a remote tool by name with JSON arguments. */
|
|
132
|
+
const ToolCallResult = type({
|
|
133
|
+
content: "unknown",
|
|
134
|
+
"isError?": "boolean",
|
|
135
|
+
});
|
|
136
|
+
export async function mcpCallTool(url, name, toolArguments, opts = {}) {
|
|
137
|
+
const result = await sendRequest(url, "tools/call", { name, arguments: toolArguments }, opts);
|
|
138
|
+
const parsed = ToolCallResult(result);
|
|
139
|
+
if (parsed instanceof type.errors) {
|
|
140
|
+
throw new McpError(`MCP server ${url} sent a malformed tools/call result for ${name}: ${parsed.summary}`);
|
|
141
|
+
}
|
|
142
|
+
return parsed;
|
|
143
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { DB } from "@intx/db";
|
|
2
|
+
import type { TenantEnv } from "@intx/hub-api";
|
|
3
|
+
import { type CredentialCipher } from "@intx/types";
|
|
4
|
+
import type { Hono, MiddlewareHandler } from "hono";
|
|
5
|
+
import { type FetchLike, type McpTool, type McpServerInfo } from "../client.js";
|
|
6
|
+
export type MountMcpDiscoveryOpts = {
|
|
7
|
+
readonly db: DB["db"];
|
|
8
|
+
readonly cipher: CredentialCipher;
|
|
9
|
+
/** The host's stock grant middleware, so authority is checked exactly once, its way. */
|
|
10
|
+
readonly requireGrant: MiddlewareHandler<TenantEnv>;
|
|
11
|
+
/** Reported when a discovery attempt fails; the caller only sees a message. */
|
|
12
|
+
readonly onError?: (error: unknown, context: {
|
|
13
|
+
url: string;
|
|
14
|
+
}) => void;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Read a tenant credential's decrypted secret. Scoped by tenant so a
|
|
18
|
+
* credential id from another tenant reads as absent, not as a secret.
|
|
19
|
+
*/
|
|
20
|
+
export declare function readCredentialSecret(opts: {
|
|
21
|
+
readonly db: DB["db"];
|
|
22
|
+
readonly cipher: CredentialCipher;
|
|
23
|
+
readonly tenantId: string;
|
|
24
|
+
readonly credentialId: string;
|
|
25
|
+
}): Promise<string | undefined>;
|
|
26
|
+
export type McpDiscovery = {
|
|
27
|
+
readonly serverInfo: McpServerInfo;
|
|
28
|
+
readonly tools: readonly McpTool[];
|
|
29
|
+
};
|
|
30
|
+
/** Handshake and read a server's catalog over an origin-pinned fetch. */
|
|
31
|
+
export declare function discoverMcpServer(args: {
|
|
32
|
+
readonly url: string;
|
|
33
|
+
readonly secret?: string;
|
|
34
|
+
readonly fetch?: FetchLike;
|
|
35
|
+
}): Promise<McpDiscovery>;
|
|
36
|
+
/**
|
|
37
|
+
* Mount `POST /mcp/discover` on a tenant router. It answers with the server's
|
|
38
|
+
* identification and its whole tool catalog, which a deployer stores and
|
|
39
|
+
* hands to the sidecar bundle; the bundle itself never discovers anything.
|
|
40
|
+
*/
|
|
41
|
+
export declare function mountMcpDiscovery(app: Hono<TenantEnv>, opts: MountMcpDiscoveryOpts): void;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// Server-side MCP catalog discovery. The browser never holds an MCP server's
|
|
2
|
+
// token, so the only place an OAuth-protected server's `tools/list` can be
|
|
3
|
+
// read is here, behind the hub's own tenant-member gate and with the secret
|
|
4
|
+
// decrypted in this process and sent only to the server's own origin.
|
|
5
|
+
import { credential } from "@intx/db/schema";
|
|
6
|
+
import { credentialAad } from "@intx/types";
|
|
7
|
+
import { MCP_NO_TOKEN_SENTINEL, mcpOriginPinnedFetch, } from "@corbits/credential-mcp";
|
|
8
|
+
import { type } from "arktype";
|
|
9
|
+
import { and, eq } from "drizzle-orm";
|
|
10
|
+
import { mcpInitialize, mcpListTools, } from "../client.js";
|
|
11
|
+
import { parseMcpEndpoint } from "../url.js";
|
|
12
|
+
const DiscoverBody = type({
|
|
13
|
+
url: "string > 0",
|
|
14
|
+
"credentialId?": "string > 0",
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* Read a tenant credential's decrypted secret. Scoped by tenant so a
|
|
18
|
+
* credential id from another tenant reads as absent, not as a secret.
|
|
19
|
+
*/
|
|
20
|
+
export async function readCredentialSecret(opts) {
|
|
21
|
+
const [row] = await opts.db
|
|
22
|
+
.select()
|
|
23
|
+
.from(credential)
|
|
24
|
+
.where(and(eq(credential.id, opts.credentialId), eq(credential.tenantId, opts.tenantId)))
|
|
25
|
+
.limit(1);
|
|
26
|
+
if (row === undefined || row.secret === null)
|
|
27
|
+
return undefined;
|
|
28
|
+
return opts.cipher.decrypt(row.secret, credentialAad(row.id, "secret"));
|
|
29
|
+
}
|
|
30
|
+
/** A 3xx would send the bearer onward, so the pinned fetch's manual redirect
|
|
31
|
+
* is turned into a refusal rather than a response the client tries to read. */
|
|
32
|
+
function refusingRedirects(inner) {
|
|
33
|
+
return async (input, init) => {
|
|
34
|
+
const response = await inner(input, init);
|
|
35
|
+
if (response.status >= 300 && response.status < 400) {
|
|
36
|
+
throw new Error(`the MCP server answered a ${String(response.status)} redirect; refusing to follow it`);
|
|
37
|
+
}
|
|
38
|
+
return response;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/** Handshake and read a server's catalog over an origin-pinned fetch. */
|
|
42
|
+
export async function discoverMcpServer(args) {
|
|
43
|
+
const target = parseMcpEndpoint(args.url);
|
|
44
|
+
const token = args.secret === undefined || args.secret === MCP_NO_TOKEN_SENTINEL
|
|
45
|
+
? undefined
|
|
46
|
+
: args.secret;
|
|
47
|
+
const pinned = refusingRedirects(mcpOriginPinnedFetch({
|
|
48
|
+
pinnedOrigin: target.origin,
|
|
49
|
+
readToken: () => token,
|
|
50
|
+
...(args.fetch !== undefined ? { fetch: args.fetch } : {}),
|
|
51
|
+
}));
|
|
52
|
+
const serverInfo = await mcpInitialize(args.url, { fetch: pinned });
|
|
53
|
+
const tools = await mcpListTools(args.url, { fetch: pinned });
|
|
54
|
+
return { serverInfo, tools };
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Mount `POST /mcp/discover` on a tenant router. It answers with the server's
|
|
58
|
+
* identification and its whole tool catalog, which a deployer stores and
|
|
59
|
+
* hands to the sidecar bundle; the bundle itself never discovers anything.
|
|
60
|
+
*/
|
|
61
|
+
export function mountMcpDiscovery(app, opts) {
|
|
62
|
+
app.post("/mcp/discover", opts.requireGrant, async (c) => {
|
|
63
|
+
const body = DiscoverBody(await c.req.json().catch(() => undefined));
|
|
64
|
+
if (body instanceof type.errors) {
|
|
65
|
+
return c.json({ error: body.summary }, 400);
|
|
66
|
+
}
|
|
67
|
+
let target;
|
|
68
|
+
try {
|
|
69
|
+
target = parseMcpEndpoint(body.url);
|
|
70
|
+
}
|
|
71
|
+
catch (cause) {
|
|
72
|
+
return c.json({ error: cause instanceof Error ? cause.message : String(cause) }, 400);
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const secret = body.credentialId === undefined
|
|
76
|
+
? undefined
|
|
77
|
+
: await readCredentialSecret({
|
|
78
|
+
db: opts.db,
|
|
79
|
+
cipher: opts.cipher,
|
|
80
|
+
tenantId: c.get("tenant").id,
|
|
81
|
+
credentialId: body.credentialId,
|
|
82
|
+
});
|
|
83
|
+
if (body.credentialId !== undefined && secret === undefined) {
|
|
84
|
+
return c.json({ error: "credential not found" }, 404);
|
|
85
|
+
}
|
|
86
|
+
const data = await discoverMcpServer({
|
|
87
|
+
url: body.url,
|
|
88
|
+
...(secret !== undefined ? { secret } : {}),
|
|
89
|
+
});
|
|
90
|
+
return c.json({ data });
|
|
91
|
+
}
|
|
92
|
+
catch (cause) {
|
|
93
|
+
opts.onError?.(cause, { url: body.url });
|
|
94
|
+
// The message describes the handshake, never the material it used.
|
|
95
|
+
return c.json({
|
|
96
|
+
error: `the MCP server at ${target.origin} could not be discovered: ${cause instanceof Error ? cause.message : String(cause)}`,
|
|
97
|
+
}, 422);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { mountMcpDiscovery, discoverMcpServer, readCredentialSecret, type McpDiscovery, type MountMcpDiscoveryOpts, } from "./discover.js";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// Server-only entry point: the hub-hosted MCP discovery mount. The root and
|
|
2
|
+
// `./sidecar-bundle` entries stay free of `hono` and `@intx/db` so neither a
|
|
3
|
+
// browser bundle nor a deployed agent ever reaches them.
|
|
4
|
+
export { mountMcpDiscovery, discoverMcpServer, readCredentialSecret, } from "./discover.js";
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { mcpTools, type McpServerConfig, type McpToolsEnv, type McpToolsOptions, } from "./tool.js";
|
|
2
|
+
export { qualifiedName, isAskExempt, toolDescription } from "./naming.js";
|
|
3
|
+
export { mcpInitialize, mcpListTools, mcpCallTool, McpError, McpToolSchema, type McpTool, type McpToolResult, type McpClientOptions, type FetchLike, } from "./client.js";
|
package/dist/index.js
ADDED
package/dist/naming.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { McpTool } from "./client.js";
|
|
2
|
+
/** `<server>.<tool>`, the grantable unit: `tool:<server>.*` covers a server. */
|
|
3
|
+
export declare function qualifiedName(server: string, tool: string): string;
|
|
4
|
+
export declare function toolDescription(tool: McpTool, server: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* Whether `qualified` may drop below the `ask` floor: it must be on the
|
|
7
|
+
* operator's `allowWithoutAsk` list AND the remote tool must not be
|
|
8
|
+
* `destructiveHint: true` -- that flag wins no matter what is listed.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isAskExempt(qualified: string, tool: McpTool, allowWithoutAsk: readonly string[]): boolean;
|
package/dist/naming.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Naming and the ask floor, shared by the author-time `mcpTools` factory and
|
|
2
|
+
// the deployed `mcpServers` sidecar bundle so both project a server's catalog
|
|
3
|
+
// onto identical tool names and identical approval marks.
|
|
4
|
+
/** `<server>.<tool>`, the grantable unit: `tool:<server>.*` covers a server. */
|
|
5
|
+
export function qualifiedName(server, tool) {
|
|
6
|
+
return `${server}.${tool}`;
|
|
7
|
+
}
|
|
8
|
+
export function toolDescription(tool, server) {
|
|
9
|
+
const hints = Object.entries(tool.annotations ?? {})
|
|
10
|
+
.filter(([, v]) => v === true)
|
|
11
|
+
.map(([k]) => k);
|
|
12
|
+
const base = tool.description ?? `Remote tool "${tool.name}" on MCP server "${server}".`;
|
|
13
|
+
return hints.length > 0
|
|
14
|
+
? `${base} (server annotations: ${hints.join(", ")})`
|
|
15
|
+
: base;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Whether `qualified` may drop below the `ask` floor: it must be on the
|
|
19
|
+
* operator's `allowWithoutAsk` list AND the remote tool must not be
|
|
20
|
+
* `destructiveHint: true` -- that flag wins no matter what is listed.
|
|
21
|
+
*/
|
|
22
|
+
export function isAskExempt(qualified, tool, allowWithoutAsk) {
|
|
23
|
+
if (tool.annotations?.destructiveHint === true)
|
|
24
|
+
return false;
|
|
25
|
+
return allowWithoutAsk.includes(qualified);
|
|
26
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type AnnotatedToolFactory, type BaseEnv } from "@intx/agent";
|
|
2
|
+
import { type McpTool } from "./client.js";
|
|
3
|
+
/** The consumer key a host matches a credential binding against. */
|
|
4
|
+
export declare const SIDECAR_BUNDLE_ID = "@corbits/mcp/sidecar-bundle";
|
|
5
|
+
type MediatedFetch = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
6
|
+
type HttpCredential = {
|
|
7
|
+
readonly kind: string;
|
|
8
|
+
fetch: MediatedFetch;
|
|
9
|
+
dispose(): void | Promise<void>;
|
|
10
|
+
};
|
|
11
|
+
/** The slice of the host-assembled runtime capabilities this bundle uses. */
|
|
12
|
+
type CredentialCapabilities = {
|
|
13
|
+
resolve(key: "credentials"): {
|
|
14
|
+
resolve(handle: string): Promise<HttpCredential>;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
/** The env keys `requires` declares, on top of the core ones. */
|
|
18
|
+
export type McpServersEnv = BaseEnv & {
|
|
19
|
+
readonly capabilities: CredentialCapabilities;
|
|
20
|
+
};
|
|
21
|
+
export interface McpBoundServer {
|
|
22
|
+
/** Credential handle the host bound this server's token to. */
|
|
23
|
+
readonly handle: string;
|
|
24
|
+
/** The server's streamable-HTTP endpoint; the handle is pinned to its origin. */
|
|
25
|
+
readonly url: string;
|
|
26
|
+
/** The catalog a deployer discovered ahead of time through the hub route. */
|
|
27
|
+
readonly tools: readonly McpTool[];
|
|
28
|
+
/**
|
|
29
|
+
* `<handle>.<tool>` names allowed below the `ask` floor. A remote tool the
|
|
30
|
+
* server flags `destructiveHint: true` stays at `ask` regardless.
|
|
31
|
+
*/
|
|
32
|
+
readonly allowWithoutAsk?: readonly string[];
|
|
33
|
+
}
|
|
34
|
+
export interface McpServersConfig {
|
|
35
|
+
readonly servers: readonly McpBoundServer[];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* MCP results are never interpreted: text blocks come back as their text so
|
|
39
|
+
* the model reads prose, and anything else is handed over verbatim as JSON.
|
|
40
|
+
*/
|
|
41
|
+
export declare function shapeMcpContent(content: unknown): string;
|
|
42
|
+
/**
|
|
43
|
+
* The sidecar bundle: one `@intx/agent` tool per catalog entry, named
|
|
44
|
+
* `<handle>.<tool>` so each is grantable on its own. Synchronous, with
|
|
45
|
+
* static definitions — the catalog is already in hand.
|
|
46
|
+
*/
|
|
47
|
+
export declare function mcpServers(config: McpServersConfig): AnnotatedToolFactory<McpServersEnv>;
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// Sidecar-bundle entry for `@corbits/mcp` — the factory a deployed agent's
|
|
2
|
+
// tool-package loader invokes, so the agent carries a remote server's tools
|
|
3
|
+
// without any agent-owned MCP client code.
|
|
4
|
+
//
|
|
5
|
+
// The bundle holds no bearer. Each server's credential reaches it only as a
|
|
6
|
+
// mediated `http` handle out of the host-assembled runtime capabilities: a
|
|
7
|
+
// fetch pinned to that server's origin that injects the token per request.
|
|
8
|
+
// The catalog is supplied by whoever deployed the agent (discovered once
|
|
9
|
+
// through the hub route), because the loader calls `factory` synchronously
|
|
10
|
+
// and the tool definitions are frozen at agent construction — there is no
|
|
11
|
+
// point at which this bundle could do a `tools/list` round trip.
|
|
12
|
+
import { defineTool, } from "@intx/agent";
|
|
13
|
+
import { type } from "arktype";
|
|
14
|
+
import { mcpCallTool, mcpInitialize, McpToolSchema, } from "./client.js";
|
|
15
|
+
import { isAskExempt, qualifiedName, toolDescription } from "./naming.js";
|
|
16
|
+
import { parseMcpEndpoint } from "./url.js";
|
|
17
|
+
/** The consumer key a host matches a credential binding against. */
|
|
18
|
+
export const SIDECAR_BUNDLE_ID = "@corbits/mcp/sidecar-bundle";
|
|
19
|
+
const BoundServerSchema = type({
|
|
20
|
+
handle: "string > 0",
|
|
21
|
+
url: "string > 0",
|
|
22
|
+
tools: McpToolSchema.array(),
|
|
23
|
+
"allowWithoutAsk?": "string[]",
|
|
24
|
+
});
|
|
25
|
+
const ConfigSchema = type({ servers: BoundServerSchema.array() });
|
|
26
|
+
/** Validate at construction: a malformed deploy config is a deploy bug, not a
|
|
27
|
+
* tool error the model should see. */
|
|
28
|
+
function assertConfig(config) {
|
|
29
|
+
const parsed = ConfigSchema(config);
|
|
30
|
+
if (parsed instanceof type.errors) {
|
|
31
|
+
throw new Error(`invalid @corbits/mcp server config: ${parsed.summary}`);
|
|
32
|
+
}
|
|
33
|
+
const seen = new Set();
|
|
34
|
+
for (const server of config.servers) {
|
|
35
|
+
if (seen.has(server.handle)) {
|
|
36
|
+
throw new Error(`invalid @corbits/mcp server config: duplicate credential handle "${server.handle}"`);
|
|
37
|
+
}
|
|
38
|
+
seen.add(server.handle);
|
|
39
|
+
try {
|
|
40
|
+
parseMcpEndpoint(server.url);
|
|
41
|
+
}
|
|
42
|
+
catch (cause) {
|
|
43
|
+
throw new Error(`invalid @corbits/mcp server config: ${cause instanceof Error ? cause.message : String(cause)}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const TextBlock = type({ type: "'text'", text: "string" }).array();
|
|
48
|
+
/**
|
|
49
|
+
* MCP results are never interpreted: text blocks come back as their text so
|
|
50
|
+
* the model reads prose, and anything else is handed over verbatim as JSON.
|
|
51
|
+
*/
|
|
52
|
+
export function shapeMcpContent(content) {
|
|
53
|
+
if (typeof content === "string")
|
|
54
|
+
return content;
|
|
55
|
+
const blocks = TextBlock(content);
|
|
56
|
+
if (!(blocks instanceof type.errors)) {
|
|
57
|
+
return blocks.map((block) => block.text).join("\n");
|
|
58
|
+
}
|
|
59
|
+
return JSON.stringify(content);
|
|
60
|
+
}
|
|
61
|
+
/** A mediated handle resolves a relative path against the origin it is pinned
|
|
62
|
+
* to, so the bundle passes the server's path and never names a host. */
|
|
63
|
+
function requestPath(url) {
|
|
64
|
+
const parsed = new URL(url);
|
|
65
|
+
return `${parsed.pathname}${parsed.search}`;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The sidecar bundle: one `@intx/agent` tool per catalog entry, named
|
|
69
|
+
* `<handle>.<tool>` so each is grantable on its own. Synchronous, with
|
|
70
|
+
* static definitions — the catalog is already in hand.
|
|
71
|
+
*/
|
|
72
|
+
export function mcpServers(config) {
|
|
73
|
+
assertConfig(config);
|
|
74
|
+
const entries = config.servers.flatMap((server) => server.tools.map((tool) => ({
|
|
75
|
+
server,
|
|
76
|
+
tool,
|
|
77
|
+
qualified: qualifiedName(server.handle, tool.name),
|
|
78
|
+
})));
|
|
79
|
+
const definitions = entries.map(({ qualified, tool, server }) => ({
|
|
80
|
+
name: qualified,
|
|
81
|
+
...(isAskExempt(qualified, tool, server.allowWithoutAsk ?? [])
|
|
82
|
+
? {}
|
|
83
|
+
: { approval: "ask" }),
|
|
84
|
+
}));
|
|
85
|
+
const toolDefinitions = entries.map(({ qualified, tool, server }) => ({
|
|
86
|
+
name: qualified,
|
|
87
|
+
description: toolDescription(tool, server.handle),
|
|
88
|
+
inputSchema: tool.inputSchema,
|
|
89
|
+
}));
|
|
90
|
+
return defineTool({
|
|
91
|
+
id: SIDECAR_BUNDLE_ID,
|
|
92
|
+
requires: ["capabilities"],
|
|
93
|
+
definitions,
|
|
94
|
+
factory: (env) => {
|
|
95
|
+
const byName = new Map(entries.map((e) => [e.qualified, e]));
|
|
96
|
+
const runtimes = new Map(config.servers.map((server) => [
|
|
97
|
+
server.handle,
|
|
98
|
+
{ server, handle: undefined, ready: undefined },
|
|
99
|
+
]));
|
|
100
|
+
/** Resolve-and-initialize once per server, retried after a failure so a
|
|
101
|
+
* transient one does not disable that server for the whole run. */
|
|
102
|
+
function connect(runtime) {
|
|
103
|
+
runtime.ready ??= (async () => {
|
|
104
|
+
runtime.handle ??= env.capabilities
|
|
105
|
+
.resolve("credentials")
|
|
106
|
+
.resolve(runtime.server.handle);
|
|
107
|
+
const credential = await runtime.handle;
|
|
108
|
+
if (credential.kind !== "http") {
|
|
109
|
+
throw new Error(`the "${runtime.server.handle}" credential is a ${credential.kind} handle; an MCP server needs an http one`);
|
|
110
|
+
}
|
|
111
|
+
const mediated = (input, init) => credential.fetch(input, init);
|
|
112
|
+
await mcpInitialize(requestPath(runtime.server.url), {
|
|
113
|
+
fetch: mediated,
|
|
114
|
+
});
|
|
115
|
+
return mediated;
|
|
116
|
+
})().catch((cause) => {
|
|
117
|
+
runtime.ready = undefined;
|
|
118
|
+
runtime.handle = undefined;
|
|
119
|
+
throw cause instanceof Error ? cause : new Error(String(cause));
|
|
120
|
+
});
|
|
121
|
+
return runtime.ready;
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
definitions: toolDefinitions,
|
|
125
|
+
async run(call, _signal) {
|
|
126
|
+
const found = byName.get(call.name);
|
|
127
|
+
const runtime = found === undefined ? undefined : runtimes.get(found.server.handle);
|
|
128
|
+
if (found === undefined || runtime === undefined) {
|
|
129
|
+
return {
|
|
130
|
+
callId: call.id,
|
|
131
|
+
isError: true,
|
|
132
|
+
content: `unknown MCP tool: ${call.name}`,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
try {
|
|
136
|
+
const mediated = await connect(runtime);
|
|
137
|
+
const result = await mcpCallTool(requestPath(found.server.url), found.tool.name, call.arguments, { fetch: mediated });
|
|
138
|
+
return {
|
|
139
|
+
callId: call.id,
|
|
140
|
+
isError: result.isError === true,
|
|
141
|
+
content: shapeMcpContent(result.content),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
catch (cause) {
|
|
145
|
+
// One server's failure is that server's tool error, never the
|
|
146
|
+
// agent's: every other bound server keeps working.
|
|
147
|
+
return {
|
|
148
|
+
callId: call.id,
|
|
149
|
+
isError: true,
|
|
150
|
+
content: cause instanceof Error ? cause.message : String(cause),
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
async dispose() {
|
|
155
|
+
// Every resolved handle is released even if one release fails; the
|
|
156
|
+
// failures surface together rather than hiding behind the first.
|
|
157
|
+
const failures = [];
|
|
158
|
+
for (const runtime of runtimes.values()) {
|
|
159
|
+
const pending = runtime.handle;
|
|
160
|
+
if (pending === undefined)
|
|
161
|
+
continue;
|
|
162
|
+
try {
|
|
163
|
+
await (await pending).dispose();
|
|
164
|
+
}
|
|
165
|
+
catch (cause) {
|
|
166
|
+
failures.push(cause);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (failures.length > 0) {
|
|
170
|
+
throw new AggregateError(failures, "one or more MCP credential handles failed to dispose");
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
}
|
package/dist/tool.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type AnnotatedToolFactory, type BaseEnv } from "@intx/agent";
|
|
2
|
+
import type { CredentialCapability } from "@intx/types";
|
|
3
|
+
export interface McpServerConfig {
|
|
4
|
+
/** Namespace prefix for this server's tools: `<name>.<remote-tool-name>`. */
|
|
5
|
+
name: string;
|
|
6
|
+
url: string;
|
|
7
|
+
/**
|
|
8
|
+
* Declared credential handle (must appear in this package's
|
|
9
|
+
* `interchange.credentials`) this server's requests authenticate with.
|
|
10
|
+
* Omit for a server that needs no credential.
|
|
11
|
+
*/
|
|
12
|
+
credentialHandle?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface McpToolsEnv extends BaseEnv {
|
|
15
|
+
/** The consumer-scoped `credentials` capability; see `tools/linear`'s `LinearEnv`. */
|
|
16
|
+
readonly credentials?: CredentialCapability;
|
|
17
|
+
}
|
|
18
|
+
export interface McpToolsOptions {
|
|
19
|
+
servers: McpServerConfig[];
|
|
20
|
+
/**
|
|
21
|
+
* `<server>.<tool>` names allowed to float below the `ask` floor onto
|
|
22
|
+
* `allow` from a resolved `allow` grant. Every generated tool starts
|
|
23
|
+
* `ask`-marked; this list is the only way to lower one, and it never
|
|
24
|
+
* applies to a remote tool the server flags `destructiveHint: true` --
|
|
25
|
+
* that flag wins no matter what the operator lists here.
|
|
26
|
+
*/
|
|
27
|
+
allowWithoutAsk?: string[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Discover every server's tool catalog and build the `@corbits/mcp` tool
|
|
31
|
+
* factory. Called directly from agent-authoring code (same pattern as
|
|
32
|
+
* `tools/linear`'s `linearTools`), not via the sidecar's dynamic
|
|
33
|
+
* package loader -- that loader requires a package's `interchange.tools`
|
|
34
|
+
* export to already be an `AnnotatedToolFactory`, which discovery's
|
|
35
|
+
* network round trip rules out.
|
|
36
|
+
*/
|
|
37
|
+
export declare function mcpTools(options: McpToolsOptions, discoveryEnv?: {
|
|
38
|
+
credentials?: CredentialCapability;
|
|
39
|
+
}): Promise<AnnotatedToolFactory<McpToolsEnv>>;
|
package/dist/tool.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// One `@intx/agent` tool per remote MCP tool, named `<server>.<tool>` so
|
|
2
|
+
// each is grantable individually. Discovery runs up front because
|
|
3
|
+
// `createAgent` calls a tool factory synchronously.
|
|
4
|
+
import { defineTool, } from "@intx/agent";
|
|
5
|
+
import { mcpCallTool, mcpInitialize, mcpListTools, } from "./client.js";
|
|
6
|
+
import { isAskExempt, qualifiedName, toolDescription } from "./naming.js";
|
|
7
|
+
async function resolveFetch(server, credentials) {
|
|
8
|
+
if (server.credentialHandle === undefined)
|
|
9
|
+
return undefined;
|
|
10
|
+
if (credentials === undefined) {
|
|
11
|
+
throw new Error(`MCP server "${server.name}" declares credentialHandle "${server.credentialHandle}" but no credentials capability was supplied`);
|
|
12
|
+
}
|
|
13
|
+
const mediated = await credentials.resolve(server.credentialHandle);
|
|
14
|
+
return (input, init) => mediated.fetch(input, init);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Discover every server's tool catalog and build the `@corbits/mcp` tool
|
|
18
|
+
* factory. Called directly from agent-authoring code (same pattern as
|
|
19
|
+
* `tools/linear`'s `linearTools`), not via the sidecar's dynamic
|
|
20
|
+
* package loader -- that loader requires a package's `interchange.tools`
|
|
21
|
+
* export to already be an `AnnotatedToolFactory`, which discovery's
|
|
22
|
+
* network round trip rules out.
|
|
23
|
+
*/
|
|
24
|
+
export async function mcpTools(options, discoveryEnv = {}) {
|
|
25
|
+
const allowWithoutAsk = options.allowWithoutAsk ?? [];
|
|
26
|
+
const discovered = [];
|
|
27
|
+
for (const server of options.servers) {
|
|
28
|
+
const clientFetch = await resolveFetch(server, discoveryEnv.credentials);
|
|
29
|
+
const clientOpts = clientFetch !== undefined ? { fetch: clientFetch } : {};
|
|
30
|
+
await mcpInitialize(server.url, clientOpts);
|
|
31
|
+
const tools = await mcpListTools(server.url, clientOpts);
|
|
32
|
+
for (const tool of tools) {
|
|
33
|
+
discovered.push({
|
|
34
|
+
server,
|
|
35
|
+
tool,
|
|
36
|
+
qualified: qualifiedName(server.name, tool.name),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const definitions = discovered.map(({ qualified, tool }) => ({
|
|
41
|
+
name: qualified,
|
|
42
|
+
...(isAskExempt(qualified, tool, allowWithoutAsk)
|
|
43
|
+
? {}
|
|
44
|
+
: { approval: "ask" }),
|
|
45
|
+
}));
|
|
46
|
+
return defineTool({
|
|
47
|
+
id: "@corbits/mcp/servers",
|
|
48
|
+
// Optional like `tools/github`'s: only servers that declare a
|
|
49
|
+
// `credentialHandle` need `env.credentials` at all.
|
|
50
|
+
requires: [],
|
|
51
|
+
definitions,
|
|
52
|
+
factory: (env) => {
|
|
53
|
+
const byName = new Map(discovered.map((d) => [d.qualified, d]));
|
|
54
|
+
const toolDefinitions = discovered.map(({ qualified, tool, server }) => ({
|
|
55
|
+
name: qualified,
|
|
56
|
+
description: toolDescription(tool, server.name),
|
|
57
|
+
inputSchema: tool.inputSchema,
|
|
58
|
+
}));
|
|
59
|
+
const fetchByServer = new Map();
|
|
60
|
+
for (const server of options.servers) {
|
|
61
|
+
fetchByServer.set(server.name, resolveFetch(server, env.credentials));
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
definitions: toolDefinitions,
|
|
65
|
+
async run(call, _signal) {
|
|
66
|
+
const found = byName.get(call.name);
|
|
67
|
+
if (found === undefined) {
|
|
68
|
+
return {
|
|
69
|
+
callId: call.id,
|
|
70
|
+
isError: true,
|
|
71
|
+
content: `unknown MCP tool: ${call.name}`,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const clientFetch = await fetchByServer.get(found.server.name);
|
|
76
|
+
const result = await mcpCallTool(found.server.url, found.tool.name, call.arguments, clientFetch !== undefined ? { fetch: clientFetch } : {});
|
|
77
|
+
return {
|
|
78
|
+
callId: call.id,
|
|
79
|
+
isError: result.isError === true,
|
|
80
|
+
content: typeof result.content === "string"
|
|
81
|
+
? result.content
|
|
82
|
+
: JSON.stringify(result.content),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
return {
|
|
87
|
+
callId: call.id,
|
|
88
|
+
isError: true,
|
|
89
|
+
content: err instanceof Error ? err.message : String(err),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
}
|
package/dist/url.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse an MCP endpoint and require https, so a bearer never crosses the
|
|
3
|
+
* network in the clear. Loopback is the one exemption: a server running on
|
|
4
|
+
* the same machine has no network hop to protect.
|
|
5
|
+
*/
|
|
6
|
+
export declare function parseMcpEndpoint(raw: string): URL;
|
package/dist/url.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// One rule for which MCP endpoints a token may be sent to, shared by the
|
|
2
|
+
// deploy-time config check and the hub's discovery route.
|
|
3
|
+
const LOOPBACK_HOSTS = new Set(["localhost", "127.0.0.1", "[::1]", "::1"]);
|
|
4
|
+
/**
|
|
5
|
+
* Parse an MCP endpoint and require https, so a bearer never crosses the
|
|
6
|
+
* network in the clear. Loopback is the one exemption: a server running on
|
|
7
|
+
* the same machine has no network hop to protect.
|
|
8
|
+
*/
|
|
9
|
+
export function parseMcpEndpoint(raw) {
|
|
10
|
+
let url;
|
|
11
|
+
try {
|
|
12
|
+
url = new URL(raw);
|
|
13
|
+
}
|
|
14
|
+
catch (cause) {
|
|
15
|
+
throw new Error(`"${raw}" is not an absolute URL (${cause instanceof Error ? cause.message : String(cause)})`);
|
|
16
|
+
}
|
|
17
|
+
if (url.protocol === "https:")
|
|
18
|
+
return url;
|
|
19
|
+
if (url.protocol === "http:" && LOOPBACK_HOSTS.has(url.hostname))
|
|
20
|
+
return url;
|
|
21
|
+
throw new Error(`MCP endpoint "${raw}" must be https (http is allowed only on loopback)`);
|
|
22
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@corbits/mcp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "MCP client tool package for Interchange: streamable HTTP, per-tool grants, OAuth.",
|
|
5
|
+
"license": "LGPL-2.1-only",
|
|
6
|
+
"author": "Sawyer Cutler <sawyer@dirtroad.dev>",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"README.md",
|
|
14
|
+
"LICENSE"
|
|
15
|
+
],
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./sidecar-bundle": {
|
|
25
|
+
"types": "./dist/sidecar-bundle.d.ts",
|
|
26
|
+
"default": "./dist/sidecar-bundle.js"
|
|
27
|
+
},
|
|
28
|
+
"./hub": {
|
|
29
|
+
"types": "./dist/hub/index.d.ts",
|
|
30
|
+
"default": "./dist/hub/index.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"interchange": {
|
|
34
|
+
"credentials": [
|
|
35
|
+
{
|
|
36
|
+
"handle": "mcp-server",
|
|
37
|
+
"scopes": []
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsc -p tsconfig.build.json",
|
|
43
|
+
"prepack": "bun run build",
|
|
44
|
+
"typecheck": "tsc --noEmit",
|
|
45
|
+
"lint": "eslint .",
|
|
46
|
+
"format": "prettier --write .",
|
|
47
|
+
"format:check": "prettier --check .",
|
|
48
|
+
"test": "bun test",
|
|
49
|
+
"check": "bun run typecheck && bun run lint && bun run format:check && bun run test"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"@corbits/credential-mcp": "^0.1.0",
|
|
53
|
+
"@intx/agent": ">=0.4.0"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@intx/db": "^0.4.0",
|
|
57
|
+
"@intx/hub-api": "^0.4.0",
|
|
58
|
+
"@intx/types": "^0.4.0",
|
|
59
|
+
"arktype": "^2.2.3",
|
|
60
|
+
"drizzle-orm": "^0.45.2",
|
|
61
|
+
"hono": "^4.11.9"
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@corbits/credential-mcp": "^0.1.0",
|
|
65
|
+
"@eslint/js": "9.34.0",
|
|
66
|
+
"@intx/agent": "0.4.0",
|
|
67
|
+
"@intx/authz": "0.4.0",
|
|
68
|
+
"@intx/harness": "0.4.0",
|
|
69
|
+
"@intx/types": "0.4.0",
|
|
70
|
+
"@types/bun": "1.3.9",
|
|
71
|
+
"eslint": "9.34.0",
|
|
72
|
+
"jiti": "2.5.1",
|
|
73
|
+
"prettier": "3.6.2",
|
|
74
|
+
"typescript": "5.9.3",
|
|
75
|
+
"typescript-eslint": "8.42.0"
|
|
76
|
+
},
|
|
77
|
+
"engines": {
|
|
78
|
+
"bun": ">=1.2.0"
|
|
79
|
+
},
|
|
80
|
+
"repository": {
|
|
81
|
+
"type": "git",
|
|
82
|
+
"url": "git+https://github.com/corbitsdev/corbits-mcp.git"
|
|
83
|
+
},
|
|
84
|
+
"homepage": "https://github.com/corbitsdev/corbits-mcp",
|
|
85
|
+
"bugs": {
|
|
86
|
+
"url": "https://github.com/corbitsdev/corbits-mcp/issues"
|
|
87
|
+
}
|
|
88
|
+
}
|