@effect/ai 0.19.2 → 0.19.4

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/src/McpSchema.ts CHANGED
@@ -2,8 +2,13 @@
2
2
  * @since 1.0.0
3
3
  */
4
4
  import * as Rpc from "@effect/rpc/Rpc"
5
+ import type * as RpcClient from "@effect/rpc/RpcClient"
5
6
  import * as RpcGroup from "@effect/rpc/RpcGroup"
7
+ import * as RpcMiddleware from "@effect/rpc/RpcMiddleware"
8
+ import * as Context from "effect/Context"
9
+ import type * as Effect from "effect/Effect"
6
10
  import * as Schema from "effect/Schema"
11
+ import type * as Scope from "effect/Scope"
7
12
 
8
13
  // =============================================================================
9
14
  // Common
@@ -53,9 +58,7 @@ export type ProgressToken = typeof ProgressToken.Type
53
58
  * @since 1.0.0
54
59
  * @category Common
55
60
  */
56
- export class RequestMeta extends Schema.Class<RequestMeta>(
57
- "@effect/ai/McpSchema/RequestMeta"
58
- )({
61
+ export class RequestMeta extends Schema.Struct({
59
62
  _meta: Schema.optional(Schema.Struct({
60
63
  /**
61
64
  * If specified, the caller is requesting out-of-band progress notifications
@@ -72,9 +75,7 @@ export class RequestMeta extends Schema.Class<RequestMeta>(
72
75
  * @since 1.0.0
73
76
  * @category Common
74
77
  */
75
- export class ResultMeta extends Schema.Class<ResultMeta>(
76
- "@effect/ai/McpSchema/ResultMeta"
77
- )({
78
+ export class ResultMeta extends Schema.Struct({
78
79
  /**
79
80
  * This result property is reserved by the protocol to allow clients and
80
81
  * servers to attach additional metadata to their responses.
@@ -86,9 +87,7 @@ export class ResultMeta extends Schema.Class<ResultMeta>(
86
87
  * @since 1.0.0
87
88
  * @category Common
88
89
  */
89
- export class NotificationMeta extends Schema.Class<NotificationMeta>(
90
- "@effect/ai/McpSchema/NotificationMeta"
91
- )({
90
+ export class NotificationMeta extends Schema.Struct({
92
91
  /**
93
92
  * This parameter name is reserved by MCP to allow clients and servers to
94
93
  * attach additional metadata to their notifications.
@@ -114,9 +113,7 @@ export type Cursor = typeof Cursor.Type
114
113
  * @since 1.0.0
115
114
  * @category Common
116
115
  */
117
- export class PaginatedRequestMeta extends Schema.Class<PaginatedRequestMeta>(
118
- "@effect/ai/McpSchema/PaginatedRequestMeta"
119
- )({
116
+ export class PaginatedRequestMeta extends Schema.Struct({
120
117
  ...RequestMeta.fields,
121
118
  /**
122
119
  * An opaque token representing the current pagination position.
@@ -129,9 +126,7 @@ export class PaginatedRequestMeta extends Schema.Class<PaginatedRequestMeta>(
129
126
  * @since 1.0.0
130
127
  * @category Common
131
128
  */
132
- export class PaginatedResultMeta extends Schema.Class<PaginatedResultMeta>(
133
- "@effect/ai/McpSchema/PaginatedResultMeta"
134
- )({
129
+ export class PaginatedResultMeta extends Schema.Struct({
135
130
  ...ResultMeta.fields,
136
131
  /**
137
132
  * An opaque token representing the pagination position after the last returned result.
@@ -160,9 +155,7 @@ export type Role = typeof Role.Type
160
155
  * @since 1.0.0
161
156
  * @category Common
162
157
  */
163
- export class Annotations extends Schema.Class<Annotations>(
164
- "@effect/ai/McpSchema/Annotations"
165
- )({
158
+ export class Annotations extends Schema.Struct({
166
159
  /**
167
160
  * Describes who the intended customer of this object or data is.
168
161
  *
@@ -186,10 +179,9 @@ export class Annotations extends Schema.Class<Annotations>(
186
179
  * @since 1.0.0
187
180
  * @category Common
188
181
  */
189
- export class Implementation extends Schema.Class<Implementation>(
190
- "@effect/ai/McpSchema/Implementation"
191
- )({
182
+ export class Implementation extends Schema.Struct({
192
183
  name: Schema.String,
184
+ title: Schema.optional(Schema.String),
193
185
  version: Schema.String
194
186
  }) {}
195
187
 
@@ -223,7 +215,11 @@ export class ClientCapabilities extends Schema.Class<ClientCapabilities>(
223
215
  /**
224
216
  * Present if the client supports sampling from an LLM.
225
217
  */
226
- sampling: Schema.optional(Schema.Struct({}))
218
+ sampling: Schema.optional(Schema.Struct({})),
219
+ /**
220
+ * Present if the client supports elicitation from the server.
221
+ */
222
+ elicitation: Schema.optional(Schema.Struct({}))
227
223
  }) {}
228
224
 
229
225
  /**
@@ -234,9 +230,7 @@ export class ClientCapabilities extends Schema.Class<ClientCapabilities>(
234
230
  * @since 1.0.0
235
231
  * @category Common
236
232
  */
237
- export class ServerCapabilities extends Schema.Class<ServerCapabilities>(
238
- "@effect/ai/McpSchema/ServerCapabilities"
239
- )({
233
+ export class ServerCapabilities extends Schema.Struct({
240
234
  /**
241
235
  * Experimental, non-standard capabilities that the server supports.
242
236
  */
@@ -561,6 +555,7 @@ export class Resource extends Schema.Class<Resource>(
561
555
  * This can be used by clients to populate UI elements.
562
556
  */
563
557
  name: Schema.String,
558
+ title: Schema.optional(Schema.String),
564
559
  /**
565
560
  * A description of what this resource represents.
566
561
  *
@@ -606,6 +601,7 @@ export class ResourceTemplate extends Schema.Class<ResourceTemplate>(
606
601
  * This can be used by clients to populate UI elements.
607
602
  */
608
603
  name: Schema.String,
604
+ title: Schema.optional(Schema.String),
609
605
  /**
610
606
  * A description of what this template is for.
611
607
  *
@@ -632,9 +628,7 @@ export class ResourceTemplate extends Schema.Class<ResourceTemplate>(
632
628
  * @since 1.0.0
633
629
  * @category Resources
634
630
  */
635
- export class ResourceContents extends Schema.Class<ResourceContents>(
636
- "@effect/ai/McpSchema/ResourceContents"
637
- )({
631
+ export class ResourceContents extends Schema.Struct({
638
632
  /**
639
633
  * The URI of this resource.
640
634
  */
@@ -651,9 +645,8 @@ export class ResourceContents extends Schema.Class<ResourceContents>(
651
645
  * @since 1.0.0
652
646
  * @category Resources
653
647
  */
654
- export class TextResourceContents extends ResourceContents.extend<TextResourceContents>(
655
- "@effect/ai/McpSchema/TextResourceContents"
656
- )({
648
+ export class TextResourceContents extends Schema.Struct({
649
+ ...ResourceContents.fields,
657
650
  /**
658
651
  * The text of the item. This must only be set if the item can actually be
659
652
  * represented as text (not binary data).
@@ -667,9 +660,8 @@ export class TextResourceContents extends ResourceContents.extend<TextResourceCo
667
660
  * @since 1.0.0
668
661
  * @category Resources
669
662
  */
670
- export class BlobResourceContents extends ResourceContents.extend<BlobResourceContents>(
671
- "@effect/ai/McpSchema/BlobResourceContents"
672
- )({
663
+ export class BlobResourceContents extends Schema.Struct({
664
+ ...ResourceContents.fields,
673
665
  /**
674
666
  * The binary data of the item decoded from a base64-encoded string.
675
667
  */
@@ -732,9 +724,7 @@ export class ListResourceTemplates extends Rpc.make("resources/templates/list",
732
724
  * @since 1.0.0
733
725
  * @category Resources
734
726
  */
735
- export class ReadResourceResult extends Schema.Class<ReadResourceResult>(
736
- "@effect/ai/McpSchema/ReadResourceResult"
737
- )({
727
+ export class ReadResourceResult extends Schema.Struct({
738
728
  ...ResultMeta.fields,
739
729
  contents: Schema.Array(Schema.Union(
740
730
  TextResourceContents,
@@ -836,13 +826,12 @@ export class ResourceUpdatedNotification extends Rpc.make("notifications/resourc
836
826
  * @since 1.0.0
837
827
  * @category Prompts
838
828
  */
839
- export class PromptArgument extends Schema.Class<PromptArgument>(
840
- "@effect/ai/McpSchema/PromptArgument"
841
- )({
829
+ export class PromptArgument extends Schema.Struct({
842
830
  /**
843
831
  * The name of the argument.
844
832
  */
845
833
  name: Schema.String,
834
+ title: Schema.optional(Schema.String),
846
835
  /**
847
836
  * A human-readable description of the argument.
848
837
  */
@@ -866,6 +855,7 @@ export class Prompt extends Schema.Class<Prompt>(
866
855
  * The name of the prompt or prompt template.
867
856
  */
868
857
  name: Schema.String,
858
+ title: Schema.optional(Schema.String),
869
859
  /**
870
860
  * An optional description of what this prompt provides
871
861
  */
@@ -882,9 +872,7 @@ export class Prompt extends Schema.Class<Prompt>(
882
872
  * @since 1.0.0
883
873
  * @category Prompts
884
874
  */
885
- export class TextContent extends Schema.Class<TextContent>(
886
- "@effect/ai/McpSchema/TextContent"
887
- )({
875
+ export class TextContent extends Schema.Struct({
888
876
  type: Schema.tag("text"),
889
877
  /**
890
878
  * The text content of the message.
@@ -902,9 +890,7 @@ export class TextContent extends Schema.Class<TextContent>(
902
890
  * @since 1.0.0
903
891
  * @category Prompts
904
892
  */
905
- export class ImageContent extends Schema.Class<ImageContent>(
906
- "@effect/ai/McpSchema/ImageContent"
907
- )({
893
+ export class ImageContent extends Schema.Struct({
908
894
  type: Schema.tag("image"),
909
895
  /**
910
896
  * The image data.
@@ -927,9 +913,7 @@ export class ImageContent extends Schema.Class<ImageContent>(
927
913
  * @since 1.0.0
928
914
  * @category Prompts
929
915
  */
930
- export class AudioContent extends Schema.Class<AudioContent>(
931
- "@effect/ai/McpSchema/AudioContent"
932
- )({
916
+ export class AudioContent extends Schema.Struct({
933
917
  type: Schema.tag("audio"),
934
918
  /**
935
919
  * The audio data.
@@ -955,9 +939,7 @@ export class AudioContent extends Schema.Class<AudioContent>(
955
939
  * @since 1.0.0
956
940
  * @category Prompts
957
941
  */
958
- export class EmbeddedResource extends Schema.Class<EmbeddedResource>(
959
- "@effect/ai/McpSchema/EmbeddedResource"
960
- )({
942
+ export class EmbeddedResource extends Schema.Struct({
961
943
  type: Schema.tag("resource"),
962
944
  resource: Schema.Union(TextResourceContents, BlobResourceContents),
963
945
  /**
@@ -966,6 +948,31 @@ export class EmbeddedResource extends Schema.Class<EmbeddedResource>(
966
948
  annotations: Schema.optional(Annotations)
967
949
  }) {}
968
950
 
951
+ /**
952
+ * A resource that the server is capable of reading, included in a prompt or tool call result.
953
+ *
954
+ * Note: resource links returned by tools are not guaranteed to appear in the results of `resources/list` requests.
955
+ *
956
+ * @since 1.0.0
957
+ * @category Prompts
958
+ */
959
+ export class ResourceLink extends Schema.Struct({
960
+ ...Resource.fields,
961
+ type: Schema.tag("resource_link")
962
+ }) {}
963
+
964
+ /**
965
+ * @since 1.0.0
966
+ * @category Prompts
967
+ */
968
+ export class ContentBlock extends Schema.Union(
969
+ TextContent,
970
+ ImageContent,
971
+ AudioContent,
972
+ EmbeddedResource,
973
+ ResourceLink
974
+ ) {}
975
+
969
976
  /**
970
977
  * Describes a message returned as part of a prompt.
971
978
  *
@@ -975,16 +982,9 @@ export class EmbeddedResource extends Schema.Class<EmbeddedResource>(
975
982
  * @since 1.0.0
976
983
  * @category Prompts
977
984
  */
978
- export class PromptMessage extends Schema.Class<PromptMessage>(
979
- "@effect/ai/McpSchema/PromptMessage"
980
- )({
985
+ export class PromptMessage extends Schema.Struct({
981
986
  role: Role,
982
- content: Schema.Union(
983
- TextContent,
984
- ImageContent,
985
- AudioContent,
986
- EmbeddedResource
987
- )
987
+ content: ContentBlock
988
988
  }) {}
989
989
 
990
990
  /**
@@ -1045,6 +1045,7 @@ export class GetPrompt extends Rpc.make("prompts/get", {
1045
1045
  * The name of the prompt or prompt template.
1046
1046
  */
1047
1047
  name: Schema.String,
1048
+ title: Schema.optional(Schema.String),
1048
1049
  /**
1049
1050
  * Arguments to use for templating the prompt.
1050
1051
  */
@@ -1139,6 +1140,7 @@ export class Tool extends Schema.Class<Tool>(
1139
1140
  * The name of the tool.
1140
1141
  */
1141
1142
  name: Schema.String,
1143
+ title: Schema.optional(Schema.String),
1142
1144
  /**
1143
1145
  * A human-readable description of the tool.
1144
1146
  *
@@ -1195,16 +1197,10 @@ export class ListTools extends Rpc.make("tools/list", {
1195
1197
  * @since 1.0.0
1196
1198
  * @category Tools
1197
1199
  */
1198
- export class CallToolResult extends Schema.Class<CallToolResult>(
1199
- "@effect/ai/McpSchema/CallToolResult"
1200
- )({
1200
+ export class CallToolResult extends Schema.Class<CallToolResult>("@effect/ai/McpSchema/CallToolResult")({
1201
1201
  ...ResultMeta.fields,
1202
- content: Schema.Array(Schema.Union(
1203
- TextContent,
1204
- ImageContent,
1205
- AudioContent,
1206
- EmbeddedResource
1207
- )),
1202
+ content: Schema.Array(ContentBlock),
1203
+ structuredContent: Schema.optional(Schema.Unknown),
1208
1204
  /**
1209
1205
  * Whether the tool call ended in an error.
1210
1206
  *
@@ -1340,9 +1336,7 @@ export class LoggingMessageNotification extends Rpc.make("notifications/message"
1340
1336
  * @since 1.0.0
1341
1337
  * @category Sampling
1342
1338
  */
1343
- export class SamplingMessage extends Schema.Class<SamplingMessage>(
1344
- "@effect/ai/McpSchema/SamplingMessage"
1345
- )({
1339
+ export class SamplingMessage extends Schema.Struct({
1346
1340
  role: Role,
1347
1341
  content: Schema.Union(TextContent, ImageContent, AudioContent)
1348
1342
  }) {}
@@ -1356,9 +1350,7 @@ export class SamplingMessage extends Schema.Class<SamplingMessage>(
1356
1350
  * @since 1.0.0
1357
1351
  * @category Sampling
1358
1352
  */
1359
- export class ModelHint extends Schema.Class<ModelHint>(
1360
- "@effect/ai/McpSchema/ModelHint"
1361
- )({
1353
+ export class ModelHint extends Schema.Struct({
1362
1354
  /**
1363
1355
  * A hint for a model name.
1364
1356
  *
@@ -1499,9 +1491,7 @@ export class CreateMessage extends Rpc.make("sampling/createMessage", {
1499
1491
  * @since 1.0.0
1500
1492
  * @category Autocomplete
1501
1493
  */
1502
- export class ResourceReference extends Schema.Class<ResourceReference>(
1503
- "@effect/ai/McpSchema/ResourceReference"
1504
- )({
1494
+ export class ResourceReference extends Schema.Struct({
1505
1495
  type: Schema.tag("ref/resource"),
1506
1496
  /**
1507
1497
  * The URI or URI template of the resource.
@@ -1515,14 +1505,13 @@ export class ResourceReference extends Schema.Class<ResourceReference>(
1515
1505
  * @since 1.0.0
1516
1506
  * @category Autocomplete
1517
1507
  */
1518
- export class PromptReference extends Schema.Class<PromptReference>(
1519
- "@effect/ai/McpSchema/PromptReference"
1520
- )({
1508
+ export class PromptReference extends Schema.Struct({
1521
1509
  type: Schema.tag("ref/prompt"),
1522
1510
  /**
1523
1511
  * The name of the prompt or prompt template
1524
1512
  */
1525
- name: Schema.String
1513
+ name: Schema.String,
1514
+ title: Schema.optional(Schema.String)
1526
1515
  }) {}
1527
1516
 
1528
1517
  /**
@@ -1531,9 +1520,7 @@ export class PromptReference extends Schema.Class<PromptReference>(
1531
1520
  * @since 1.0.0
1532
1521
  * @category Autocomplete
1533
1522
  */
1534
- export class CompleteResult extends Schema.Class<CompleteResult>(
1535
- "@effect/ai/McpSchema/CompleteResult"
1536
- )({
1523
+ export class CompleteResult extends Schema.Class<CompleteResult>("@effect/ai/McpSchema/CompleteResult")({
1537
1524
  completion: Schema.Struct({
1538
1525
  /**
1539
1526
  * An array of completion values. Must not exceed 100 items.
@@ -1554,7 +1541,7 @@ export class CompleteResult extends Schema.Class<CompleteResult>(
1554
1541
  /**
1555
1542
  * @since 1.0.0
1556
1543
  */
1557
- static readonly empty = new CompleteResult({
1544
+ static readonly empty = CompleteResult.make({
1558
1545
  completion: {
1559
1546
  values: [],
1560
1547
  total: 0,
@@ -1572,7 +1559,7 @@ export class CompleteResult extends Schema.Class<CompleteResult>(
1572
1559
  export class Complete extends Rpc.make("completion/complete", {
1573
1560
  success: CompleteResult,
1574
1561
  error: McpError,
1575
- payload: {
1562
+ payload: Schema.Struct({
1576
1563
  ref: Schema.Union(PromptReference, ResourceReference),
1577
1564
  /**
1578
1565
  * The argument's information
@@ -1586,8 +1573,26 @@ export class Complete extends Rpc.make("completion/complete", {
1586
1573
  * The value of the argument to use for completion matching.
1587
1574
  */
1588
1575
  value: Schema.String
1589
- })
1590
- }
1576
+ }),
1577
+ /**
1578
+ * Additional, optional context for completions
1579
+ */
1580
+ context: Schema.optionalWith(
1581
+ Schema.Struct({
1582
+ /**
1583
+ * Previously-resolved variables in a URI template or prompt.
1584
+ */
1585
+ arguments: Schema.optionalWith(
1586
+ Schema.Record({
1587
+ key: Schema.String,
1588
+ value: Schema.String
1589
+ }),
1590
+ { default: () => ({}) }
1591
+ )
1592
+ }),
1593
+ { default: () => ({ arguments: {} }) }
1594
+ )
1595
+ })
1591
1596
  }) {}
1592
1597
 
1593
1598
  // =============================================================================
@@ -1664,6 +1669,122 @@ export class RootsListChangedNotification extends Rpc.make("notifications/roots/
1664
1669
  payload: Schema.UndefinedOr(NotificationMeta)
1665
1670
  }) {}
1666
1671
 
1672
+ // =============================================================================
1673
+ // Elicitation
1674
+ // =============================================================================
1675
+
1676
+ /**
1677
+ * The client's response to an elicitation request
1678
+ *
1679
+ * @since 1.0.0
1680
+ * @category Elicitation
1681
+ */
1682
+ export class ElicitAcceptResult extends Schema.Class<ElicitAcceptResult>(
1683
+ "@effect/ai/McpSchema/ElicitAcceptResult"
1684
+ )({
1685
+ ...ResultMeta.fields,
1686
+ /**
1687
+ * The user action in response to the elicitation.
1688
+ * - "accept": User submitted the form/confirmed the action
1689
+ * - "decline": User explicitly declined the action
1690
+ * - "cancel": User dismissed without making an explicit choice
1691
+ */
1692
+ action: Schema.Literal("accept"),
1693
+ /**
1694
+ * The submitted form data, only present when action is "accept".
1695
+ * Contains values matching the requested schema.
1696
+ */
1697
+ content: Schema.Unknown
1698
+ }) {}
1699
+
1700
+ /**
1701
+ * The client's response to an elicitation request
1702
+ *
1703
+ * @since 1.0.0
1704
+ * @category Elicitation
1705
+ */
1706
+ export class ElicitDeclineResult extends Schema.Class<ElicitDeclineResult>(
1707
+ "@effect/ai/McpSchema/ElicitDeclineResult"
1708
+ )({
1709
+ ...ResultMeta.fields,
1710
+ /**
1711
+ * The user action in response to the elicitation.
1712
+ * - "accept": User submitted the form/confirmed the action
1713
+ * - "decline": User explicitly declined the action
1714
+ * - "cancel": User dismissed without making an explicit choice
1715
+ */
1716
+ action: Schema.Literal("cancel", "decline")
1717
+ }) {}
1718
+
1719
+ /**
1720
+ * The client's response to an elicitation request
1721
+ *
1722
+ * @since 1.0.0
1723
+ * @category Elicitation
1724
+ */
1725
+ export const ElicitResult = Schema.Union(
1726
+ ElicitAcceptResult,
1727
+ ElicitDeclineResult
1728
+ )
1729
+
1730
+ /**
1731
+ * @since 1.0.0
1732
+ * @category Elicitation
1733
+ */
1734
+ export class Elicit extends Rpc.make("elicitation/create", {
1735
+ success: ElicitResult,
1736
+ error: McpError,
1737
+ payload: {
1738
+ /**
1739
+ * A message to display to the user, explaining what they are being
1740
+ * elicited for.
1741
+ */
1742
+ message: Schema.String,
1743
+ /**
1744
+ * A restricted subset of JSON Schema.
1745
+ * Only top-level properties are allowed, without nesting.
1746
+ */
1747
+ requestedSchema: Schema.Unknown
1748
+ }
1749
+ }) {}
1750
+
1751
+ /**
1752
+ * @since 1.0.0
1753
+ * @category Elicitation
1754
+ */
1755
+ export class ElicitationDeclined
1756
+ extends Schema.TaggedError<ElicitationDeclined>("@effect/ai/McpSchema/ElicitationDeclined")("ElicitationDeclined", {
1757
+ request: Elicit.payloadSchema,
1758
+ cause: Schema.optional(Schema.Defect)
1759
+ })
1760
+ {}
1761
+
1762
+ // =============================================================================
1763
+ // McpServerClient
1764
+ // =============================================================================
1765
+
1766
+ /**
1767
+ * @since 1.0.0
1768
+ * @category McpServerClient
1769
+ */
1770
+ export class McpServerClient extends Context.Tag("@effect/ai/McpSchema/McpServerClient")<
1771
+ McpServerClient,
1772
+ {
1773
+ readonly clientId: number
1774
+ readonly getClient: Effect.Effect<RpcClient.RpcClient<RpcGroup.Rpcs<typeof ServerRequestRpcs>>, never, Scope.Scope>
1775
+ }
1776
+ >() {}
1777
+
1778
+ /**
1779
+ * @since 1.0.0
1780
+ * @category McpServerClient
1781
+ */
1782
+ export class McpServerClientMiddleware
1783
+ extends RpcMiddleware.Tag<McpServerClientMiddleware>()("@effect/ai/McpSchema/McpServerClientMiddleware", {
1784
+ provides: McpServerClient
1785
+ })
1786
+ {}
1787
+
1667
1788
  // =============================================================================
1668
1789
  // Protocol
1669
1790
  // =============================================================================
@@ -1767,7 +1888,7 @@ export class ClientRequestRpcs extends RpcGroup.make(
1767
1888
  Unsubscribe,
1768
1889
  CallTool,
1769
1890
  ListTools
1770
- ) {}
1891
+ ).middleware(McpServerClientMiddleware) {}
1771
1892
 
1772
1893
  /**
1773
1894
  * @since 1.0.0
@@ -1817,7 +1938,8 @@ export type ClientFailureEncoded = FailureEncoded<typeof ServerRequestRpcs>
1817
1938
  export class ServerRequestRpcs extends RpcGroup.make(
1818
1939
  Ping,
1819
1940
  CreateMessage,
1820
- ListRoots
1941
+ ListRoots,
1942
+ Elicit
1821
1943
  ) {}
1822
1944
 
1823
1945
  /**