@stratabook/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-APACHE +201 -0
- package/LICENSE-MIT +21 -0
- package/README.md +173 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +140 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/server.d.ts +14 -0
- package/dist/src/server.js +178 -0
- package/package.json +55 -0
package/LICENSE-APACHE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/LICENSE-MIT
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Strata Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="./assets/readme-hero.svg" alt="Strata — The deepest book in DeFi." width="100%" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">Strata MCP</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
Put live Strata markets and Sonar pricing inside any MCP-compatible agent.
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://stratabook.org/docs/agent-mcp">Documentation</a>
|
|
13
|
+
·
|
|
14
|
+
<a href="https://github.com/alsk1992/strata-sdk-ts">TypeScript</a>
|
|
15
|
+
·
|
|
16
|
+
<a href="https://github.com/alsk1992/strata-agent-skills">Agent Skills</a>
|
|
17
|
+
·
|
|
18
|
+
<a href="https://stratabook.app">Strata</a>
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
One hosted connection gives an agent current market availability and
|
|
22
|
+
decision-ready quotes from Sonar—Strata's unified liquidity and matching
|
|
23
|
+
system. No local daemon is required.
|
|
24
|
+
|
|
25
|
+
## Connect
|
|
26
|
+
|
|
27
|
+
Add Strata as a Streamable HTTP server:
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
{
|
|
31
|
+
"mcpServers": {
|
|
32
|
+
"strata": {
|
|
33
|
+
"type": "streamable-http",
|
|
34
|
+
"url": "https://api.stratabook.app/mcp"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
That is the complete hosted setup. Once connected, the client discovers the
|
|
41
|
+
Strata tools currently available to it.
|
|
42
|
+
|
|
43
|
+
## See Strata answer from a terminal
|
|
44
|
+
|
|
45
|
+
Use the official MCP Inspector (Node.js 22.7.5+) to list the hosted tools:
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
npx -y @modelcontextprotocol/inspector --cli \
|
|
49
|
+
https://api.stratabook.app/mcp \
|
|
50
|
+
--transport http \
|
|
51
|
+
--method tools/list
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Call Strata directly:
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
npx -y @modelcontextprotocol/inspector --cli \
|
|
58
|
+
https://api.stratabook.app/mcp \
|
|
59
|
+
--transport http \
|
|
60
|
+
--method tools/call \
|
|
61
|
+
--tool-name strata_markets \
|
|
62
|
+
--tool-arg includePaused=false
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Request a live Sonar quote through the same connection:
|
|
66
|
+
|
|
67
|
+
```sh
|
|
68
|
+
npx -y @modelcontextprotocol/inspector --cli \
|
|
69
|
+
https://api.stratabook.app/mcp \
|
|
70
|
+
--transport http \
|
|
71
|
+
--method tools/call \
|
|
72
|
+
--tool-name strata_quote \
|
|
73
|
+
--tool-arg market=SOL/USDC \
|
|
74
|
+
--tool-arg side=sell \
|
|
75
|
+
--tool-arg 'amountInAtoms="10000000"' \
|
|
76
|
+
--tool-arg slippageBps=50
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
The response is structured data, ready for terminals, scripts, and agents.
|
|
80
|
+
|
|
81
|
+
## What lands in the agent
|
|
82
|
+
|
|
83
|
+
| Tool | Result |
|
|
84
|
+
| --- | --- |
|
|
85
|
+
| `strata_capabilities` | The Strata features available in the current session |
|
|
86
|
+
| `strata_markets` | Markets, token decimals, and current Sonar quote readiness |
|
|
87
|
+
| `strata_quote` | Expected output, consumed input, fees, minimum output, price impact, and expiry |
|
|
88
|
+
|
|
89
|
+
### A Sonar quote call
|
|
90
|
+
|
|
91
|
+
```json
|
|
92
|
+
{
|
|
93
|
+
"market": "SOL/USDC",
|
|
94
|
+
"side": "sell",
|
|
95
|
+
"amountInAtoms": "10000000",
|
|
96
|
+
"slippageBps": 50
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The result gives an agent the economics it needs to reason clearly:
|
|
101
|
+
|
|
102
|
+
```json
|
|
103
|
+
{
|
|
104
|
+
"provider": "Sonar",
|
|
105
|
+
"amount_in_consumed_atoms": "10000000",
|
|
106
|
+
"amount_out_atoms": "1990000",
|
|
107
|
+
"minimum_output_atoms": "1980050",
|
|
108
|
+
"output_fee_atoms": "995",
|
|
109
|
+
"reference_price": "199.1",
|
|
110
|
+
"price_impact_pct": "0.0005"
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
The values above use the repository's versioned example fixture. Live quotes
|
|
115
|
+
also include a unique quote ID and authoritative expiry.
|
|
116
|
+
|
|
117
|
+
Sonar handles the market. Your agent works with one economic result.
|
|
118
|
+
|
|
119
|
+
## Hosted or local
|
|
120
|
+
|
|
121
|
+
| | Hosted Streamable HTTP | Local stdio |
|
|
122
|
+
| --- | --- | --- |
|
|
123
|
+
| Start with | `https://api.stratabook.app/mcp` | `npx -y @stratabook/mcp` |
|
|
124
|
+
| Best for | Agents with remote MCP support | Desktop clients and local toolchains |
|
|
125
|
+
| You operate | Nothing | The local Node.js process |
|
|
126
|
+
| Strata market data | Live | Live |
|
|
127
|
+
|
|
128
|
+
Local stdio configuration:
|
|
129
|
+
|
|
130
|
+
```json
|
|
131
|
+
{
|
|
132
|
+
"mcpServers": {
|
|
133
|
+
"strata": {
|
|
134
|
+
"command": "npx",
|
|
135
|
+
"args": ["-y", "@stratabook/mcp"]
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Node.js 20+ is required for the local package.
|
|
142
|
+
|
|
143
|
+
## Self-host Streamable HTTP
|
|
144
|
+
|
|
145
|
+
```sh
|
|
146
|
+
npx -y @stratabook/mcp \
|
|
147
|
+
--transport http \
|
|
148
|
+
--host 127.0.0.1 \
|
|
149
|
+
--port 8787
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
The server binds to loopback by default. Add TLS, authentication, and rate
|
|
153
|
+
limiting before making a self-hosted instance remotely accessible.
|
|
154
|
+
|
|
155
|
+
## Built for exact automation
|
|
156
|
+
|
|
157
|
+
- Token values stay as atomic-unit decimal strings.
|
|
158
|
+
- Quote expiry and minimum output remain explicit fields.
|
|
159
|
+
- The tool set follows what Strata currently makes available.
|
|
160
|
+
- Errors include stable codes and retryability hints.
|
|
161
|
+
|
|
162
|
+
`0.1.x` provides market discovery and read-only Sonar quotes. It cannot prepare,
|
|
163
|
+
sign, or submit transactions and never asks for wallet or private-key material.
|
|
164
|
+
|
|
165
|
+
## Resources
|
|
166
|
+
|
|
167
|
+
- [Agent quick start](https://stratabook.org/docs/hello-agents)
|
|
168
|
+
- [MCP documentation](https://stratabook.org/docs/agent-mcp)
|
|
169
|
+
- [TypeScript SDK](https://github.com/alsk1992/strata-sdk-ts)
|
|
170
|
+
- [Issues and feature requests](https://github.com/alsk1992/strata-mcp/issues)
|
|
171
|
+
- [Security policy](SECURITY.md)
|
|
172
|
+
|
|
173
|
+
Licensed under either [Apache-2.0](LICENSE-APACHE) or [MIT](LICENSE-MIT).
|
package/dist/src/cli.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
5
|
+
import { DEFAULT_API_BASE } from "@stratabook/sdk";
|
|
6
|
+
import { createStrataMcpServer } from "./server.js";
|
|
7
|
+
function parse(argv) {
|
|
8
|
+
const values = new Map();
|
|
9
|
+
for (let index = 0; index < argv.length; index++) {
|
|
10
|
+
const token = argv[index];
|
|
11
|
+
if (token === "--help" || token === "-h") {
|
|
12
|
+
help();
|
|
13
|
+
process.exit(0);
|
|
14
|
+
}
|
|
15
|
+
if (!token?.startsWith("--"))
|
|
16
|
+
throw new Error(`unexpected argument: ${token}`);
|
|
17
|
+
const next = argv[index + 1];
|
|
18
|
+
if (!next || next.startsWith("--"))
|
|
19
|
+
throw new Error(`${token} requires a value`);
|
|
20
|
+
values.set(token.slice(2), next);
|
|
21
|
+
index++;
|
|
22
|
+
}
|
|
23
|
+
const transport = values.get("transport") ?? process.env.STRATA_MCP_TRANSPORT ?? "stdio";
|
|
24
|
+
if (transport !== "stdio" && transport !== "http") {
|
|
25
|
+
throw new Error("--transport must be stdio or http");
|
|
26
|
+
}
|
|
27
|
+
const timeoutMs = boundedInteger(values.get("timeout-ms") ?? process.env.STRATA_MCP_TIMEOUT_MS ?? "10000", "timeout-ms", 250, 60_000);
|
|
28
|
+
const port = boundedInteger(values.get("port") ?? process.env.STRATA_MCP_PORT ?? "8787", "port", 1, 65_535);
|
|
29
|
+
const host = values.get("host") ?? process.env.STRATA_MCP_HOST ?? "127.0.0.1";
|
|
30
|
+
if (!/^[a-zA-Z0-9.:[\]-]+$/.test(host))
|
|
31
|
+
throw new Error("host is invalid");
|
|
32
|
+
return {
|
|
33
|
+
transport,
|
|
34
|
+
apiBase: values.get("api-base") ?? process.env.STRATA_API_BASE ?? DEFAULT_API_BASE,
|
|
35
|
+
timeoutMs,
|
|
36
|
+
host,
|
|
37
|
+
port,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function boundedInteger(raw, name, min, max) {
|
|
41
|
+
const value = Number(raw);
|
|
42
|
+
if (!Number.isSafeInteger(value) || value < min || value > max) {
|
|
43
|
+
throw new Error(`${name} must be an integer between ${min} and ${max}`);
|
|
44
|
+
}
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
function help() {
|
|
48
|
+
process.stdout.write(`Strata MCP server
|
|
49
|
+
|
|
50
|
+
Usage:
|
|
51
|
+
strata-mcp
|
|
52
|
+
strata-mcp --transport http [--host 127.0.0.1] [--port 8787]
|
|
53
|
+
|
|
54
|
+
Options:
|
|
55
|
+
--transport stdio|http Local stdio by default; Streamable HTTP for hosting
|
|
56
|
+
--api-base URL Strata public API (default: ${DEFAULT_API_BASE})
|
|
57
|
+
--timeout-ms N Upstream timeout, 250..60000 (default: 10000)
|
|
58
|
+
--host HOST HTTP bind host (default: 127.0.0.1)
|
|
59
|
+
--port N HTTP port (default: 8787)
|
|
60
|
+
|
|
61
|
+
This server is read-only. It accepts no wallet, private key, or session key.
|
|
62
|
+
`);
|
|
63
|
+
}
|
|
64
|
+
async function runStdio(options) {
|
|
65
|
+
const runtime = await createStrataMcpServer(options);
|
|
66
|
+
const transport = new StdioServerTransport();
|
|
67
|
+
await runtime.server.connect(transport);
|
|
68
|
+
const close = async () => {
|
|
69
|
+
await runtime.close();
|
|
70
|
+
process.exit(0);
|
|
71
|
+
};
|
|
72
|
+
process.once("SIGINT", close);
|
|
73
|
+
process.once("SIGTERM", close);
|
|
74
|
+
}
|
|
75
|
+
async function runHttp(options) {
|
|
76
|
+
// The official helper validates Host headers for loopback binds, protecting
|
|
77
|
+
// local MCP installations from DNS-rebinding attacks.
|
|
78
|
+
const app = createMcpExpressApp({ host: options.host });
|
|
79
|
+
app.disable("x-powered-by");
|
|
80
|
+
app.get("/health", (_request, response) => {
|
|
81
|
+
response
|
|
82
|
+
.status(200)
|
|
83
|
+
.set("Cache-Control", "no-store")
|
|
84
|
+
.json({ ok: true, service: "strata-mcp", version: "0.1.0" });
|
|
85
|
+
});
|
|
86
|
+
app.post("/mcp", async (request, response) => {
|
|
87
|
+
let runtime;
|
|
88
|
+
let transport;
|
|
89
|
+
try {
|
|
90
|
+
runtime = await createStrataMcpServer(options);
|
|
91
|
+
transport = new StreamableHTTPServerTransport({
|
|
92
|
+
sessionIdGenerator: undefined,
|
|
93
|
+
enableJsonResponse: true,
|
|
94
|
+
});
|
|
95
|
+
response.once("close", () => {
|
|
96
|
+
transport?.close().catch(() => undefined);
|
|
97
|
+
runtime?.close().catch(() => undefined);
|
|
98
|
+
});
|
|
99
|
+
await runtime.server.connect(transport);
|
|
100
|
+
await transport.handleRequest(request, response, request.body);
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
if (!response.headersSent) {
|
|
104
|
+
response.status(500).json({
|
|
105
|
+
jsonrpc: "2.0",
|
|
106
|
+
error: { code: -32603, message: "Strata MCP request failed." },
|
|
107
|
+
id: null,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
const methodNotAllowed = (_request, response) => {
|
|
113
|
+
response.status(405).json({
|
|
114
|
+
jsonrpc: "2.0",
|
|
115
|
+
error: { code: -32000, message: "Method not allowed." },
|
|
116
|
+
id: null,
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
app.get("/mcp", methodNotAllowed);
|
|
120
|
+
app.delete("/mcp", methodNotAllowed);
|
|
121
|
+
const listener = app.listen(options.port, options.host, () => {
|
|
122
|
+
process.stderr.write(`[strata-mcp] listening on http://${options.host}:${options.port}/mcp\n`);
|
|
123
|
+
});
|
|
124
|
+
const close = () => {
|
|
125
|
+
listener.close(() => process.exit(0));
|
|
126
|
+
};
|
|
127
|
+
process.once("SIGINT", close);
|
|
128
|
+
process.once("SIGTERM", close);
|
|
129
|
+
}
|
|
130
|
+
async function main() {
|
|
131
|
+
const options = parse(process.argv.slice(2));
|
|
132
|
+
if (options.transport === "stdio")
|
|
133
|
+
await runStdio(options);
|
|
134
|
+
else
|
|
135
|
+
await runHttp(options);
|
|
136
|
+
}
|
|
137
|
+
main().catch((error) => {
|
|
138
|
+
process.stderr.write(`${error instanceof Error ? error.message : "Strata MCP failed to start."}\n`);
|
|
139
|
+
process.exitCode = 1;
|
|
140
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { capabilityAvailable, createStrataMcpServer, type StrataMcpOptions, type StrataMcpRuntime, } from "./server.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { capabilityAvailable, createStrataMcpServer, } from "./server.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { StrataClient, type CapabilityCatalog } from "@stratabook/sdk";
|
|
3
|
+
export interface StrataMcpOptions {
|
|
4
|
+
apiBase?: string;
|
|
5
|
+
timeoutMs?: number;
|
|
6
|
+
client?: StrataClient;
|
|
7
|
+
}
|
|
8
|
+
export interface StrataMcpRuntime {
|
|
9
|
+
server: McpServer;
|
|
10
|
+
refreshCapabilities(): Promise<void>;
|
|
11
|
+
close(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export declare function capabilityAvailable(catalog: CapabilityCatalog, id: string): boolean;
|
|
14
|
+
export declare function createStrataMcpServer(options?: StrataMcpOptions): Promise<StrataMcpRuntime>;
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { StrataApiError, StrataClient, } from "@stratabook/sdk";
|
|
3
|
+
import * as z from "zod/v4";
|
|
4
|
+
const SERVER_VERSION = "0.1.0";
|
|
5
|
+
const REFRESH_INTERVAL_MS = 5_000;
|
|
6
|
+
export function capabilityAvailable(catalog, id) {
|
|
7
|
+
return catalog.capabilities.some((capability) => capability.id === id
|
|
8
|
+
&& capability.default_enabled
|
|
9
|
+
&& capability.public_sdk
|
|
10
|
+
&& capability.risk === "read"
|
|
11
|
+
&& capability.mcp_exposure === "read");
|
|
12
|
+
}
|
|
13
|
+
export async function createStrataMcpServer(options = {}) {
|
|
14
|
+
const client = options.client
|
|
15
|
+
?? new StrataClient({
|
|
16
|
+
apiBase: options.apiBase,
|
|
17
|
+
timeoutMs: options.timeoutMs,
|
|
18
|
+
});
|
|
19
|
+
const initialCatalog = await client.capabilities();
|
|
20
|
+
const server = new McpServer({
|
|
21
|
+
name: "strata",
|
|
22
|
+
version: SERVER_VERSION,
|
|
23
|
+
}, {
|
|
24
|
+
instructions: "Use Strata to discover available markets and request short-lived Sonar quotes. "
|
|
25
|
+
+ "Token values use exact atomic decimal strings. Check quote expiry and minimum output.",
|
|
26
|
+
});
|
|
27
|
+
server.registerTool("strata_capabilities", {
|
|
28
|
+
title: "Strata capabilities",
|
|
29
|
+
description: "See which Strata features are currently available to MCP clients.",
|
|
30
|
+
annotations: {
|
|
31
|
+
readOnlyHint: true,
|
|
32
|
+
destructiveHint: false,
|
|
33
|
+
idempotentHint: true,
|
|
34
|
+
openWorldHint: true,
|
|
35
|
+
},
|
|
36
|
+
}, async () => toolResult(await client.capabilities(), "Current Strata capabilities."));
|
|
37
|
+
const markets = server.registerTool("strata_markets", {
|
|
38
|
+
title: "Strata markets",
|
|
39
|
+
description: "List Strata markets and their current Sonar quote availability.",
|
|
40
|
+
inputSchema: {
|
|
41
|
+
includePaused: z
|
|
42
|
+
.boolean()
|
|
43
|
+
.optional()
|
|
44
|
+
.default(false)
|
|
45
|
+
.describe("Include markets whose public Sonar quote operation is paused."),
|
|
46
|
+
},
|
|
47
|
+
annotations: {
|
|
48
|
+
readOnlyHint: true,
|
|
49
|
+
destructiveHint: false,
|
|
50
|
+
idempotentHint: true,
|
|
51
|
+
openWorldHint: true,
|
|
52
|
+
},
|
|
53
|
+
}, async ({ includePaused }) => guardedTool(client, "markets.read", async () => {
|
|
54
|
+
const response = await client.markets();
|
|
55
|
+
const output = includePaused
|
|
56
|
+
? response
|
|
57
|
+
: {
|
|
58
|
+
...response,
|
|
59
|
+
markets: response.markets.filter((market) => market.ready),
|
|
60
|
+
};
|
|
61
|
+
return toolResult(output, `${output.markets.length} Strata markets available.`);
|
|
62
|
+
}));
|
|
63
|
+
const quote = server.registerTool("strata_quote", {
|
|
64
|
+
title: "Sonar quote",
|
|
65
|
+
description: "Request a short-lived Sonar quote for a Strata market. Returns expected "
|
|
66
|
+
+ "output, minimum output, fees, price impact, and expiry.",
|
|
67
|
+
inputSchema: {
|
|
68
|
+
market: z
|
|
69
|
+
.string()
|
|
70
|
+
.min(1)
|
|
71
|
+
.max(128)
|
|
72
|
+
.describe("Market label such as SOL/USDC, or its public market ID."),
|
|
73
|
+
side: z.enum(["buy", "sell"]).describe("Buy or sell the market's base asset."),
|
|
74
|
+
amountInAtoms: z
|
|
75
|
+
.string()
|
|
76
|
+
.regex(/^[0-9]+$/)
|
|
77
|
+
.max(20)
|
|
78
|
+
.describe("Exact input amount in the input token's smallest atomic unit."),
|
|
79
|
+
slippageBps: z
|
|
80
|
+
.number()
|
|
81
|
+
.int()
|
|
82
|
+
.min(0)
|
|
83
|
+
.max(1_000)
|
|
84
|
+
.optional()
|
|
85
|
+
.default(50)
|
|
86
|
+
.describe("Maximum slippage in basis points."),
|
|
87
|
+
},
|
|
88
|
+
annotations: {
|
|
89
|
+
readOnlyHint: true,
|
|
90
|
+
destructiveHint: false,
|
|
91
|
+
idempotentHint: false,
|
|
92
|
+
openWorldHint: true,
|
|
93
|
+
},
|
|
94
|
+
}, async ({ market, side, amountInAtoms, slippageBps }) => guardedTool(client, "quotes.read", async () => {
|
|
95
|
+
const request = {
|
|
96
|
+
market,
|
|
97
|
+
side,
|
|
98
|
+
amountInAtoms,
|
|
99
|
+
slippageBps,
|
|
100
|
+
};
|
|
101
|
+
const response = await client.quote(request);
|
|
102
|
+
return toolResult(response, `Sonar ${response.side} quote: ${response.amount_in_consumed_atoms} input atoms `
|
|
103
|
+
+ `for ${response.amount_out_atoms} output atoms; minimum `
|
|
104
|
+
+ `${response.minimum_output_atoms}; expires at ${response.expires_at_ms}.`);
|
|
105
|
+
}));
|
|
106
|
+
const handles = { markets, quote };
|
|
107
|
+
applyCapabilityCatalog(handles, initialCatalog);
|
|
108
|
+
let closed = false;
|
|
109
|
+
const refresh = async () => {
|
|
110
|
+
if (closed)
|
|
111
|
+
return;
|
|
112
|
+
applyCapabilityCatalog(handles, await client.capabilities());
|
|
113
|
+
};
|
|
114
|
+
const timer = setInterval(() => {
|
|
115
|
+
refresh().catch((error) => {
|
|
116
|
+
process.stderr.write(`[strata-mcp] capability refresh failed: ${safeMessage(error)}\n`);
|
|
117
|
+
});
|
|
118
|
+
}, REFRESH_INTERVAL_MS);
|
|
119
|
+
timer.unref();
|
|
120
|
+
return {
|
|
121
|
+
server,
|
|
122
|
+
refreshCapabilities: refresh,
|
|
123
|
+
close: async () => {
|
|
124
|
+
closed = true;
|
|
125
|
+
clearInterval(timer);
|
|
126
|
+
await server.close();
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function applyCapabilityCatalog(handles, catalog) {
|
|
131
|
+
setToolEnabled(handles.markets, capabilityAvailable(catalog, "markets.read"));
|
|
132
|
+
setToolEnabled(handles.quote, capabilityAvailable(catalog, "quotes.read"));
|
|
133
|
+
}
|
|
134
|
+
function setToolEnabled(tool, enabled) {
|
|
135
|
+
if (enabled)
|
|
136
|
+
tool.enable();
|
|
137
|
+
else
|
|
138
|
+
tool.disable();
|
|
139
|
+
}
|
|
140
|
+
async function guardedTool(client, capabilityId, operation) {
|
|
141
|
+
try {
|
|
142
|
+
const catalog = await client.capabilities();
|
|
143
|
+
if (!capabilityAvailable(catalog, capabilityId)) {
|
|
144
|
+
return toolError("capability_disabled", `${capabilityId} is not currently exposed to MCP clients.`, true);
|
|
145
|
+
}
|
|
146
|
+
return await operation();
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
if (error instanceof StrataApiError) {
|
|
150
|
+
return toolError(error.code, error.message, error.retryable);
|
|
151
|
+
}
|
|
152
|
+
return toolError("request_failed", safeMessage(error), true);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function toolResult(value, summary) {
|
|
156
|
+
return {
|
|
157
|
+
content: [
|
|
158
|
+
{
|
|
159
|
+
type: "text",
|
|
160
|
+
text: `${summary}\n${JSON.stringify(value)}`,
|
|
161
|
+
},
|
|
162
|
+
],
|
|
163
|
+
structuredContent: value,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function toolError(code, message, retryable) {
|
|
167
|
+
const error = { error: { code, message, retryable } };
|
|
168
|
+
return {
|
|
169
|
+
isError: true,
|
|
170
|
+
content: [{ type: "text", text: JSON.stringify(error) }],
|
|
171
|
+
structuredContent: error,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
function safeMessage(error) {
|
|
175
|
+
if (error instanceof Error && error.message.trim())
|
|
176
|
+
return error.message;
|
|
177
|
+
return "Strata could not complete the request.";
|
|
178
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stratabook/mcp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Connect AI agents to Strata markets and Sonar quotes with MCP.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT OR Apache-2.0",
|
|
7
|
+
"homepage": "https://stratabook.org/docs/agent-mcp",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/alsk1992/strata-mcp.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/alsk1992/strata-mcp/issues"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public",
|
|
17
|
+
"provenance": true
|
|
18
|
+
},
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=20"
|
|
22
|
+
},
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/src/index.d.ts",
|
|
26
|
+
"import": "./dist/src/index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"bin": {
|
|
30
|
+
"strata-mcp": "dist/src/cli.js"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist/src",
|
|
34
|
+
"README.md",
|
|
35
|
+
"LICENSE-APACHE",
|
|
36
|
+
"LICENSE-MIT"
|
|
37
|
+
],
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsc -p tsconfig.json",
|
|
40
|
+
"test": "npm run build && node --test dist/test/*.test.js",
|
|
41
|
+
"pack:check": "npm pack --dry-run",
|
|
42
|
+
"ci": "npm test && npm run pack:check",
|
|
43
|
+
"prepublishOnly": "npm run ci"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@modelcontextprotocol/sdk": "1.30.0",
|
|
47
|
+
"@stratabook/sdk": "0.1.0",
|
|
48
|
+
"zod": "^3.25.76"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/express": "^5.0.3",
|
|
52
|
+
"@types/node": "^24.12.3",
|
|
53
|
+
"typescript": "~6.0.2"
|
|
54
|
+
}
|
|
55
|
+
}
|