@shardflux/mcp 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +56 -0
- package/LICENSE +202 -0
- package/README.md +289 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +6 -0
- package/dist/config.d.ts +29 -0
- package/dist/config.js +75 -0
- package/dist/errors.d.ts +24 -0
- package/dist/errors.js +72 -0
- package/dist/http.d.ts +13 -0
- package/dist/http.js +21 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +10 -0
- package/dist/main.d.ts +5 -0
- package/dist/main.js +60 -0
- package/dist/server.d.ts +204 -0
- package/dist/server.js +687 -0
- package/package.json +62 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Every tool, field and variable the README shows is available from the version named here. Below 1.0, a minor release
|
|
4
|
+
may break compatibility; breaking changes are marked **Breaking**. Versions before 0.3.0 were not published.
|
|
5
|
+
|
|
6
|
+
## 0.3.0 (first public npm release; not yet published)
|
|
7
|
+
|
|
8
|
+
Needs `@shardflux/sdk` 0.7.0 or later. New dependency: `yaml` (template.yaml).
|
|
9
|
+
|
|
10
|
+
### Public npm package
|
|
11
|
+
|
|
12
|
+
- First release on npm: `npx -y @shardflux/mcp` (bin `shardflux-mcp`) runs the stdio server. The package ships
|
|
13
|
+
compiled JavaScript and type declarations (`dist/`); Node.js 24 or later. Earlier versions ran only from a source
|
|
14
|
+
checkout.
|
|
15
|
+
- Depends on the published `@shardflux/sdk` (`^0.7.0`), `@modelcontextprotocol/sdk` 1.30.0, `yaml` and `zod` (the MCP
|
|
16
|
+
SDK's peer dependency).
|
|
17
|
+
- `mcpName` `dev.shardflux/mcp` in package.json and a `server.json` for the official MCP Registry.
|
|
18
|
+
- The README covers setup for Claude Code, Cursor, Codex and Claude Desktop. License: Apache-2.0.
|
|
19
|
+
|
|
20
|
+
### Tools
|
|
21
|
+
|
|
22
|
+
- `workspace_open` takes `inputs` (`{"NAME": "value"}`: the template's text inputs); workspace results carry
|
|
23
|
+
`startup` (start commands and services: pending, running, ready or failed with the step, exit code and output
|
|
24
|
+
tail).
|
|
25
|
+
- `template_get`: a template's versions with their settings (the inputs `workspace_open` takes); with `version`, that
|
|
26
|
+
version's recipe (the export).
|
|
27
|
+
- `template_languages`: the languages and versions a base offers `build.languages`.
|
|
28
|
+
- `template_build`: builds a version from a recipe v2 given as `recipe` (an object) or `file` (a template.yaml or
|
|
29
|
+
.json path). Local `from` paths are uploaded through the SDK. Every local path must resolve inside the server's
|
|
30
|
+
working directory (a path outside it is `invalid_arguments`, before any request). The version stays unpublished
|
|
31
|
+
unless `publish`; `wait` follows the build within the call's deadline. Returns the build (state, registration,
|
|
32
|
+
recipe_sha256, denied_hosts, failure) and the uploads.
|
|
33
|
+
- An upload the storage refused is `upload_failed` with the storage's code.
|
|
34
|
+
|
|
35
|
+
## 0.2.1
|
|
36
|
+
|
|
37
|
+
Needs `@shardflux/sdk` 0.6.2 (the workspace version).
|
|
38
|
+
|
|
39
|
+
The API no longer lets a start (open, resume, fork) wait in `capacity_pending` forever: one that no host could admit
|
|
40
|
+
15 minutes after it began fails with `capacity_unavailable` (retryable; nothing was started, a suspended workspace
|
|
41
|
+
stays suspended).
|
|
42
|
+
|
|
43
|
+
- Failed-operation errors (`code: operation_failed`) carry `retryable`, the operation error's own flag, and
|
|
44
|
+
`details.reason` when the operation error has one. A `capacity_unavailable` failure's message adds that nothing was
|
|
45
|
+
started and the agent may retry later. The server does not retry.
|
|
46
|
+
- A wait that times out while the start waits for capacity names when it gives up (the SDK's message).
|
|
47
|
+
- Server instructions and the `workspace_open` description say a start waits for capacity for at most 15 minutes.
|
|
48
|
+
|
|
49
|
+
## 0.2.0
|
|
50
|
+
|
|
51
|
+
- `timing` (the SDK's lifecycle timing, compacted) in `workspace_open`, waited lifecycle, `operation_wait` and wake
|
|
52
|
+
results, and next to `error` when they fail.
|
|
53
|
+
|
|
54
|
+
## 0.1.0
|
|
55
|
+
|
|
56
|
+
- First version.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
# @shardflux/mcp: `shardflux-mcp`
|
|
2
|
+
|
|
3
|
+
The [Shardflux](https://shardflux.dev) MCP server. It gives Claude Code, Claude Desktop, Cursor,
|
|
4
|
+
Codex or any other MCP client persistent cloud workspaces: open a workspace by key, then run
|
|
5
|
+
commands, read and write files, use git, terminals and a browser in it, and suspend, resume or
|
|
6
|
+
fork it.
|
|
7
|
+
|
|
8
|
+
It runs locally over stdio and uses [`@shardflux/sdk`](https://www.npmjs.com/package/@shardflux/sdk)
|
|
9
|
+
with the scoped project API key you give it. Each tool call becomes one SDK request or wait:
|
|
10
|
+
|
|
11
|
+
- it has **no agent loop** of its own;
|
|
12
|
+
- it keeps **no local workspace directory**;
|
|
13
|
+
- it keeps **no state** beyond per-key workspace handles, so tool tokens are reused between calls.
|
|
14
|
+
|
|
15
|
+
Documentation: <https://docs.shardflux.dev/reference/mcp>.
|
|
16
|
+
|
|
17
|
+
> **Early access.** Shardflux is in early access, and this server is below 1.0: tools and results
|
|
18
|
+
> may still change in a minor release.
|
|
19
|
+
|
|
20
|
+
Requires Node.js 24 or later and a Shardflux project API key (`sfk_...`, from the Shardflux console).
|
|
21
|
+
|
|
22
|
+
## Run
|
|
23
|
+
|
|
24
|
+
MCP clients start the server themselves (see "Client setup"). The command is:
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
npx -y @shardflux/mcp
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
with `SHARDFLUX_API_KEY` in its environment. To try it by hand:
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
SHARDFLUX_API_KEY=sfk_... npx -y @shardflux/mcp
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
It logs one JSON `ready` line on stderr and then waits for MCP messages on stdin (stdout is the
|
|
37
|
+
protocol). Close stdin or press Ctrl-C to stop it.
|
|
38
|
+
|
|
39
|
+
Or install it globally and use the `shardflux-mcp` command instead of `npx -y @shardflux/mcp`:
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
npm install -g @shardflux/mcp
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Client setup
|
|
46
|
+
|
|
47
|
+
Each example registers the server as `shardflux`. Replace `sfk_...` with your key, and add any
|
|
48
|
+
other variable from "Configuration" the same way.
|
|
49
|
+
|
|
50
|
+
### Claude Code
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
claude mcp add --scope user --env SHARDFLUX_API_KEY=sfk_... --transport stdio shardflux -- npx -y @shardflux/mcp
|
|
54
|
+
claude mcp get shardflux
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Options go before the name (`shardflux`), and everything after `--` is the command. `--scope user`
|
|
58
|
+
makes the server available in every project; leave it out for the current project only, or use
|
|
59
|
+
`--scope project` to write it to `.mcp.json` for your team. In `.mcp.json`, read the key from the
|
|
60
|
+
environment instead of committing it:
|
|
61
|
+
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"mcpServers": {
|
|
65
|
+
"shardflux": {
|
|
66
|
+
"command": "npx",
|
|
67
|
+
"args": ["-y", "@shardflux/mcp"],
|
|
68
|
+
"env": { "SHARDFLUX_API_KEY": "${SHARDFLUX_API_KEY}" }
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
In a session, `/mcp` shows the server's status.
|
|
75
|
+
|
|
76
|
+
### Cursor
|
|
77
|
+
|
|
78
|
+
Add the server to `~/.cursor/mcp.json` (every project) or `.cursor/mcp.json` (one project):
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
{
|
|
82
|
+
"mcpServers": {
|
|
83
|
+
"shardflux": {
|
|
84
|
+
"command": "npx",
|
|
85
|
+
"args": ["-y", "@shardflux/mcp"],
|
|
86
|
+
"env": { "SHARDFLUX_API_KEY": "${env:SHARDFLUX_API_KEY}" }
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
`${env:SHARDFLUX_API_KEY}` reads the key from the environment Cursor runs in; you can also put the
|
|
93
|
+
key itself there.
|
|
94
|
+
|
|
95
|
+
### Codex
|
|
96
|
+
|
|
97
|
+
Add the server to `~/.codex/config.toml` (or `.codex/config.toml` in a trusted project):
|
|
98
|
+
|
|
99
|
+
```toml
|
|
100
|
+
[mcp_servers.shardflux]
|
|
101
|
+
command = "npx"
|
|
102
|
+
args = ["-y", "@shardflux/mcp"]
|
|
103
|
+
env_vars = ["SHARDFLUX_API_KEY"] # forward the key from the environment Codex runs in
|
|
104
|
+
startup_timeout_sec = 30 # the first run downloads the package (Codex default: 10)
|
|
105
|
+
tool_timeout_sec = 180 # above the server's per-call deadline, 120 s by default (Codex default: 60)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
To set the key in the file instead, replace `env_vars` with:
|
|
109
|
+
|
|
110
|
+
```toml
|
|
111
|
+
[mcp_servers.shardflux.env]
|
|
112
|
+
SHARDFLUX_API_KEY = "sfk_..."
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Or from the command line:
|
|
116
|
+
|
|
117
|
+
```sh
|
|
118
|
+
codex mcp add shardflux --env SHARDFLUX_API_KEY=sfk_... -- npx -y @shardflux/mcp
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
`workspace_open` waits until the workspace is ready, up to the server's per-call deadline
|
|
122
|
+
(`SHARDFLUX_MCP_TOOL_TIMEOUT_MS`, default 120000 ms). Keep `tool_timeout_sec` above it, or Codex
|
|
123
|
+
gives up on the call first.
|
|
124
|
+
|
|
125
|
+
### Claude Desktop
|
|
126
|
+
|
|
127
|
+
Open Settings, then Developer, then Edit Config. This opens `claude_desktop_config.json`
|
|
128
|
+
(`~/Library/Application Support/Claude/claude_desktop_config.json` on macOS,
|
|
129
|
+
`%APPDATA%\Claude\claude_desktop_config.json` on Windows). Add:
|
|
130
|
+
|
|
131
|
+
```json
|
|
132
|
+
{
|
|
133
|
+
"mcpServers": {
|
|
134
|
+
"shardflux": {
|
|
135
|
+
"command": "npx",
|
|
136
|
+
"args": ["-y", "@shardflux/mcp"],
|
|
137
|
+
"env": { "SHARDFLUX_API_KEY": "sfk_..." }
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Then quit Claude Desktop completely and start it again. The server's stderr goes to
|
|
144
|
+
`mcp-server-shardflux.log` in Claude Desktop's log folder (`~/Library/Logs/Claude` on macOS,
|
|
145
|
+
`%APPDATA%\Claude\logs` on Windows).
|
|
146
|
+
|
|
147
|
+
### Other clients
|
|
148
|
+
|
|
149
|
+
Any client that starts stdio servers works: command `npx`, arguments `-y @shardflux/mcp`,
|
|
150
|
+
environment `SHARDFLUX_API_KEY`.
|
|
151
|
+
|
|
152
|
+
## Configuration (environment)
|
|
153
|
+
|
|
154
|
+
| Variable | Meaning |
|
|
155
|
+
| --- | --- |
|
|
156
|
+
| `SHARDFLUX_API_KEY` | Scoped project API key. Required. Its tool permissions decide which workspace tools are listed. |
|
|
157
|
+
| `SHARDFLUX_API_URL` | Default `https://api.shardflux.dev`. Plain `http://` is allowed only for loopback hosts. |
|
|
158
|
+
| `SHARDFLUX_WORKSPACE_KEY` | Pins one workspace. `workspace_key` becomes optional on every tool, and a different key is refused with `workspace_pinned`. |
|
|
159
|
+
| `SHARDFLUX_TEMPLATE` | Default template for `workspace_open`. |
|
|
160
|
+
| `SHARDFLUX_MCP_TOOL_TIMEOUT_MS` | Default **and maximum** deadline per tool call, 1000-3600000 ms. Default 120000. A call's `timeout_ms` can only shorten it. |
|
|
161
|
+
| `SHARDFLUX_WAKE` | `on` (default) or `off`. On: workspace tools resume a suspended workspace and then run (see "Contract"). Off: they return the `workspace_not_running` refusal. |
|
|
162
|
+
| `SHARDFLUX_WAKE_TIMEOUT_MS` | Longest wait per tool call for a workspace to wake or finish a transition, 1000-3600000 ms. Default 120000. It is clamped to `SHARDFLUX_MCP_TOOL_TIMEOUT_MS`, and each wake also ends 250 ms before the call's own deadline. |
|
|
163
|
+
| `SHARDFLUX_AGENT_LABEL` | Attribution label of every tool token this server obtains. Default `mcp`. It appears as an agent session in `GET /v1/workspaces/{id}/agent-sessions`, the console and `shard ws sessions`. |
|
|
164
|
+
| `SHARDFLUX_MCP_LOG_LEVEL` | `debug`, `info` (default), `warn` or `error`. Logs are JSON lines on **stderr**; stdout is the protocol. The key is never logged, and anything key-shaped is redacted. |
|
|
165
|
+
| `SHARDFLUX_HTTP_KEEPALIVE=1` | Reuse HTTP connections. By default every request uses a fresh connection (`Connection: close`), because on some Node.js releases a request sent on a reused keep-alive connection can stall until the request timeout. |
|
|
166
|
+
|
|
167
|
+
Invalid configuration exits with code 2 before serving, with one JSON line on stderr, for example:
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
{"time":"2026-09-28T20:18:25.654Z","level":"error","service":"shardflux-mcp","message":"configuration error: SHARDFLUX_API_KEY is required (a scoped Shardflux project API key)"}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
`template_build` reads local files (`file`, and `from` paths in a recipe) only inside the server's
|
|
174
|
+
working directory: the directory your MCP client starts it in.
|
|
175
|
+
|
|
176
|
+
## Tools
|
|
177
|
+
|
|
178
|
+
The management tools:
|
|
179
|
+
|
|
180
|
+
| Tool | Does |
|
|
181
|
+
| --- | --- |
|
|
182
|
+
| `workspace_open` | Open by key: create on first use, reconnect or resume afterwards, never reset. Waits until the workspace is ready (its template's start commands and services included) unless `wait: false`. `lifetime: "session"` opens a workspace that is discarded after its idle timeout. `inputs` (0.3.0) passes the template's text inputs, `{"NAME": "value"}`. |
|
|
183
|
+
| `workspace_list` | List the project's workspaces, with `prefix`, `state`, `lifetime`, `purpose`, `include_deleted`, `limit` and `cursor`. By default only persistent standard workspaces are listed. |
|
|
184
|
+
| `workspace_status` | One workspace plus its five most recent operations. |
|
|
185
|
+
| `workspace_suspend`, `workspace_resume` | Lifecycle operation. Returns at once unless `wait: true` (then once it finished, through the SDK's own `wait`). |
|
|
186
|
+
| `workspace_fork` | Fork into `new_key`. |
|
|
187
|
+
| `operation_wait` | Keep waiting for an operation. |
|
|
188
|
+
| `usage_summary` | The organization's usage summary for the current period. |
|
|
189
|
+
| `template_get` | (0.3.0) A template's versions with their settings (env, inputs, start commands, services, defaults); with `version`, that version's recipe in request form. |
|
|
190
|
+
| `template_languages` | (0.3.0) The languages and versions a base (`<slug>@<version>`) offers `build.languages`. |
|
|
191
|
+
| `template_build` | (0.3.0) Build a version of an organization template from a recipe v2: `recipe` (the document) or `file` (a template.yaml or .json path). File entries may name local `from` paths, uploaded first (folders as a tar). **Every local path must resolve inside the server's working directory**; others are refused before any request. Unpublished unless `publish: true`; `wait: true` follows the build within the call's deadline. |
|
|
192
|
+
|
|
193
|
+
The SDK's workspace tools come from `workspaceTools()`:
|
|
194
|
+
|
|
195
|
+
- `exec`
|
|
196
|
+
- `read_file`, `write_file`, `list_files`
|
|
197
|
+
- `list_processes`, `signal_process`
|
|
198
|
+
- `terminal_open`, `terminal_send`, `terminal_read`, `terminal_close`
|
|
199
|
+
- `git_clone`, `git_status`, `git_commit`
|
|
200
|
+
- `browser_screenshot`, `browser_content`
|
|
201
|
+
|
|
202
|
+
They are published with **the SDK's JSON Schemas verbatim**, plus `workspace_key` and, where the
|
|
203
|
+
SDK schema has none, `timeout_ms`. They are filtered by the key's tool permissions (if the server
|
|
204
|
+
cannot read them, for example because the API is unreachable, it lists every workspace tool and logs
|
|
205
|
+
a warning). `browser_screenshot` returns an MCP image content block.
|
|
206
|
+
|
|
207
|
+
Deleting a workspace is deliberately not exposed to agents; use the
|
|
208
|
+
[CLI](https://www.npmjs.com/package/@shardflux/cli) or the console.
|
|
209
|
+
|
|
210
|
+
Every tool finds its workspace by exact key across every lifetime and purpose, so sessions, template drafts and test
|
|
211
|
+
instances resolve too. The live workspace wins over tombstones that ended sessions left with the same key. Workspace
|
|
212
|
+
results include `lifetime`, `purpose`, `disk_layout`, `idle_timeout_seconds`, `ended_reason` and (0.3.0) `startup`:
|
|
213
|
+
the state of the template's start commands and services (`failed` names the step, its exit code and output tail).
|
|
214
|
+
|
|
215
|
+
## Contract
|
|
216
|
+
|
|
217
|
+
- **Arguments.** They are validated against the published schema with the SDK's `validateArgs`
|
|
218
|
+
before any request. A failure returns `isError` with `code: invalid_arguments` and the issues.
|
|
219
|
+
- **Errors are tool results.** They carry `isError: true` and
|
|
220
|
+
`structuredContent.error = {code, message, status, request_id, retryable, operation_id, details, source}`,
|
|
221
|
+
using the API's or cell gateway's closed error codes. They are never protocol failures. The
|
|
222
|
+
only protocol error is an unknown tool name (`InvalidParams`).
|
|
223
|
+
- A failed operation is `code: operation_failed` with `details.error_code` (and `details.reason` when the
|
|
224
|
+
operation error has one) and, from 0.2.1, `retryable`: the operation error's own flag.
|
|
225
|
+
- An API or cell gateway the server cannot reach is `code: network_error`, `retryable: true`.
|
|
226
|
+
- **Starts wait for capacity for at most 15 minutes (0.2.1+).** An open, resume or fork that no host can admit waits
|
|
227
|
+
in `capacity_pending`; a wait that ends first returns `code: timeout`, and its message names when the start gives
|
|
228
|
+
up. A start still pending then fails: `operation_failed`, `details.error_code: capacity_unavailable`,
|
|
229
|
+
`retryable: true`, and a message telling the agent that nothing was started and it may retry later. The server
|
|
230
|
+
never retries it itself. The server instructions say the same.
|
|
231
|
+
- **Timing (0.2.0+).** A call that opens a workspace or waits says where the time went, from the SDK's lifecycle
|
|
232
|
+
timing, compact for model context:
|
|
233
|
+
|
|
234
|
+
```json
|
|
235
|
+
"timing": {
|
|
236
|
+
"action": "open", "outcome": "succeeded", "operation_id": "01a0e5a8-3ef0-7ecb-975e-dff2d5ca6e33", "total_ms": 34180,
|
|
237
|
+
"phases": ["request(held) 20010 ms", "capacity_pending(no_ready_host) 13520 ms", "running 590 ms", "view 42 ms", "token 61 ms"],
|
|
238
|
+
"server": { "queued_ms": 33400, "run_ms": 620, "total_ms": 34020, "start_path": "warm" },
|
|
239
|
+
"outside_server_ms": 160, "retries": 0
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
- `workspace_open` and `operation_wait` always carry it. `workspace_suspend`, `workspace_resume` and
|
|
244
|
+
`workspace_fork` carry it with `wait: true`. Workspace tools carry it when they had to wake the workspace
|
|
245
|
+
(`action: "wake"`). Other results do not.
|
|
246
|
+
- Phases are in order, as `phase(reason) ms`. `request(held)` means the API held the open until the workspace was
|
|
247
|
+
ready. `capacity_pending(no_ready_host)` is time spent waiting for a host.
|
|
248
|
+
- `server` is the operation's own queued, run and total time, plus the start or resume path the cell reported.
|
|
249
|
+
- `outside_server_ms` is everything else: network, polling, reading the workspace, the tool token.
|
|
250
|
+
- A failed or timed-out call carries it too, next to `error` (`{error, timing}`).
|
|
251
|
+
- `workspace_open` uses the SDK's waited open: the API holds the request until the workspace is ready and answers
|
|
252
|
+
with the first tool token, which the next tool call reuses.
|
|
253
|
+
- **Deadlines.** Every call has one: `timeout_ms`, clamped to the ceiling.
|
|
254
|
+
- Waits time out just before the deadline with `code: timeout` and the `operation_id`; the
|
|
255
|
+
operation continues server side (a start waiting for capacity for at most 15 minutes).
|
|
256
|
+
- Any request still in flight at the deadline is aborted.
|
|
257
|
+
- `exec`'s command timeout is capped at the deadline minus 2 s, so its output comes back.
|
|
258
|
+
- **Cancellation.** MCP `notifications/cancelled` aborts the SDK work behind the call: waits,
|
|
259
|
+
HTTP requests to the API and to the cell gateway, and backoff sleeps. No response is sent, and
|
|
260
|
+
the server stays up. The lifecycle operation itself is not canceled.
|
|
261
|
+
- **Workspace tools wake suspended workspaces, but do not open new ones.** A workspace that was
|
|
262
|
+
never opened is `not_found`: call `workspace_open` first.
|
|
263
|
+
- A suspended workspace is resumed (or the resume or open already running is joined), and the
|
|
264
|
+
call runs once it is running. A call made during a suspend or resume waits for it to finish.
|
|
265
|
+
The call never runs twice: the refused attempt did nothing.
|
|
266
|
+
- The wait is bounded by `SHARDFLUX_WAKE_TIMEOUT_MS` and the call's deadline. Past it the
|
|
267
|
+
result is `code: timeout` with the `operation_id` and `last_state` of the resume or open. That
|
|
268
|
+
operation continues server side: `operation_wait` keeps waiting. A resume or open that fails
|
|
269
|
+
returns `code: operation_failed` (`retryable: true` for `capacity_unavailable`: the workspace stays
|
|
270
|
+
suspended).
|
|
271
|
+
- With `SHARDFLUX_WAKE=off` the API's refusal comes back instead (`conflict`,
|
|
272
|
+
`details.reason: workspace_not_running`, or `workspace_not_running` from the cell gateway).
|
|
273
|
+
- Tool tokens are never returned to the model.
|
|
274
|
+
- **Keys, not ids.** Tools take workspace keys, resolved by exact match within the key's project.
|
|
275
|
+
|
|
276
|
+
## Use as a library
|
|
277
|
+
|
|
278
|
+
The package also exports the server for other MCP transports:
|
|
279
|
+
|
|
280
|
+
```ts
|
|
281
|
+
import { createShardfluxMcpServer, loadConfig } from '@shardflux/mcp';
|
|
282
|
+
|
|
283
|
+
const server = createShardfluxMcpServer(loadConfig(process.env)); // an MCP SDK Server
|
|
284
|
+
await server.connect(transport); // any @modelcontextprotocol/sdk transport
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
## License
|
|
288
|
+
|
|
289
|
+
Apache-2.0
|
package/dist/bin.d.ts
ADDED
package/dist/bin.js
ADDED
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment configuration of the local MCP server (README "Configuration").
|
|
3
|
+
* The API key is validated for shape only here; it is never logged or echoed.
|
|
4
|
+
*/
|
|
5
|
+
export interface McpConfig {
|
|
6
|
+
apiKey: string;
|
|
7
|
+
apiUrl: string;
|
|
8
|
+
/** Pinned workspace key: workspace tools default to (and are restricted to) it. */
|
|
9
|
+
workspaceKey: string | undefined;
|
|
10
|
+
/** Template used by workspace_open when the call names none. */
|
|
11
|
+
template: string | undefined;
|
|
12
|
+
/** Default and maximum per-call deadline (ms). */
|
|
13
|
+
toolTimeoutMs: number;
|
|
14
|
+
/** Workspace tools resume a suspended workspace on use (SHARDFLUX_WAKE, default on). */
|
|
15
|
+
wake: boolean;
|
|
16
|
+
/** Longest wait for a workspace to wake or finish a transition per call (ms); never above toolTimeoutMs. */
|
|
17
|
+
wakeTimeoutMs: number;
|
|
18
|
+
/** Attribution label on every tool token this server obtains (agent session). */
|
|
19
|
+
agentLabel: string;
|
|
20
|
+
logLevel: 'debug' | 'info' | 'warn' | 'error';
|
|
21
|
+
}
|
|
22
|
+
export declare class ConfigError extends Error {
|
|
23
|
+
name: string;
|
|
24
|
+
}
|
|
25
|
+
export declare const DEFAULT_TOOL_TIMEOUT_MS = 120000;
|
|
26
|
+
export declare const MAX_TOOL_TIMEOUT_MS = 3600000;
|
|
27
|
+
export declare const DEFAULT_WAKE_TIMEOUT_MS = 120000;
|
|
28
|
+
export declare function apiUrlFrom(raw: string | undefined): string;
|
|
29
|
+
export declare function loadConfig(env: Record<string, string | undefined>): McpConfig;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment configuration of the local MCP server (README "Configuration").
|
|
3
|
+
* The API key is validated for shape only here; it is never logged or echoed.
|
|
4
|
+
*/
|
|
5
|
+
export class ConfigError extends Error {
|
|
6
|
+
name = 'ConfigError';
|
|
7
|
+
}
|
|
8
|
+
const KEY_SHAPE = /^sfk_[a-z2-7]{16}_[A-Za-z0-9]+$/;
|
|
9
|
+
/** Non-empty and free of C0 controls and DEL (the API's key/label pattern). */
|
|
10
|
+
const printable = (s) => s.length > 0 && ![...s].some((ch) => ch.charCodeAt(0) < 0x20 || ch.charCodeAt(0) === 0x7f);
|
|
11
|
+
const SLUG = /^[a-z0-9](?:[a-z0-9._-]{0,98}[a-z0-9])?$/;
|
|
12
|
+
const LOOPBACK = new Set(['localhost', '127.0.0.1', '[::1]', '::1']);
|
|
13
|
+
export const DEFAULT_TOOL_TIMEOUT_MS = 120_000;
|
|
14
|
+
export const MAX_TOOL_TIMEOUT_MS = 3_600_000;
|
|
15
|
+
export const DEFAULT_WAKE_TIMEOUT_MS = 120_000;
|
|
16
|
+
export function apiUrlFrom(raw) {
|
|
17
|
+
const text = (raw ?? '').trim() || 'https://api.shardflux.dev';
|
|
18
|
+
let u;
|
|
19
|
+
try {
|
|
20
|
+
u = new URL(text);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
throw new ConfigError(`SHARDFLUX_API_URL is not a valid URL: "${text}"`);
|
|
24
|
+
}
|
|
25
|
+
if (u.protocol !== 'https:' && !(u.protocol === 'http:' && (LOOPBACK.has(u.hostname) || u.hostname.endsWith('.localhost')))) {
|
|
26
|
+
throw new ConfigError('SHARDFLUX_API_URL must use https (plain http only for localhost): the API key is a bearer credential');
|
|
27
|
+
}
|
|
28
|
+
if (u.username || u.password || u.search || u.hash)
|
|
29
|
+
throw new ConfigError('SHARDFLUX_API_URL must not contain credentials, a query or a fragment');
|
|
30
|
+
return u.toString().replace(/\/+$/, '');
|
|
31
|
+
}
|
|
32
|
+
export function loadConfig(env) {
|
|
33
|
+
const apiKey = env.SHARDFLUX_API_KEY?.trim();
|
|
34
|
+
if (!apiKey)
|
|
35
|
+
throw new ConfigError('SHARDFLUX_API_KEY is required (a scoped Shardflux project API key)');
|
|
36
|
+
if (!KEY_SHAPE.test(apiKey))
|
|
37
|
+
throw new ConfigError('SHARDFLUX_API_KEY is not a Shardflux project key (expected sfk_<key id>_<secret>)');
|
|
38
|
+
const workspaceKey = env.SHARDFLUX_WORKSPACE_KEY?.trim() || undefined;
|
|
39
|
+
if (workspaceKey !== undefined && (workspaceKey.length > 200 || !printable(workspaceKey))) {
|
|
40
|
+
throw new ConfigError('SHARDFLUX_WORKSPACE_KEY must be 1-200 printable characters');
|
|
41
|
+
}
|
|
42
|
+
const template = env.SHARDFLUX_TEMPLATE?.trim() || undefined;
|
|
43
|
+
if (template !== undefined && !SLUG.test(template))
|
|
44
|
+
throw new ConfigError('SHARDFLUX_TEMPLATE must be a template slug (lowercase letters, digits, . _ -)');
|
|
45
|
+
let toolTimeoutMs = DEFAULT_TOOL_TIMEOUT_MS;
|
|
46
|
+
const t = env.SHARDFLUX_MCP_TOOL_TIMEOUT_MS?.trim();
|
|
47
|
+
if (t) {
|
|
48
|
+
if (!/^\d+$/.test(t))
|
|
49
|
+
throw new ConfigError('SHARDFLUX_MCP_TOOL_TIMEOUT_MS must be an integer number of milliseconds');
|
|
50
|
+
toolTimeoutMs = Number(t);
|
|
51
|
+
if (toolTimeoutMs < 1000 || toolTimeoutMs > MAX_TOOL_TIMEOUT_MS)
|
|
52
|
+
throw new ConfigError(`SHARDFLUX_MCP_TOOL_TIMEOUT_MS must be between 1000 and ${MAX_TOOL_TIMEOUT_MS}`);
|
|
53
|
+
}
|
|
54
|
+
const wakeText = (env.SHARDFLUX_WAKE?.trim() || 'on').toLowerCase();
|
|
55
|
+
if (wakeText !== 'on' && wakeText !== 'off')
|
|
56
|
+
throw new ConfigError('SHARDFLUX_WAKE must be on or off');
|
|
57
|
+
let wakeTimeoutMs = DEFAULT_WAKE_TIMEOUT_MS;
|
|
58
|
+
const w = env.SHARDFLUX_WAKE_TIMEOUT_MS?.trim();
|
|
59
|
+
if (w) {
|
|
60
|
+
if (!/^\d+$/.test(w))
|
|
61
|
+
throw new ConfigError('SHARDFLUX_WAKE_TIMEOUT_MS must be an integer number of milliseconds');
|
|
62
|
+
wakeTimeoutMs = Number(w);
|
|
63
|
+
if (wakeTimeoutMs < 1000 || wakeTimeoutMs > MAX_TOOL_TIMEOUT_MS)
|
|
64
|
+
throw new ConfigError(`SHARDFLUX_WAKE_TIMEOUT_MS must be between 1000 and ${MAX_TOOL_TIMEOUT_MS}`);
|
|
65
|
+
}
|
|
66
|
+
// A wake can never outlast the call it serves.
|
|
67
|
+
wakeTimeoutMs = Math.min(wakeTimeoutMs, toolTimeoutMs);
|
|
68
|
+
const agentLabel = env.SHARDFLUX_AGENT_LABEL?.trim() || 'mcp';
|
|
69
|
+
if (agentLabel.length > 100 || !printable(agentLabel))
|
|
70
|
+
throw new ConfigError('SHARDFLUX_AGENT_LABEL must be 1-100 printable characters');
|
|
71
|
+
const level = (env.SHARDFLUX_MCP_LOG_LEVEL?.trim() || 'info');
|
|
72
|
+
if (!['debug', 'info', 'warn', 'error'].includes(level))
|
|
73
|
+
throw new ConfigError('SHARDFLUX_MCP_LOG_LEVEL must be debug, info, warn or error');
|
|
74
|
+
return { apiKey, apiUrl: apiUrlFrom(env.SHARDFLUX_API_URL), workspaceKey, template, toolTimeoutMs, wake: wakeText === 'on', wakeTimeoutMs, agentLabel, logLevel: level };
|
|
75
|
+
}
|