effect 4.1.2 → 4.1.3
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/ai-docs/package.json +1 -1
- package/ai-docs/tsconfig.json +2 -1
- package/dist/DateTime.d.ts +33 -2
- package/dist/DateTime.d.ts.map +1 -1
- package/dist/DateTime.js +16 -0
- package/dist/DateTime.js.map +1 -1
- package/dist/Match.d.ts +6 -6
- package/dist/Match.d.ts.map +1 -1
- package/dist/Match.js.map +1 -1
- package/dist/Queue.d.ts +2 -1
- package/dist/Queue.d.ts.map +1 -1
- package/dist/Queue.js +16 -9
- package/dist/Queue.js.map +1 -1
- package/dist/Rational.d.ts +1214 -0
- package/dist/Rational.d.ts.map +1 -0
- package/dist/Rational.js +880 -0
- package/dist/Rational.js.map +1 -0
- package/dist/RcMap.d.ts +3 -0
- package/dist/RcMap.d.ts.map +1 -1
- package/dist/RcMap.js +13 -14
- package/dist/RcMap.js.map +1 -1
- package/dist/Runtime.d.ts +75 -3
- package/dist/Runtime.d.ts.map +1 -1
- package/dist/Runtime.js +81 -4
- package/dist/Runtime.js.map +1 -1
- package/dist/Schema.d.ts +131 -29
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +128 -22
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +24 -12
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaParser.js +2 -2
- package/dist/SchemaParser.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts +9 -0
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +9 -0
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/ScopedCache.d.ts +7 -0
- package/dist/ScopedCache.d.ts.map +1 -1
- package/dist/ScopedCache.js +18 -1
- package/dist/ScopedCache.js.map +1 -1
- package/dist/ai/AgUi.d.ts +109 -0
- package/dist/ai/AgUi.d.ts.map +1 -0
- package/dist/ai/AgUi.js +543 -0
- package/dist/ai/AgUi.js.map +1 -0
- package/dist/ai/AgUiSchema.d.ts +6965 -0
- package/dist/ai/AgUiSchema.d.ts.map +1 -0
- package/dist/ai/AgUiSchema.js +974 -0
- package/dist/ai/AgUiSchema.js.map +1 -0
- package/dist/ai/AgUiServer.d.ts +6400 -0
- package/dist/ai/AgUiServer.d.ts.map +1 -0
- package/dist/ai/AgUiServer.js +309 -0
- package/dist/ai/AgUiServer.js.map +1 -0
- package/dist/ai/Chat.d.ts +30 -4
- package/dist/ai/Chat.d.ts.map +1 -1
- package/dist/ai/Chat.js +34 -4
- package/dist/ai/Chat.js.map +1 -1
- package/dist/ai/LanguageModel.d.ts +1 -1
- package/dist/ai/LanguageModel.d.ts.map +1 -1
- package/dist/ai/LanguageModel.js +18 -8
- package/dist/ai/LanguageModel.js.map +1 -1
- package/dist/ai/McpClient.d.ts +5 -0
- package/dist/ai/McpClient.d.ts.map +1 -1
- package/dist/ai/McpClient.js +11 -1
- package/dist/ai/McpClient.js.map +1 -1
- package/dist/ai/McpServer.d.ts +18 -1
- package/dist/ai/McpServer.d.ts.map +1 -1
- package/dist/ai/McpServer.js +214 -34
- package/dist/ai/McpServer.js.map +1 -1
- package/dist/ai/Prompt.d.ts +6 -2
- package/dist/ai/Prompt.d.ts.map +1 -1
- package/dist/ai/Prompt.js.map +1 -1
- package/dist/ai/Response.d.ts +5 -2
- package/dist/ai/Response.d.ts.map +1 -1
- package/dist/ai/Response.js +5 -1
- package/dist/ai/Response.js.map +1 -1
- package/dist/ai/Tool.d.ts +265 -69
- package/dist/ai/Tool.d.ts.map +1 -1
- package/dist/ai/Tool.js +19 -2
- package/dist/ai/Tool.js.map +1 -1
- package/dist/ai/Toolkit.d.ts +32 -2
- package/dist/ai/Toolkit.d.ts.map +1 -1
- package/dist/ai/Toolkit.js +61 -8
- package/dist/ai/Toolkit.js.map +1 -1
- package/dist/ai/index.d.ts +15 -0
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai/index.js +15 -0
- package/dist/ai/index.js.map +1 -1
- package/dist/ai/internal/mcpCore.d.ts +0 -2
- package/dist/ai/internal/mcpCore.d.ts.map +1 -1
- package/dist/ai/internal/mcpCore.js +2 -8
- package/dist/ai/internal/mcpCore.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2024_11_05.js +6 -11
- package/dist/ai/internal/mcpProtocol/v2024_11_05.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2025_03_26.js +6 -11
- package/dist/ai/internal/mcpProtocol/v2025_03_26.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2025_06_18.js +6 -8
- package/dist/ai/internal/mcpProtocol/v2025_06_18.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2025_11_25.js +6 -8
- package/dist/ai/internal/mcpProtocol/v2025_11_25.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2026_07_28.js +60 -51
- package/dist/ai/internal/mcpProtocol/v2026_07_28.js.map +1 -1
- package/dist/ai/internal/mcpProtocol.js +11 -1
- package/dist/ai/internal/mcpProtocol.js.map +1 -1
- package/dist/ai/internal/mcpProtocolRegistry.js +4 -0
- package/dist/ai/internal/mcpProtocolRegistry.js.map +1 -1
- package/dist/ai/internal/mcpRuntime.js +6 -2
- package/dist/ai/internal/mcpRuntime.js.map +1 -1
- package/dist/ai/internal/mcpSchema/v2024_11_05.js +0 -2
- package/dist/ai/internal/mcpSchema/v2024_11_05.js.map +1 -1
- package/dist/ai/internal/mcpSchema/v2025_03_26.d.ts.map +1 -1
- package/dist/ai/internal/mcpSchema/v2025_03_26.js +0 -2
- package/dist/ai/internal/mcpSchema/v2025_03_26.js.map +1 -1
- package/dist/ai/internal/mcpSchema/v2025_06_18.d.ts.map +1 -1
- package/dist/ai/internal/mcpSchema/v2025_06_18.js +0 -2
- package/dist/ai/internal/mcpSchema/v2025_06_18.js.map +1 -1
- package/dist/ai/internal/mcpSchema/v2025_11_25.d.ts.map +1 -1
- package/dist/ai/internal/mcpSchema/v2025_11_25.js +0 -2
- package/dist/ai/internal/mcpSchema/v2025_11_25.js.map +1 -1
- package/dist/ai/internal/mcpSchema/v2026_07_28.d.ts.map +1 -1
- package/dist/ai/internal/mcpSchema/v2026_07_28.js +0 -2
- package/dist/ai/internal/mcpSchema/v2026_07_28.js.map +1 -1
- package/dist/ai/internal/mcpSkills.js +3 -93
- package/dist/ai/internal/mcpSkills.js.map +1 -1
- package/dist/ai/internal/mcpStatefulRuntime.js +0 -2
- package/dist/ai/internal/mcpStatefulRuntime.js.map +1 -1
- package/dist/ai/internal/structured-output.js +1 -1
- package/dist/ai/internal/structured-output.js.map +1 -1
- package/dist/cli/Argument.d.ts +81 -0
- package/dist/cli/Argument.d.ts.map +1 -1
- package/dist/cli/Argument.js +26 -0
- package/dist/cli/Argument.js.map +1 -1
- package/dist/cli/CliError.d.ts +7 -4
- package/dist/cli/CliError.d.ts.map +1 -1
- package/dist/cli/CliError.js +7 -4
- package/dist/cli/CliError.js.map +1 -1
- package/dist/cli/Command.d.ts +241 -22
- package/dist/cli/Command.d.ts.map +1 -1
- package/dist/cli/Command.js +85 -9
- package/dist/cli/Command.js.map +1 -1
- package/dist/cli/CommandSpec.d.ts +287 -0
- package/dist/cli/CommandSpec.d.ts.map +1 -0
- package/dist/cli/CommandSpec.js +277 -0
- package/dist/cli/CommandSpec.js.map +1 -0
- package/dist/cli/Completions.d.ts +5 -0
- package/dist/cli/Completions.d.ts.map +1 -1
- package/dist/cli/Completions.js.map +1 -1
- package/dist/cli/Flag.d.ts +102 -0
- package/dist/cli/Flag.d.ts.map +1 -1
- package/dist/cli/Flag.js +47 -0
- package/dist/cli/Flag.js.map +1 -1
- package/dist/cli/Param.d.ts +154 -1
- package/dist/cli/Param.d.ts.map +1 -1
- package/dist/cli/Param.js +87 -29
- package/dist/cli/Param.js.map +1 -1
- package/dist/cli/index.d.ts +5 -0
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +5 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/internal/command.d.ts +2 -2
- package/dist/cli/internal/command.d.ts.map +1 -1
- package/dist/cli/internal/command.js +1 -1
- package/dist/cli/internal/command.js.map +1 -1
- package/dist/cli/internal/completions/bash.js +6 -7
- package/dist/cli/internal/completions/bash.js.map +1 -1
- package/dist/cli/internal/completions/descriptor.js +21 -7
- package/dist/cli/internal/completions/descriptor.js.map +1 -1
- package/dist/cli/internal/completions/fish.js +3 -3
- package/dist/cli/internal/completions/fish.js.map +1 -1
- package/dist/cli/internal/completions/powershell.js +2 -2
- package/dist/cli/internal/completions/powershell.js.map +1 -1
- package/dist/cli/internal/completions/zsh.js +2 -2
- package/dist/cli/internal/completions/zsh.js.map +1 -1
- package/dist/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
- package/dist/cluster/ClusterWorkflowEngine.js +15 -13
- package/dist/cluster/ClusterWorkflowEngine.js.map +1 -1
- package/dist/cluster/Entity.d.ts +17 -0
- package/dist/cluster/Entity.d.ts.map +1 -1
- package/dist/cluster/Entity.js +20 -0
- package/dist/cluster/Entity.js.map +1 -1
- package/dist/cluster/MessageRetention.d.ts +71 -0
- package/dist/cluster/MessageRetention.d.ts.map +1 -0
- package/dist/cluster/MessageRetention.js +100 -0
- package/dist/cluster/MessageRetention.js.map +1 -0
- package/dist/cluster/MessageStorage.d.ts +81 -0
- package/dist/cluster/MessageStorage.d.ts.map +1 -1
- package/dist/cluster/MessageStorage.js +34 -2
- package/dist/cluster/MessageStorage.js.map +1 -1
- package/dist/cluster/ShardingConfig.d.ts +24 -2
- package/dist/cluster/ShardingConfig.d.ts.map +1 -1
- package/dist/cluster/ShardingConfig.js.map +1 -1
- package/dist/cluster/SqlMessageStorage.d.ts.map +1 -1
- package/dist/cluster/SqlMessageStorage.js +187 -29
- package/dist/cluster/SqlMessageStorage.js.map +1 -1
- package/dist/cluster/index.d.ts +5 -0
- package/dist/cluster/index.d.ts.map +1 -1
- package/dist/cluster/index.js +5 -0
- package/dist/cluster/index.js.map +1 -1
- package/dist/encoding/Base64.d.ts +0 -6
- package/dist/encoding/Base64.d.ts.map +1 -1
- package/dist/encoding/Base64.js +25 -5
- package/dist/encoding/Base64.js.map +1 -1
- package/dist/encoding/Base64Url.d.ts +0 -6
- package/dist/encoding/Base64Url.d.ts.map +1 -1
- package/dist/encoding/Base64Url.js +91 -8
- package/dist/encoding/Base64Url.js.map +1 -1
- package/dist/encoding/Csv.d.ts.map +1 -1
- package/dist/encoding/Csv.js +11 -5
- package/dist/encoding/Csv.js.map +1 -1
- package/dist/encoding/Hex.d.ts.map +1 -1
- package/dist/encoding/Hex.js +51 -34
- package/dist/encoding/Hex.js.map +1 -1
- package/dist/encoding/SchemaBinary.d.ts +14 -2
- package/dist/encoding/SchemaBinary.d.ts.map +1 -1
- package/dist/encoding/SchemaBinary.js +78 -5
- package/dist/encoding/SchemaBinary.js.map +1 -1
- package/dist/encoding/Xml.d.ts +25 -0
- package/dist/encoding/Xml.d.ts.map +1 -1
- package/dist/encoding/Xml.js +44 -19
- package/dist/encoding/Xml.js.map +1 -1
- package/dist/graphql/GraphQL.d.ts.map +1 -1
- package/dist/graphql/GraphQL.js +4 -1
- package/dist/graphql/GraphQL.js.map +1 -1
- package/dist/http/Headers.d.ts +5 -1
- package/dist/http/Headers.d.ts.map +1 -1
- package/dist/http/Headers.js +7 -2
- package/dist/http/Headers.js.map +1 -1
- package/dist/http/HttpClient.d.ts +57 -12
- package/dist/http/HttpClient.d.ts.map +1 -1
- package/dist/http/HttpClient.js +92 -54
- package/dist/http/HttpClient.js.map +1 -1
- package/dist/http/HttpClientError.d.ts +22 -8
- package/dist/http/HttpClientError.d.ts.map +1 -1
- package/dist/http/HttpClientError.js +68 -14
- package/dist/http/HttpClientError.js.map +1 -1
- package/dist/http/HttpEffect.d.ts +63 -4
- package/dist/http/HttpEffect.d.ts.map +1 -1
- package/dist/http/HttpEffect.js +89 -9
- package/dist/http/HttpEffect.js.map +1 -1
- package/dist/http/HttpMiddleware.js +1 -1
- package/dist/http/HttpMiddleware.js.map +1 -1
- package/dist/http/HttpServer.d.ts +80 -0
- package/dist/http/HttpServer.d.ts.map +1 -1
- package/dist/http/HttpServer.js +16 -0
- package/dist/http/HttpServer.js.map +1 -1
- package/dist/http/HttpServerRequest.d.ts.map +1 -1
- package/dist/http/HttpServerRequest.js +1 -14
- package/dist/http/HttpServerRequest.js.map +1 -1
- package/dist/http/HttpStaticServer.js +10 -16
- package/dist/http/HttpStaticServer.js.map +1 -1
- package/dist/http-api/HttpApiBuilder.js +9 -1
- package/dist/http-api/HttpApiBuilder.js.map +1 -1
- package/dist/http-api/HttpApiSchema.d.ts +19 -0
- package/dist/http-api/HttpApiSchema.d.ts.map +1 -1
- package/dist/http-api/HttpApiSchema.js +8 -1
- package/dist/http-api/HttpApiSchema.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/base64.d.ts +2 -0
- package/dist/internal/base64.d.ts.map +1 -0
- package/dist/internal/base64.js +30 -0
- package/dist/internal/base64.js.map +1 -0
- package/dist/internal/core.js +3 -4
- package/dist/internal/core.js.map +1 -1
- package/dist/internal/dateTime.js +18 -10
- package/dist/internal/dateTime.js.map +1 -1
- package/dist/internal/effect.js +41 -17
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/equal.js +7 -0
- package/dist/internal/equal.js.map +1 -1
- package/dist/internal/matcher.js +1 -1
- package/dist/internal/matcher.js.map +1 -1
- package/dist/internal/schema/codegen.js +7 -7
- package/dist/internal/schema/codegen.js.map +1 -1
- package/dist/internal/schema/fromJsonSchemaDocument.js +20 -1
- package/dist/internal/schema/fromJsonSchemaDocument.js.map +1 -1
- package/dist/internal/schema/interpreter.js +10 -10
- package/dist/internal/schema/interpreter.js.map +1 -1
- package/dist/internal/schema/parser.js +9 -4
- package/dist/internal/schema/parser.js.map +1 -1
- package/dist/internal/schema/toEquivalence.js +6 -5
- package/dist/internal/schema/toEquivalence.js.map +1 -1
- package/dist/internal/schema/toFormatter.js +3 -2
- package/dist/internal/schema/toFormatter.js.map +1 -1
- package/dist/internal/version.js +1 -1
- package/dist/observability/OtlpMetrics.js +1 -1
- package/dist/observability/OtlpMetrics.js.map +1 -1
- package/dist/observability/OtlpTracer.js +2 -2
- package/dist/observability/OtlpTracer.js.map +1 -1
- package/dist/persistence/PersistedQueue.d.ts +72 -3
- package/dist/persistence/PersistedQueue.d.ts.map +1 -1
- package/dist/persistence/PersistedQueue.js +142 -29
- package/dist/persistence/PersistedQueue.js.map +1 -1
- package/dist/persistence/RateLimiter.d.ts +12 -2
- package/dist/persistence/RateLimiter.d.ts.map +1 -1
- package/dist/persistence/RateLimiter.js +11 -4
- package/dist/persistence/RateLimiter.js.map +1 -1
- package/dist/process/CommandLine.d.ts +9 -9
- package/dist/process/CommandLine.js +6 -6
- package/dist/process/index.d.ts +1 -1
- package/dist/process/index.js +1 -1
- package/dist/reactivity/Atom.d.ts.map +1 -1
- package/dist/reactivity/Atom.js +24 -3
- package/dist/reactivity/Atom.js.map +1 -1
- package/dist/reactivity/AtomRpc.d.ts +24 -6
- package/dist/reactivity/AtomRpc.d.ts.map +1 -1
- package/dist/reactivity/AtomRpc.js.map +1 -1
- package/dist/rpc/OpenRpc.d.ts +384 -0
- package/dist/rpc/OpenRpc.d.ts.map +1 -0
- package/dist/rpc/OpenRpc.js +490 -0
- package/dist/rpc/OpenRpc.js.map +1 -0
- package/dist/rpc/Rpc.d.ts +22 -3
- package/dist/rpc/Rpc.d.ts.map +1 -1
- package/dist/rpc/Rpc.js.map +1 -1
- package/dist/rpc/RpcClient.d.ts +20 -21
- package/dist/rpc/RpcClient.d.ts.map +1 -1
- package/dist/rpc/RpcClient.js.map +1 -1
- package/dist/rpc/RpcServer.d.ts +23 -2
- package/dist/rpc/RpcServer.d.ts.map +1 -1
- package/dist/rpc/RpcServer.js +67 -25
- package/dist/rpc/RpcServer.js.map +1 -1
- package/dist/rpc/index.d.ts +5 -0
- package/dist/rpc/index.d.ts.map +1 -1
- package/dist/rpc/index.js +5 -0
- package/dist/rpc/index.js.map +1 -1
- package/dist/schema/SchemaCompiler/runtime.js +3 -2
- package/dist/schema/SchemaCompiler/runtime.js.map +1 -1
- package/dist/sql/SqlClient.d.ts +59 -6
- package/dist/sql/SqlClient.d.ts.map +1 -1
- package/dist/sql/SqlClient.js +64 -17
- package/dist/sql/SqlClient.js.map +1 -1
- package/dist/sql/Statement.d.ts +1 -1
- package/dist/sql/Statement.d.ts.map +1 -1
- package/dist/sql/Statement.js +9 -16
- package/dist/sql/Statement.js.map +1 -1
- package/dist/testing/TestClock.d.ts +2 -12
- package/dist/testing/TestClock.d.ts.map +1 -1
- package/dist/testing/TestClock.js +177 -169
- package/dist/testing/TestClock.js.map +1 -1
- package/dist/workflow/DurableClock.d.ts +27 -0
- package/dist/workflow/DurableClock.d.ts.map +1 -1
- package/dist/workflow/DurableClock.js +18 -2
- package/dist/workflow/DurableClock.js.map +1 -1
- package/dist/workflow/Workflow.d.ts.map +1 -1
- package/dist/workflow/Workflow.js +5 -4
- package/dist/workflow/Workflow.js.map +1 -1
- package/dist/workflow/WorkflowEngine.d.ts.map +1 -1
- package/dist/workflow/WorkflowEngine.js +14 -3
- package/dist/workflow/WorkflowEngine.js.map +1 -1
- package/package.json +3 -3
- package/src/DateTime.ts +35 -2
- package/src/Match.ts +10 -8
- package/src/Queue.ts +16 -11
- package/src/Rational.ts +1549 -0
- package/src/RcMap.ts +16 -14
- package/src/Runtime.ts +84 -4
- package/src/Schema.ts +188 -29
- package/src/SchemaAST.ts +29 -13
- package/src/SchemaParser.ts +2 -2
- package/src/SchemaRepresentation.ts +13 -0
- package/src/ScopedCache.ts +18 -1
- package/src/ai/AgUi.ts +485 -0
- package/src/ai/AgUiSchema.ts +1666 -0
- package/src/ai/AgUiServer.ts +451 -0
- package/src/ai/Chat.ts +78 -16
- package/src/ai/LanguageModel.ts +27 -9
- package/src/ai/McpClient.ts +11 -1
- package/src/ai/McpServer.ts +247 -50
- package/src/ai/Prompt.ts +6 -2
- package/src/ai/Response.ts +19 -3
- package/src/ai/Tool.ts +426 -110
- package/src/ai/Toolkit.ts +71 -10
- package/src/ai/index.ts +18 -0
- package/src/ai/internal/mcpCore.ts +11 -15
- package/src/ai/internal/mcpProtocol/v2024_11_05.ts +9 -14
- package/src/ai/internal/mcpProtocol/v2025_03_26.ts +9 -14
- package/src/ai/internal/mcpProtocol/v2025_06_18.ts +9 -11
- package/src/ai/internal/mcpProtocol/v2025_11_25.ts +9 -11
- package/src/ai/internal/mcpProtocol/v2026_07_28.ts +76 -55
- package/src/ai/internal/mcpProtocol.ts +22 -3
- package/src/ai/internal/mcpProtocolRegistry.ts +5 -0
- package/src/ai/internal/mcpRuntime.ts +10 -4
- package/src/ai/internal/mcpSchema/v2024_11_05.ts +0 -2
- package/src/ai/internal/mcpSchema/v2025_03_26.ts +0 -2
- package/src/ai/internal/mcpSchema/v2025_06_18.ts +0 -2
- package/src/ai/internal/mcpSchema/v2025_11_25.ts +0 -2
- package/src/ai/internal/mcpSchema/v2026_07_28.ts +0 -2
- package/src/ai/internal/mcpSkills.ts +3 -86
- package/src/ai/internal/mcpStatefulRuntime.ts +0 -2
- package/src/ai/internal/structured-output.ts +1 -1
- package/src/cli/Argument.ts +86 -0
- package/src/cli/CliError.ts +7 -4
- package/src/cli/Command.ts +261 -35
- package/src/cli/CommandSpec.ts +508 -0
- package/src/cli/Completions.ts +5 -0
- package/src/cli/Flag.ts +106 -0
- package/src/cli/Param.ts +225 -23
- package/src/cli/index.ts +6 -0
- package/src/cli/internal/command.ts +3 -4
- package/src/cli/internal/completions/bash.ts +9 -7
- package/src/cli/internal/completions/descriptor.ts +37 -5
- package/src/cli/internal/completions/fish.ts +9 -3
- package/src/cli/internal/completions/powershell.ts +2 -1
- package/src/cli/internal/completions/zsh.ts +2 -2
- package/src/cluster/ClusterWorkflowEngine.ts +14 -15
- package/src/cluster/Entity.ts +24 -0
- package/src/cluster/MessageRetention.ts +111 -0
- package/src/cluster/MessageStorage.ts +73 -2
- package/src/cluster/ShardingConfig.ts +12 -1
- package/src/cluster/SqlMessageStorage.ts +271 -41
- package/src/cluster/index.ts +6 -0
- package/src/encoding/Base64.ts +26 -5
- package/src/encoding/Base64Url.ts +93 -10
- package/src/encoding/Csv.ts +11 -5
- package/src/encoding/Hex.ts +56 -42
- package/src/encoding/SchemaBinary.ts +76 -5
- package/src/encoding/Xml.ts +65 -16
- package/src/graphql/GraphQL.ts +7 -4
- package/src/http/Headers.ts +7 -2
- package/src/http/HttpClient.ts +118 -68
- package/src/http/HttpClientError.ts +82 -15
- package/src/http/HttpEffect.ts +101 -10
- package/src/http/HttpMiddleware.ts +2 -2
- package/src/http/HttpServer.ts +80 -0
- package/src/http/HttpServerRequest.ts +1 -19
- package/src/http/HttpStaticServer.ts +10 -16
- package/src/http-api/HttpApiBuilder.ts +11 -1
- package/src/http-api/HttpApiSchema.ts +22 -1
- package/src/index.ts +6 -0
- package/src/internal/base64.ts +42 -0
- package/src/internal/core.ts +3 -4
- package/src/internal/dateTime.ts +27 -13
- package/src/internal/effect.ts +45 -18
- package/src/internal/equal.ts +8 -0
- package/src/internal/matcher.ts +7 -3
- package/src/internal/schema/codegen.ts +8 -7
- package/src/internal/schema/fromJsonSchemaDocument.ts +21 -1
- package/src/internal/schema/interpreter.ts +10 -10
- package/src/internal/schema/parser.ts +8 -4
- package/src/internal/schema/toEquivalence.ts +7 -5
- package/src/internal/schema/toFormatter.ts +3 -2
- package/src/internal/version.ts +1 -1
- package/src/observability/OtlpMetrics.ts +1 -1
- package/src/observability/OtlpTracer.ts +2 -2
- package/src/persistence/PersistedQueue.ts +199 -41
- package/src/persistence/RateLimiter.ts +17 -5
- package/src/process/CommandLine.ts +10 -10
- package/src/process/index.ts +1 -1
- package/src/reactivity/Atom.ts +25 -3
- package/src/reactivity/AtomRpc.ts +61 -45
- package/src/rpc/OpenRpc.ts +747 -0
- package/src/rpc/Rpc.ts +38 -6
- package/src/rpc/RpcClient.ts +45 -82
- package/src/rpc/RpcServer.ts +77 -28
- package/src/rpc/index.ts +6 -0
- package/src/schema/SchemaCompiler/runtime.ts +8 -3
- package/src/sql/SqlClient.ts +112 -26
- package/src/sql/Statement.ts +19 -23
- package/src/testing/TestClock.ts +204 -189
- package/src/workflow/DurableClock.ts +20 -3
- package/src/workflow/Workflow.ts +5 -3
- package/src/workflow/WorkflowEngine.ts +20 -5
package/src/ai/LanguageModel.ts
CHANGED
|
@@ -36,7 +36,7 @@ import * as Response from "./Response.ts"
|
|
|
36
36
|
import * as ResponseIdTracker from "./ResponseIdTracker.ts"
|
|
37
37
|
import type { SpanTransformer } from "./Telemetry.ts"
|
|
38
38
|
import { CurrentSpanTransformer } from "./Telemetry.ts"
|
|
39
|
-
import
|
|
39
|
+
import * as Tool from "./Tool.ts"
|
|
40
40
|
import * as Toolkit from "./Toolkit.ts"
|
|
41
41
|
|
|
42
42
|
/**
|
|
@@ -1310,7 +1310,7 @@ export const make: (params: {
|
|
|
1310
1310
|
.filter((part): part is Response.ToolCallPartEncoded =>
|
|
1311
1311
|
part.type === "tool-call" &&
|
|
1312
1312
|
part.providerExecuted !== true &&
|
|
1313
|
-
toolkit
|
|
1313
|
+
resolvableTool(toolkit, part.name) !== undefined
|
|
1314
1314
|
)
|
|
1315
1315
|
.map((part) => makeInterruptedToolResult(part, incompleteFinishReason) as ToolResolutionResult<Tools>)
|
|
1316
1316
|
: yield* resolveToolCalls(
|
|
@@ -1651,7 +1651,7 @@ export const make: (params: {
|
|
|
1651
1651
|
|
|
1652
1652
|
// Helper function to handle tool calls with approval logic
|
|
1653
1653
|
const handleToolCall = Effect.fnUntraced(function*(part: Response.ToolCallPartEncoded) {
|
|
1654
|
-
const tool = toolkit
|
|
1654
|
+
const tool = resolvableTool(toolkit, part.name)
|
|
1655
1655
|
if (!tool) return
|
|
1656
1656
|
|
|
1657
1657
|
const needsApproval = yield* isApprovalNeeded(
|
|
@@ -1747,7 +1747,7 @@ export const make: (params: {
|
|
|
1747
1747
|
// the stream - use the raw chunk for encoded params
|
|
1748
1748
|
for (const part of chunk) {
|
|
1749
1749
|
if (part.type === "tool-call" && part.providerExecuted !== true) {
|
|
1750
|
-
if (toolkit
|
|
1750
|
+
if (resolvableTool(toolkit, part.name) !== undefined) {
|
|
1751
1751
|
pendingToolCalls.set(part.id, part.name)
|
|
1752
1752
|
}
|
|
1753
1753
|
bufferedToolCalls.push(part)
|
|
@@ -2204,7 +2204,7 @@ const isApprovalNeeded = Effect.fnUntraced(function*<T extends Tool.Any>(
|
|
|
2204
2204
|
}
|
|
2205
2205
|
|
|
2206
2206
|
if (typeof tool.needsApproval === "function") {
|
|
2207
|
-
const params = yield* Schema.decodeUnknownEffect(tool.parametersSchema)(
|
|
2207
|
+
const params = yield* Schema.decodeUnknownEffect(Schema.toCodecJson(tool.parametersSchema))(
|
|
2208
2208
|
toolCall.params
|
|
2209
2209
|
) as any
|
|
2210
2210
|
|
|
@@ -2362,6 +2362,16 @@ type ToolResolutionResult<Tools extends Record<string, Tool.Any>> =
|
|
|
2362
2362
|
>
|
|
2363
2363
|
| Response.ToolApprovalRequestPart
|
|
2364
2364
|
|
|
2365
|
+
// Returns the tool whose handler resolves calls to `name`. Calls to unknown
|
|
2366
|
+
// and client-executed tools are left for the caller to answer.
|
|
2367
|
+
const resolvableTool = (
|
|
2368
|
+
toolkit: { readonly tools: Record<string, Tool.Any> },
|
|
2369
|
+
name: string
|
|
2370
|
+
): Tool.Any | undefined => {
|
|
2371
|
+
const tool = toolkit.tools[name]
|
|
2372
|
+
return tool === undefined || Tool.isClientExecuted(tool) ? undefined : tool
|
|
2373
|
+
}
|
|
2374
|
+
|
|
2365
2375
|
const resolveToolCalls = <Tools extends Record<string, Tool.Any>>(
|
|
2366
2376
|
content: ReadonlyArray<Response.AllPartsEncoded>,
|
|
2367
2377
|
toolkit: Toolkit.WithHandler<Tools>,
|
|
@@ -2393,7 +2403,7 @@ const resolveToolCalls = <Tools extends Record<string, Tool.Any>>(
|
|
|
2393
2403
|
|
|
2394
2404
|
const streams = toolCalls.map((toolCall) =>
|
|
2395
2405
|
Effect.gen(function*() {
|
|
2396
|
-
const tool = toolkit
|
|
2406
|
+
const tool = resolvableTool(toolkit, toolCall.name)
|
|
2397
2407
|
if (!tool) {
|
|
2398
2408
|
return Stream.empty
|
|
2399
2409
|
}
|
|
@@ -2470,14 +2480,18 @@ const resolveToolCalls = <Tools extends Record<string, Tool.Any>>(
|
|
|
2470
2480
|
// Utilities
|
|
2471
2481
|
// =============================================================================
|
|
2472
2482
|
|
|
2483
|
+
// Provider-executed tools keep the provider's payload; locally handled tool
|
|
2484
|
+
// calls carry the JSON encoding of their parameters.
|
|
2485
|
+
const hasProviderParameters = (tool: Tool.Any): boolean => Tool.isProviderDefined(tool) && !tool.requiresHandler
|
|
2486
|
+
|
|
2473
2487
|
// Cache one decoder per model and response kind, keyed by validation mode
|
|
2474
|
-
// and tool names and schema identities in insertion order.
|
|
2488
|
+
// and tool names, parameter encodings and schema identities in insertion order.
|
|
2475
2489
|
const makeResponseDecoder = <Decode>(make: (toolkit: Toolkit.Any, deferred: boolean) => Decode) => {
|
|
2476
2490
|
let cached: { readonly key: ReadonlyArray<unknown>; readonly decode: Decode } | undefined
|
|
2477
2491
|
return (toolkit: Toolkit.WithHandler<any>, encoded: boolean, deferred: boolean): Decode => {
|
|
2478
2492
|
const key: Array<unknown> = [encoded, deferred]
|
|
2479
2493
|
for (const tool of Object.values(toolkit.tools as Record<string, Tool.Any>)) {
|
|
2480
|
-
key.push(tool.name, tool.parametersSchema, tool.successSchema, tool.failureSchema)
|
|
2494
|
+
key.push(tool.name, hasProviderParameters(tool), tool.parametersSchema, tool.successSchema, tool.failureSchema)
|
|
2481
2495
|
}
|
|
2482
2496
|
if (cached !== undefined && cached.key.length === key.length && cached.key.every((part, i) => part === key[i])) {
|
|
2483
2497
|
return cached.decode
|
|
@@ -2501,7 +2515,11 @@ const withParameterMode = (tool: Tool.Any, mode: "encoded" | "opaque"): Tool.Any
|
|
|
2501
2515
|
parameterModeTools.set(tool, tools)
|
|
2502
2516
|
}
|
|
2503
2517
|
return tools[mode] ??= tool.setParameters(
|
|
2504
|
-
mode === "
|
|
2518
|
+
mode === "opaque"
|
|
2519
|
+
? Schema.Unknown
|
|
2520
|
+
: hasProviderParameters(tool)
|
|
2521
|
+
? Schema.toEncoded(tool.parametersSchema)
|
|
2522
|
+
: Schema.toEncoded(Schema.toCodecJson(tool.parametersSchema))
|
|
2505
2523
|
)
|
|
2506
2524
|
}
|
|
2507
2525
|
|
package/src/ai/McpClient.ts
CHANGED
|
@@ -259,6 +259,11 @@ export const isMcpClient = (value: unknown): value is McpClient => Predicate.has
|
|
|
259
259
|
* `crypto.subtle`.
|
|
260
260
|
* Schema decoding requires the schema's services from the caller.
|
|
261
261
|
*
|
|
262
|
+
* **Gotchas**
|
|
263
|
+
*
|
|
264
|
+
* The Skills extension requires protocol 2026-07-28. With `skills: true` on an
|
|
265
|
+
* earlier protocol, construction fails with an `UnsupportedError`.
|
|
266
|
+
*
|
|
262
267
|
* @stability experimental
|
|
263
268
|
* @category constructors
|
|
264
269
|
* @since 4.0.6
|
|
@@ -291,6 +296,12 @@ export const make: (options: {
|
|
|
291
296
|
const protocol = transport.protocol
|
|
292
297
|
const version = protocol.protocolVersion
|
|
293
298
|
const modern = version === "2026-07-28"
|
|
299
|
+
const skillsEnabled = options.extensions?.skills === true
|
|
300
|
+
if (skillsEnabled && !modern) {
|
|
301
|
+
return yield* fail(
|
|
302
|
+
new UnsupportedError({ description: "The MCP Skills extension requires at least protocol 2026-07-28" })
|
|
303
|
+
)
|
|
304
|
+
}
|
|
294
305
|
const timeout = options.timeout ?? DEFAULT_TIMEOUT
|
|
295
306
|
const discoveryLimits = yield* resolveDiscoveryLimits(options.discoveryLimits, DEFAULT_DISCOVERY_LIMITS)
|
|
296
307
|
const closed = yield* Deferred.make<never, McpClientError>()
|
|
@@ -310,7 +321,6 @@ export const make: (options: {
|
|
|
310
321
|
|
|
311
322
|
// Modern requests carry the client identity in every request.
|
|
312
323
|
// https://modelcontextprotocol.io/specification/2026-07-28/basic/index
|
|
313
|
-
const skillsEnabled = options.extensions?.skills === true
|
|
314
324
|
const clientCapabilities = skillsEnabled ? { extensions: { [McpSkills.EXTENSION_ID]: {} } } : {}
|
|
315
325
|
const meta = {
|
|
316
326
|
"io.modelcontextprotocol/protocolVersion": version,
|
package/src/ai/McpServer.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import * as Arr from "../Array.ts"
|
|
15
15
|
import * as Cause from "../Cause.ts"
|
|
16
|
+
import * as Clock from "../Clock.ts"
|
|
16
17
|
import * as Context from "../Context.ts"
|
|
17
18
|
import * as Digest from "../crypto/Digest.ts"
|
|
18
19
|
import * as Data from "../Data.ts"
|
|
@@ -28,7 +29,9 @@ import { appendPreResponseHandlerUnsafe } from "../http/HttpEffect.ts"
|
|
|
28
29
|
import * as HttpRouter from "../http/HttpRouter.ts"
|
|
29
30
|
import * as HttpServerRequest from "../http/HttpServerRequest.ts"
|
|
30
31
|
import * as HttpServerResponse from "../http/HttpServerResponse.ts"
|
|
32
|
+
import * as HttpTraceContext from "../http/HttpTraceContext.ts"
|
|
31
33
|
import type * as JsonSchema from "../JsonSchema.ts"
|
|
34
|
+
import * as Latch from "../Latch.ts"
|
|
32
35
|
import * as Layer from "../Layer.ts"
|
|
33
36
|
import * as Option from "../Option.ts"
|
|
34
37
|
import * as Predicate from "../Predicate.ts"
|
|
@@ -104,6 +107,7 @@ interface QueuedServerNotification {
|
|
|
104
107
|
readonly delivered: Deferred.Deferred<void>
|
|
105
108
|
readonly requestContext?: McpRequestContext["Service"] | undefined
|
|
106
109
|
readonly requestHeaders?: Headers.Headers | undefined
|
|
110
|
+
readonly requestLiveness?: { active: boolean } | undefined
|
|
107
111
|
}
|
|
108
112
|
|
|
109
113
|
const internalState = new WeakMap<object, {
|
|
@@ -121,6 +125,10 @@ const RequestNotificationQueue = Context.Reference<Queue.Queue<QueuedServerNotif
|
|
|
121
125
|
"effect/ai/McpServer/RequestNotificationQueue",
|
|
122
126
|
{ defaultValue: () => undefined }
|
|
123
127
|
)
|
|
128
|
+
const RequestLiveness = Context.Reference<{ active: boolean } | undefined>(
|
|
129
|
+
"effect/ai/McpServer/RequestLiveness",
|
|
130
|
+
{ defaultValue: () => undefined }
|
|
131
|
+
)
|
|
124
132
|
// Progress and logs belong to the request that emitted them.
|
|
125
133
|
const isRequestNotification = (notification: McpCore.ServerNotification) =>
|
|
126
134
|
notification._tag === "Progress" || notification._tag === "LoggingMessage"
|
|
@@ -1117,6 +1125,7 @@ export class McpServer extends Context.Service<McpServer, {
|
|
|
1117
1125
|
const queued: QueuedServerNotification = {
|
|
1118
1126
|
notification,
|
|
1119
1127
|
delivered,
|
|
1128
|
+
requestLiveness: Context.get(fiber.context, RequestLiveness),
|
|
1120
1129
|
requestContext: Context.getOrUndefined(fiber.context, McpRequestContext),
|
|
1121
1130
|
requestHeaders: Context.getOrUndefined(fiber.context, HttpServerRequest.HttpServerRequest)?.headers
|
|
1122
1131
|
}
|
|
@@ -1233,8 +1242,8 @@ export class McpServer extends Context.Service<McpServer, {
|
|
|
1233
1242
|
}),
|
|
1234
1243
|
visible: visible("tools/list", options.tool.name),
|
|
1235
1244
|
isVisible: isEnabled(options.annotations),
|
|
1236
|
-
handle: (call, invocation) =>
|
|
1237
|
-
invoke(options.handle(call.arguments), invocation, {
|
|
1245
|
+
handle: (call, invocation, beforeHandle) =>
|
|
1246
|
+
invoke(Effect.andThen(beforeHandle, () => options.handle(call.arguments)), invocation, {
|
|
1238
1247
|
method: "tools/call",
|
|
1239
1248
|
target: call.name,
|
|
1240
1249
|
payload: call
|
|
@@ -1485,10 +1494,123 @@ const requestKey = (requestId: string | number): string => `${typeof requestId}:
|
|
|
1485
1494
|
interface ActiveRequest {
|
|
1486
1495
|
readonly requestId: RpcMessage.RequestId
|
|
1487
1496
|
readonly prepared: McpRuntime.PreparedRequest
|
|
1497
|
+
readonly liveness: { active: boolean }
|
|
1488
1498
|
readonly cancelled: boolean
|
|
1489
1499
|
readonly httpPost: { expected: number } | undefined
|
|
1490
1500
|
}
|
|
1491
1501
|
|
|
1502
|
+
// JSON-RPC errors caused by the request rather than the server: parse error,
|
|
1503
|
+
// invalid request, method not found, invalid params and resource not found.
|
|
1504
|
+
// Per the MCP semantic conventions they do not mark the server span as failed.
|
|
1505
|
+
const requestErrorCodes: ReadonlySet<number> = new Set([-32700, -32600, -32601, -32602, -32002])
|
|
1506
|
+
|
|
1507
|
+
// Only the W3C keys are read: other `_meta` members can carry protocol claims.
|
|
1508
|
+
const remoteParentSpan = (params: Readonly<Record<string, unknown>> | undefined): Tracer.ExternalSpan | undefined => {
|
|
1509
|
+
const meta = params?._meta
|
|
1510
|
+
if (!Predicate.isReadonlyObject(meta) || typeof meta.traceparent !== "string") {
|
|
1511
|
+
return undefined
|
|
1512
|
+
}
|
|
1513
|
+
return Option.getOrUndefined(HttpTraceContext.w3c(Headers.fromInput({ traceparent: meta.traceparent })))
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
const requestSpanOptions = (
|
|
1517
|
+
method: string,
|
|
1518
|
+
request: RpcMessage.Request<Rpc.Any>,
|
|
1519
|
+
options: {
|
|
1520
|
+
readonly protocolVersion: string
|
|
1521
|
+
readonly networkTransport: string | undefined
|
|
1522
|
+
readonly sessionId: string | undefined
|
|
1523
|
+
readonly recordToolArguments: boolean
|
|
1524
|
+
}
|
|
1525
|
+
): Tracer.SpanOptionsNoTrace & { readonly name: string } => {
|
|
1526
|
+
const params = Predicate.isReadonlyObject(request.payload)
|
|
1527
|
+
? request.payload as Readonly<Record<string, unknown>>
|
|
1528
|
+
: undefined
|
|
1529
|
+
const attributes: Record<string, unknown> = {
|
|
1530
|
+
"mcp.method.name": method,
|
|
1531
|
+
"mcp.protocol.version": options.protocolVersion
|
|
1532
|
+
}
|
|
1533
|
+
if (request.isNotification !== true) attributes["jsonrpc.request.id"] = String(request.id)
|
|
1534
|
+
if (options.sessionId !== undefined) attributes["mcp.session.id"] = options.sessionId
|
|
1535
|
+
if (options.networkTransport !== undefined) attributes["network.transport"] = options.networkTransport
|
|
1536
|
+
let target: string | undefined
|
|
1537
|
+
switch (method) {
|
|
1538
|
+
case "tools/call": {
|
|
1539
|
+
attributes["gen_ai.operation.name"] = "execute_tool"
|
|
1540
|
+
if (typeof params?.name === "string") {
|
|
1541
|
+
target = params.name
|
|
1542
|
+
attributes["gen_ai.tool.name"] = target
|
|
1543
|
+
}
|
|
1544
|
+
if (options.recordToolArguments && params?.arguments !== undefined) {
|
|
1545
|
+
attributes["gen_ai.tool.call.arguments"] = Toolkit.stringifyToolArguments(params.arguments)
|
|
1546
|
+
}
|
|
1547
|
+
break
|
|
1548
|
+
}
|
|
1549
|
+
case "prompts/get": {
|
|
1550
|
+
if (typeof params?.name === "string") {
|
|
1551
|
+
target = params.name
|
|
1552
|
+
attributes["gen_ai.prompt.name"] = target
|
|
1553
|
+
}
|
|
1554
|
+
break
|
|
1555
|
+
}
|
|
1556
|
+
case "resources/read":
|
|
1557
|
+
case "resources/subscribe":
|
|
1558
|
+
case "resources/unsubscribe": {
|
|
1559
|
+
// Resource URIs can be unbounded and sensitive, so they stay out of the span name.
|
|
1560
|
+
if (typeof params?.uri === "string") attributes["mcp.resource.uri"] = params.uri
|
|
1561
|
+
break
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
return {
|
|
1565
|
+
name: target === undefined ? method : `${method} ${target}`,
|
|
1566
|
+
kind: "server",
|
|
1567
|
+
attributes,
|
|
1568
|
+
parent: remoteParentSpan(params)
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
// The MCP span of the request being handled. Unlike `Tracer.ParentSpan`, it is
|
|
1573
|
+
// unset outside a request, so code that sends a response for a request can
|
|
1574
|
+
// tell whether that request has an MCP span.
|
|
1575
|
+
const CurrentRequestSpan = Context.Reference<Tracer.Span | undefined>("effect/ai/McpServer/CurrentRequestSpan", {
|
|
1576
|
+
defaultValue: () => undefined
|
|
1577
|
+
})
|
|
1578
|
+
|
|
1579
|
+
// Spans whose request was answered with an error response sent by `McpServer`
|
|
1580
|
+
// itself. That response, not the handler's exit, classifies the span.
|
|
1581
|
+
const errorResponseSpans = new WeakSet<Tracer.Span>()
|
|
1582
|
+
|
|
1583
|
+
const recordErrorResponse = (span: Tracer.Span, code: number) => {
|
|
1584
|
+
errorResponseSpans.add(span)
|
|
1585
|
+
span.attribute("rpc.status_code", String(code))
|
|
1586
|
+
span.attribute("error.type", String(code))
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
const endRequestSpan = (span: Tracer.Span, method: string, exit: Exit.Exit<unknown, unknown>, endTime: bigint) => {
|
|
1590
|
+
if (errorResponseSpans.has(span)) {
|
|
1591
|
+
return span.end(endTime, exit)
|
|
1592
|
+
}
|
|
1593
|
+
if (Exit.isSuccess(exit)) {
|
|
1594
|
+
if (method === "tools/call" && Predicate.hasProperty(exit.value, "isError") && exit.value.isError === true) {
|
|
1595
|
+
span.attribute("error.type", "tool_error")
|
|
1596
|
+
}
|
|
1597
|
+
return span.end(endTime, exit)
|
|
1598
|
+
}
|
|
1599
|
+
// Interruptions and defects carry no JSON-RPC error. When one is answered
|
|
1600
|
+
// with an internal error, the response write records it on the span.
|
|
1601
|
+
const error = Cause.findErrorOption(exit.cause)
|
|
1602
|
+
if (Option.isNone(error) || !Predicate.hasProperty(error.value, "code") || typeof error.value.code !== "number") {
|
|
1603
|
+
return span.end(endTime, exit)
|
|
1604
|
+
}
|
|
1605
|
+
const code = error.value.code
|
|
1606
|
+
span.attribute("rpc.status_code", String(code))
|
|
1607
|
+
if (requestErrorCodes.has(code)) {
|
|
1608
|
+
return span.end(endTime, Exit.void)
|
|
1609
|
+
}
|
|
1610
|
+
span.attribute("error.type", String(code))
|
|
1611
|
+
span.end(endTime, exit)
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1492
1614
|
class McpClientKey extends Data.Class<{
|
|
1493
1615
|
readonly clientId: number
|
|
1494
1616
|
readonly profile: McpCore.NegotiatedProtocolProfile<string>
|
|
@@ -1582,6 +1704,14 @@ const normalizeCacheHints = (
|
|
|
1582
1704
|
* runtime handles protocol lifecycle state and determines which clients receive
|
|
1583
1705
|
* queued server notifications.
|
|
1584
1706
|
*
|
|
1707
|
+
* Each request handled by the server runs in a server span that follows the
|
|
1708
|
+
* OpenTelemetry MCP semantic conventions. Spans are named after the JSON-RPC
|
|
1709
|
+
* method, with the tool or prompt name appended for `tools/call` and
|
|
1710
|
+
* `prompts/get` (for example `tools/call get_weather`). A W3C `traceparent` in
|
|
1711
|
+
* `params._meta` becomes the span's parent, and the transport span (such as
|
|
1712
|
+
* the HTTP server span) is linked. Tool arguments are recorded only when
|
|
1713
|
+
* `Toolkit.RecordToolArguments` is `true`.
|
|
1714
|
+
*
|
|
1585
1715
|
* @stability unstable
|
|
1586
1716
|
* @category running
|
|
1587
1717
|
* @since 4.0.0
|
|
@@ -1642,14 +1772,56 @@ const runWithRuntime = Effect.fnUntraced(function*(
|
|
|
1642
1772
|
const server = yield* McpServer
|
|
1643
1773
|
const defaultLogLevel = yield* CurrentLogLevel
|
|
1644
1774
|
const isHttp = transport === "http"
|
|
1775
|
+
const networkTransport = isHttp ? "tcp" : transport === "stdio" ? "pipe" : undefined
|
|
1776
|
+
// `RpcServer` tracing is disabled so that this span can follow the MCP
|
|
1777
|
+
// semantic conventions and continue the client's `_meta` trace. Wrapping the
|
|
1778
|
+
// request effect keeps the span on its lifecycle: it ends after the response
|
|
1779
|
+
// is written, or when the request is interrupted.
|
|
1780
|
+
const traceRequest = <X, E, R>(
|
|
1781
|
+
effect: Effect.Effect<X, E, R>,
|
|
1782
|
+
request: RpcMessage.Request<Rpc.Any>
|
|
1783
|
+
): Effect.Effect<X, E, R> =>
|
|
1784
|
+
Effect.withFiber((fiber) => {
|
|
1785
|
+
const method = runtime.methodForInternalTag(request.tag)
|
|
1786
|
+
const { name, ...spanOptions } = requestSpanOptions(method, request, {
|
|
1787
|
+
protocolVersion: runtime.protocolForInternalTag(request.tag).protocolVersion,
|
|
1788
|
+
networkTransport,
|
|
1789
|
+
sessionId: isHttp
|
|
1790
|
+
? Context.getOrUndefined(fiber.context, HttpServerRequest.HttpServerRequest)?.headers[MCP_SESSION_ID_HEADER]
|
|
1791
|
+
: undefined,
|
|
1792
|
+
recordToolArguments: fiber.getRef(Toolkit.RecordToolArguments)
|
|
1793
|
+
})
|
|
1794
|
+
const ambientParent = Context.getOrUndefined(fiber.context, Tracer.ParentSpan)
|
|
1795
|
+
return Effect.flatMap(
|
|
1796
|
+
Effect.makeSpan(name, {
|
|
1797
|
+
...spanOptions,
|
|
1798
|
+
links: spanOptions.parent !== undefined && ambientParent !== undefined
|
|
1799
|
+
? [{ span: ambientParent, attributes: {} }]
|
|
1800
|
+
: undefined
|
|
1801
|
+
}),
|
|
1802
|
+
(span) =>
|
|
1803
|
+
Effect.onExit(
|
|
1804
|
+
effect.pipe(
|
|
1805
|
+
Effect.provideService(Tracer.ParentSpan, span),
|
|
1806
|
+
Effect.provideService(CurrentRequestSpan, span)
|
|
1807
|
+
),
|
|
1808
|
+
(exit) =>
|
|
1809
|
+
Effect.sync(() => endRequestSpan(span, method, exit, fiber.getRef(Clock.Clock).currentTimeNanosUnsafe()))
|
|
1810
|
+
)
|
|
1811
|
+
)
|
|
1812
|
+
})
|
|
1645
1813
|
const clientStates = new Map<number, {
|
|
1646
1814
|
protocol: McpProtocol.AnyProtocolAdapter
|
|
1647
1815
|
profile: McpCore.NegotiatedProtocolProfile<string> | undefined
|
|
1648
1816
|
sessionHeaders: Headers.Headers | undefined
|
|
1649
1817
|
}>()
|
|
1650
1818
|
const activeRequests = new Map<number, Map<string, ActiveRequest>>()
|
|
1819
|
+
// Stdio has a single client whose session ends with stdin, so one latch is
|
|
1820
|
+
// enough; built-in subscriptions complete on it while finite requests drain.
|
|
1821
|
+
const stdioEnd = transport === "stdio" ? Latch.makeUnsafe() : undefined
|
|
1651
1822
|
const reverseRequestClients = new Map<string, Array<McpClientKey>>()
|
|
1652
1823
|
const disconnectClient = (clientId: number) => {
|
|
1824
|
+
for (const request of activeRequests.get(clientId)?.values() ?? []) request.liveness.active = false
|
|
1653
1825
|
activeRequests.delete(clientId)
|
|
1654
1826
|
clientStates.delete(clientId)
|
|
1655
1827
|
runtime.disconnect(clientId)
|
|
@@ -1712,6 +1884,7 @@ const runWithRuntime = Effect.fnUntraced(function*(
|
|
|
1712
1884
|
if (request === undefined) {
|
|
1713
1885
|
return false
|
|
1714
1886
|
}
|
|
1887
|
+
request.liveness.active = false
|
|
1715
1888
|
requests!.set(key, { ...request, cancelled: true })
|
|
1716
1889
|
return true
|
|
1717
1890
|
}
|
|
@@ -1740,6 +1913,7 @@ const runWithRuntime = Effect.fnUntraced(function*(
|
|
|
1740
1913
|
getListChangeRevision: () => notificationDelivery.listChangeRevision,
|
|
1741
1914
|
...(!protocol.supportsNotifications || options.allowSubscriptions === false ? {} : {
|
|
1742
1915
|
sendNotification,
|
|
1916
|
+
awaitClientEnd: stdioEnd?.await,
|
|
1743
1917
|
markSubscriptionCancelled: (clientId: number, requestId: RpcMessage.RequestId) =>
|
|
1744
1918
|
Effect.sync(() => {
|
|
1745
1919
|
cancelRequest(clientId, requestId)
|
|
@@ -1879,6 +2053,7 @@ const runWithRuntime = Effect.fnUntraced(function*(
|
|
|
1879
2053
|
const requests = activeRequests.get(clientId)
|
|
1880
2054
|
const key = requestKey(response.requestId)
|
|
1881
2055
|
const active = requests?.get(key)
|
|
2056
|
+
if (active !== undefined) active.liveness.active = false
|
|
1882
2057
|
if (requests !== undefined && requests.delete(key) && requests.size === 0) {
|
|
1883
2058
|
activeRequests.delete(clientId)
|
|
1884
2059
|
}
|
|
@@ -1895,7 +2070,12 @@ const runWithRuntime = Effect.fnUntraced(function*(
|
|
|
1895
2070
|
return sendRequestError(clientId, response.requestId, {
|
|
1896
2071
|
code: McpSchema.INTERNAL_ERROR_CODE,
|
|
1897
2072
|
message: "Internal error"
|
|
1898
|
-
})
|
|
2073
|
+
}).pipe(
|
|
2074
|
+
Effect.andThen(CurrentRequestSpan),
|
|
2075
|
+
Effect.map((span) => {
|
|
2076
|
+
if (span !== undefined) recordErrorResponse(span, McpSchema.INTERNAL_ERROR_CODE)
|
|
2077
|
+
})
|
|
2078
|
+
)
|
|
1899
2079
|
}
|
|
1900
2080
|
}
|
|
1901
2081
|
return protocol.send(clientId, response)
|
|
@@ -2058,17 +2238,19 @@ const runWithRuntime = Effect.fnUntraced(function*(
|
|
|
2058
2238
|
? Effect.void
|
|
2059
2239
|
: sendRequestError(clientId, request.id, new InvalidParams({ message: "Invalid method parameters" }))
|
|
2060
2240
|
}
|
|
2241
|
+
const liveness = { active: true }
|
|
2061
2242
|
if (request.isNotification !== true) {
|
|
2062
2243
|
const requests = activeRequests.get(clientId) ?? new Map<string, ActiveRequest>()
|
|
2063
2244
|
requests.set(requestKey(request.id), {
|
|
2064
2245
|
requestId: RpcMessage.RequestId(request.id),
|
|
2065
2246
|
prepared,
|
|
2247
|
+
liveness,
|
|
2066
2248
|
cancelled: false,
|
|
2067
2249
|
httpPost: httpRequest === undefined ? undefined : httpPostResponses.get(httpRequest)
|
|
2068
2250
|
})
|
|
2069
2251
|
activeRequests.set(clientId, requests)
|
|
2070
2252
|
}
|
|
2071
|
-
const handled = f(clientId, routedRequest)
|
|
2253
|
+
const handled = Effect.provideService(f(clientId, routedRequest), RequestLiveness, liveness)
|
|
2072
2254
|
return yield* prepared.requestContext === undefined
|
|
2073
2255
|
? handled
|
|
2074
2256
|
: Effect.provideService(handled, McpRequestContext, prepared.requestContext)
|
|
@@ -2092,6 +2274,7 @@ const runWithRuntime = Effect.fnUntraced(function*(
|
|
|
2092
2274
|
return f(clientId, request)
|
|
2093
2275
|
case "Eof":
|
|
2094
2276
|
if (!isHttp) {
|
|
2277
|
+
stdioEnd?.openUnsafe()
|
|
2095
2278
|
disconnectClient(clientId)
|
|
2096
2279
|
}
|
|
2097
2280
|
return f(clientId, request)
|
|
@@ -2260,6 +2443,12 @@ const runWithRuntime = Effect.fnUntraced(function*(
|
|
|
2260
2443
|
return
|
|
2261
2444
|
}
|
|
2262
2445
|
const encoded = yield* selectedProtocol.payloadCodecs(rpc).encode(projected.payload)
|
|
2446
|
+
// Projection and encoding can suspend after the request has ended.
|
|
2447
|
+
if (notification._tag === "Progress") {
|
|
2448
|
+
// The disconnect hook may still be scheduled when an interrupted handler resumes delivery.
|
|
2449
|
+
if (!(yield* patchedProtocol.clientIds).has(clientId)) return
|
|
2450
|
+
if (queued.requestLiveness?.active === false) return
|
|
2451
|
+
}
|
|
2263
2452
|
yield* patchedProtocol.send(clientId, {
|
|
2264
2453
|
_tag: "Request",
|
|
2265
2454
|
id: "",
|
|
@@ -2288,8 +2477,12 @@ const runWithRuntime = Effect.fnUntraced(function*(
|
|
|
2288
2477
|
)
|
|
2289
2478
|
|
|
2290
2479
|
return yield* RpcServer.make(runtime.clientRpcs, {
|
|
2291
|
-
|
|
2292
|
-
disableFatalDefects: true
|
|
2480
|
+
disableTracing: true,
|
|
2481
|
+
disableFatalDefects: true,
|
|
2482
|
+
onDisconnect: (clientId) => Effect.sync(() => disconnectClient(clientId)),
|
|
2483
|
+
// Wrapped so `RpcServer.make` infers the group's rpcs from `clientRpcs`
|
|
2484
|
+
// rather than from `traceRequest`'s parameter type.
|
|
2485
|
+
onRequest: (effect, request) => traceRequest(effect, request)
|
|
2293
2486
|
}).pipe(
|
|
2294
2487
|
Effect.provideService(RpcServer.Protocol, patchedProtocol),
|
|
2295
2488
|
Effect.provideService(McpServerClientMiddleware, clientMiddleware),
|
|
@@ -2346,6 +2539,9 @@ type RegistrationServices<RR> = Exclude<McpRequest.Without<RR>, McpServer>
|
|
|
2346
2539
|
* `McpServer.layer`, so registration layers can use the `McpServer` service
|
|
2347
2540
|
* while the server is running.
|
|
2348
2541
|
*
|
|
2542
|
+
* Core lists return one complete page; supplying a cursor, including an empty
|
|
2543
|
+
* string, fails with `InvalidParams`.
|
|
2544
|
+
*
|
|
2349
2545
|
* Pass registration layers as `registrations` to build them before the server
|
|
2350
2546
|
* reads its first request. The transport discharges the request-level
|
|
2351
2547
|
* dependencies it supplies (see `ProvidedServices`); any other `McpRequest`
|
|
@@ -2434,6 +2630,10 @@ const layerWithRuntime = (options: {
|
|
|
2434
2630
|
* dependencies it supplies (see `ProvidedServices`); any other `McpRequest`
|
|
2435
2631
|
* marker stays in the layer's requirements and must be met by MCP middleware.
|
|
2436
2632
|
*
|
|
2633
|
+
* Each call builds its own `RpcServer.Protocol`, so several stdio servers can
|
|
2634
|
+
* live in one layer graph as long as each is provided its own `Stdio`. They
|
|
2635
|
+
* still share the memoized `McpServer` registry.
|
|
2636
|
+
*
|
|
2437
2637
|
* @see {@link layer} for running over an existing `RpcServer.Protocol`
|
|
2438
2638
|
* @see {@link layerHttp} for the single-endpoint HTTP transport
|
|
2439
2639
|
*
|
|
@@ -2466,7 +2666,11 @@ export const layerStdio = <
|
|
|
2466
2666
|
> =>
|
|
2467
2667
|
layerWithRuntime(options, "stdio").pipe(
|
|
2468
2668
|
Layer.provide(McpRuntime.layer(options.protocols)),
|
|
2469
|
-
|
|
2669
|
+
// Build a fresh protocol layer per call. `RpcServer.layerProtocolStdio` is
|
|
2670
|
+
// a module-level constant, and layers are memoized by reference, so two
|
|
2671
|
+
// `layerStdio` servers in one layer graph would otherwise share a single
|
|
2672
|
+
// protocol bound to whichever `Stdio` was built first.
|
|
2673
|
+
Layer.provide(Layer.effect(RpcServer.Protocol, RpcServer.makeProtocolStdio)),
|
|
2470
2674
|
Layer.provide(Layer.succeed(
|
|
2471
2675
|
RpcSerialization.RpcSerialization,
|
|
2472
2676
|
mcpStdioSerialization(options.protocols)
|
|
@@ -3106,40 +3310,33 @@ export const registerToolkit: <Tools extends Record<string, Tool.Any>>(
|
|
|
3106
3310
|
const annotations = tool.annotations
|
|
3107
3311
|
const toolMeta = Context.getOrUndefined(annotations, Tool.Meta)
|
|
3108
3312
|
const isDeclaredFailure = Schema.is(tool.failureSchema)
|
|
3109
|
-
// MCP content is JSON
|
|
3110
|
-
const
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
}))
|
|
3125
|
-
}
|
|
3126
|
-
const encodeFailure = encodeJson(tool.failureSchema)
|
|
3127
|
-
// Successes and "return"-mode failures arrive already encoded by the Toolkit; only their JSON conversion runs here.
|
|
3128
|
-
const encodeReturnedFailure = encodeJson(Schema.toEncoded(tool.failureSchema))
|
|
3129
|
-
const encodeStructured = encodeJson(Schema.toEncoded(tool.successSchema))
|
|
3313
|
+
// MCP content is JSON. Failures raised in "error" mode skip the Toolkit's encoding, so they use the JSON codec here.
|
|
3314
|
+
const encodeFailureJson = Schema.encodeUnknownEffect(Schema.toCodecJson(tool.failureSchema)) as (
|
|
3315
|
+
value: unknown
|
|
3316
|
+
) => Effect.Effect<unknown, Schema.SchemaError, Tool.HandlerServices<Tools[keyof Tools]>>
|
|
3317
|
+
const encodeFailure = (toolResult: unknown) =>
|
|
3318
|
+
Effect.mapError(encodeFailureJson(toolResult), (cause) =>
|
|
3319
|
+
AiError.make({
|
|
3320
|
+
module: "McpServer",
|
|
3321
|
+
method: "registerToolkit",
|
|
3322
|
+
reason: new AiError.ToolResultEncodingError({
|
|
3323
|
+
toolName: tool.name,
|
|
3324
|
+
toolResult,
|
|
3325
|
+
description: cause.message
|
|
3326
|
+
})
|
|
3327
|
+
}))
|
|
3130
3328
|
const failureResult = (encoded: unknown) =>
|
|
3131
3329
|
new CallToolResult({ isError: true, content: toolResultContent(encoded) })
|
|
3132
3330
|
const declaredFailureResult = (error: unknown) =>
|
|
3133
3331
|
error instanceof Error && error.message !== ""
|
|
3134
3332
|
? Effect.succeed(toolErrorResult(error.message))
|
|
3135
3333
|
: Effect.map(encodeFailure(error), failureResult)
|
|
3136
|
-
const successResult = (
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
}))
|
|
3334
|
+
const successResult = (structuredContent: unknown) =>
|
|
3335
|
+
new CallToolResult({
|
|
3336
|
+
isError: false,
|
|
3337
|
+
structuredContent,
|
|
3338
|
+
content: toolResultContent(structuredContent)
|
|
3339
|
+
})
|
|
3143
3340
|
const handleCause = (cause: Cause.Cause<unknown>) => {
|
|
3144
3341
|
const failure = Cause.findFail(cause)
|
|
3145
3342
|
if (Result.isSuccess(failure)) {
|
|
@@ -3200,15 +3397,18 @@ export const registerToolkit: <Tools extends Record<string, Tool.Any>>(
|
|
|
3200
3397
|
unknown,
|
|
3201
3398
|
Tool.HandlerServices<Tools[keyof Tools]>
|
|
3202
3399
|
> => {
|
|
3400
|
+
// The Toolkit encodes successes and "return"-mode failures with their JSON codec.
|
|
3203
3401
|
if (!result.isFailure) {
|
|
3204
3402
|
// An absent result, such as `Schema.Void`, has no structured form.
|
|
3205
|
-
return
|
|
3206
|
-
|
|
3207
|
-
|
|
3403
|
+
return Effect.succeed(
|
|
3404
|
+
result.result === undefined
|
|
3405
|
+
? new CallToolResult({ isError: false, content: [] })
|
|
3406
|
+
: successResult(result.encodedResult)
|
|
3407
|
+
)
|
|
3208
3408
|
}
|
|
3209
3409
|
// Declared failures return their encoded payload; anything else is classified by origin.
|
|
3210
3410
|
return result.failureOrigin === "handler"
|
|
3211
|
-
? Effect.
|
|
3411
|
+
? Effect.succeed(failureResult(result.encodedResult))
|
|
3212
3412
|
: Effect.failCause(Cause.annotate(
|
|
3213
3413
|
Cause.fail(result.result),
|
|
3214
3414
|
Context.make(Toolkit.FailureOrigin, result.failureOrigin ?? "result")
|
|
@@ -3486,7 +3686,7 @@ export const registerResource: {
|
|
|
3486
3686
|
}),
|
|
3487
3687
|
services,
|
|
3488
3688
|
handle: options.content.pipe(
|
|
3489
|
-
Effect.map((content) => resolveResourceContent(options.uri, content)),
|
|
3689
|
+
Effect.map((content) => resolveResourceContent(options.uri, options.mimeType, content)),
|
|
3490
3690
|
Effect.catchCause(handlerFailureToInternalError)
|
|
3491
3691
|
),
|
|
3492
3692
|
annotations: options.annotations ?? Context.empty()
|
|
@@ -3550,7 +3750,7 @@ export const registerResource: {
|
|
|
3550
3750
|
Effect.mapError((error) => new InvalidParams({ message: error.message })),
|
|
3551
3751
|
Effect.flatMap((params: any) =>
|
|
3552
3752
|
options.content(uri, ...params).pipe(
|
|
3553
|
-
Effect.map((content) => resolveResourceContent(uri, content)),
|
|
3753
|
+
Effect.map((content) => resolveResourceContent(uri, options.mimeType, content)),
|
|
3554
3754
|
Effect.catchCause(handlerFailureToInternalError)
|
|
3555
3755
|
)
|
|
3556
3756
|
)
|
|
@@ -3711,7 +3911,9 @@ const toSkillSourceFile = (path: string, file: SkillFile): McpSkills.SourceFile
|
|
|
3711
3911
|
* `skills/list` and `skills/get` with a manifest of every file's SHA-256
|
|
3712
3912
|
* digest and size, computed from the bytes served. Every directory of the
|
|
3713
3913
|
* skill namespace is readable with `resources/directory/read`. The server
|
|
3714
|
-
* declares the extension once any skill is registered.
|
|
3914
|
+
* declares the extension on protocol 2026-07-28 once any skill is registered.
|
|
3915
|
+
* Earlier revisions neither declare it nor answer its methods, but still serve
|
|
3916
|
+
* the skill's files through `resources/read`.
|
|
3715
3917
|
*
|
|
3716
3918
|
* Fails when the skill breaks the extension's rules: a name that does not
|
|
3717
3919
|
* match the URI, a `SKILL.md` without YAML frontmatter, frontmatter that is
|
|
@@ -4076,21 +4278,16 @@ const compileUriTemplate = (segments: TemplateStringsArray, ...schemas: Readonly
|
|
|
4076
4278
|
|
|
4077
4279
|
const resolveResourceContent = (
|
|
4078
4280
|
uri: string,
|
|
4281
|
+
mimeType: string | undefined,
|
|
4079
4282
|
content: ReadResourceResult | string | Uint8Array
|
|
4080
4283
|
): ReadResourceResult => {
|
|
4081
4284
|
if (typeof content === "string") {
|
|
4082
4285
|
return {
|
|
4083
|
-
contents: [{
|
|
4084
|
-
uri,
|
|
4085
|
-
text: content
|
|
4086
|
-
}]
|
|
4286
|
+
contents: [mimeType === undefined ? { uri, text: content } : { uri, mimeType, text: content }]
|
|
4087
4287
|
}
|
|
4088
4288
|
} else if (content instanceof Uint8Array) {
|
|
4089
4289
|
return {
|
|
4090
|
-
contents: [{
|
|
4091
|
-
uri,
|
|
4092
|
-
blob: content
|
|
4093
|
-
}]
|
|
4290
|
+
contents: [mimeType === undefined ? { uri, blob: content } : { uri, mimeType, blob: content }]
|
|
4094
4291
|
}
|
|
4095
4292
|
}
|
|
4096
4293
|
return content
|
package/src/ai/Prompt.ts
CHANGED
|
@@ -788,7 +788,9 @@ export interface ToolResultPart extends BasePart<"tool-result", ToolResultPartOp
|
|
|
788
788
|
*/
|
|
789
789
|
readonly isFailure: boolean
|
|
790
790
|
/**
|
|
791
|
-
* The result returned by the tool execution.
|
|
791
|
+
* The result returned by the tool execution. Results of locally handled
|
|
792
|
+
* tools hold their JSON encoding; provider-executed tools keep the
|
|
793
|
+
* provider's payload.
|
|
792
794
|
*/
|
|
793
795
|
readonly result: unknown
|
|
794
796
|
/**
|
|
@@ -822,7 +824,9 @@ export interface ToolResultPartEncoded extends BasePartEncoded<"tool-result", To
|
|
|
822
824
|
*/
|
|
823
825
|
readonly isFailure: boolean
|
|
824
826
|
/**
|
|
825
|
-
* The result returned by the tool execution.
|
|
827
|
+
* The result returned by the tool execution. Results of locally handled
|
|
828
|
+
* tools hold their JSON encoding; provider-executed tools keep the
|
|
829
|
+
* provider's payload.
|
|
826
830
|
*/
|
|
827
831
|
readonly result: unknown
|
|
828
832
|
/**
|