@mostra/mcp 0.0.0-stage → 0.10.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 +202 -0
- package/README.md +27 -2
- package/dist/index.d.ts +283 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1405 -0
- package/dist/index.js.map +1 -0
- package/package.json +64 -3
- package/schemas/mcp-tools.draft-07.json +421 -0
- package/schemas/mcp-tools.schema.json +421 -0
- package/src/http.ts +188 -0
- package/src/index.ts +52 -0
- package/src/patch.ts +232 -0
- package/src/ports.ts +116 -0
- package/src/results.ts +45 -0
- package/src/search.ts +98 -0
- package/src/server.ts +273 -0
- package/src/tools.ts +812 -0
- package/src/workspace.ts +351 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [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
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @mostra/mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Mostra's MCP server: the tools, resources and instructions an MCP client uses to create, write,
|
|
4
|
+
verify and publish an artifact, hand a person its link, wait for their answer and read the
|
|
5
|
+
results. Most people run it as `mostra mcp` (stdio, or Streamable HTTP with `--http`); this
|
|
6
|
+
package is for serving the same tools from your own process.
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import { createMcpServerFactory, localWorkspace, defaultWorkspaceRoot } from "@mostra/mcp";
|
|
10
|
+
import { serveStdio } from "@modelcontextprotocol/server/stdio";
|
|
11
|
+
|
|
12
|
+
const factory = createMcpServerFactory({
|
|
13
|
+
instance, // calls the host protocol (e.g. through @mostra/sdk)
|
|
14
|
+
workspace: localWorkspace(defaultWorkspaceRoot()),
|
|
15
|
+
docs, // Mostra's reference by topic
|
|
16
|
+
version: "0.9.0",
|
|
17
|
+
});
|
|
18
|
+
serveStdio(factory);
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The tools: `artifact_create`, `artifact_write`, `artifact_patch`, `artifact_verify`,
|
|
22
|
+
`artifact_publish`, `artifact_open`, `artifact_wait` (at most 50 s, then `still_waiting` with a
|
|
23
|
+
cursor), `artifact_results`, `artifact_list`, `live_push`, `state_get`, `state_patch` and
|
|
24
|
+
`docs_search`. The resources: `mostra://docs/{topic}` and `mostra://artifacts/{id}/report`.
|
|
25
|
+
`createHttpEndpoint(factory, { origin, hosts, token })` serves the factory over Streamable HTTP
|
|
26
|
+
behind exact `Host` and `Origin` checks and a bearer token.
|
|
27
|
+
|
|
28
|
+
Part of [Mostra](https://github.com/mostra-dev/mostra), the agent artifact runtime. Apache-2.0.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { CallToolResult, McpServerFactory, ToolAnnotations } from "@modelcontextprotocol/server";
|
|
2
|
+
import { ArtifactProgressParams, MethodDefinition, RequestPolicy } from "@mostra/protocol";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
//#region src/http.d.ts
|
|
5
|
+
/** The path the endpoint serves. */
|
|
6
|
+
export declare const MCP_PATH = "/mcp";
|
|
7
|
+
/** The largest request body the endpoint reads: a whole artifact's files fit (16 MiB). */
|
|
8
|
+
export declare const MCP_MAX_BODY_BYTES: number;
|
|
9
|
+
/** Failed tokens past this many in {@link GUESS_WINDOW_MS} refuse every token (D97 item 8). */
|
|
10
|
+
export declare const GUESS_LIMIT = 30;
|
|
11
|
+
/** The guessing limit's window. */
|
|
12
|
+
export declare const GUESS_WINDOW_MS = 6e4;
|
|
13
|
+
/** How the endpoint is reached and what it requires. */
|
|
14
|
+
interface HttpEndpointPolicy extends RequestPolicy {
|
|
15
|
+
/** The bearer token every request must carry (`Authorization: Bearer <token>`). */
|
|
16
|
+
readonly token: string;
|
|
17
|
+
/** The clock; tests move it. */
|
|
18
|
+
readonly now?: () => number;
|
|
19
|
+
/** Told each refusal, for the server's log (never the token). */
|
|
20
|
+
readonly onRefusal?: (refused: {
|
|
21
|
+
readonly status: number;
|
|
22
|
+
readonly code: string;
|
|
23
|
+
}) => void;
|
|
24
|
+
/** Told an error the SDK met outside a request's answer. */
|
|
25
|
+
readonly onError?: (error: Error) => void;
|
|
26
|
+
}
|
|
27
|
+
/** The request as the transport received it, before any URL parser normalized it. */
|
|
28
|
+
interface RawRequest {
|
|
29
|
+
/** The request target exactly as sent (`/mcp`, with any query). */
|
|
30
|
+
readonly target: string;
|
|
31
|
+
/** Every header in arrival order, so a repeated one is visible. */
|
|
32
|
+
readonly headers: readonly (readonly [string, string])[];
|
|
33
|
+
}
|
|
34
|
+
/** The endpoint. */
|
|
35
|
+
interface McpHttpEndpoint {
|
|
36
|
+
/** Answers one request. Give `raw` where the transport has it (Node's `rawHeaders`, `req.url`). */
|
|
37
|
+
fetch(request: Request, raw?: RawRequest): Promise<Response>;
|
|
38
|
+
/** Ends every exchange in flight. */
|
|
39
|
+
close(): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
/** Builds the endpoint. */
|
|
42
|
+
export declare function createHttpEndpoint(factory: McpServerFactory, policy: HttpEndpointPolicy): McpHttpEndpoint;
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/patch.d.ts
|
|
45
|
+
/** One exact replacement: `old` must appear exactly once in the file. */
|
|
46
|
+
interface TextEdit {
|
|
47
|
+
/** Text that appears exactly once in the file; empty to write a new or empty file. */
|
|
48
|
+
readonly old: string;
|
|
49
|
+
/** What replaces it. */
|
|
50
|
+
readonly new: string;
|
|
51
|
+
}
|
|
52
|
+
/** What `artifact_patch` asks for. */
|
|
53
|
+
type PatchRequest = {
|
|
54
|
+
readonly path: string;
|
|
55
|
+
readonly edits: readonly TextEdit[];
|
|
56
|
+
} | {
|
|
57
|
+
readonly path?: string;
|
|
58
|
+
readonly diff: string;
|
|
59
|
+
};
|
|
60
|
+
/** One edit or hunk that didn't apply. */
|
|
61
|
+
interface PatchRejection {
|
|
62
|
+
/** The file it was for. */
|
|
63
|
+
readonly path: string;
|
|
64
|
+
/** The edit's index in `edits`, from 0. */
|
|
65
|
+
readonly edit?: number;
|
|
66
|
+
/** The hunk's index in its file's diff, from 0, and its header (`@@ -4,6 +4,7 @@`). */
|
|
67
|
+
readonly hunk?: number;
|
|
68
|
+
/** The hunk's header, for a hunk. */
|
|
69
|
+
readonly header?: string;
|
|
70
|
+
/**
|
|
71
|
+
* Why: `not-found` (the text isn't in the file), `ambiguous` (it is, more than once),
|
|
72
|
+
* `missing` (the file doesn't exist), `exists` (a diff creates a file that already exists),
|
|
73
|
+
* `context` (the hunk's lines don't match the file), `binary` (the file isn't UTF-8 text),
|
|
74
|
+
* `malformed` (the diff can't be read, or names no file).
|
|
75
|
+
*/
|
|
76
|
+
readonly reason: "not-found" | "ambiguous" | "missing" | "exists" | "context" | "binary" | "malformed";
|
|
77
|
+
/** For `ambiguous`: how many times the text appears. */
|
|
78
|
+
readonly occurrences?: number;
|
|
79
|
+
}
|
|
80
|
+
/** The planned change: whole files to write and files to delete. */
|
|
81
|
+
interface PlannedPatch {
|
|
82
|
+
/** Files to write whole, by path inside the artifact. */
|
|
83
|
+
readonly write: readonly {
|
|
84
|
+
readonly path: string;
|
|
85
|
+
readonly content: string;
|
|
86
|
+
}[];
|
|
87
|
+
/** Files to delete. */
|
|
88
|
+
readonly delete: readonly string[];
|
|
89
|
+
}
|
|
90
|
+
/** Reads a file of the artifact as bytes, `undefined` when missing. */
|
|
91
|
+
type ReadFile = (path: string) => Promise<Uint8Array | undefined>;
|
|
92
|
+
/** Plans a patch against the current files: the change, or every rejection. */
|
|
93
|
+
export declare function planPatch(request: PatchRequest, read: ReadFile): Promise<{
|
|
94
|
+
readonly ok: true;
|
|
95
|
+
readonly change: PlannedPatch;
|
|
96
|
+
} | {
|
|
97
|
+
readonly ok: false;
|
|
98
|
+
readonly rejected: PatchRejection[];
|
|
99
|
+
}>;
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/ports.d.ts
|
|
102
|
+
/** The Mostra instance the tools act on, through the host protocol (INTERFACES §6). */
|
|
103
|
+
interface McpInstance {
|
|
104
|
+
/**
|
|
105
|
+
* Calls a host protocol method. Rejects with an `RpcError` carrying the instance's diagnostic,
|
|
106
|
+
* which the tool hands the model as its error.
|
|
107
|
+
*/
|
|
108
|
+
call<P, R>(method: MethodDefinition<P, R>, params: P): Promise<R>;
|
|
109
|
+
/**
|
|
110
|
+
* Listens for `artifact/progress` with this `progressToken` (sent while `artifact/verify`
|
|
111
|
+
* runs); returns the function that stops listening.
|
|
112
|
+
*/
|
|
113
|
+
onProgress(progressToken: string, listener: (progress: ArtifactProgressParams) => void): () => void;
|
|
114
|
+
}
|
|
115
|
+
/** One file to write into an artifact's directory. */
|
|
116
|
+
interface WorkspaceFile {
|
|
117
|
+
/** The path relative to the artifact's directory, with `/` between folders. */
|
|
118
|
+
readonly path: string;
|
|
119
|
+
/** The file's bytes. */
|
|
120
|
+
readonly content: Uint8Array;
|
|
121
|
+
}
|
|
122
|
+
/** Where artifacts' files live, and how they are read and written. */
|
|
123
|
+
interface McpWorkspace {
|
|
124
|
+
/** The directory relative `dir` arguments resolve in, and where a new artifact goes by default. */
|
|
125
|
+
readonly root: string;
|
|
126
|
+
/**
|
|
127
|
+
* The absolute directory `dir` names: itself when absolute, else inside the workspace's root.
|
|
128
|
+
* Throws `MOSTRA_ARTIFACT_PATH_INVALID` for a name it can't use.
|
|
129
|
+
*/
|
|
130
|
+
resolveDir(dir: string): string;
|
|
131
|
+
/** A new directory for an artifact titled `title`, inside the root, that doesn't exist yet. */
|
|
132
|
+
allocateDir(title: string | undefined): Promise<string>;
|
|
133
|
+
/** Reads a file of the artifact, or `undefined` when it doesn't exist. */
|
|
134
|
+
read(dir: string, path: string): Promise<Uint8Array | undefined>;
|
|
135
|
+
/**
|
|
136
|
+
* Writes and deletes files of the artifact in `dir` (created when missing). Every path is
|
|
137
|
+
* checked before anything is written; a path outside the directory, or through a link, throws
|
|
138
|
+
* `MOSTRA_ARTIFACT_PATH_INVALID`. Each file is replaced whole (written aside, then renamed).
|
|
139
|
+
*/
|
|
140
|
+
apply(dir: string, changes: {
|
|
141
|
+
readonly write: readonly WorkspaceFile[];
|
|
142
|
+
readonly delete: readonly string[];
|
|
143
|
+
}): Promise<{
|
|
144
|
+
readonly written: string[];
|
|
145
|
+
readonly deleted: string[];
|
|
146
|
+
}>;
|
|
147
|
+
}
|
|
148
|
+
/** One topic of Mostra's bundled reference (`mostra docs`, D140 item 17). */
|
|
149
|
+
interface DocsTopicSummary {
|
|
150
|
+
/** Its stable slug: `guide`, `guide/answers`, `cli`, a diagnostic code. */
|
|
151
|
+
readonly topic: string;
|
|
152
|
+
/** Its title, from the page's first heading. */
|
|
153
|
+
readonly title: string;
|
|
154
|
+
/** Where the docs site serves it. */
|
|
155
|
+
readonly url: string;
|
|
156
|
+
}
|
|
157
|
+
/** The reference the docs tools and resources read. */
|
|
158
|
+
interface McpDocs {
|
|
159
|
+
/** Every topic, the pages first. */
|
|
160
|
+
topics(): readonly DocsTopicSummary[];
|
|
161
|
+
/** A topic's Markdown, or `undefined` for a topic that doesn't exist. */
|
|
162
|
+
read(topic: string): string | undefined;
|
|
163
|
+
}
|
|
164
|
+
/** Opens a link in a browser on the person's computer, for a server that runs there. */
|
|
165
|
+
interface McpBrowser {
|
|
166
|
+
/**
|
|
167
|
+
* Opens a one-time launch URL (`view/launch`), never a link's own secret, which a command line
|
|
168
|
+
* would show every local user (D140 item 15); whether a browser started.
|
|
169
|
+
*/
|
|
170
|
+
open(launchUrl: string): Promise<boolean>;
|
|
171
|
+
}
|
|
172
|
+
/** The MCP client a session serves, as its `clientInfo` names it. */
|
|
173
|
+
interface McpClientInfo {
|
|
174
|
+
/** The client's own name (`clientInfo.name`). */
|
|
175
|
+
readonly name: string;
|
|
176
|
+
/** Its version, when it gives one. */
|
|
177
|
+
readonly version?: string;
|
|
178
|
+
}
|
|
179
|
+
/** Everything the server is built from. */
|
|
180
|
+
interface McpServerOptions {
|
|
181
|
+
/** The instance the tools act on. */
|
|
182
|
+
readonly instance: McpInstance;
|
|
183
|
+
/** Where artifacts' files are. */
|
|
184
|
+
readonly workspace: McpWorkspace;
|
|
185
|
+
/** The reference `docs_search` and the docs resources read. */
|
|
186
|
+
readonly docs: McpDocs;
|
|
187
|
+
/** Present when the server runs on the person's computer. */
|
|
188
|
+
readonly browser?: McpBrowser;
|
|
189
|
+
/**
|
|
190
|
+
* Reads a screenshot a verdict names, to return it as an image. Default: this computer's file
|
|
191
|
+
* system, where the instance that ran verify wrote it.
|
|
192
|
+
*/
|
|
193
|
+
readonly readScreenshot?: (path: string) => Promise<Uint8Array>;
|
|
194
|
+
/** The server's version, as `serverInfo` reports it (the release's). */
|
|
195
|
+
readonly version: string;
|
|
196
|
+
/**
|
|
197
|
+
* Told the client a server instance serves (one per stdio connection, one per HTTP request) the
|
|
198
|
+
* first time it calls a tool or reads a resource, for whoever counts sessions (the standalone
|
|
199
|
+
* CLI's telemetry, D164 item 4, which counts each client once per process). Never throws into a
|
|
200
|
+
* tool.
|
|
201
|
+
*/
|
|
202
|
+
readonly onClient?: (client: McpClientInfo) => void;
|
|
203
|
+
}
|
|
204
|
+
//#endregion
|
|
205
|
+
//#region src/search.d.ts
|
|
206
|
+
/** One hit. */
|
|
207
|
+
interface DocsHit {
|
|
208
|
+
/** The topic's slug. */
|
|
209
|
+
readonly topic: string;
|
|
210
|
+
/** Its title. */
|
|
211
|
+
readonly title: string;
|
|
212
|
+
/** The resource that reads the whole topic: `mostra://docs/<topic>`. */
|
|
213
|
+
readonly uri: string;
|
|
214
|
+
/** The docs site's page. */
|
|
215
|
+
readonly url: string;
|
|
216
|
+
/** The passage that matched best, up to about 400 characters. */
|
|
217
|
+
readonly snippet: string;
|
|
218
|
+
}
|
|
219
|
+
/** The URI of a topic's resource. */
|
|
220
|
+
export declare function docsUri(topic: string): string;
|
|
221
|
+
/** The best hits for `query`, at most `limit`. */
|
|
222
|
+
export declare function searchDocs(docs: McpDocs, query: string, limit?: number): DocsHit[];
|
|
223
|
+
//#endregion
|
|
224
|
+
//#region src/server.d.ts
|
|
225
|
+
/** The name the server gives in `serverInfo`. */
|
|
226
|
+
export declare const SERVER_NAME = "mostra";
|
|
227
|
+
/** The instructions a client gives its model with the tools (D164 item 6). */
|
|
228
|
+
export declare function serverInstructions(workspaceRoot: string): string;
|
|
229
|
+
/** Builds the factory every transport serves. */
|
|
230
|
+
export declare function createMcpServerFactory(options: McpServerOptions): McpServerFactory;
|
|
231
|
+
//#endregion
|
|
232
|
+
//#region src/tools.d.ts
|
|
233
|
+
/** The registry of every tool's input schema, published as the `mcp-tools` bundle. */
|
|
234
|
+
export declare const toolRegistry: z.core.$ZodRegistry<{
|
|
235
|
+
id: string;
|
|
236
|
+
description?: string;
|
|
237
|
+
}>;
|
|
238
|
+
/** The longest `artifact_wait`, in seconds (INTERFACES §12, FAILURE_MODEL §9). */
|
|
239
|
+
export declare const WAIT_MAX_SECONDS = 50;
|
|
240
|
+
/** What a tool's run gets besides its arguments. */
|
|
241
|
+
interface ToolCall {
|
|
242
|
+
/** The ports and settings the server was built with. */
|
|
243
|
+
readonly options: McpServerOptions;
|
|
244
|
+
/** Reports progress to a client that asked for it (`progressToken`); a no-op otherwise. */
|
|
245
|
+
progress(message: string): void;
|
|
246
|
+
}
|
|
247
|
+
/** One tool. */
|
|
248
|
+
interface ToolDefinition<Input> {
|
|
249
|
+
/** Its name in `tools/list`: short and stable (D32). */
|
|
250
|
+
readonly name: string;
|
|
251
|
+
/** Its display name. */
|
|
252
|
+
readonly title: string;
|
|
253
|
+
/** What the model reads to choose it (agent-facing prose, D74). */
|
|
254
|
+
readonly description: string;
|
|
255
|
+
/** Its arguments' schema, published in the `mcp-tools` bundle. */
|
|
256
|
+
readonly input: z.ZodType<Input>;
|
|
257
|
+
/** Hints for the client: whether it reads only, changes or destroys anything. */
|
|
258
|
+
readonly annotations: ToolAnnotations;
|
|
259
|
+
/** Does the tool's work; a throw becomes an `isError` result with its diagnostic. */
|
|
260
|
+
run(args: Input, call: ToolCall): Promise<CallToolResult>;
|
|
261
|
+
}
|
|
262
|
+
/** Every tool, in the order clients list them: the authoring loop first. */
|
|
263
|
+
export declare function createTools(readScreenshot: (path: string) => Promise<Uint8Array | undefined>): readonly ToolDefinition<unknown>[];
|
|
264
|
+
//#endregion
|
|
265
|
+
//#region src/workspace.d.ts
|
|
266
|
+
/** The default workspace: `~/mostra-artifacts`. */
|
|
267
|
+
export declare function defaultWorkspaceRoot(home?: string): string;
|
|
268
|
+
/**
|
|
269
|
+
* A file's path inside its artifact, checked and spelled with `/`: relative, no `.` or `..`
|
|
270
|
+
* segments, no empty segment, no drive or control characters, and only names every system can
|
|
271
|
+
* hold, so an artifact written on one moves to another whole: no `<>:"|?*`, no Windows device
|
|
272
|
+
* name and no name ending in a dot or a space, which Windows strips, making `index.tsx.` the same
|
|
273
|
+
* file as `index.tsx` (Opus review of WP-15, finding 5). Throws `MOSTRA_ARTIFACT_PATH_INVALID`
|
|
274
|
+
* otherwise.
|
|
275
|
+
*/
|
|
276
|
+
export declare function artifactPath(path: string): string;
|
|
277
|
+
/** A directory name for a title: lowercase words joined by `-`, at most 48 characters. */
|
|
278
|
+
export declare function slug(title: string | undefined): string;
|
|
279
|
+
/** The workspace on this computer, rooted at `root` (absolute). */
|
|
280
|
+
export declare function localWorkspace(root: string): McpWorkspace;
|
|
281
|
+
//#endregion
|
|
282
|
+
export type { DocsHit, DocsTopicSummary, HttpEndpointPolicy, McpBrowser, McpClientInfo, McpDocs, McpHttpEndpoint, McpInstance, McpServerOptions, McpWorkspace, PatchRejection, PatchRequest, PlannedPatch, RawRequest, ReadFile, TextEdit, ToolCall, ToolDefinition, WorkspaceFile };
|
|
283
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/http.ts","../src/patch.ts","../src/ports.ts","../src/search.ts","../src/server.ts","../src/tools.ts","../src/workspace.ts"],"mappings":";;;;;qBAuBa;;qBAGA;;qBAGA;;qBAEA;;UAGI,2BAA2B;;WAEjC;;WAEA;;WAEA,aAAa;aAAoB;aAAyB;;;WAE1D,WAAW,OAAO;;;UAIZ;;WAEN;;WAEA;;;UAIM;;EAEf,MAAM,SAAS,SAAS,MAAM,aAAa,QAAQ;;EAEnD,SAAS;;;wBAmCK,mBACd,SAAS,kBACT,QAAQ,qBACP;;;;UCvFc;;WAEN;;WAEA;;;KAIC;WACG;WAAuB,gBAAgB;;WACvC;WAAwB;;;UAGtB;;WAEN;;WAEA;;WAEA;;WAEA;;;;;;;WAOA;;WASA;;;UAIM;;WAEN;aAA2B;aAAuB;;;WAElD;;;KAIC,YAAY,iBAAiB,QAAQ;;wBAK3B,UACpB,SAAS,cACT,MAAM,WACL;WACY;WAAmB,QAAQ;;WAC3B;WAAoB,UAAU;;;;;UC5D5B;;;;;EAKf,KAAK,GAAG,GAAG,QAAQ,iBAAiB,GAAG,IAAI,QAAQ,IAAI,QAAQ;;;;;EAK/D,WACE,uBACA,WAAW,UAAU;;;UAKR;;WAEN;;WAEA,SAAS;;;UAIH;;WAEN;;;;;EAKT,WAAW;;EAEX,YAAY,4BAA4B;;EAExC,KAAK,aAAa,eAAe,QAAQ;;;;;;EAMzC,MACE,aACA;aAAoB,gBAAgB;aAA0B;MAC7D;aAAmB;aAA4B;;;;UAInC;;WAEN;;WAEA;;WAEA;;;UAIM;;EAEf,mBAAmB;;EAEnB,KAAK;;;UAIU;;;;;EAKf,KAAK,oBAAoB;;;UAIV;;WAEN;;WAEA;;;UAIM;;WAEN,UAAU;;WAEV,WAAW;;WAEX,MAAM;;WAEN,UAAU;;;;;WAKV,kBAAkB,iBAAiB,QAAQ;;WAE3C;;;;;;;WAOA,YAAY,QAAQ;;;;;UCzGd;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;;wBAIK,QAAQ;;wBA0BR,WAAW,MAAM,SAAS,eAAe,iBAAY;;;;qBCnBxD;;wBAQG,mBAAmB;;wBAwFnB,uBAAuB,SAAS,mBAAmB;;;;qBCxFtD,cAAc,EAAE,KAAK;EAAe;EAAY;;;qBAMhD;;UAGI;;WAEN,SAAS;;EAElB,SAAS;;;UAIM,eAAe;;WAErB;;WAEA;;WAEA;;WAEA,OAAO,EAAE,QAAQ;;WAEjB,aAAa;;EAEtB,IAAI,MAAM,OAAO,MAAM,WAAW,QAAQ;;;wBAyT5B,YACd,iBAAiB,iBAAiB,QAAQ,mCAChC;;;;wBC/WI,qBAAqB;;;;;;;;;wBAyBrB,aAAa;;wBAuEb,KAAK;;wBAsGL,eAAe,eAAe"}
|