@yolk-sdk/mcp 0.0.1-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +82 -0
- package/dist/client/client.d.mts +40 -0
- package/dist/client/client.d.mts.map +1 -0
- package/dist/client/client.mjs +225 -0
- package/dist/client/client.mjs.map +1 -0
- package/dist/client/config.d.mts +29 -0
- package/dist/client/config.d.mts.map +1 -0
- package/dist/client/config.mjs +13 -0
- package/dist/client/config.mjs.map +1 -0
- package/dist/client/errors.d.mts +14 -0
- package/dist/client/errors.d.mts.map +1 -0
- package/dist/client/errors.mjs +22 -0
- package/dist/client/errors.mjs.map +1 -0
- package/dist/client/index.d.mts +5 -0
- package/dist/client/index.mjs +5 -0
- package/dist/client/node.d.mts +16 -0
- package/dist/client/node.d.mts.map +1 -0
- package/dist/client/node.mjs +13 -0
- package/dist/client/node.mjs.map +1 -0
- package/dist/client/protocol.d.mts +175 -0
- package/dist/client/protocol.d.mts.map +1 -0
- package/dist/client/protocol.mjs +225 -0
- package/dist/client/protocol.mjs.map +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +1 -0
- package/dist/server/errors.d.mts +11 -0
- package/dist/server/errors.d.mts.map +1 -0
- package/dist/server/errors.mjs +16 -0
- package/dist/server/errors.mjs.map +1 -0
- package/dist/server/index.d.mts +4 -0
- package/dist/server/index.mjs +4 -0
- package/dist/server/server.d.mts +22 -0
- package/dist/server/server.d.mts.map +1 -0
- package/dist/server/server.mjs +180 -0
- package/dist/server/server.mjs.map +1 -0
- package/dist/server/stdio.d.mts +8 -0
- package/dist/server/stdio.d.mts.map +1 -0
- package/dist/server/stdio.mjs +18 -0
- package/dist/server/stdio.mjs.map +1 -0
- package/package.json +77 -0
- package/src/client/README.md +24 -0
- package/src/client/client.ts +494 -0
- package/src/client/config.ts +37 -0
- package/src/client/errors.ts +20 -0
- package/src/client/index.ts +48 -0
- package/src/client/node.ts +32 -0
- package/src/client/protocol.ts +364 -0
- package/src/index.ts +2 -0
- package/src/server/README.md +22 -0
- package/src/server/errors.ts +6 -0
- package/src/server/index.ts +4 -0
- package/src/server/server.ts +331 -0
- package/src/server/stdio.ts +37 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { McpError } from "./errors.mjs";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import * as Schema from "effect/Schema";
|
|
4
|
+
import { ToolDef, ToolResult } from "@yolk-sdk/agent/protocol";
|
|
5
|
+
|
|
6
|
+
//#region src/client/protocol.d.ts
|
|
7
|
+
declare const latestMcpProtocolVersion = "2024-11-05";
|
|
8
|
+
declare const JsonRpcErrorObject: Schema.Struct<{
|
|
9
|
+
readonly code: Schema.Number;
|
|
10
|
+
readonly message: Schema.String;
|
|
11
|
+
readonly data: Schema.optional<Schema.Unknown>;
|
|
12
|
+
}>;
|
|
13
|
+
type JsonRpcErrorObject = typeof JsonRpcErrorObject.Type;
|
|
14
|
+
declare const JsonRpcSuccessResponse: Schema.Struct<{
|
|
15
|
+
readonly jsonrpc: Schema.Literal<"2.0">;
|
|
16
|
+
readonly id: Schema.Union<readonly [Schema.String, Schema.Number, Schema.Null]>;
|
|
17
|
+
readonly result: Schema.Unknown;
|
|
18
|
+
}>;
|
|
19
|
+
type JsonRpcSuccessResponse = typeof JsonRpcSuccessResponse.Type;
|
|
20
|
+
declare const JsonRpcErrorResponse: Schema.Struct<{
|
|
21
|
+
readonly jsonrpc: Schema.Literal<"2.0">;
|
|
22
|
+
readonly id: Schema.Union<readonly [Schema.String, Schema.Number, Schema.Null]>;
|
|
23
|
+
readonly error: Schema.Struct<{
|
|
24
|
+
readonly code: Schema.Number;
|
|
25
|
+
readonly message: Schema.String;
|
|
26
|
+
readonly data: Schema.optional<Schema.Unknown>;
|
|
27
|
+
}>;
|
|
28
|
+
}>;
|
|
29
|
+
type JsonRpcErrorResponse = typeof JsonRpcErrorResponse.Type;
|
|
30
|
+
declare const JsonRpcResponse: Schema.Union<readonly [Schema.Struct<{
|
|
31
|
+
readonly jsonrpc: Schema.Literal<"2.0">;
|
|
32
|
+
readonly id: Schema.Union<readonly [Schema.String, Schema.Number, Schema.Null]>;
|
|
33
|
+
readonly result: Schema.Unknown;
|
|
34
|
+
}>, Schema.Struct<{
|
|
35
|
+
readonly jsonrpc: Schema.Literal<"2.0">;
|
|
36
|
+
readonly id: Schema.Union<readonly [Schema.String, Schema.Number, Schema.Null]>;
|
|
37
|
+
readonly error: Schema.Struct<{
|
|
38
|
+
readonly code: Schema.Number;
|
|
39
|
+
readonly message: Schema.String;
|
|
40
|
+
readonly data: Schema.optional<Schema.Unknown>;
|
|
41
|
+
}>;
|
|
42
|
+
}>]>;
|
|
43
|
+
type JsonRpcResponse = typeof JsonRpcResponse.Type;
|
|
44
|
+
declare const JsonRpcRequest: Schema.Struct<{
|
|
45
|
+
readonly jsonrpc: Schema.Literal<"2.0">;
|
|
46
|
+
readonly id: Schema.Union<readonly [Schema.String, Schema.Number]>;
|
|
47
|
+
readonly method: Schema.String;
|
|
48
|
+
readonly params: Schema.optional<Schema.Unknown>;
|
|
49
|
+
}>;
|
|
50
|
+
type JsonRpcRequest = typeof JsonRpcRequest.Type;
|
|
51
|
+
declare const JsonRpcNotification: Schema.Struct<{
|
|
52
|
+
readonly jsonrpc: Schema.Literal<"2.0">;
|
|
53
|
+
readonly method: Schema.String;
|
|
54
|
+
readonly params: Schema.optional<Schema.Unknown>;
|
|
55
|
+
}>;
|
|
56
|
+
type JsonRpcNotification = typeof JsonRpcNotification.Type;
|
|
57
|
+
declare const JsonRpcMessage: Schema.Union<readonly [Schema.Struct<{
|
|
58
|
+
readonly jsonrpc: Schema.Literal<"2.0">;
|
|
59
|
+
readonly id: Schema.Union<readonly [Schema.String, Schema.Number]>;
|
|
60
|
+
readonly method: Schema.String;
|
|
61
|
+
readonly params: Schema.optional<Schema.Unknown>;
|
|
62
|
+
}>, Schema.Struct<{
|
|
63
|
+
readonly jsonrpc: Schema.Literal<"2.0">;
|
|
64
|
+
readonly method: Schema.String;
|
|
65
|
+
readonly params: Schema.optional<Schema.Unknown>;
|
|
66
|
+
}>]>;
|
|
67
|
+
type JsonRpcMessage = typeof JsonRpcMessage.Type;
|
|
68
|
+
declare const McpTool: Schema.Struct<{
|
|
69
|
+
readonly name: Schema.String;
|
|
70
|
+
readonly description: Schema.optional<Schema.String>;
|
|
71
|
+
readonly inputSchema: Schema.optional<Schema.Unknown>;
|
|
72
|
+
}>;
|
|
73
|
+
type McpTool = typeof McpTool.Type;
|
|
74
|
+
declare const ToolsListResult: Schema.Struct<{
|
|
75
|
+
readonly tools: Schema.$Array<Schema.Struct<{
|
|
76
|
+
readonly name: Schema.String;
|
|
77
|
+
readonly description: Schema.optional<Schema.String>;
|
|
78
|
+
readonly inputSchema: Schema.optional<Schema.Unknown>;
|
|
79
|
+
}>>;
|
|
80
|
+
}>;
|
|
81
|
+
type ToolsListResult = typeof ToolsListResult.Type;
|
|
82
|
+
declare const TextContentBlock: Schema.Struct<{
|
|
83
|
+
readonly type: Schema.Literal<"text">;
|
|
84
|
+
readonly text: Schema.String;
|
|
85
|
+
}>;
|
|
86
|
+
type TextContentBlock = typeof TextContentBlock.Type;
|
|
87
|
+
declare const GenericContentBlock: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
88
|
+
type GenericContentBlock = typeof GenericContentBlock.Type;
|
|
89
|
+
declare const ToolCallResult: Schema.Struct<{
|
|
90
|
+
readonly content: Schema.optional<Schema.$Array<Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
91
|
+
readonly isError: Schema.optional<Schema.Boolean>;
|
|
92
|
+
readonly structuredContent: Schema.optional<Schema.Unknown>;
|
|
93
|
+
}>;
|
|
94
|
+
type ToolCallResult = typeof ToolCallResult.Type;
|
|
95
|
+
declare const makeJsonRpcRequest: (input: {
|
|
96
|
+
readonly id: string | number;
|
|
97
|
+
readonly method: string;
|
|
98
|
+
readonly params?: unknown;
|
|
99
|
+
}) => JsonRpcRequest;
|
|
100
|
+
declare const makeInitializedNotification: () => JsonRpcNotification;
|
|
101
|
+
declare const makeInitializeParams: (input: {
|
|
102
|
+
readonly name: string;
|
|
103
|
+
readonly version: string;
|
|
104
|
+
}) => {
|
|
105
|
+
protocolVersion: string;
|
|
106
|
+
capabilities: {};
|
|
107
|
+
clientInfo: {
|
|
108
|
+
name: string;
|
|
109
|
+
version: string;
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
declare const jsonRpcErrorToMcpError: (server: string, error: JsonRpcErrorObject) => McpError;
|
|
113
|
+
declare const mcpToolToToolDef: (input: {
|
|
114
|
+
readonly serverName: string;
|
|
115
|
+
readonly tool: McpTool;
|
|
116
|
+
}) => ToolDef;
|
|
117
|
+
declare const sanitizeMcpName: (name: string) => string;
|
|
118
|
+
declare const toolCallResultToToolResult: (input: {
|
|
119
|
+
readonly toolCallId: string;
|
|
120
|
+
readonly result: ToolCallResult;
|
|
121
|
+
}) => ToolResult;
|
|
122
|
+
declare const decodeJsonRpcResponse: (input: unknown, options?: import("effect/SchemaAST").ParseOptions) => Effect.Effect<{
|
|
123
|
+
readonly jsonrpc: "2.0";
|
|
124
|
+
readonly id: string | number | null;
|
|
125
|
+
readonly result: unknown;
|
|
126
|
+
} | {
|
|
127
|
+
readonly jsonrpc: "2.0";
|
|
128
|
+
readonly id: string | number | null;
|
|
129
|
+
readonly error: {
|
|
130
|
+
readonly message: string;
|
|
131
|
+
readonly code: number;
|
|
132
|
+
readonly data?: unknown;
|
|
133
|
+
};
|
|
134
|
+
}, Schema.SchemaError, never>;
|
|
135
|
+
declare const decodeToolsListResult: (input: unknown, options?: import("effect/SchemaAST").ParseOptions) => Effect.Effect<{
|
|
136
|
+
readonly tools: readonly {
|
|
137
|
+
readonly name: string;
|
|
138
|
+
readonly description?: string | undefined;
|
|
139
|
+
readonly inputSchema?: unknown;
|
|
140
|
+
}[];
|
|
141
|
+
}, Schema.SchemaError, never>;
|
|
142
|
+
declare const decodeToolCallResult: (input: unknown, options?: import("effect/SchemaAST").ParseOptions) => Effect.Effect<{
|
|
143
|
+
readonly content?: readonly {
|
|
144
|
+
readonly [x: string]: unknown;
|
|
145
|
+
}[] | undefined;
|
|
146
|
+
readonly isError?: boolean | undefined;
|
|
147
|
+
readonly structuredContent?: unknown;
|
|
148
|
+
}, Schema.SchemaError, never>;
|
|
149
|
+
declare const encodeJsonRpcMessage: (server: string, message: JsonRpcRequest | JsonRpcNotification) => Effect.Effect<string, McpError, never>;
|
|
150
|
+
declare const decodeJsonRpcResponseFromJson: (server: string, text: string) => Effect.Effect<{
|
|
151
|
+
readonly jsonrpc: "2.0";
|
|
152
|
+
readonly id: string | number | null;
|
|
153
|
+
readonly result: unknown;
|
|
154
|
+
} | {
|
|
155
|
+
readonly jsonrpc: "2.0";
|
|
156
|
+
readonly id: string | number | null;
|
|
157
|
+
readonly error: {
|
|
158
|
+
readonly message: string;
|
|
159
|
+
readonly code: number;
|
|
160
|
+
readonly data?: unknown;
|
|
161
|
+
};
|
|
162
|
+
}, McpError, never>;
|
|
163
|
+
declare const decodeJsonRpcMessageFromJson: (server: string, text: string) => Effect.Effect<{
|
|
164
|
+
readonly jsonrpc: "2.0";
|
|
165
|
+
readonly id: string | number;
|
|
166
|
+
readonly method: string;
|
|
167
|
+
readonly params?: unknown;
|
|
168
|
+
} | {
|
|
169
|
+
readonly jsonrpc: "2.0";
|
|
170
|
+
readonly method: string;
|
|
171
|
+
readonly params?: unknown;
|
|
172
|
+
}, McpError, never>;
|
|
173
|
+
//#endregion
|
|
174
|
+
export { GenericContentBlock, JsonRpcErrorObject, JsonRpcErrorResponse, JsonRpcMessage, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, JsonRpcSuccessResponse, McpTool, TextContentBlock, ToolCallResult, ToolsListResult, decodeJsonRpcMessageFromJson, decodeJsonRpcResponse, decodeJsonRpcResponseFromJson, decodeToolCallResult, decodeToolsListResult, encodeJsonRpcMessage, jsonRpcErrorToMcpError, latestMcpProtocolVersion, makeInitializeParams, makeInitializedNotification, makeJsonRpcRequest, mcpToolToToolDef, sanitizeMcpName, toolCallResultToToolResult };
|
|
175
|
+
//# sourceMappingURL=protocol.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.mts","names":[],"sources":["../../src/client/protocol.ts"],"mappings":";;;;;;cAMa,wBAAA;AAAA,cAEA,kBAAA,EAAkB,MAAA,CAAA,MAAA;EAAA;;;;KAKnB,kBAAA,UAA4B,kBAAA,CAAmB,IAAI;AAAA,cAElD,sBAAA,EAAsB,MAAA,CAAA,MAAA;EAAA;;;;KAKvB,sBAAA,UAAgC,sBAAA,CAAuB,IAAI;AAAA,cAE1D,oBAAA,EAAoB,MAAA,CAAA,MAAA;EAAA;;;;;;;;KAKrB,oBAAA,UAA8B,oBAAA,CAAqB,IAAI;AAAA,cAEtD,eAAA,EAAe,MAAA,CAAA,KAAA,WAAA,MAAA,CAAA,MAAA;EAAA;;;;;;;;;;;;KAChB,eAAA,UAAyB,eAAA,CAAgB,IAAI;AAAA,cAE5C,cAAA,EAAc,MAAA,CAAA,MAAA;EAAA;;;;;KAMf,cAAA,UAAwB,cAAA,CAAe,IAAI;AAAA,cAE1C,mBAAA,EAAmB,MAAA,CAAA,MAAA;EAAA;;;;KAKpB,mBAAA,UAA6B,mBAAA,CAAoB,IAAI;AAAA,cAEpD,cAAA,EAAc,MAAA,CAAA,KAAA,WAAA,MAAA,CAAA,MAAA;EAAA;;;;;;;;;KACf,cAAA,UAAwB,cAAA,CAAe,IAAI;AAAA,cAE1C,OAAA,EAAO,MAAA,CAAA,MAAA;EAAA;;;;KAKR,OAAA,UAAiB,OAAA,CAAQ,IAAI;AAAA,cAE5B,eAAA,EAAe,MAAA,CAAA,MAAA;EAAA;;;;;;KAGhB,eAAA,UAAyB,eAAA,CAAgB,IAAI;AAAA,cAE5C,gBAAA,EAAgB,MAAA,CAAA,MAAA;EAAA;;;KAIjB,gBAAA,UAA0B,gBAAA,CAAiB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,cAyBlC,6BAAA,GAAiC,MAAA,UAAgB,IAAA,aAAY,MAAA,CAAA,MAAA;EAAA;;;;;;;;;;;GAYvE,QAAA;AAAA,cAEU,4BAAA,GAAgC,MAAA,UAAgB,IAAA,aAAY,MAAA,CAAA,MAAA;EAAA;;;;;;;;GAYtE,QAAA"}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { McpError } from "./errors.mjs";
|
|
2
|
+
import { Array, Effect, Option } from "effect";
|
|
3
|
+
import * as Schema from "effect/Schema";
|
|
4
|
+
import { AudioPart, ImagePart, TextPart, ToolDef, ToolResult } from "@yolk-sdk/agent/protocol";
|
|
5
|
+
//#region src/client/protocol.ts
|
|
6
|
+
const latestMcpProtocolVersion = "2024-11-05";
|
|
7
|
+
const JsonRpcErrorObject = Schema.Struct({
|
|
8
|
+
code: Schema.Number,
|
|
9
|
+
message: Schema.String,
|
|
10
|
+
data: Schema.optional(Schema.Unknown)
|
|
11
|
+
});
|
|
12
|
+
const JsonRpcSuccessResponse = Schema.Struct({
|
|
13
|
+
jsonrpc: Schema.Literal("2.0"),
|
|
14
|
+
id: Schema.Union([
|
|
15
|
+
Schema.String,
|
|
16
|
+
Schema.Number,
|
|
17
|
+
Schema.Null
|
|
18
|
+
]),
|
|
19
|
+
result: Schema.Unknown
|
|
20
|
+
});
|
|
21
|
+
const JsonRpcErrorResponse = Schema.Struct({
|
|
22
|
+
jsonrpc: Schema.Literal("2.0"),
|
|
23
|
+
id: Schema.Union([
|
|
24
|
+
Schema.String,
|
|
25
|
+
Schema.Number,
|
|
26
|
+
Schema.Null
|
|
27
|
+
]),
|
|
28
|
+
error: JsonRpcErrorObject
|
|
29
|
+
});
|
|
30
|
+
const JsonRpcResponse = Schema.Union([JsonRpcSuccessResponse, JsonRpcErrorResponse]);
|
|
31
|
+
const JsonRpcRequest = Schema.Struct({
|
|
32
|
+
jsonrpc: Schema.Literal("2.0"),
|
|
33
|
+
id: Schema.Union([Schema.String, Schema.Number]),
|
|
34
|
+
method: Schema.String,
|
|
35
|
+
params: Schema.optional(Schema.Unknown)
|
|
36
|
+
});
|
|
37
|
+
const JsonRpcNotification = Schema.Struct({
|
|
38
|
+
jsonrpc: Schema.Literal("2.0"),
|
|
39
|
+
method: Schema.String,
|
|
40
|
+
params: Schema.optional(Schema.Unknown)
|
|
41
|
+
});
|
|
42
|
+
const JsonRpcMessage = Schema.Union([JsonRpcRequest, JsonRpcNotification]);
|
|
43
|
+
const McpTool = Schema.Struct({
|
|
44
|
+
name: Schema.String,
|
|
45
|
+
description: Schema.optional(Schema.String),
|
|
46
|
+
inputSchema: Schema.optional(Schema.Unknown)
|
|
47
|
+
});
|
|
48
|
+
const ToolsListResult = Schema.Struct({ tools: Schema.Array(McpTool) });
|
|
49
|
+
const TextContentBlock = Schema.Struct({
|
|
50
|
+
type: Schema.Literal("text"),
|
|
51
|
+
text: Schema.String
|
|
52
|
+
});
|
|
53
|
+
const GenericContentBlock = Schema.Record(Schema.String, Schema.Unknown);
|
|
54
|
+
const EmbeddedResourceContentBlock = Schema.Struct({
|
|
55
|
+
type: Schema.Literal("resource"),
|
|
56
|
+
resource: Schema.Struct({
|
|
57
|
+
uri: Schema.optional(Schema.String),
|
|
58
|
+
text: Schema.optional(Schema.String),
|
|
59
|
+
blob: Schema.optional(Schema.String),
|
|
60
|
+
mimeType: Schema.optional(Schema.String)
|
|
61
|
+
})
|
|
62
|
+
});
|
|
63
|
+
const ResourceLinkContentBlock = Schema.Struct({
|
|
64
|
+
type: Schema.Literal("resource_link"),
|
|
65
|
+
uri: Schema.String,
|
|
66
|
+
name: Schema.optional(Schema.String),
|
|
67
|
+
mimeType: Schema.optional(Schema.String)
|
|
68
|
+
});
|
|
69
|
+
const ToolCallResult = Schema.Struct({
|
|
70
|
+
content: Schema.optional(Schema.Array(GenericContentBlock)),
|
|
71
|
+
isError: Schema.optional(Schema.Boolean),
|
|
72
|
+
structuredContent: Schema.optional(Schema.Unknown)
|
|
73
|
+
});
|
|
74
|
+
const makeJsonRpcRequest = (input) => ({
|
|
75
|
+
jsonrpc: "2.0",
|
|
76
|
+
id: input.id,
|
|
77
|
+
method: input.method,
|
|
78
|
+
...input.params === void 0 ? {} : { params: input.params }
|
|
79
|
+
});
|
|
80
|
+
const makeInitializedNotification = () => ({
|
|
81
|
+
jsonrpc: "2.0",
|
|
82
|
+
method: "notifications/initialized"
|
|
83
|
+
});
|
|
84
|
+
const makeInitializeParams = (input) => ({
|
|
85
|
+
protocolVersion: latestMcpProtocolVersion,
|
|
86
|
+
capabilities: {},
|
|
87
|
+
clientInfo: {
|
|
88
|
+
name: input.name,
|
|
89
|
+
version: input.version
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
const jsonRpcErrorToMcpError = (server, error) => new McpError({
|
|
93
|
+
server,
|
|
94
|
+
message: `MCP JSON-RPC error ${error.code}: ${error.message}`,
|
|
95
|
+
cause: "protocol"
|
|
96
|
+
});
|
|
97
|
+
const mcpToolToToolDef = (input) => ToolDef.make({
|
|
98
|
+
name: `${sanitizeMcpName(input.serverName)}_${sanitizeMcpName(input.tool.name)}`,
|
|
99
|
+
description: input.tool.description ?? `MCP tool ${input.serverName}/${input.tool.name}`,
|
|
100
|
+
parameters: input.tool.inputSchema ?? {
|
|
101
|
+
type: "object",
|
|
102
|
+
additionalProperties: true
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
const sanitizeMcpName = (name) => {
|
|
106
|
+
const sanitized = name.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
107
|
+
return sanitized.length === 0 ? "mcp" : sanitized;
|
|
108
|
+
};
|
|
109
|
+
const stringProperty = (block, key) => {
|
|
110
|
+
const value = block[key];
|
|
111
|
+
return typeof value === "string" ? Option.some(value) : Option.none();
|
|
112
|
+
};
|
|
113
|
+
const audioFormatFromMimeType = (mimeType) => {
|
|
114
|
+
switch (mimeType) {
|
|
115
|
+
case "audio/pcm":
|
|
116
|
+
case "audio/pcm16": return Option.some("pcm16");
|
|
117
|
+
case "audio/wav":
|
|
118
|
+
case "audio/wave":
|
|
119
|
+
case "audio/x-wav": return Option.some("wav");
|
|
120
|
+
case "audio/mpeg":
|
|
121
|
+
case "audio/mp3": return Option.some("mp3");
|
|
122
|
+
case "audio/opus":
|
|
123
|
+
case "audio/ogg; codecs=opus": return Option.some("opus");
|
|
124
|
+
default: return Option.none();
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
const contentBlockText = (block) => {
|
|
128
|
+
const type = block["type"];
|
|
129
|
+
const text = stringProperty(block, "text");
|
|
130
|
+
if (type === "text") return text;
|
|
131
|
+
return Option.none();
|
|
132
|
+
};
|
|
133
|
+
const fallbackTextForContentBlock = (block) => {
|
|
134
|
+
const type = stringProperty(block, "type").pipe(Option.getOrElse(() => "unknown"));
|
|
135
|
+
const name = stringProperty(block, "name");
|
|
136
|
+
const uri = stringProperty(block, "uri");
|
|
137
|
+
const url = stringProperty(block, "url");
|
|
138
|
+
const label = Option.getOrElse(Option.firstSomeOf([
|
|
139
|
+
name,
|
|
140
|
+
uri,
|
|
141
|
+
url
|
|
142
|
+
]), () => type);
|
|
143
|
+
switch (type) {
|
|
144
|
+
case "resource": return `MCP resource: ${label}`;
|
|
145
|
+
case "resource_link": return `MCP resource link: ${label}`;
|
|
146
|
+
case "image": return `MCP image: ${label}`;
|
|
147
|
+
case "audio": return `MCP audio: ${label}`;
|
|
148
|
+
default: return `Unsupported MCP ${type} content.`;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
const embeddedResourceText = (block) => Schema.decodeUnknownOption(EmbeddedResourceContentBlock)(block).pipe(Option.flatMap(({ resource }) => {
|
|
152
|
+
if (resource.text !== void 0) return Option.some(resource.text);
|
|
153
|
+
return Option.all({
|
|
154
|
+
uri: Option.fromNullishOr(resource.uri),
|
|
155
|
+
blob: Option.fromNullishOr(resource.blob)
|
|
156
|
+
}).pipe(Option.map(({ uri, blob }) => `MCP resource: ${uri}\n${blob}`));
|
|
157
|
+
}));
|
|
158
|
+
const resourceLinkText = (block) => Schema.decodeUnknownOption(ResourceLinkContentBlock)(block).pipe(Option.map(({ name, uri }) => {
|
|
159
|
+
return `MCP resource link: ${name ?? uri} (${uri})`;
|
|
160
|
+
}));
|
|
161
|
+
const imagePartFromBlock = (block) => Option.all({
|
|
162
|
+
data: stringProperty(block, "data"),
|
|
163
|
+
mimeType: stringProperty(block, "mimeType")
|
|
164
|
+
}).pipe(Option.map(({ data, mimeType }) => ImagePart.make({
|
|
165
|
+
data,
|
|
166
|
+
mimeType
|
|
167
|
+
})));
|
|
168
|
+
const audioPartFromBlock = (block) => Option.all({
|
|
169
|
+
data: stringProperty(block, "data"),
|
|
170
|
+
mimeType: stringProperty(block, "mimeType")
|
|
171
|
+
}).pipe(Option.flatMap(({ data, mimeType }) => audioFormatFromMimeType(mimeType).pipe(Option.map((format) => AudioPart.make({
|
|
172
|
+
data,
|
|
173
|
+
format
|
|
174
|
+
})))));
|
|
175
|
+
const contentPartFromBlock = (block) => {
|
|
176
|
+
const type = block["type"];
|
|
177
|
+
if (type === "text") return TextPart.make({ text: Option.getOrElse(contentBlockText(block), () => "") });
|
|
178
|
+
if (type === "image") return Option.getOrElse(imagePartFromBlock(block), () => TextPart.make({ text: fallbackTextForContentBlock(block) }));
|
|
179
|
+
if (type === "audio") return Option.getOrElse(audioPartFromBlock(block), () => TextPart.make({ text: fallbackTextForContentBlock(block) }));
|
|
180
|
+
if (type === "resource") return TextPart.make({ text: embeddedResourceText(block).pipe(Option.getOrElse(() => fallbackTextForContentBlock(block))) });
|
|
181
|
+
if (type === "resource_link") return TextPart.make({ text: resourceLinkText(block).pipe(Option.getOrElse(() => fallbackTextForContentBlock(block))) });
|
|
182
|
+
return TextPart.make({ text: fallbackTextForContentBlock(block) });
|
|
183
|
+
};
|
|
184
|
+
const contentFromBlocks = (blocks) => {
|
|
185
|
+
const textBlocks = Array.getSomes(Array.map(blocks, contentBlockText));
|
|
186
|
+
if (textBlocks.length === blocks.length) return textBlocks.join("\n");
|
|
187
|
+
return Array.map(blocks, contentPartFromBlock);
|
|
188
|
+
};
|
|
189
|
+
const toolCallResultToToolResult = (input) => {
|
|
190
|
+
const content = input.result.content ?? [];
|
|
191
|
+
const resultContent = content.length > 0 ? contentFromBlocks(content) : input.result.structuredContent === void 0 ? "Unsupported MCP tool content." : "Structured MCP tool result.";
|
|
192
|
+
return ToolResult.make({
|
|
193
|
+
toolCallId: input.toolCallId,
|
|
194
|
+
content: resultContent,
|
|
195
|
+
isError: input.result.isError,
|
|
196
|
+
structuredContent: input.result.structuredContent
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
const decodeJsonRpcResponse = Schema.decodeUnknownEffect(JsonRpcResponse);
|
|
200
|
+
const decodeToolsListResult = Schema.decodeUnknownEffect(ToolsListResult);
|
|
201
|
+
const decodeToolCallResult = Schema.decodeUnknownEffect(ToolCallResult);
|
|
202
|
+
const encodeJsonRpcMessage = (server, message) => Schema.encodeUnknownEffect(Schema.UnknownFromJsonString)(message).pipe(Effect.mapError((error) => new McpError({
|
|
203
|
+
server,
|
|
204
|
+
message: `Could not encode MCP JSON-RPC message: ${String(error)}`,
|
|
205
|
+
cause: "encoding"
|
|
206
|
+
})));
|
|
207
|
+
const decodeJsonString = (server, text) => Schema.decodeUnknownEffect(Schema.UnknownFromJsonString)(text).pipe(Effect.mapError((error) => new McpError({
|
|
208
|
+
server,
|
|
209
|
+
message: `Malformed MCP JSON: ${String(error)}`,
|
|
210
|
+
cause: "parse"
|
|
211
|
+
})));
|
|
212
|
+
const decodeJsonRpcResponseFromJson = (server, text) => decodeJsonString(server, text).pipe(Effect.flatMap(decodeJsonRpcResponse), Effect.mapError((error) => error instanceof McpError ? error : new McpError({
|
|
213
|
+
server,
|
|
214
|
+
message: `Invalid MCP JSON-RPC response: ${String(error)}`,
|
|
215
|
+
cause: "validation"
|
|
216
|
+
})));
|
|
217
|
+
const decodeJsonRpcMessageFromJson = (server, text) => decodeJsonString(server, text).pipe(Effect.flatMap(Schema.decodeUnknownEffect(JsonRpcMessage)), Effect.mapError((error) => error instanceof McpError ? error : new McpError({
|
|
218
|
+
server,
|
|
219
|
+
message: `Invalid MCP JSON-RPC message: ${String(error)}`,
|
|
220
|
+
cause: "validation"
|
|
221
|
+
})));
|
|
222
|
+
//#endregion
|
|
223
|
+
export { GenericContentBlock, JsonRpcErrorObject, JsonRpcErrorResponse, JsonRpcMessage, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, JsonRpcSuccessResponse, McpTool, TextContentBlock, ToolCallResult, ToolsListResult, decodeJsonRpcMessageFromJson, decodeJsonRpcResponse, decodeJsonRpcResponseFromJson, decodeToolCallResult, decodeToolsListResult, encodeJsonRpcMessage, jsonRpcErrorToMcpError, latestMcpProtocolVersion, makeInitializeParams, makeInitializedNotification, makeJsonRpcRequest, mcpToolToToolDef, sanitizeMcpName, toolCallResultToToolResult };
|
|
224
|
+
|
|
225
|
+
//# sourceMappingURL=protocol.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.mjs","names":["Arr"],"sources":["../../src/client/protocol.ts"],"sourcesContent":["import { Array as Arr, Effect, Option } from 'effect'\nimport * as Schema from 'effect/Schema'\nimport { AudioPart, ImagePart, TextPart, ToolDef, ToolResult } from '@yolk-sdk/agent/protocol'\nimport type { Content, ContentPart } from '@yolk-sdk/agent/protocol'\nimport { McpError } from './errors.ts'\n\nexport const latestMcpProtocolVersion = '2024-11-05'\n\nexport const JsonRpcErrorObject = Schema.Struct({\n code: Schema.Number,\n message: Schema.String,\n data: Schema.optional(Schema.Unknown)\n})\nexport type JsonRpcErrorObject = typeof JsonRpcErrorObject.Type\n\nexport const JsonRpcSuccessResponse = Schema.Struct({\n jsonrpc: Schema.Literal('2.0'),\n id: Schema.Union([Schema.String, Schema.Number, Schema.Null]),\n result: Schema.Unknown\n})\nexport type JsonRpcSuccessResponse = typeof JsonRpcSuccessResponse.Type\n\nexport const JsonRpcErrorResponse = Schema.Struct({\n jsonrpc: Schema.Literal('2.0'),\n id: Schema.Union([Schema.String, Schema.Number, Schema.Null]),\n error: JsonRpcErrorObject\n})\nexport type JsonRpcErrorResponse = typeof JsonRpcErrorResponse.Type\n\nexport const JsonRpcResponse = Schema.Union([JsonRpcSuccessResponse, JsonRpcErrorResponse])\nexport type JsonRpcResponse = typeof JsonRpcResponse.Type\n\nexport const JsonRpcRequest = Schema.Struct({\n jsonrpc: Schema.Literal('2.0'),\n id: Schema.Union([Schema.String, Schema.Number]),\n method: Schema.String,\n params: Schema.optional(Schema.Unknown)\n})\nexport type JsonRpcRequest = typeof JsonRpcRequest.Type\n\nexport const JsonRpcNotification = Schema.Struct({\n jsonrpc: Schema.Literal('2.0'),\n method: Schema.String,\n params: Schema.optional(Schema.Unknown)\n})\nexport type JsonRpcNotification = typeof JsonRpcNotification.Type\n\nexport const JsonRpcMessage = Schema.Union([JsonRpcRequest, JsonRpcNotification])\nexport type JsonRpcMessage = typeof JsonRpcMessage.Type\n\nexport const McpTool = Schema.Struct({\n name: Schema.String,\n description: Schema.optional(Schema.String),\n inputSchema: Schema.optional(Schema.Unknown)\n})\nexport type McpTool = typeof McpTool.Type\n\nexport const ToolsListResult = Schema.Struct({\n tools: Schema.Array(McpTool)\n})\nexport type ToolsListResult = typeof ToolsListResult.Type\n\nexport const TextContentBlock = Schema.Struct({\n type: Schema.Literal('text'),\n text: Schema.String\n})\nexport type TextContentBlock = typeof TextContentBlock.Type\n\nexport const GenericContentBlock = Schema.Record(Schema.String, Schema.Unknown)\nexport type GenericContentBlock = typeof GenericContentBlock.Type\n\nconst EmbeddedResourceContentBlock = Schema.Struct({\n type: Schema.Literal('resource'),\n resource: Schema.Struct({\n uri: Schema.optional(Schema.String),\n text: Schema.optional(Schema.String),\n blob: Schema.optional(Schema.String),\n mimeType: Schema.optional(Schema.String)\n })\n})\n\nconst ResourceLinkContentBlock = Schema.Struct({\n type: Schema.Literal('resource_link'),\n uri: Schema.String,\n name: Schema.optional(Schema.String),\n mimeType: Schema.optional(Schema.String)\n})\n\nexport const ToolCallResult = Schema.Struct({\n content: Schema.optional(Schema.Array(GenericContentBlock)),\n isError: Schema.optional(Schema.Boolean),\n structuredContent: Schema.optional(Schema.Unknown)\n})\nexport type ToolCallResult = typeof ToolCallResult.Type\n\nexport const makeJsonRpcRequest = (input: {\n readonly id: string | number\n readonly method: string\n readonly params?: unknown\n}): JsonRpcRequest => ({\n jsonrpc: '2.0',\n id: input.id,\n method: input.method,\n ...(input.params === undefined ? {} : { params: input.params })\n})\n\nexport const makeInitializedNotification = (): JsonRpcNotification => ({\n jsonrpc: '2.0',\n method: 'notifications/initialized'\n})\n\nexport const makeInitializeParams = (input: {\n readonly name: string\n readonly version: string\n}) => ({\n protocolVersion: latestMcpProtocolVersion,\n capabilities: {},\n clientInfo: {\n name: input.name,\n version: input.version\n }\n})\n\nexport const jsonRpcErrorToMcpError = (server: string, error: JsonRpcErrorObject) =>\n new McpError({\n server,\n message: `MCP JSON-RPC error ${error.code}: ${error.message}`,\n cause: 'protocol'\n })\n\nexport const mcpToolToToolDef = (input: { readonly serverName: string; readonly tool: McpTool }) =>\n ToolDef.make({\n name: `${sanitizeMcpName(input.serverName)}_${sanitizeMcpName(input.tool.name)}`,\n description: input.tool.description ?? `MCP tool ${input.serverName}/${input.tool.name}`,\n parameters: input.tool.inputSchema ?? { type: 'object', additionalProperties: true }\n })\n\nexport const sanitizeMcpName = (name: string) => {\n const sanitized = name.replace(/[^a-zA-Z0-9_-]/g, '_')\n return sanitized.length === 0 ? 'mcp' : sanitized\n}\n\nconst stringProperty = (block: GenericContentBlock, key: string) => {\n const value = block[key]\n\n return typeof value === 'string' ? Option.some(value) : Option.none<string>()\n}\n\nconst audioFormatFromMimeType = (\n mimeType: string\n): Option.Option<'pcm16' | 'wav' | 'mp3' | 'opus'> => {\n switch (mimeType) {\n case 'audio/pcm':\n case 'audio/pcm16':\n return Option.some('pcm16')\n case 'audio/wav':\n case 'audio/wave':\n case 'audio/x-wav':\n return Option.some('wav')\n case 'audio/mpeg':\n case 'audio/mp3':\n return Option.some('mp3')\n case 'audio/opus':\n case 'audio/ogg; codecs=opus':\n return Option.some('opus')\n default:\n return Option.none<'pcm16' | 'wav' | 'mp3' | 'opus'>()\n }\n}\n\nconst contentBlockText = (block: GenericContentBlock): Option.Option<string> => {\n const type = block['type']\n const text = stringProperty(block, 'text')\n\n if (type === 'text') {\n return text\n }\n\n return Option.none()\n}\n\nconst fallbackTextForContentBlock = (block: GenericContentBlock) => {\n const type = stringProperty(block, 'type').pipe(Option.getOrElse(() => 'unknown'))\n const name = stringProperty(block, 'name')\n const uri = stringProperty(block, 'uri')\n const url = stringProperty(block, 'url')\n const label = Option.getOrElse(Option.firstSomeOf([name, uri, url]), () => type)\n\n switch (type) {\n case 'resource':\n return `MCP resource: ${label}`\n case 'resource_link':\n return `MCP resource link: ${label}`\n case 'image':\n return `MCP image: ${label}`\n case 'audio':\n return `MCP audio: ${label}`\n default:\n return `Unsupported MCP ${type} content.`\n }\n}\n\nconst embeddedResourceText = (block: GenericContentBlock): Option.Option<string> =>\n Schema.decodeUnknownOption(EmbeddedResourceContentBlock)(block).pipe(\n Option.flatMap(({ resource }) => {\n if (resource.text !== undefined) {\n return Option.some(resource.text)\n }\n\n return Option.all({\n uri: Option.fromNullishOr(resource.uri),\n blob: Option.fromNullishOr(resource.blob)\n }).pipe(Option.map(({ uri, blob }) => `MCP resource: ${uri}\\n${blob}`))\n })\n )\n\nconst resourceLinkText = (block: GenericContentBlock): Option.Option<string> =>\n Schema.decodeUnknownOption(ResourceLinkContentBlock)(block).pipe(\n Option.map(({ name, uri }) => {\n const label = name ?? uri\n return `MCP resource link: ${label} (${uri})`\n })\n )\n\nconst imagePartFromBlock = (block: GenericContentBlock): Option.Option<ContentPart> =>\n Option.all({\n data: stringProperty(block, 'data'),\n mimeType: stringProperty(block, 'mimeType')\n }).pipe(Option.map(({ data, mimeType }) => ImagePart.make({ data, mimeType })))\n\nconst audioPartFromBlock = (block: GenericContentBlock): Option.Option<ContentPart> =>\n Option.all({\n data: stringProperty(block, 'data'),\n mimeType: stringProperty(block, 'mimeType')\n }).pipe(\n Option.flatMap(({ data, mimeType }) =>\n audioFormatFromMimeType(mimeType).pipe(Option.map(format => AudioPart.make({ data, format })))\n )\n )\n\nconst contentPartFromBlock = (block: GenericContentBlock): ContentPart => {\n const type = block['type']\n\n if (type === 'text') {\n return TextPart.make({ text: Option.getOrElse(contentBlockText(block), () => '') })\n }\n\n if (type === 'image') {\n return Option.getOrElse(imagePartFromBlock(block), () =>\n TextPart.make({ text: fallbackTextForContentBlock(block) })\n )\n }\n\n if (type === 'audio') {\n return Option.getOrElse(audioPartFromBlock(block), () =>\n TextPart.make({ text: fallbackTextForContentBlock(block) })\n )\n }\n\n if (type === 'resource') {\n return TextPart.make({\n text: embeddedResourceText(block).pipe(\n Option.getOrElse(() => fallbackTextForContentBlock(block))\n )\n })\n }\n\n if (type === 'resource_link') {\n return TextPart.make({\n text: resourceLinkText(block).pipe(Option.getOrElse(() => fallbackTextForContentBlock(block)))\n })\n }\n\n return TextPart.make({ text: fallbackTextForContentBlock(block) })\n}\n\nconst contentFromBlocks = (blocks: ReadonlyArray<GenericContentBlock>): Content => {\n const textBlocks = Arr.getSomes(Arr.map(blocks, contentBlockText))\n\n if (textBlocks.length === blocks.length) {\n return textBlocks.join('\\n')\n }\n\n return Arr.map(blocks, contentPartFromBlock)\n}\n\nexport const toolCallResultToToolResult = (input: {\n readonly toolCallId: string\n readonly result: ToolCallResult\n}) => {\n const content = input.result.content ?? []\n const resultContent =\n content.length > 0\n ? contentFromBlocks(content)\n : input.result.structuredContent === undefined\n ? 'Unsupported MCP tool content.'\n : 'Structured MCP tool result.'\n\n return ToolResult.make({\n toolCallId: input.toolCallId,\n content: resultContent,\n isError: input.result.isError,\n structuredContent: input.result.structuredContent\n })\n}\n\nexport const decodeJsonRpcResponse = Schema.decodeUnknownEffect(JsonRpcResponse)\nexport const decodeToolsListResult = Schema.decodeUnknownEffect(ToolsListResult)\nexport const decodeToolCallResult = Schema.decodeUnknownEffect(ToolCallResult)\n\nexport const encodeJsonRpcMessage = (\n server: string,\n message: JsonRpcRequest | JsonRpcNotification\n) =>\n Schema.encodeUnknownEffect(Schema.UnknownFromJsonString)(message).pipe(\n Effect.mapError(\n error =>\n new McpError({\n server,\n message: `Could not encode MCP JSON-RPC message: ${String(error)}`,\n cause: 'encoding'\n })\n )\n )\n\nconst decodeJsonString = (server: string, text: string) =>\n Schema.decodeUnknownEffect(Schema.UnknownFromJsonString)(text).pipe(\n Effect.mapError(\n error =>\n new McpError({\n server,\n message: `Malformed MCP JSON: ${String(error)}`,\n cause: 'parse'\n })\n )\n )\n\nexport const decodeJsonRpcResponseFromJson = (server: string, text: string) =>\n decodeJsonString(server, text).pipe(\n Effect.flatMap(decodeJsonRpcResponse),\n Effect.mapError(error =>\n error instanceof McpError\n ? error\n : new McpError({\n server,\n message: `Invalid MCP JSON-RPC response: ${String(error)}`,\n cause: 'validation'\n })\n )\n )\n\nexport const decodeJsonRpcMessageFromJson = (server: string, text: string) =>\n decodeJsonString(server, text).pipe(\n Effect.flatMap(Schema.decodeUnknownEffect(JsonRpcMessage)),\n Effect.mapError(error =>\n error instanceof McpError\n ? error\n : new McpError({\n server,\n message: `Invalid MCP JSON-RPC message: ${String(error)}`,\n cause: 'validation'\n })\n )\n )\n"],"mappings":";;;;;AAMA,MAAa,2BAA2B;AAExC,MAAa,qBAAqB,OAAO,OAAO;CAC9C,MAAM,OAAO;CACb,SAAS,OAAO;CAChB,MAAM,OAAO,SAAS,OAAO,OAAO;AACtC,CAAC;AAGD,MAAa,yBAAyB,OAAO,OAAO;CAClD,SAAS,OAAO,QAAQ,KAAK;CAC7B,IAAI,OAAO,MAAM;EAAC,OAAO;EAAQ,OAAO;EAAQ,OAAO;CAAI,CAAC;CAC5D,QAAQ,OAAO;AACjB,CAAC;AAGD,MAAa,uBAAuB,OAAO,OAAO;CAChD,SAAS,OAAO,QAAQ,KAAK;CAC7B,IAAI,O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AC7B,OAAO,QAAQ,qBAAqB,GACpC,OAAO,UAAS,UACd,iBAAiB,WACb,QACA,IAAI,SAAS;CACX;CACA,SAAS,kCAAkC,OAAO,KAAK;CACvD,OAAO;AACT,CAAC,CACP,CACF;AAEF,MAAa,gCAAgC,QAAgB,SAC3D,iBAAiB,QAAQ,IAAI,EAAE,KAC7B,OAAO,QAAQ,OAAO,oBAAoB,cAAc,CAAC,GACzD,OAAO,UAAS,UACd,iBAAiB,WACb,QACA,IAAI,SAAS;CACX;CACA,SAAS,iCAAiC,OAAO,KAAK;CACtD,OAAO;AACT,CAAC,CACP,CACF"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
|
|
3
|
+
//#region src/server/errors.d.ts
|
|
4
|
+
declare const McpServerError_base: Schema.Class<McpServerError, Schema.TaggedStruct<"McpServerError", {
|
|
5
|
+
readonly message: Schema.String;
|
|
6
|
+
readonly cause: Schema.Literals<readonly ["parse", "validation", "protocol", "tool_error", "encoding"]>;
|
|
7
|
+
}>, import("effect/Cause").YieldableError>;
|
|
8
|
+
declare class McpServerError extends McpServerError_base {}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { McpServerError };
|
|
11
|
+
//# sourceMappingURL=errors.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.mts","names":[],"sources":["../../src/server/errors.ts"],"mappings":";;;cAAuC,mBAAA;;;;cAE1B,cAAA,SAAuB,mBAGlC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
//#region src/server/errors.ts
|
|
3
|
+
var McpServerError = class extends Schema.TaggedErrorClass()("McpServerError", {
|
|
4
|
+
message: Schema.String,
|
|
5
|
+
cause: Schema.Literals([
|
|
6
|
+
"parse",
|
|
7
|
+
"validation",
|
|
8
|
+
"protocol",
|
|
9
|
+
"tool_error",
|
|
10
|
+
"encoding"
|
|
11
|
+
])
|
|
12
|
+
}) {};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { McpServerError };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=errors.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.mjs","names":[],"sources":["../../src/server/errors.ts"],"sourcesContent":["import * as Schema from 'effect/Schema'\n\nexport class McpServerError extends Schema.TaggedErrorClass<McpServerError>()('McpServerError', {\n message: Schema.String,\n cause: Schema.Literals(['parse', 'validation', 'protocol', 'tool_error', 'encoding'])\n}) {}\n"],"mappings":";;AAEA,IAAa,iBAAb,cAAoC,OAAO,iBAAiC,EAAE,kBAAkB;CAC9F,SAAS,OAAO;CAChB,OAAO,OAAO,SAAS;EAAC;EAAS;EAAc;EAAY;EAAc;CAAU,CAAC;AACtF,CAAC,EAAE,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { McpServerError } from "./errors.mjs";
|
|
2
|
+
import { McpServerTool, McpToolServer, makeMcpToolServer } from "./server.mjs";
|
|
3
|
+
import { runStdioMcpServer } from "./stdio.mjs";
|
|
4
|
+
export { McpServerError, type McpServerTool, type McpToolServer, makeMcpToolServer, runStdioMcpServer };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { McpServerError } from "./errors.mjs";
|
|
2
|
+
import { Effect, Option } from "effect";
|
|
3
|
+
import { ToolCall, ToolDef, ToolResult } from "@yolk-sdk/agent/protocol";
|
|
4
|
+
|
|
5
|
+
//#region src/server/server.d.ts
|
|
6
|
+
type McpServerTool<R = never> = {
|
|
7
|
+
readonly def: ToolDef;
|
|
8
|
+
readonly execute: (call: ToolCall) => Effect.Effect<ToolResult, McpServerError, R>;
|
|
9
|
+
};
|
|
10
|
+
type McpToolServer<R = never> = {
|
|
11
|
+
readonly handleLine: (line: string) => Effect.Effect<Option.Option<string>, McpServerError, R>;
|
|
12
|
+
readonly handleJson: (body: string) => Effect.Effect<string, McpServerError, R>;
|
|
13
|
+
readonly handleHttpRequest: (request: Request) => Effect.Effect<Response, never, R>;
|
|
14
|
+
};
|
|
15
|
+
declare const makeMcpToolServer: <R>(input: {
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly version: string;
|
|
18
|
+
readonly tools: ReadonlyArray<McpServerTool<R>>;
|
|
19
|
+
}) => McpToolServer<R>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { McpServerTool, McpToolServer, makeMcpToolServer };
|
|
22
|
+
//# sourceMappingURL=server.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.mts","names":[],"sources":["../../src/server/server.ts"],"mappings":";;;;;KAkLY,aAAA;EAAA,SACD,GAAA,EAAK,OAAA;EAAA,SACL,OAAA,GAAU,IAAA,EAAM,QAAA,KAAa,MAAA,CAAO,MAAA,CAAO,UAAA,EAAY,cAAA,EAAgB,CAAA;AAAA;AAAA,KAGtE,aAAA;EAAA,SACD,UAAA,GAAa,IAAA,aAAiB,MAAA,CAAO,MAAA,CAAO,MAAA,CAAO,MAAA,UAAgB,cAAA,EAAgB,CAAA;EAAA,SACnF,UAAA,GAAa,IAAA,aAAiB,MAAA,CAAO,MAAA,SAAe,cAAA,EAAgB,CAAA;EAAA,SACpE,iBAAA,GAAoB,OAAA,EAAS,OAAA,KAAY,MAAA,CAAO,MAAA,CAAO,QAAA,SAAiB,CAAA;AAAA;AAAA,cA0BtE,iBAAA,MAAwB,KAAA;EAAA,SAC1B,IAAA;EAAA,SACA,OAAA;EAAA,SACA,KAAA,EAAO,aAAA,CAAc,aAAA,CAAc,CAAA;AAAA,MAC1C,aAAA,CAAc,CAAA"}
|