@gjermundgaraba/effect-actions 0.39.0 → 0.40.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 +2 -2
- package/dist/ActionMcp.d.mts +25 -15
- package/dist/ActionMcp.mjs +15 -13
- package/dist/Testing.d.mts +1 -1
- package/dist/Testing.mjs +4 -3
- package/dist/http/client.d.mts +4 -1
- package/dist/mcp/client.d.mts +3 -1
- package/docs/ActionMcp-failures.md +1 -1
- package/docs/setup-failures.md +1 -1
- package/docs/setup.md +6 -6
- package/package.json +13 -13
package/README.md
CHANGED
|
@@ -76,10 +76,10 @@ Effect.gen(function* () {
|
|
|
76
76
|
## Install
|
|
77
77
|
|
|
78
78
|
```sh
|
|
79
|
-
pnpm add @gjermundgaraba/effect-actions effect@~4.
|
|
79
|
+
pnpm add @gjermundgaraba/effect-actions effect@~4.2.0
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
-
It needs TypeScript 7 or newer and is ESM only ([docs/setup.md](docs/setup.md#install)). Add `@effect/platform-node@~4.
|
|
82
|
+
It needs TypeScript 7 or newer and is ESM only ([docs/setup.md](docs/setup.md#install)). Add `@effect/platform-node@~4.2.0` to serve or run a CLI from Node, and `@types/node` for its `node:` imports. Every module is a subpath import (`.../Action`, `.../ActionHttp`, ...); there is no package root, so a contracts-only bundle never loads a server.
|
|
83
83
|
|
|
84
84
|
## Examples
|
|
85
85
|
|
package/dist/ActionMcp.d.mts
CHANGED
|
@@ -9,13 +9,15 @@ import { Params, RequestOptions, request } from "./mcp/request.mjs";
|
|
|
9
9
|
import { Cause, Effect, Layer, Scope, Stdio } from "effect";
|
|
10
10
|
import { HttpRouter } from "effect/http";
|
|
11
11
|
import { McpSchema, McpServer } from "effect/ai";
|
|
12
|
+
type NativeStdioOptions = Parameters<typeof McpServer.layerStdio>[0];
|
|
13
|
+
type NativeHttpOptions = Parameters<typeof McpServer.layerHttp>[0];
|
|
12
14
|
/**
|
|
13
|
-
* An MCP server, over HTTP or stdio: every native `McpServer.layerStdio`
|
|
14
|
-
* and `registrations`, the server information,
|
|
15
|
-
* among them, the actions `A` that are its tools and the event types `A` it serves, and the
|
|
15
|
+
* An MCP server, over HTTP or stdio: every native option `McpServer.layerStdio` and
|
|
16
|
+
* `McpServer.layerHttp` both take but `protocols` and `registrations`, the server information,
|
|
17
|
+
* `instructions`, `extensions` and `cacheHints` among them, the actions `A` that are its tools and the event types `A` it serves, and the
|
|
16
18
|
* native features it serves beside them.
|
|
17
19
|
*/
|
|
18
|
-
export interface Options<E = never, R = never, A extends Any$1 | Any$2 = Any$1 | Any$2> extends Omit<
|
|
20
|
+
export interface Options<E = never, R = never, A extends Any$1 | Any$2 = Any$1 | Any$2> extends Omit<Pick<NativeStdioOptions, keyof NativeStdioOptions & keyof NativeHttpOptions>, "protocols" | "registrations"> {
|
|
19
21
|
/**
|
|
20
22
|
* The actions that are tools and the event types it serves, among the implementations':
|
|
21
23
|
* `[GetUser, RenameUser, UserRenamed]`, exactly those. Each keeps its implementation's
|
|
@@ -44,10 +46,10 @@ export interface Options<E = never, R = never, A extends Any$1 | Any$2 = Any$1 |
|
|
|
44
46
|
}
|
|
45
47
|
/**
|
|
46
48
|
* One Streamable HTTP MCP endpoint: `Options`, `authentication`, `requestScoped`, and every native
|
|
47
|
-
* `McpServer.layerHttp` option, `allowedOrigins` among them, except `protocols`,
|
|
48
|
-
* and `allowSessionTermination`, which are fixed.
|
|
49
|
+
* `McpServer.layerHttp` option, `allowedOrigins` and `maxSessions` among them, except `protocols`,
|
|
50
|
+
* `registrations` and `allowSessionTermination`, which are fixed.
|
|
49
51
|
*/
|
|
50
|
-
export interface LayerHttpOptions<E = never, R = never, A extends Any$1 | Any$2 = Any$1 | Any$2> extends Options<E, R, A>, Omit<
|
|
52
|
+
export interface LayerHttpOptions<E = never, R = never, A extends Any$1 | Any$2 = Any$1 | Any$2> extends Options<E, R, A>, Omit<NativeHttpOptions, "protocols" | "path" | "allowSessionTermination" | "registrations"> {
|
|
51
53
|
/** The endpoint's route; defaults to `/mcp`. */
|
|
52
54
|
readonly path?: HttpRouter.PathInput;
|
|
53
55
|
/**
|
|
@@ -104,7 +106,9 @@ type Inferring<D, A extends Pick<Any$1, "caller">> = [D] extends [undefined] ? [
|
|
|
104
106
|
* Serve MCP tools over one Streamable HTTP endpoint, speaking MCP 2026-07-28, 2025-11-25 or
|
|
105
107
|
* 2025-06-18, as the client negotiates. A 2026-07-28 request stands alone; a client of a 2025
|
|
106
108
|
* revision opens a session with `initialize`, which holds what it sent there and no identity,
|
|
107
|
-
* and lasts until that client ends it with a DELETE, answered 204, or the process stops
|
|
109
|
+
* and lasts until that client ends it with a DELETE, answered 204, or the process stops, or until
|
|
110
|
+
* it is the least recently used idle one beyond the native `maxSessions`, whose id is then
|
|
111
|
+
* answered 404. Protected
|
|
108
112
|
* tools need `authentication`; for a serverless host, see `requestScoped`. In a tool call, what
|
|
109
113
|
* middleware provides per request wins over what the endpoint was built with. The event
|
|
110
114
|
* types among `implementations`, or those `actions` lists, are served as SEP-3415 events,
|
|
@@ -119,12 +123,12 @@ type Inferring<D, A extends Pick<Any$1, "caller">> = [D] extends [undefined] ? [
|
|
|
119
123
|
* - A success is `isError: false` with `structuredContent` its JSON and the same JSON as one text block, both `null` for an action without `success`; an `Action.Image` field is left out of `structuredContent` and its text, its block following them, and a success of images alone has no `structuredContent`.
|
|
120
124
|
* - A success whose schema encodes only to a string, such as `Schema.String`, a string literal or `Schema.DateTimeUtc`, is its raw text as one text block on every revision, with no `structuredContent` and no `outputSchema`, since Claude Code shows a model serialized `structuredContent` in place of every text block: return file contents or command output as such a string, never as a field of an object, which reaches a model JSON-escaped.
|
|
121
125
|
* - A union holding a string, such as `Schema.NullOr(Schema.String)` or an optional string, is sent as any other success, so a 2026-07-28 client gets the string as `structuredContent` and JSON-quoted text, which reaches a Claude Code model escaped: return `""` for nothing, not `null`.
|
|
122
|
-
* - A declared error is an `isError: true` tool result in a 200 whose one text block is its `message`, or the error itself when it is a string, or its JSON when it has no `message` or an empty one, with its JSON in `_meta["io.github.gjermundgaraba.effect-actions/error"]`, from which `client` decodes it, and no `structuredContent`: write each `message` for the model, since its other fields reach a model only through it; a refusal is answered as `Action.Unauthenticated` and `Action.Forbidden` say.
|
|
126
|
+
* - A declared error is an `isError: true` tool result in a 200 whose one text block is its `message`, or the error itself when it is a string, or its JSON when it has no `message` or an empty one, with its JSON in `_meta["io.github.gjermundgaraba.effect-actions/error"]`, from which `client` decodes it, Effect's `McpSchema.ToolErrorInfo` `{ kind: "failure" }` in `_meta["website.effect/toolError"]`, with `tag` its `_tag` where it has a non-empty one, and no `structuredContent`: write each `message` for the model, since its other fields reach a model only through it; a refusal is answered as `Action.Unauthenticated` and `Action.Forbidden` say.
|
|
123
127
|
* - An action answering a stream, `Action.Stream`, answers its elements collected into one array once the stream ends, a success of that array.
|
|
124
128
|
* - An action declaring `progress` sends each value as `notifications/progress` on the `progressToken` its call's `_meta` carries, before the result: `progress` counts from 1, `message` is the value's JSON and `_meta["io.github.gjermundgaraba.effect-actions/progress"]` the value; a call without a token gets none.
|
|
125
|
-
* - Arguments that do not decode never reach the handler: an `isError: true` result in a 200, text `Invalid parameters for tool '<name>':
|
|
126
|
-
* - A defect, an undeclared failure, or a success or an error that does not encode is `isError: true`, text `Tool execution failed due to an internal server error
|
|
127
|
-
* - An unknown tool is a JSON-RPC error `-32602` in a 200; a body that is not JSON a JSON-RPC error `-32700` in a 200; a `Content-Type` missing or not JSON
|
|
129
|
+
* - Arguments that do not decode never reach the handler: an `isError: true` result in a 200, text `Invalid parameters for tool '<name>': …` with `{ kind: "invalidInput" }` in `_meta["website.effect/toolError"]`, or for a 2025-06-18 client a JSON-RPC error.
|
|
130
|
+
* - A defect, an undeclared failure, or a success or an error that does not encode is `isError: true`, text `Tool execution failed due to an internal server error.`, with `{ kind: "internal" }` in `_meta["website.effect/toolError"]`: the cause goes to the log and to the call's `ErrorReporter`s, never to the client.
|
|
131
|
+
* - An unknown tool is a JSON-RPC error `-32602` in a 200; a body that is not JSON a JSON-RPC error `-32700` in a 200; a `Content-Type` missing or not JSON a JSON-RPC error `-32600` in a 415; another HTTP method an empty 405 with `Allow: POST, DELETE`, `Allow: POST` where `requestScoped`, or the 401 of an endpoint with authentication when signed out.
|
|
128
132
|
* - A 2025-11-25 or 2025-06-18 client gets `structuredContent` only for a success that is an object: a number, an array or `null` arrives as its JSON text block alone, and a string a union success returns as its text unquoted.
|
|
129
133
|
* - A client asking for an earlier revision, such as 2025-03-26, is offered 2025-11-25, so a client speaking only that earlier one cannot connect.
|
|
130
134
|
* - A request body is read whole, however large, and a 2025 session holds what its `initialize` sent until it ends, so an oversized `initialize` costs memory for that long: limit bodies as `ActionHttp.layer` says.
|
|
@@ -137,11 +141,17 @@ type Inferring<D, A extends Pick<Any$1, "caller">> = [D] extends [undefined] ? [
|
|
|
137
141
|
* - A push stream's failure that no refusal explains, such as an upstream's outage, is `notifications/events/error`, its cause logged and reported, and the stream resumes from where it reached after 5 seconds; a refusal ends it with `notifications/events/terminated`. One before `active`, or a poll's, is a JSON-RPC `-32603`, which `client`'s `watch` reconnects after, as after a 5xx.
|
|
138
142
|
*/
|
|
139
143
|
export declare function layerHttp<const Apps extends Served, const O extends Selection<ActionOf<Member<Apps>> | EventOf<Member<Apps>>> = {}, E = never, R = never, const D extends Any | undefined = undefined>(implementations: Apps, options: LayerHttpOptions<E, R, ActionOf<Member<Apps>> | EventOf<Member<Apps>>> & O & NoInfer<Known<O, LayerHttpOptions<E, R>>> & NoInfer<Required<Contracts<Apps, O>>> & Matching<NoInfer<Contracts<Apps, O>>, NoInfer<D>> & Inferring<D, NoInfer<Contracts<Apps, O>>>): Layer.Layer<never, ServerError<Apps, O> | E, ServerBuildServices<Holding<Member<Apps>, SelectedOf<O, Apps>>, SelectedOf<O, Apps>> | EventServices<Apps, O> | HttpRouter.HttpRouter | HttpRouter.Request.From<"Requires", HttpToolRequestContext<RemoteRequest<Member<Apps>, SelectedOf<O, Apps>> | EventServedRequest<Member<Apps>, SelectedEventsOf<O, Apps>> | FeatureRequest<R>>> | ProviderOf<D> | Features<R>>;
|
|
144
|
+
/**
|
|
145
|
+
* `runStdio`'s options: `Options` and every native `McpServer.layerStdio` option, `onStdinEnd`
|
|
146
|
+
* among them, except `protocols` and `registrations`, which are fixed.
|
|
147
|
+
*/
|
|
148
|
+
export interface RunStdioOptions<E = never, R = never, A extends Any$1 | Any$2 = Any$1 | Any$2> extends Options<E, R, A>, Omit<NativeStdioOptions, "protocols" | "registrations"> {}
|
|
140
149
|
/**
|
|
141
150
|
* Serve MCP tools through newline-delimited JSON-RPC on standard I/O, speaking MCP
|
|
142
151
|
* 2026-07-28, 2025-11-25 or 2025-06-18, as the host negotiates: the whole
|
|
143
152
|
* program of an MCP subprocess, which succeeds once the host closes its side and every call
|
|
144
|
-
* in flight has been answered
|
|
153
|
+
* in flight has been answered, or, with `onStdinEnd: "interrupt"`, once the host closes its
|
|
154
|
+
* side, interrupting the calls in flight unanswered. A signal interrupts it. Its own Effect logs and `Console` output
|
|
145
155
|
* go to stderr, since stdout carries the protocol. The host supplies the `Stdio` service, and
|
|
146
156
|
* provides the identity around `runStdio`; arguments are tool input only and never establish
|
|
147
157
|
* request identity or authority, and each implementation's `authorize` runs for its protected
|
|
@@ -150,8 +160,8 @@ export declare function layerHttp<const Apps extends Served, const O extends Sel
|
|
|
150
160
|
*
|
|
151
161
|
* **Gotchas**
|
|
152
162
|
*
|
|
153
|
-
* - A line that is not JSON
|
|
163
|
+
* - A line that is not JSON is answered `-32700` with `id: null`, as over HTTP, and a line of JSON that is no JSON-RPC message, such as `5` or `{}`, `-32600`; the lines after either are still answered.
|
|
154
164
|
* - The layers provided around it log to stdout, among the protocol's lines: apply `ActionCli.logToStderr` to the program, last, as its JSDoc says.
|
|
155
165
|
*/
|
|
156
|
-
export declare function runStdio<const Apps extends Served, const O extends Selection<ActionOf<Member<Apps>> | EventOf<Member<Apps>>> = {}, E = never, R = never>(implementations: Apps, options:
|
|
166
|
+
export declare function runStdio<const Apps extends Served, const O extends Selection<ActionOf<Member<Apps>> | EventOf<Member<Apps>>> = {}, E = never, R = never>(implementations: Apps, options: RunStdioOptions<E, R, ActionOf<Member<Apps>> | EventOf<Member<Apps>>> & O & NoInfer<Known<O, RunStdioOptions<E, R>>>): Effect.Effect<void, ServerError<Apps, O> | E, BuildServices<Holding<Member<Apps>, SelectedOf<O, Apps>>, SelectedOf<O, Apps>> | EventServices<Apps, O> | Stdio.Stdio | ToolRequestContext<ServedRequest<Member<Apps>, SelectedOf<O, Apps>> | EventRequestOf<Member<Apps>, SelectedEventsOf<O, Apps>> | Exclude<FeatureRequest<R>, Scope.Scope>> | Features<R>>;
|
|
157
167
|
export { type Client, type ClientOptions, McpCallError, type Params, type RequestOptions, client, request };
|
package/dist/ActionMcp.mjs
CHANGED
|
@@ -17,7 +17,7 @@ import { defaultPath, errorKey, fieldKey, httpProtocol, isMisplaced, isObjectSch
|
|
|
17
17
|
import { client } from "./mcp/client.mjs";
|
|
18
18
|
import { McpCallError } from "./mcp/reply.mjs";
|
|
19
19
|
import { request } from "./mcp/request.mjs";
|
|
20
|
-
import { Cause, Context, Effect, ErrorReporter, Exit, Fiber, Layer,
|
|
20
|
+
import { Cause, Context, Effect, ErrorReporter, Exit, Fiber, Layer, Predicate, Schema } from "effect";
|
|
21
21
|
import { HttpRouter, HttpServerRequest } from "effect/http";
|
|
22
22
|
import { AiError, McpSchema, McpServer } from "effect/ai";
|
|
23
23
|
// src/mcp/ActionMcp.ts
|
|
@@ -27,13 +27,13 @@ const assertToolsServable = (lifted) => {
|
|
|
27
27
|
const misplaced = lifted.flatMap(([action, lift]) => isMisplaced(action, lift) ? [action.name] : []);
|
|
28
28
|
if (misplaced.length > 0) throw new Error(`MCP media must be the success or an array of it, or a top-level field of a struct success, one, optional or a required array: ${misplaced.join(", ")} (make the image such a field, or give an optional array as a required one, empty when absent; an image in input or an error is not served over MCP, so leave that action out of actions)`);
|
|
29
29
|
};
|
|
30
|
-
const
|
|
31
|
-
const textErrorResult = (text) => new McpSchema.CallToolResult({
|
|
30
|
+
const internalErrorResult = new McpSchema.CallToolResult({
|
|
32
31
|
isError: true,
|
|
33
32
|
content: [{
|
|
34
33
|
type: "text",
|
|
35
|
-
text
|
|
36
|
-
}]
|
|
34
|
+
text: "Tool execution failed due to an internal server error."
|
|
35
|
+
}],
|
|
36
|
+
_meta: { [McpSchema.TOOL_ERROR_META_KEY]: { kind: "internal" } }
|
|
37
37
|
});
|
|
38
38
|
const nativeJsonTextOf = (encoded) => encoded === void 0 ? [] : [{
|
|
39
39
|
type: "text",
|
|
@@ -43,13 +43,20 @@ const errorTextOf = (encoded) => {
|
|
|
43
43
|
if (Predicate.isString(encoded)) return encoded;
|
|
44
44
|
return Predicate.hasProperty(encoded, "message") && Predicate.isString(encoded.message) && encoded.message !== "" ? encoded.message : JSON.stringify(encoded);
|
|
45
45
|
};
|
|
46
|
+
const failureInfoOf = (encoded) => Predicate.hasProperty(encoded, "_tag") && Predicate.isString(encoded._tag) && encoded._tag !== "" ? {
|
|
47
|
+
kind: "failure",
|
|
48
|
+
tag: encoded._tag
|
|
49
|
+
} : { kind: "failure" };
|
|
46
50
|
const declaredErrorResult = (encoded) => new McpSchema.CallToolResult({
|
|
47
51
|
isError: true,
|
|
48
52
|
content: [{
|
|
49
53
|
type: "text",
|
|
50
54
|
text: errorTextOf(encoded)
|
|
51
55
|
}],
|
|
52
|
-
_meta: {
|
|
56
|
+
_meta: {
|
|
57
|
+
[errorKey]: encoded,
|
|
58
|
+
[McpSchema.TOOL_ERROR_META_KEY]: failureInfoOf(encoded)
|
|
59
|
+
}
|
|
53
60
|
});
|
|
54
61
|
const contentBlockOf = ({ kind, field, value }) => ({
|
|
55
62
|
type: kind,
|
|
@@ -68,7 +75,7 @@ const toolOf = (action, outputSchema) => Effect.map(Schema.decodeUnknownEffect(M
|
|
|
68
75
|
},
|
|
69
76
|
_meta: action.mcp._meta === void 0 ? void 0 : { ...action.mcp._meta }
|
|
70
77
|
}));
|
|
71
|
-
const internalError = (cause) => Effect.logError(cause).pipe(Effect.andThen(ErrorReporter.report(cause)), Effect.as(
|
|
78
|
+
const internalError = (cause) => Effect.logError(cause).pipe(Effect.andThen(ErrorReporter.report(cause)), Effect.as(internalErrorResult));
|
|
72
79
|
const internalErrorOnDefect = (cause) => Cause.hasDies(cause) ? internalError(cause) : Effect.failCause(cause);
|
|
73
80
|
const encoder = (schema) => {
|
|
74
81
|
const encode = Schema.encodeUnknownEffect(Schema.toCodecJson(schema));
|
|
@@ -218,11 +225,6 @@ function layerHttp(apps, { actions, features, path = defaultPath, authentication
|
|
|
218
225
|
const middleware = HttpRouter.middleware(Effect.map(providerOf(authentication), (runtime) => (route) => Effect.flatMap(HttpServerRequest.HttpServerRequest, (request) => request.method !== "POST" || required(request.headers) ? runtime.http(readsItsBody(route), false) : Effect.flatMap(namesItsMethod(request), (named) => runtime.http(readsItsBody(route), named)))));
|
|
219
226
|
return transport.pipe(Layer.provide(middleware.layer));
|
|
220
227
|
}
|
|
221
|
-
const isJsonLine = (line) => Option.isSome(Schema.decodeOption(Schema.fromJsonString(Schema.Json))(line));
|
|
222
|
-
const jsonLinesOnly = Layer.effect(Stdio.Stdio, Effect.map(Stdio.Stdio, (stdio) => Stdio.make({
|
|
223
|
-
...stdio,
|
|
224
|
-
stdin: stdio.stdin.pipe(Stream.decodeText, Stream.splitLines, Stream.filter(isJsonLine), Stream.map((line) => `${line}\n`), Stream.encodeText)
|
|
225
|
-
})));
|
|
226
228
|
function runStdio(apps, { actions, features, ...options }) {
|
|
227
229
|
const { apps: selected, events } = selectFrom(apps, actions);
|
|
228
230
|
assertEventsServable(events.flatMap((app) => app.events));
|
|
@@ -234,7 +236,7 @@ function runStdio(apps, { actions, features, ...options }) {
|
|
|
234
236
|
...options,
|
|
235
237
|
protocols: servingEvents(protocols, serving),
|
|
236
238
|
registrations
|
|
237
|
-
})
|
|
239
|
+
}), features);
|
|
238
240
|
return Layer.launch(transport).pipe(withStderrConsole, Effect.forkChild, Effect.flatMap(Fiber.await), Effect.flatMap((exit) => Exit.isFailure(exit) && !Cause.hasInterruptsOnly(exit.cause) ? Effect.failCause(exit.cause) : Effect.void));
|
|
239
241
|
}
|
|
240
242
|
export { McpCallError, client, layerHttp, request, runStdio };
|
package/dist/Testing.d.mts
CHANGED
|
@@ -24,7 +24,7 @@ export declare function layer(handler: (request: Request) => Promise<Response>):
|
|
|
24
24
|
* - The client is the layer's own: the program's other HTTP clients get none of its requests, so a fake upstream is another `HttpClient`, provided to the service that calls out.
|
|
25
25
|
* - A service the test reads too is provided around it once, with `Layer.provideMerge`: provided to the routes and again to the test, it is two instances, and the test reads one the handlers never changed.
|
|
26
26
|
* - Requests run in the context it is built in: a `ConfigProvider` or the test clock provided around the test reaches middleware and handlers.
|
|
27
|
-
* - No request is logged: only the cause of a defect, of a result that does not encode or of a failure a route leaves unhandled, as an error on the process console, even under `it.effect`'s `TestConsole`; a client reads it as an empty 500.
|
|
27
|
+
* - No request is logged: only the cause of a defect, of a result that does not encode or of a failure a route leaves unhandled, as an error on the process console, even under `it.effect`'s `TestConsole`; a client reads it as an empty 500. A `SchemaError` or `NoSuchElementError` a route fails with is not logged: the server answers it 400 or 404 and reports it to no `ErrorReporter`.
|
|
28
28
|
* - It never requires `FileSystem`, `Path`, `HttpPlatform` or `Etag.Generator`: one provided around it is the routes', and `HttpServer.layerServices`' defaults stand in for the rest, whose `FileSystem` is a no-op, so a file the routes read is `NotFound` until `NodeFileSystem.layer` is provided around it.
|
|
29
29
|
* - It answers HTTP requests and cannot upgrade a WebSocket: give an rpc layer `RpcServer.layerProtocolHttp` in the test, and its client `RpcClient.layerProtocolHttp` over this layer.
|
|
30
30
|
*/
|
package/dist/Testing.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { clientOf } from "./testing/memory.mjs";
|
|
2
|
-
import { Cause, Console, Context, Effect, ErrorReporter, FileSystem, Layer, Option, Path } from "effect";
|
|
3
|
-
import { Etag, HttpEffect, HttpPlatform, HttpRouter } from "effect/http";
|
|
2
|
+
import { Cause, Console, Context, Effect, ErrorReporter, FileSystem, Layer, Option, Path, Schema } from "effect";
|
|
3
|
+
import { Etag, HttpEffect, HttpPlatform, HttpRouter, HttpServerRespondable } from "effect/http";
|
|
4
4
|
// src/testing/Testing.ts
|
|
5
|
-
const
|
|
5
|
+
const isClientError = (error) => !HttpServerRespondable.isRespondable(error) && (Schema.isSchemaError(error) || Cause.isNoSuchElementError(error));
|
|
6
|
+
const reachedRouterUnhandled = (cause) => cause.reasons.some((reason) => Cause.isFailReason(reason) && !ErrorReporter.isIgnored(reason.error) && !isClientError(reason.error) || Cause.isDieReason(reason) && !ErrorReporter.isIgnored(reason.defect));
|
|
6
7
|
const logUnhandledToProcessConsole = (cause) => reachedRouterUnhandled(cause) ? Effect.logError(cause).pipe(Effect.provideService(Console.Console, globalThis.console)) : Effect.void;
|
|
7
8
|
function layer(routes) {
|
|
8
9
|
if (!Layer.isLayer(routes)) return clientOf(routes);
|
package/dist/http/client.d.mts
CHANGED
|
@@ -30,7 +30,10 @@ export interface Options<E = HttpClientError.HttpClientError, R = never> {
|
|
|
30
30
|
readonly baseUrl?: NonNullable<Parameters<typeof HttpApiClient.make>[1]>["baseUrl"];
|
|
31
31
|
/**
|
|
32
32
|
* Wraps the native `HttpClient` the calls send with: a bearer token is
|
|
33
|
-
* `HttpClient.mapRequest(HttpClientRequest.bearerToken(token))`,
|
|
33
|
+
* `HttpClient.mapRequest(HttpClientRequest.bearerToken(token))`, a credential in the scheme an
|
|
34
|
+
* `Authentication` declares, API key or Basic included,
|
|
35
|
+
* `HttpClient.mapRequest((request) => HttpApiClient.securityEncode(request, Auth.security, credential))`,
|
|
36
|
+
* and a credential read or
|
|
34
37
|
* refreshed as each request is sent `(client) => HttpClient.mapRequestEffect(client, authorize)`.
|
|
35
38
|
* A method also fails with what the returned client fails with beyond an `HttpClientError`, as
|
|
36
39
|
* it is, and requires what it requires.
|
package/dist/mcp/client.d.mts
CHANGED
|
@@ -21,7 +21,9 @@ export interface ClientOptions<D extends Any | undefined = Any | undefined, E =
|
|
|
21
21
|
readonly url?: string;
|
|
22
22
|
/**
|
|
23
23
|
* Wraps the native `HttpClient`, as `ActionHttp.client` takes it: a bearer token is
|
|
24
|
-
* `HttpClient.mapRequest(HttpClientRequest.bearerToken(token))
|
|
24
|
+
* `HttpClient.mapRequest(HttpClientRequest.bearerToken(token))`, and a credential in the scheme
|
|
25
|
+
* an `Authentication` declares
|
|
26
|
+
* `HttpClient.mapRequest((request) => HttpApiClient.securityEncode(request, Auth.security, credential))`.
|
|
25
27
|
*/
|
|
26
28
|
readonly transformClient?: (client: HttpClient.HttpClient) => HttpClient.HttpClient.With<E, R>;
|
|
27
29
|
/**
|
|
@@ -12,7 +12,7 @@ What you see when something is wrong, and the fix. Search for a fragment of the
|
|
|
12
12
|
- A hand-written HTTP request answers 400 with JSON-RPC error `-32602`, `Required request metadata is missing` or `io.modelcontextprotocol/clientCapabilities request metadata is required`: it names 2026-07-28 in `MCP-Protocol-Version` and its `params._meta` lacks `io.modelcontextprotocol/protocolVersion`, for the first message, or `io.modelcontextprotocol/clientCapabilities`, for the second. Build it with `ActionMcp.request`, or copy the `curl` of [mcp-tools](../examples/mcp-tools/README.md#connect-a-client).
|
|
13
13
|
- A hand-written HTTP request answers 400 with JSON-RPC error `-32020`, `MCP-Protocol-Version header is required`, `Mcp-Method header does not match request method` or `Mcp-Name header does not match request parameters`: those headers repeat a 2026-07-28 request's revision, method and `tools/call`, `events/poll`, `events/stream`, `events/subscribe` or `events/unsubscribe` name, and one is absent or differs from its body. Build it with `ActionMcp.request`.
|
|
14
14
|
- `events/list`, `events/poll` or `events/stream` answered with JSON-RPC error `-32601`, Method not found: the client opened a 2025 session with `initialize`, and events are served to 2026-07-28 requests alone. Send those, as `ActionMcp.client` does.
|
|
15
|
-
- A hand-written HTTP request answers
|
|
15
|
+
- A hand-written HTTP request answers 406 with JSON-RPC error `-32600`, `Accept header must include both application/json and text/event-stream`: its `Accept` header does not list both `application/json` and `text/event-stream`, as `*/*` does not. Send both.
|
|
16
16
|
- A request written by hand to a stdio server answers JSON-RPC error `-32602`, `Invalid request metadata`: it is neither preceded by `initialize` nor carries the 2026-07-28 metadata. Open with `initialize` and `notifications/initialized`, or give the request's `_meta` its `io.modelcontextprotocol/protocolVersion` and `io.modelcontextprotocol/clientCapabilities`.
|
|
17
17
|
- `Tool <name> has an output schema but did not return structured content` raised by a Python MCP client for an action that returns nothing: its success is sent as `null`, which a Python SDK release before the fix of python-sdk#3345 reads as missing. Update the SDK.
|
|
18
18
|
- `UrlError` from `HttpClientRequest.toWebResult` or `toWeb` of an `ActionMcp.request`, or an `HttpClientError` whose reason is `InvalidUrlError` from a client method or a sent `ActionMcp.request`: the `url` is relative, such as the default `/mcp`, which only the `HttpClient` of `Testing.layer` resolves. Pass an absolute one.
|
package/docs/setup-failures.md
CHANGED
|
@@ -8,5 +8,5 @@ What you see when something is wrong, and the fix. Search for a fragment of the
|
|
|
8
8
|
- A page that loads Effect from an import map still bundles a second copy of Effect or of some of its modules, or fails to resolve `effect/Schema` in the browser when its bundler externalizes subpaths, as esbuild's `--external:effect` does: a module of the page imports an Effect specifier the map does not serve. Serve the specifiers [Bundle for a browser](setup.md#bundle-for-a-browser) lists, and import Effect through them in the page's own modules too.
|
|
9
9
|
- A page loading Effect from an import map fails with `Failed to resolve module specifier "effect/Cause"` in Chromium: the map points at Effect's published files and lacks a specifier Effect imports itself. Map `effect/Cause`, `effect/Effect`, `effect/Exit` and `effect/Function` to the same files, or serve Effect from a build that resolves its own imports.
|
|
10
10
|
- A page fails at load with `does not provide an export named …`: it serves only the names it uses of an Effect specifier, from a vendored module or a trimmed bundle, and the package imports another. Serve each specifier whole.
|
|
11
|
-
- Type errors inside `effect/*` modules after install, an unmet peer warning for `effect`, such as `found 4.
|
|
11
|
+
- Type errors inside `effect/*` modules after install, an unmet peer warning for `effect`, such as `found 4.3.0`, or a start failing with `Cannot find module '…/effect/dist/…'` under an `@effect/*` package: more than one Effect release is installed, or one outside the peer range. Install the `effect` range [Install](setup.md#install) names, with every `@effect/*` package at the version `effect` resolved to, such as `@effect/platform-node@4.2.0` beside `effect@4.2.0`.
|
|
12
12
|
- `Cannot find module 'effect/unstable/http'` (or `…/httpapi`, `…/cli`, `…/ai`): these modules are now `effect/http`, `effect/http-api`, `effect/cli` and `effect/ai`.
|
package/docs/setup.md
CHANGED
|
@@ -7,21 +7,21 @@ A message the library throws says its fix; for a compiler diagnostic or Effect's
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
|
-
pnpm add @gjermundgaraba/effect-actions effect@~4.
|
|
10
|
+
pnpm add @gjermundgaraba/effect-actions effect@~4.2.0
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
| Need | Add |
|
|
14
14
|
| --- | --- |
|
|
15
|
-
| Node HTTP server, stdio host or CLI | `@effect/platform-node@~4.
|
|
16
|
-
| `Stored`'s event logs and idempotency on Node's SQLite, or an entity's storage on Effect's SQL runners | `@effect/sql-sqlite-node@~4.
|
|
17
|
-
| Tests | `vitest@^5` and `@effect/vitest@~4.
|
|
15
|
+
| Node HTTP server, stdio host or CLI | `@effect/platform-node@~4.2.0` |
|
|
16
|
+
| `Stored`'s event logs and idempotency on Node's SQLite, or an entity's storage on Effect's SQL runners | `@effect/sql-sqlite-node@~4.2.0` |
|
|
17
|
+
| Tests | `vitest@^5` and `@effect/vitest@~4.2.0`, as dev dependencies |
|
|
18
18
|
| Type checking | `typescript@^7.0.2`, as a dev dependency |
|
|
19
19
|
| Node's types, for `node:` imports | `@types/node`, as a dev dependency |
|
|
20
20
|
| Running a TypeScript entrypoint | `tsx`, as a dev dependency: `node --import tsx <entrypoint>.ts` |
|
|
21
21
|
|
|
22
|
-
The `effect` peer admits the 4.
|
|
22
|
+
The `effect` peer admits the 4.2.x patches from the oldest whose APIs and behavior the package relies on, and no minor release: a minor release may change the unstable Effect modules the surfaces build on.
|
|
23
23
|
|
|
24
|
-
Keep the tilde in `package.json`: `^4.
|
|
24
|
+
Keep the tilde in `package.json`: `^4.2.0`, which npm writes for `effect@4.2.0`, admits a minor release outside the peer range. `npm install effect@~4.2.0` keeps it.
|
|
25
25
|
|
|
26
26
|
Node `>=26.13.1`: the package's `engines`, the Node the library is developed and tested on. TypeScript 7 or newer. ESM only. The repository checks the examples with a stricter `tsconfig.json`; this is the minimum a project needs. The package's modules resolve only through its `exports`, which `"module": "nodenext"` reads, as a bundler project's `"moduleResolution": "bundler"` does. `"strict": true` is required, by Effect:
|
|
27
27
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjermundgaraba/effect-actions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.40.0",
|
|
4
4
|
"description": "Define Effect action contracts once and project them onto HTTP, MCP, Effect RPC, native Toolkits, and CLIs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai-agents",
|
|
@@ -54,28 +54,28 @@
|
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@clanker-stuff/oxlint-config": "0.
|
|
58
|
-
"@effect/platform-node": "4.
|
|
59
|
-
"@effect/sql-sqlite-node": "4.
|
|
60
|
-
"@effect/tsgo": "0.
|
|
61
|
-
"@effect/vitest": "4.
|
|
57
|
+
"@clanker-stuff/oxlint-config": "0.6.1",
|
|
58
|
+
"@effect/platform-node": "4.2.0",
|
|
59
|
+
"@effect/sql-sqlite-node": "4.2.0",
|
|
60
|
+
"@effect/tsgo": "0.74.4",
|
|
61
|
+
"@effect/vitest": "4.2.0",
|
|
62
62
|
"@modelcontextprotocol/client": "2.4.0",
|
|
63
|
-
"@types/node": "26.6.
|
|
64
|
-
"effect": "4.
|
|
63
|
+
"@types/node": "26.6.11",
|
|
64
|
+
"effect": "4.2.0",
|
|
65
65
|
"tsx": "4.23.15",
|
|
66
66
|
"typescript": "7.0.2",
|
|
67
67
|
"ultracite": "8.3.1",
|
|
68
|
-
"vite": "npm:@voidzero-dev/vite-plus-core@8.3.
|
|
69
|
-
"vite-plus": "1.
|
|
70
|
-
"vitest": "5.1.
|
|
68
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@8.3.8001",
|
|
69
|
+
"vite-plus": "1.8.0",
|
|
70
|
+
"vitest": "5.1.1"
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|
|
73
|
-
"effect": "~4.
|
|
73
|
+
"effect": "~4.2.0"
|
|
74
74
|
},
|
|
75
75
|
"devEngines": {
|
|
76
76
|
"packageManager": {
|
|
77
77
|
"name": "pnpm",
|
|
78
|
-
"version": "12.
|
|
78
|
+
"version": "12.23.0",
|
|
79
79
|
"onFail": "download"
|
|
80
80
|
}
|
|
81
81
|
},
|