run402-mcp 4.142.0 → 4.143.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/README.md +1 -1
- package/dist/docs/llms-sdk.txt +17 -6
- package/dist/index.js +6 -8
- package/dist/index.js.map +1 -1
- package/dist/input-guard.d.ts +7 -17
- package/dist/input-guard.d.ts.map +1 -1
- package/dist/input-guard.js +6 -42
- package/dist/input-guard.js.map +1 -1
- package/dist/mcp-server.d.ts +71 -0
- package/dist/mcp-server.d.ts.map +1 -0
- package/dist/mcp-server.js +162 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/schema.d.ts +241 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +589 -0
- package/dist/schema.js.map +1 -0
- package/dist/structured.d.ts +771 -8940
- package/dist/structured.d.ts.map +1 -1
- package/dist/structured.js +7 -7
- package/dist/structured.js.map +1 -1
- package/dist/tools/deploy.d.ts +214 -1104
- package/dist/tools/deploy.d.ts.map +1 -1
- package/dist/tools/deploy.js +5 -5
- package/dist/tools/deploy.js.map +1 -1
- package/dist/tools/docs.d.ts +2 -3
- package/dist/tools/docs.d.ts.map +1 -1
- package/dist/tools/docs.js +1 -1
- package/dist/tools/docs.js.map +1 -1
- package/dist/tools/doctor.d.ts +1 -2
- package/dist/tools/doctor.d.ts.map +1 -1
- package/dist/tools/doctor.js +1 -1
- package/dist/tools/doctor.js.map +1 -1
- package/dist/tools/expand-result.d.ts +3 -4
- package/dist/tools/expand-result.d.ts.map +1 -1
- package/dist/tools/expand-result.js +1 -1
- package/dist/tools/expand-result.js.map +1 -1
- package/dist/tools/run.d.ts +2 -3
- package/dist/tools/run.d.ts.map +1 -1
- package/dist/tools/run.js +1 -1
- package/dist/tools/run.js.map +1 -1
- package/dist/tools/up.d.ts +15 -16
- package/dist/tools/up.d.ts.map +1 -1
- package/dist/tools/up.js +1 -1
- package/dist/tools/up.js.map +1 -1
- package/package.json +4 -5
- package/sdk/dist/index.d.ts +5 -4
- package/sdk/dist/index.d.ts.map +1 -1
- package/sdk/dist/index.js +5 -4
- package/sdk/dist/index.js.map +1 -1
- package/sdk/dist/namespaces/auth.d.ts +10 -0
- package/sdk/dist/namespaces/auth.d.ts.map +1 -1
- package/sdk/dist/namespaces/auth.js +7 -0
- package/sdk/dist/namespaces/auth.js.map +1 -1
- package/sdk/dist/namespaces/push.d.ts +24 -5
- package/sdk/dist/namespaces/push.d.ts.map +1 -1
- package/sdk/dist/namespaces/push.js +47 -4
- package/sdk/dist/namespaces/push.js.map +1 -1
- package/sdk/dist/namespaces/push.types.d.ts +81 -5
- package/sdk/dist/namespaces/push.types.d.ts.map +1 -1
- package/sdk/dist/namespaces/push.types.js +4 -2
- package/sdk/dist/namespaces/push.types.js.map +1 -1
- package/sdk/dist/scoped.d.ts +6 -2
- package/sdk/dist/scoped.d.ts.map +1 -1
- package/sdk/dist/scoped.js +9 -1
- package/sdk/dist/scoped.js.map +1 -1
- package/sdk/dist/secret-gate.d.ts +4 -0
- package/sdk/dist/secret-gate.d.ts.map +1 -1
- package/sdk/dist/secret-gate.js +5 -0
- package/sdk/dist/secret-gate.js.map +1 -1
package/README.md
CHANGED
|
@@ -302,7 +302,7 @@ export default async (req: Request) => {
|
|
|
302
302
|
|
|
303
303
|
`assets.put(key, source, opts?)` uploads bytes from inside a deployed function through the same CAS-backed apply substrate as deploy-time assets. It uses `RUN402_SERVICE_KEY`, accepts a string, `Uint8Array`, or `{ content | bytes }`, and returns an SDK-compatible `AssetRef` with mutable and immutable URLs.
|
|
304
304
|
|
|
305
|
-
`push.send({ title, body?, url?, tag?, to? })` queues a
|
|
305
|
+
`push.send({ title, body?, url?, tag?, data?, to? })` queues a push notification to the phones the app's signed-in users signed up from its page (`<script src="/_run402/push.js">`, then `Run402Push.subscribe({ accessToken })`) and to the devices its own phone app registered with its native session (`POST /_run402/push/devices`, after `run402 push fcm set --service-account <file>` gives Run402 the app's Firebase key); omit `to` to reach every phone, or pass `{ user_id }`. With `data`, a phone app gets only that data, never the title or body. Deliveries count against the organization's daily cap, and `run402 push status [--message <message_id>]` shows who is signed up and whether each message landed. Run402 Cloud only.
|
|
306
306
|
|
|
307
307
|
`repo` and `repos` keep content your app's users edit in app repos: plain git repositories the project owns (not encrypted, not a KyGit vault). `repo.readJson(path)` reads the `default` repo (one commit per request, `null` when absent), `repo.commit({ [path]: value })` commits with the signed-in end user as author, and `repos.open(name)` / `repos.create(name, { from? })` reach the others. Agents read them with `run402 app-repos log|cat|ls`, clone and push with `run402 app-repos clone`, hand someone git over one repo with `run402 app-repos tokens create <name> --access read|write`, and serve the latest commit through a `{ type: "repo", repo, path? }` route target with no deploy. Each file is at most 4 MiB; media goes to `assets.put`.
|
|
308
308
|
|
package/dist/docs/llms-sdk.txt
CHANGED
|
@@ -2179,22 +2179,33 @@ sub.close(); await sub.done;
|
|
|
2179
2179
|
|
|
2180
2180
|
### `r.push`
|
|
2181
2181
|
|
|
2182
|
-
|
|
2182
|
+
Push notifications, the agent-side check, and the Firebase key for the app's own phone app. A deployed function sends with `push.send({ title, body?, url?, tag?, data?, to? })` from `@run402/functions`; a signed-in user signs a phone up from the app's page through `/_run402/push.js` (`Run402Push.subscribe({ accessToken })`), and the app's phone app registers its device with its native session (`POST /_run402/push/devices`). The two reads show who is signed up, how much of the organization's daily delivery cap is used, and what happened to each message. Also project-scoped as `r.project(id).push.status()` / `.getMessage(messageId)` / `.setFcmCredential(serviceAccount)` / `.removeFcmCredential()`.
|
|
2183
2183
|
|
|
2184
2184
|
```
|
|
2185
2185
|
status(projectId): Promise<PushStatus> // GET /projects/v1/:project_id/push
|
|
2186
2186
|
// PushStatus = { project_id,
|
|
2187
|
+
// providers: { fcm: { configured: false } | { configured: true, provider: "fcm", firebase_project_id, client_email,
|
|
2188
|
+
// key_id, set_at, last_error: string | null, last_error_at: string | null } },
|
|
2187
2189
|
// subscriptions: { total, users: [{ user_id, phones: PushPhone[] }], users_shown, users_total, has_more },
|
|
2190
|
+
// devices: { total, users: [{ user_id, devices: PushDevice[] }], users_shown, users_total, has_more },
|
|
2188
2191
|
// usage: { deliveries_today, limit, resets_at, scope: "organization", org_id },
|
|
2189
2192
|
// messages: PushMessageSummary[] } ← the latest 10
|
|
2190
2193
|
// PushPhone = { subscription_id, push_service, created_at, last_confirmed_at, last_accepted_at: string | null }
|
|
2194
|
+
// PushDevice = { device_id, provider: "fcm", created_at, last_confirmed_at, last_accepted_at: string | null }
|
|
2191
2195
|
// PushMessageSummary = { message_id, created_at, status: "no_subscribers" | "queued" | "sending" | "completed",
|
|
2192
2196
|
// devices, outcomes: { queued, retrying, accepted, removed, failed } }
|
|
2193
2197
|
getMessage(projectId, messageId): Promise<PushMessage> // GET …/push/messages/:message_id
|
|
2194
|
-
// PushMessage = PushMessageSummary & { project_id, title, body, url, tag,
|
|
2195
|
-
// deliveries: PushDelivery[], deliveries_shown, has_more }
|
|
2196
|
-
// PushDelivery = {
|
|
2197
|
-
//
|
|
2198
|
+
// PushMessage = PushMessageSummary & { project_id, title: string | null, body, url, tag, data: Record<string, string> | null,
|
|
2199
|
+
// to: { user_id } | null, deliveries: PushDelivery[], deliveries_shown, has_more }
|
|
2200
|
+
// PushDelivery = { kind: "web" | "native", subscription_id? (web), device_id? and provider? (native), user_id, push_service,
|
|
2201
|
+
// status: "queued" | "retrying" | "accepted" | "removed" | "failed", attempts, last_status: number | null,
|
|
2202
|
+
// last_error: string | null, updated_at }
|
|
2203
|
+
setFcmCredential(projectId, serviceAccount): Promise<PushFcmCredential> // POST …/push/providers/fcm
|
|
2204
|
+
// serviceAccount: the JSON object Firebase downloads for a service account. Checked with Google first.
|
|
2205
|
+
// PushFcmCredential = { provider: "fcm", firebase_project_id, client_email, key_id, set_at, last_error, last_error_at,
|
|
2206
|
+
// devices_removed } ← never the key
|
|
2207
|
+
removeFcmCredential(projectId): Promise<PushFcmRemoval> // DELETE …/push/providers/fcm
|
|
2208
|
+
// PushFcmRemoval = { provider: "fcm", status: "removed", devices_removed }
|
|
2198
2209
|
```
|
|
2199
2210
|
|
|
2200
2211
|
```ts
|
|
@@ -2209,7 +2220,7 @@ if (latest) {
|
|
|
2209
2220
|
}
|
|
2210
2221
|
```
|
|
2211
2222
|
|
|
2212
|
-
`removed` means the push service said the phone is gone and the platform deleted its subscription. Accepted credentials: the project's service_key, a wallet/control-plane principal with `project.read`, or a grant key; the SDK sends your principal when the credential provider has one, else the locally cached service key. An unknown message id, or another project's, is a 404 `ApiError` carrying the gateway's `code`. Neither read carries a subscription's endpoint or
|
|
2223
|
+
`removed` means the push service said the phone is gone and the platform deleted its subscription. Accepted credentials: the project's service_key, a wallet/control-plane principal with `project.read`, or a grant key; the SDK sends your principal when the credential provider has one, else the locally cached service key. An unknown message id, or another project's, is a 404 `ApiError` carrying the gateway's `code`. Neither read carries a subscription's endpoint, a device's token or the Firebase key, so both run on the MCP `run` sandbox. `setFcmCredential` takes a key, so the sandbox refuses it with `SECRET_REQUIRES_CLI` naming `run402 push fcm set --service-account <path>`; a key Google refuses is a 422 `ApiError` (`details.reason: "provider_rejected"`), and one for another Firebase project removes the devices registered under the old one (`devices_removed`). The daily cap counts deliveries per organization per UTC day (100 / 1,000 / 10,000 on prototype / hobby / team); `push.send` refuses a message that does not fit whole with `403 QUOTA_EXCEEDED`. Push needs Run402 Cloud.
|
|
2213
2224
|
|
|
2214
2225
|
### `r.appRepos`
|
|
2215
2226
|
|
package/dist/index.js
CHANGED
|
@@ -12,8 +12,7 @@
|
|
|
12
12
|
* (`src/structured.ts`).
|
|
13
13
|
*/
|
|
14
14
|
import { readFileSync } from "node:fs";
|
|
15
|
-
import { McpServer } from "
|
|
16
|
-
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
15
|
+
import { McpServer } from "./mcp-server.js";
|
|
17
16
|
import { selectWallet } from "../sdk/dist/node/index.js";
|
|
18
17
|
import { upSchema, handleUp } from "./tools/up.js";
|
|
19
18
|
import { deploySchema, handleDeploy } from "./tools/deploy.js";
|
|
@@ -24,7 +23,7 @@ import { docsSchema, handleDocs } from "./tools/docs.js";
|
|
|
24
23
|
import { runSchema, handleRun } from "./tools/run.js";
|
|
25
24
|
import { expandResultSchema, handleExpandResult } from "./tools/expand-result.js";
|
|
26
25
|
import { OUTPUT_SCHEMAS } from "./structured.js";
|
|
27
|
-
import {
|
|
26
|
+
import { strictInput } from "./input-guard.js";
|
|
28
27
|
import { closeSnippetChecker } from "./snippet-check.js";
|
|
29
28
|
function currentPackageVersion() {
|
|
30
29
|
const raw = readFileSync(new URL("../package.json", import.meta.url), "utf8");
|
|
@@ -101,9 +100,8 @@ server.registerTool("expand_result", {
|
|
|
101
100
|
inputSchema: INPUT_SCHEMAS.expand_result,
|
|
102
101
|
outputSchema: OUTPUT_SCHEMAS.expand_result,
|
|
103
102
|
}, async (args) => handleExpandResult(args));
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
process.stdin.once("end", () => void closeSnippetChecker());
|
|
103
|
+
// Serve until the host closes stdin; then, with every call in flight answered, stop the type checker
|
|
104
|
+
// (a child process), so it never keeps this server alive.
|
|
105
|
+
await server.listen(process.stdin, process.stdout);
|
|
106
|
+
await closeSnippetChecker();
|
|
109
107
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,C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,EAAE,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC,CACzC,CAAC;AAEF,qGAAqG;AACrG,0DAA0D;AAC1D,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;AACnD,MAAM,mBAAmB,EAAE,CAAC"}
|
package/dist/input-guard.d.ts
CHANGED
|
@@ -3,27 +3,17 @@
|
|
|
3
3
|
* never silently dropped.
|
|
4
4
|
*
|
|
5
5
|
* Every tool is registered with its strict schema (`strictInput`), so the
|
|
6
|
-
* published JSON Schema says `additionalProperties: false
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* guard below validates a `tools/call` against the same strict schema before
|
|
10
|
-
* the SDK sees it, and answers a failure itself with the structured error:
|
|
6
|
+
* published JSON Schema says `additionalProperties: false`, and the server
|
|
7
|
+
* (`mcp-server.ts`) checks each `tools/call` against the same schema before
|
|
8
|
+
* the handler runs, answering a failure with the structured error:
|
|
11
9
|
* `UNKNOWN_ARGUMENT` (with the closest declared names) or `INVALID_ARGUMENTS`.
|
|
12
|
-
* A valid call passes through untouched.
|
|
13
10
|
*/
|
|
14
|
-
import {
|
|
15
|
-
import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
11
|
+
import { type ObjectSchema, type RawShape } from "./schema.js";
|
|
16
12
|
import type { ToolError } from "./structured.js";
|
|
17
13
|
/** A tool's input shape as a strict object: unknown keys fail. */
|
|
18
|
-
export declare function strictInput<T extends
|
|
19
|
-
|
|
14
|
+
export declare function strictInput<T extends RawShape>(shape: T): ObjectSchema<T, "strict">;
|
|
15
|
+
/** A tool's strict input schema, whatever its shape (`any`: `refine` makes schemas invariant). */
|
|
16
|
+
export type StrictSchema = ObjectSchema<any, "strict">;
|
|
20
17
|
/** The structured refusal for arguments that fail a tool's strict schema, or null when they pass. */
|
|
21
18
|
export declare function argumentError(tool: string, schema: StrictSchema, args: unknown): ToolError | null;
|
|
22
|
-
/**
|
|
23
|
-
* Refuse invalid tool arguments with a structured result before the server
|
|
24
|
-
* dispatches the call. Install after `server.connect(transport)`, which sets
|
|
25
|
-
* the transport's `onmessage`.
|
|
26
|
-
*/
|
|
27
|
-
export declare function guardToolArguments(transport: Transport, schemas: Record<string, StrictSchema>): void;
|
|
28
|
-
export {};
|
|
29
19
|
//# sourceMappingURL=input-guard.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input-guard.d.ts","sourceRoot":"","sources":["../src/input-guard.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"input-guard.d.ts","sourceRoot":"","sources":["../src/input-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAK,KAAK,YAAY,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAElE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,kEAAkE;AAClE,wBAAgB,WAAW,CAAC,CAAC,SAAS,QAAQ,EAAE,KAAK,EAAE,CAAC,6BAEvD;AAED,kGAAkG;AAClG,MAAM,MAAM,YAAY,GAAG,YAAY,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;AAEvD,qGAAqG;AACrG,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,OAAO,GAAG,SAAS,GAAG,IAAI,CAoCjG"}
|
package/dist/input-guard.js
CHANGED
|
@@ -3,15 +3,12 @@
|
|
|
3
3
|
* never silently dropped.
|
|
4
4
|
*
|
|
5
5
|
* Every tool is registered with its strict schema (`strictInput`), so the
|
|
6
|
-
* published JSON Schema says `additionalProperties: false
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* guard below validates a `tools/call` against the same strict schema before
|
|
10
|
-
* the SDK sees it, and answers a failure itself with the structured error:
|
|
6
|
+
* published JSON Schema says `additionalProperties: false`, and the server
|
|
7
|
+
* (`mcp-server.ts`) checks each `tools/call` against the same schema before
|
|
8
|
+
* the handler runs, answering a failure with the structured error:
|
|
11
9
|
* `UNKNOWN_ARGUMENT` (with the closest declared names) or `INVALID_ARGUMENTS`.
|
|
12
|
-
* A valid call passes through untouched.
|
|
13
10
|
*/
|
|
14
|
-
import { z } from "
|
|
11
|
+
import { z } from "./schema.js";
|
|
15
12
|
import { closestMembers } from "./sandbox-proxy.js";
|
|
16
13
|
/** A tool's input shape as a strict object: unknown keys fail. */
|
|
17
14
|
export function strictInput(shape) {
|
|
@@ -25,9 +22,9 @@ export function argumentError(tool, schema, args) {
|
|
|
25
22
|
const declared = Object.keys(schema.shape);
|
|
26
23
|
const unknown = [];
|
|
27
24
|
const issues = [];
|
|
28
|
-
for (const issue of parsed.
|
|
25
|
+
for (const issue of parsed.issues) {
|
|
29
26
|
if (issue.code === "unrecognized_keys")
|
|
30
|
-
unknown.push(...issue.keys);
|
|
27
|
+
unknown.push(...(issue.keys ?? []));
|
|
31
28
|
else
|
|
32
29
|
issues.push({ path: issue.path.join(".") || "(arguments)", message: issue.message });
|
|
33
30
|
}
|
|
@@ -59,37 +56,4 @@ export function argumentError(tool, schema, args) {
|
|
|
59
56
|
details: { issues },
|
|
60
57
|
};
|
|
61
58
|
}
|
|
62
|
-
function isToolCall(message) {
|
|
63
|
-
const m = message;
|
|
64
|
-
return m.method === "tools/call" && (typeof m.id === "string" || typeof m.id === "number") && typeof m.params?.name === "string";
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Refuse invalid tool arguments with a structured result before the server
|
|
68
|
-
* dispatches the call. Install after `server.connect(transport)`, which sets
|
|
69
|
-
* the transport's `onmessage`.
|
|
70
|
-
*/
|
|
71
|
-
export function guardToolArguments(transport, schemas) {
|
|
72
|
-
const dispatch = transport.onmessage;
|
|
73
|
-
if (!dispatch)
|
|
74
|
-
throw new Error("guardToolArguments: install after server.connect(transport)");
|
|
75
|
-
transport.onmessage = (message, extra) => {
|
|
76
|
-
if (isToolCall(message)) {
|
|
77
|
-
const schema = schemas[message.params.name];
|
|
78
|
-
const error = schema ? argumentError(message.params.name, schema, message.params.arguments) : null;
|
|
79
|
-
if (error) {
|
|
80
|
-
void transport.send({
|
|
81
|
-
jsonrpc: "2.0",
|
|
82
|
-
id: message.id,
|
|
83
|
-
result: {
|
|
84
|
-
content: [{ type: "text", text: `Error: ${error.message}` }],
|
|
85
|
-
structuredContent: { status: "error", error },
|
|
86
|
-
isError: true,
|
|
87
|
-
},
|
|
88
|
-
});
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
dispatch.call(transport, message, extra);
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
59
|
//# sourceMappingURL=input-guard.js.map
|
package/dist/input-guard.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input-guard.js","sourceRoot":"","sources":["../src/input-guard.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"input-guard.js","sourceRoot":"","sources":["../src/input-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,CAAC,EAAoC,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGpD,kEAAkE;AAClE,MAAM,UAAU,WAAW,CAAqB,KAAQ;IACtD,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;AAClC,CAAC;AAKD,qGAAqG;AACrG,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,MAAoB,EAAE,IAAa;IAC7E,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;IAC5C,IAAI,MAAM,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC;IAChC,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC3C,MAAM,OAAO,GAAa,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AA+E;oBACpF,IAAI;oBACJ,OAAO;oBACP,YAAY,EAAE,UAAU;oBACxB,QAAQ,EAAE,QAAQ;iBACnB,CAAC;YACF,OAAO,EAAE,EAAE,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE;SAC/D,CAAC;IACJ,CAAC;IACD,OAAO;QACL,IAAI,EAAE,mBAAmB;QACzB,OAAO,EAAE,GAAG,IAAI,KAAK,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QAC9E,YAAY,EAAE,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,GAAG,EAAE,sEAAsE,EAAE,IAAI,EAAE,CAAC;QAC3H,OAAO,EAAE,EAAE,MAAM,EAAE;KACpB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The MCP server, in-house: the stdio transport and the server side of the
|
|
3
|
+
* protocol this package uses, so a customer's install carries no MCP library
|
|
4
|
+
* (and none of the HTTP framework one brings).
|
|
5
|
+
*
|
|
6
|
+
* Framing is newline-delimited JSON-RPC 2.0 on stdin and stdout; stdout
|
|
7
|
+
* carries nothing else. The server answers `initialize`, `ping`,
|
|
8
|
+
* `tools/list` and `tools/call`, accepts notifications without answering,
|
|
9
|
+
* and answers any other request with `-32601`. Tool argument and result
|
|
10
|
+
* problems are ordinary tool results, never protocol errors, as the MCP SDK
|
|
11
|
+
* this replaced answered them.
|
|
12
|
+
*/
|
|
13
|
+
import type { Readable, Writable } from "node:stream";
|
|
14
|
+
import { type StrictSchema } from "./input-guard.js";
|
|
15
|
+
import { type AnySchema } from "./schema.js";
|
|
16
|
+
/** Newest first: the version a client gets when it asks for one this server does not know. */
|
|
17
|
+
export declare const SUPPORTED_PROTOCOL_VERSIONS: readonly ["2025-11-25", "2025-06-18", "2025-03-26", "2024-11-05"];
|
|
18
|
+
export declare const JSONRPC_PARSE_ERROR = -32700;
|
|
19
|
+
export declare const JSONRPC_INVALID_REQUEST = -32600;
|
|
20
|
+
export declare const JSONRPC_METHOD_NOT_FOUND = -32601;
|
|
21
|
+
export declare const JSONRPC_INVALID_PARAMS = -32602;
|
|
22
|
+
type JsonRpcId = string | number;
|
|
23
|
+
export interface JsonRpcResponse {
|
|
24
|
+
jsonrpc: "2.0";
|
|
25
|
+
id: JsonRpcId | null;
|
|
26
|
+
result?: unknown;
|
|
27
|
+
error?: {
|
|
28
|
+
code: number;
|
|
29
|
+
message: string;
|
|
30
|
+
data?: unknown;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export interface ToolResult {
|
|
34
|
+
content: Array<{
|
|
35
|
+
type: "text";
|
|
36
|
+
text: string;
|
|
37
|
+
}>;
|
|
38
|
+
structuredContent?: unknown;
|
|
39
|
+
isError?: boolean;
|
|
40
|
+
}
|
|
41
|
+
export declare class McpServer {
|
|
42
|
+
#private;
|
|
43
|
+
readonly info: {
|
|
44
|
+
name: string;
|
|
45
|
+
version: string;
|
|
46
|
+
};
|
|
47
|
+
constructor(info: {
|
|
48
|
+
name: string;
|
|
49
|
+
version: string;
|
|
50
|
+
});
|
|
51
|
+
/** The same call shape the MCP SDK's `registerTool` had, so the registrations in `index.ts` read as before. */
|
|
52
|
+
registerTool<S extends StrictSchema>(name: string, config: {
|
|
53
|
+
description: string;
|
|
54
|
+
inputSchema: S;
|
|
55
|
+
outputSchema: AnySchema;
|
|
56
|
+
}, handler: (args: S["_output"]) => ToolResult | Promise<ToolResult>): void;
|
|
57
|
+
/** The tool names, in registration order. */
|
|
58
|
+
toolNames(): string[];
|
|
59
|
+
/**
|
|
60
|
+
* One decoded JSON-RPC message in, the response out; `undefined` for a
|
|
61
|
+
* notification or a client response, which are never answered.
|
|
62
|
+
*/
|
|
63
|
+
handle(message: unknown): Promise<JsonRpcResponse | undefined>;
|
|
64
|
+
/**
|
|
65
|
+
* Serve newline-delimited JSON-RPC on `input` and `output` until `input`
|
|
66
|
+
* ends; resolves once every call in flight has answered.
|
|
67
|
+
*/
|
|
68
|
+
listen(input: Readable, output: Writable): Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
export {};
|
|
71
|
+
//# sourceMappingURL=mcp-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAO,EAAiB,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAgB,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAE3D,8FAA8F;AAC9F,eAAO,MAAM,2BAA2B,YAAI,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,CAAU,CAAC;AAE7G,eAAO,MAAM,mBAAmB,SAAS,CAAC;AAC1C,eAAO,MAAM,uBAAuB,SAAS,CAAC;AAC9C,eAAO,MAAM,wBAAwB,SAAS,CAAC;AAC/C,eAAO,MAAM,sBAAsB,SAAS,CAAC;AAE7C,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;AAEjC,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,SAAS,GAAG,IAAI,CAAC;IACrB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;CAC3D;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAsBD,qBAAa,SAAS;;IAGR,QAAQ,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE;IAA5D,YAAqB,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAAI;IAEhE,+GAA+G;IAC/G,YAAY,CAAC,CAAC,SAAS,YAAY,EACjC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,CAAC,CAAC;QAAC,YAAY,EAAE,SAAS,CAAA;KAAE,EACxE,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,SAAS,CAAC,KAAK,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,GAChE,IAAI,CAcN;IAED,6CAA6C;IAC7C,SAAS,IAAI,MAAM,EAAE,CAEpB;IAED;;;OAGG;IACG,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC,CAyBnE;IAsCD;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAuCvD;CACF"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { argumentError } from "./input-guard.js";
|
|
2
|
+
import { toJsonSchema } from "./schema.js";
|
|
3
|
+
/** Newest first: the version a client gets when it asks for one this server does not know. */
|
|
4
|
+
export const SUPPORTED_PROTOCOL_VERSIONS = ["2025-11-25", "2025-06-18", "2025-03-26", "2024-11-05"];
|
|
5
|
+
export const JSONRPC_PARSE_ERROR = -32700;
|
|
6
|
+
export const JSONRPC_INVALID_REQUEST = -32600;
|
|
7
|
+
export const JSONRPC_METHOD_NOT_FOUND = -32601;
|
|
8
|
+
export const JSONRPC_INVALID_PARAMS = -32602;
|
|
9
|
+
function textError(text) {
|
|
10
|
+
return { content: [{ type: "text", text }], isError: true };
|
|
11
|
+
}
|
|
12
|
+
function rpcError(id, code, message) {
|
|
13
|
+
return { jsonrpc: "2.0", id, error: { code, message } };
|
|
14
|
+
}
|
|
15
|
+
function isId(value) {
|
|
16
|
+
return typeof value === "string" || typeof value === "number";
|
|
17
|
+
}
|
|
18
|
+
export class McpServer {
|
|
19
|
+
info;
|
|
20
|
+
#tools = new Map();
|
|
21
|
+
constructor(info) {
|
|
22
|
+
this.info = info;
|
|
23
|
+
}
|
|
24
|
+
/** The same call shape the MCP SDK's `registerTool` had, so the registrations in `index.ts` read as before. */
|
|
25
|
+
registerTool(name, config, handler) {
|
|
26
|
+
if (this.#tools.has(name))
|
|
27
|
+
throw new Error(`Tool ${name} is already registered`);
|
|
28
|
+
this.#tools.set(name, {
|
|
29
|
+
...config,
|
|
30
|
+
handler: handler,
|
|
31
|
+
// The listing entry as the MCP SDK published it (key order included), built once.
|
|
32
|
+
listing: {
|
|
33
|
+
name,
|
|
34
|
+
description: config.description,
|
|
35
|
+
inputSchema: toJsonSchema(config.inputSchema),
|
|
36
|
+
execution: { taskSupport: "forbidden" },
|
|
37
|
+
outputSchema: toJsonSchema(config.outputSchema),
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/** The tool names, in registration order. */
|
|
42
|
+
toolNames() {
|
|
43
|
+
return [...this.#tools.keys()];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* One decoded JSON-RPC message in, the response out; `undefined` for a
|
|
47
|
+
* notification or a client response, which are never answered.
|
|
48
|
+
*/
|
|
49
|
+
async handle(message) {
|
|
50
|
+
if (typeof message !== "object" || message === null || Array.isArray(message)) {
|
|
51
|
+
return rpcError(null, JSONRPC_INVALID_REQUEST, "Invalid Request");
|
|
52
|
+
}
|
|
53
|
+
const m = message;
|
|
54
|
+
const hasId = isId(m.id);
|
|
55
|
+
if (typeof m.method !== "string") {
|
|
56
|
+
// A response to a request this server never sends, or junk: answer junk that carries an id.
|
|
57
|
+
return "result" in m || "error" in m ? undefined : rpcError(hasId ? m.id : null, JSONRPC_INVALID_REQUEST, "Invalid Request");
|
|
58
|
+
}
|
|
59
|
+
if (!hasId)
|
|
60
|
+
return undefined; // notifications/initialized, notifications/cancelled, and any other notification
|
|
61
|
+
const id = m.id;
|
|
62
|
+
const params = (typeof m.params === "object" && m.params !== null ? m.params : {});
|
|
63
|
+
switch (m.method) {
|
|
64
|
+
case "initialize":
|
|
65
|
+
return { jsonrpc: "2.0", id, result: this.#initialize(params) };
|
|
66
|
+
case "ping":
|
|
67
|
+
return { jsonrpc: "2.0", id, result: {} };
|
|
68
|
+
case "tools/list":
|
|
69
|
+
return { jsonrpc: "2.0", id, result: { tools: [...this.#tools.values()].map((t) => t.listing) } };
|
|
70
|
+
case "tools/call":
|
|
71
|
+
return { jsonrpc: "2.0", id, result: await this.#call(params) };
|
|
72
|
+
default:
|
|
73
|
+
return rpcError(id, JSONRPC_METHOD_NOT_FOUND, "Method not found");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
#initialize(params) {
|
|
77
|
+
const requested = params.protocolVersion;
|
|
78
|
+
const protocolVersion = SUPPORTED_PROTOCOL_VERSIONS.includes(requested) ? requested : SUPPORTED_PROTOCOL_VERSIONS[0];
|
|
79
|
+
return { protocolVersion, capabilities: { tools: { listChanged: true } }, serverInfo: { ...this.info } };
|
|
80
|
+
}
|
|
81
|
+
async #call(params) {
|
|
82
|
+
const name = typeof params.name === "string" ? params.name : "";
|
|
83
|
+
const tool = this.#tools.get(name);
|
|
84
|
+
if (!tool)
|
|
85
|
+
return textError(`MCP error ${JSONRPC_INVALID_PARAMS}: Tool ${name} not found`);
|
|
86
|
+
const refusal = argumentError(name, tool.inputSchema, params.arguments);
|
|
87
|
+
if (refusal) {
|
|
88
|
+
return { content: [{ type: "text", text: `Error: ${refusal.message}` }], structuredContent: { status: "error", error: refusal }, isError: true };
|
|
89
|
+
}
|
|
90
|
+
const args = tool.inputSchema.parse(params.arguments ?? {});
|
|
91
|
+
let result;
|
|
92
|
+
try {
|
|
93
|
+
result = await tool.handler(args);
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
return textError(err instanceof Error ? err.message : String(err));
|
|
97
|
+
}
|
|
98
|
+
return this.#checkOutput(name, tool, result);
|
|
99
|
+
}
|
|
100
|
+
/** A successful result's structuredContent must satisfy the tool's output schema, as the MCP SDK checked it. */
|
|
101
|
+
#checkOutput(name, tool, result) {
|
|
102
|
+
if (result.isError)
|
|
103
|
+
return result;
|
|
104
|
+
if (result.structuredContent === undefined) {
|
|
105
|
+
return textError(`MCP error ${JSONRPC_INVALID_PARAMS}: Output validation error: Tool ${name} has an output schema but no structured content was provided`);
|
|
106
|
+
}
|
|
107
|
+
const checked = tool.outputSchema.safeParse(result.structuredContent);
|
|
108
|
+
if (checked.success)
|
|
109
|
+
return result;
|
|
110
|
+
const detail = checked.issues.map((i) => `${i.path.join(".") || "(result)"}: ${i.message}`).join("; ");
|
|
111
|
+
return textError(`MCP error ${JSONRPC_INVALID_PARAMS}: Output validation error: Invalid structured content for tool ${name}: ${detail}`);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Serve newline-delimited JSON-RPC on `input` and `output` until `input`
|
|
115
|
+
* ends; resolves once every call in flight has answered.
|
|
116
|
+
*/
|
|
117
|
+
listen(input, output) {
|
|
118
|
+
const inFlight = new Set();
|
|
119
|
+
const write = (response) => {
|
|
120
|
+
if (response)
|
|
121
|
+
output.write(`${JSON.stringify(response)}\n`);
|
|
122
|
+
};
|
|
123
|
+
const dispatch = (line) => {
|
|
124
|
+
let message;
|
|
125
|
+
try {
|
|
126
|
+
message = JSON.parse(line);
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
write(rpcError(null, JSONRPC_PARSE_ERROR, "Parse error"));
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const task = this.handle(message)
|
|
133
|
+
.then(write)
|
|
134
|
+
.catch((err) => {
|
|
135
|
+
console.error(`run402-mcp: ${err instanceof Error ? err.message : String(err)}`);
|
|
136
|
+
})
|
|
137
|
+
.finally(() => inFlight.delete(task));
|
|
138
|
+
inFlight.add(task);
|
|
139
|
+
};
|
|
140
|
+
let buffer = "";
|
|
141
|
+
input.setEncoding("utf8");
|
|
142
|
+
input.on("data", (chunk) => {
|
|
143
|
+
buffer += chunk;
|
|
144
|
+
let newline;
|
|
145
|
+
while ((newline = buffer.indexOf("\n")) >= 0) {
|
|
146
|
+
const line = buffer.slice(0, newline).replace(/\r$/, "");
|
|
147
|
+
buffer = buffer.slice(newline + 1);
|
|
148
|
+
if (line.trim() !== "")
|
|
149
|
+
dispatch(line);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
return new Promise((resolve) => {
|
|
153
|
+
input.once("end", () => {
|
|
154
|
+
if (buffer.trim() !== "")
|
|
155
|
+
dispatch(buffer.replace(/\r$/, ""));
|
|
156
|
+
buffer = "";
|
|
157
|
+
void Promise.allSettled([...inFlight]).then(() => resolve());
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=mcp-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-server.js","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,aAAa,EAAqB,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,YAAY,EAAkB,MAAM,aAAa,CAAC;AAE3D,8FAA8F;AAC9F,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,CAAU,CAAC;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