@mcp-web/types 0.1.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 +201 -0
- package/dist/apps.d.ts +125 -0
- package/dist/apps.d.ts.map +1 -0
- package/dist/apps.js +50 -0
- package/dist/apps.js.map +1 -0
- package/dist/config.d.ts +51 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +48 -0
- package/dist/config.js.map +1 -0
- package/dist/errors.d.ts +54 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +35 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp.d.ts +60 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +21 -0
- package/dist/mcp.js.map +1 -0
- package/dist/query.d.ts +127 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +71 -0
- package/dist/query.js.map +1 -0
- package/dist/resources.d.ts +108 -0
- package/dist/resources.d.ts.map +1 -0
- package/dist/resources.js +47 -0
- package/dist/resources.js.map +1 -0
- package/dist/tools.d.ts +114 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +55 -0
- package/dist/tools.js.map +1 -0
- package/package.json +38 -0
package/dist/mcp.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ListPromptsResult, ListResourcesResult, ListToolsResult } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
export declare const McpRequestMetaParamsSchema: z.ZodObject<{
|
|
4
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
5
|
+
queryId: z.ZodOptional<z.ZodString>;
|
|
6
|
+
}, z.core.$strip>;
|
|
7
|
+
export type McpRequestMetaParams = z.infer<typeof McpRequestMetaParamsSchema>;
|
|
8
|
+
export interface AvailableSession {
|
|
9
|
+
session_id: string;
|
|
10
|
+
session_name: string | undefined;
|
|
11
|
+
origin: string;
|
|
12
|
+
page_title: string | undefined;
|
|
13
|
+
connected_at: string;
|
|
14
|
+
last_activity: string;
|
|
15
|
+
available_tools: string[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Fatal error with no recoverable data.
|
|
19
|
+
* These should be thrown/sent as JSON-RPC errors.
|
|
20
|
+
*/
|
|
21
|
+
export interface FatalError {
|
|
22
|
+
error: string;
|
|
23
|
+
error_message: string;
|
|
24
|
+
error_is_fatal: true;
|
|
25
|
+
error_details?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Recoverable error with partial data.
|
|
29
|
+
* These should be returned in the JSON-RPC result with isError: true.
|
|
30
|
+
* Includes [key: string]: unknown for context like available_sessions.
|
|
31
|
+
*/
|
|
32
|
+
export interface RecoverableError {
|
|
33
|
+
isError: true;
|
|
34
|
+
error: string;
|
|
35
|
+
error_message: string;
|
|
36
|
+
error_is_fatal: false;
|
|
37
|
+
[key: string]: unknown;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* List tools result with recoverable error and session context.
|
|
41
|
+
*/
|
|
42
|
+
export type ErroredListToolsResult = ListToolsResult & RecoverableError & {
|
|
43
|
+
available_sessions: AvailableSession[];
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* List resources result with recoverable error and session context.
|
|
47
|
+
*/
|
|
48
|
+
export type ErroredListResourcesResult = ListResourcesResult & RecoverableError & {
|
|
49
|
+
available_sessions: AvailableSession[];
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* List prompts result with recoverable error and session context.
|
|
53
|
+
*/
|
|
54
|
+
export type ErroredListPromptsResult = ListPromptsResult & RecoverableError & {
|
|
55
|
+
available_sessions: AvailableSession[];
|
|
56
|
+
};
|
|
57
|
+
export declare function isErroredListToolsResult(result: ListToolsResult | ErroredListToolsResult): result is ErroredListToolsResult;
|
|
58
|
+
export declare function isErroredListResourcesResult(result: ListResourcesResult | ErroredListResourcesResult): result is ErroredListResourcesResult;
|
|
59
|
+
export declare function isErroredListPromptsResult(result: ListPromptsResult | ErroredListPromptsResult): result is ErroredListPromptsResult;
|
|
60
|
+
//# sourceMappingURL=mcp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EAChB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,0BAA0B;;;iBAGrC,CAAC;AAEH,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAE9E,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,IAAI,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,IAAI,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,KAAK,CAAC;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,eAAe,GAAG,gBAAgB,GAAG;IACxE,kBAAkB,EAAE,gBAAgB,EAAE,CAAC;CACxC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,0BAA0B,GAAG,mBAAmB,GAAG,gBAAgB,GAAG;IAChF,kBAAkB,EAAE,gBAAgB,EAAE,CAAC;CACxC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,iBAAiB,GAAG,gBAAgB,GAAG;IAC5E,kBAAkB,EAAE,gBAAgB,EAAE,CAAC;CACxC,CAAC;AASF,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,eAAe,GAAG,sBAAsB,GAAG,MAAM,IAAI,sBAAsB,CAE3H;AAED,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,mBAAmB,GAAG,0BAA0B,GAAG,MAAM,IAAI,0BAA0B,CAE3I;AAED,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,iBAAiB,GAAG,wBAAwB,GAAG,MAAM,IAAI,wBAAwB,CAEnI"}
|
package/dist/mcp.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const McpRequestMetaParamsSchema = z.object({
|
|
3
|
+
sessionId: z.string().optional(),
|
|
4
|
+
queryId: z.string().optional(),
|
|
5
|
+
});
|
|
6
|
+
/**
|
|
7
|
+
* Type guard to check if a list result is an errored result.
|
|
8
|
+
*/
|
|
9
|
+
function hasIsError(result) {
|
|
10
|
+
return 'isError' in result && result.isError === true;
|
|
11
|
+
}
|
|
12
|
+
export function isErroredListToolsResult(result) {
|
|
13
|
+
return hasIsError(result);
|
|
14
|
+
}
|
|
15
|
+
export function isErroredListResourcesResult(result) {
|
|
16
|
+
return hasIsError(result);
|
|
17
|
+
}
|
|
18
|
+
export function isErroredListPromptsResult(result) {
|
|
19
|
+
return hasIsError(result);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=mcp.js.map
|
package/dist/mcp.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC,MAAM,CAAC;IACjD,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAChC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC/B,CAAC,CAAC;AA2DH;;GAEG;AACH,SAAS,UAAU,CAAC,MAAkJ;IACpK,OAAO,SAAS,IAAI,MAAM,IAAI,MAAM,CAAC,OAAO,KAAK,IAAI,CAAC;AACxD,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,MAAgD;IACvF,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAC,MAAwD;IACnG,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,MAAoD;IAC7F,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC;AAC5B,CAAC"}
|
package/dist/query.d.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const ProcessedContextItemSchema: z.ZodObject<{
|
|
3
|
+
name: z.ZodString;
|
|
4
|
+
value: z.ZodUnknown;
|
|
5
|
+
schema: z.ZodOptional<z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>>;
|
|
6
|
+
description: z.ZodOptional<z.ZodString>;
|
|
7
|
+
type: z.ZodEnum<{
|
|
8
|
+
tool: "tool";
|
|
9
|
+
ephemeral: "ephemeral";
|
|
10
|
+
}>;
|
|
11
|
+
}, z.core.$strip>;
|
|
12
|
+
export declare const QuerySchema: z.ZodObject<{
|
|
13
|
+
uuid: z.ZodString;
|
|
14
|
+
prompt: z.ZodString;
|
|
15
|
+
context: z.ZodArray<z.ZodObject<{
|
|
16
|
+
name: z.ZodString;
|
|
17
|
+
value: z.ZodUnknown;
|
|
18
|
+
schema: z.ZodOptional<z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>>;
|
|
19
|
+
description: z.ZodOptional<z.ZodString>;
|
|
20
|
+
type: z.ZodEnum<{
|
|
21
|
+
tool: "tool";
|
|
22
|
+
ephemeral: "ephemeral";
|
|
23
|
+
}>;
|
|
24
|
+
}, z.core.$strip>>;
|
|
25
|
+
responseTool: z.ZodOptional<z.ZodObject<{
|
|
26
|
+
name: z.ZodString;
|
|
27
|
+
description: z.ZodString;
|
|
28
|
+
inputSchema: z.ZodOptional<z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>>;
|
|
29
|
+
outputSchema: z.ZodOptional<z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>>;
|
|
30
|
+
}, z.core.$strip>>;
|
|
31
|
+
tools: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
32
|
+
name: z.ZodString;
|
|
33
|
+
description: z.ZodString;
|
|
34
|
+
inputSchema: z.ZodOptional<z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>>;
|
|
35
|
+
outputSchema: z.ZodOptional<z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>>;
|
|
36
|
+
}, z.core.$strip>>>;
|
|
37
|
+
restrictTools: z.ZodOptional<z.ZodBoolean>;
|
|
38
|
+
}, z.core.$strip>;
|
|
39
|
+
/**
|
|
40
|
+
* Wire-format query message schemas.
|
|
41
|
+
*
|
|
42
|
+
* These schemas represent messages sent over WebSocket between the bridge server and frontends.
|
|
43
|
+
* They are used for:
|
|
44
|
+
* - Bridge <-> Web communication (WebSocket messages)
|
|
45
|
+
* - Agent <-> Bridge communication (HTTP endpoints for progress/complete)
|
|
46
|
+
*
|
|
47
|
+
* Note: The web package (@mcp-web/core) has similar but slightly different schemas optimized
|
|
48
|
+
* for client-side consumption. These wire-format schemas are the source of truth for network
|
|
49
|
+
* communication.
|
|
50
|
+
*/
|
|
51
|
+
export declare const QueryMessageSchema: z.ZodObject<{
|
|
52
|
+
uuid: z.ZodString;
|
|
53
|
+
prompt: z.ZodString;
|
|
54
|
+
context: z.ZodArray<z.ZodObject<{
|
|
55
|
+
name: z.ZodString;
|
|
56
|
+
value: z.ZodUnknown;
|
|
57
|
+
schema: z.ZodOptional<z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>>;
|
|
58
|
+
description: z.ZodOptional<z.ZodString>;
|
|
59
|
+
type: z.ZodEnum<{
|
|
60
|
+
tool: "tool";
|
|
61
|
+
ephemeral: "ephemeral";
|
|
62
|
+
}>;
|
|
63
|
+
}, z.core.$strip>>;
|
|
64
|
+
responseTool: z.ZodOptional<z.ZodObject<{
|
|
65
|
+
name: z.ZodString;
|
|
66
|
+
description: z.ZodString;
|
|
67
|
+
inputSchema: z.ZodOptional<z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>>;
|
|
68
|
+
outputSchema: z.ZodOptional<z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>>;
|
|
69
|
+
}, z.core.$strip>>;
|
|
70
|
+
tools: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
71
|
+
name: z.ZodString;
|
|
72
|
+
description: z.ZodString;
|
|
73
|
+
inputSchema: z.ZodOptional<z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>>;
|
|
74
|
+
outputSchema: z.ZodOptional<z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>>;
|
|
75
|
+
}, z.core.$strip>>>;
|
|
76
|
+
restrictTools: z.ZodOptional<z.ZodBoolean>;
|
|
77
|
+
type: z.ZodDefault<z.ZodLiteral<"query">>;
|
|
78
|
+
}, z.core.$strip>;
|
|
79
|
+
export declare const QueryAcceptedMessageSchema: z.ZodObject<{
|
|
80
|
+
type: z.ZodDefault<z.ZodLiteral<"query_accepted">>;
|
|
81
|
+
uuid: z.ZodString;
|
|
82
|
+
}, z.core.$strip>;
|
|
83
|
+
export declare const QueryProgressMessageSchema: z.ZodObject<{
|
|
84
|
+
type: z.ZodDefault<z.ZodLiteral<"query_progress">>;
|
|
85
|
+
uuid: z.ZodString;
|
|
86
|
+
message: z.ZodString;
|
|
87
|
+
}, z.core.$strip>;
|
|
88
|
+
export declare const QueryCompleteBaseMessageSchema: z.ZodObject<{
|
|
89
|
+
type: z.ZodDefault<z.ZodLiteral<"query_complete">>;
|
|
90
|
+
uuid: z.ZodString;
|
|
91
|
+
}, z.core.$strip>;
|
|
92
|
+
export declare const QueryCompleteClientMessageSchema: z.ZodObject<{
|
|
93
|
+
message: z.ZodString;
|
|
94
|
+
type: z.ZodDefault<z.ZodLiteral<"query_complete">>;
|
|
95
|
+
uuid: z.ZodString;
|
|
96
|
+
}, z.core.$strip>;
|
|
97
|
+
export declare const QueryCompleteBridgeMessageSchema: z.ZodObject<{
|
|
98
|
+
message: z.ZodOptional<z.ZodString>;
|
|
99
|
+
toolCalls: z.ZodArray<z.ZodObject<{
|
|
100
|
+
tool: z.ZodString;
|
|
101
|
+
arguments: z.ZodUnknown;
|
|
102
|
+
result: z.ZodUnknown;
|
|
103
|
+
}, z.core.$strip>>;
|
|
104
|
+
type: z.ZodDefault<z.ZodLiteral<"query_complete">>;
|
|
105
|
+
uuid: z.ZodString;
|
|
106
|
+
}, z.core.$strip>;
|
|
107
|
+
export declare const QueryFailureMessageSchema: z.ZodObject<{
|
|
108
|
+
type: z.ZodDefault<z.ZodLiteral<"query_failure">>;
|
|
109
|
+
uuid: z.ZodString;
|
|
110
|
+
error: z.ZodString;
|
|
111
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
112
|
+
}, z.core.$strip>;
|
|
113
|
+
export declare const QueryCancelMessageSchema: z.ZodObject<{
|
|
114
|
+
type: z.ZodDefault<z.ZodLiteral<"query_cancel">>;
|
|
115
|
+
uuid: z.ZodString;
|
|
116
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
117
|
+
}, z.core.$strip>;
|
|
118
|
+
export type ProcessedContextItem = z.infer<typeof ProcessedContextItemSchema>;
|
|
119
|
+
export type Query = z.infer<typeof QuerySchema>;
|
|
120
|
+
export type QueryMessage = z.output<typeof QueryMessageSchema>;
|
|
121
|
+
export type QueryAcceptedMessage = z.output<typeof QueryAcceptedMessageSchema>;
|
|
122
|
+
export type QueryProgressMessage = z.output<typeof QueryProgressMessageSchema>;
|
|
123
|
+
export type QueryCompleteClientMessage = z.output<typeof QueryCompleteClientMessageSchema>;
|
|
124
|
+
export type QueryCompleteBridgeMessage = z.output<typeof QueryCompleteBridgeMessageSchema>;
|
|
125
|
+
export type QueryFailureMessage = z.output<typeof QueryFailureMessageSchema>;
|
|
126
|
+
export type QueryCancelMessage = z.output<typeof QueryCancelMessageSchema>;
|
|
127
|
+
//# sourceMappingURL=query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,eAAO,MAAM,0BAA0B;;;;;;;;;iBAMrC,CAAC;AAEH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;iBAOtB,CAAC;AAEH;;;;;;;;;;;GAWG;AAEH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAG7B,CAAC;AAEH,eAAO,MAAM,0BAA0B;;;iBAGrC,CAAC;AAEH,eAAO,MAAM,0BAA0B;;;;iBAIrC,CAAC;AAEH,eAAO,MAAM,8BAA8B;;;iBAGzC,CAAC;AAEH,eAAO,MAAM,gCAAgC;;;;iBAG3C,CAAC;AAEH,eAAO,MAAM,gCAAgC;;;;;;;;;iBAQ3C,CAAC;AAEH,eAAO,MAAM,yBAAyB;;;;;iBAKpC,CAAC;AAEH,eAAO,MAAM,wBAAwB;;;;iBAInC,CAAC;AAGH,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAC9E,MAAM,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAChD,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAC/D,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAC/E,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAC/E,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,gCAAgC,CAAC,CAAC;AAC3F,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,gCAAgC,CAAC,CAAC;AAC3F,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAC7E,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,wBAAwB,CAAC,CAAC"}
|
package/dist/query.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ToolMetadataJsonSchema } from './tools.js';
|
|
3
|
+
export const ProcessedContextItemSchema = z.object({
|
|
4
|
+
name: z.string(),
|
|
5
|
+
value: z.unknown(),
|
|
6
|
+
schema: z.custom().optional(),
|
|
7
|
+
description: z.string().optional(),
|
|
8
|
+
type: z.enum(['tool', 'ephemeral']),
|
|
9
|
+
});
|
|
10
|
+
export const QuerySchema = z.object({
|
|
11
|
+
uuid: z.string(),
|
|
12
|
+
prompt: z.string(),
|
|
13
|
+
context: z.array(ProcessedContextItemSchema),
|
|
14
|
+
responseTool: ToolMetadataJsonSchema.optional(),
|
|
15
|
+
tools: z.array(ToolMetadataJsonSchema).optional(),
|
|
16
|
+
restrictTools: z.boolean().optional()
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* Wire-format query message schemas.
|
|
20
|
+
*
|
|
21
|
+
* These schemas represent messages sent over WebSocket between the bridge server and frontends.
|
|
22
|
+
* They are used for:
|
|
23
|
+
* - Bridge <-> Web communication (WebSocket messages)
|
|
24
|
+
* - Agent <-> Bridge communication (HTTP endpoints for progress/complete)
|
|
25
|
+
*
|
|
26
|
+
* Note: The web package (@mcp-web/core) has similar but slightly different schemas optimized
|
|
27
|
+
* for client-side consumption. These wire-format schemas are the source of truth for network
|
|
28
|
+
* communication.
|
|
29
|
+
*/
|
|
30
|
+
export const QueryMessageSchema = z.object({
|
|
31
|
+
type: z.literal('query').default('query'),
|
|
32
|
+
...QuerySchema.shape
|
|
33
|
+
});
|
|
34
|
+
export const QueryAcceptedMessageSchema = z.object({
|
|
35
|
+
type: z.literal('query_accepted').default('query_accepted'),
|
|
36
|
+
uuid: z.string()
|
|
37
|
+
});
|
|
38
|
+
export const QueryProgressMessageSchema = z.object({
|
|
39
|
+
type: z.literal('query_progress').default('query_progress'),
|
|
40
|
+
uuid: z.string(),
|
|
41
|
+
message: z.string(),
|
|
42
|
+
});
|
|
43
|
+
export const QueryCompleteBaseMessageSchema = z.object({
|
|
44
|
+
type: z.literal('query_complete').default('query_complete'),
|
|
45
|
+
uuid: z.string(),
|
|
46
|
+
});
|
|
47
|
+
export const QueryCompleteClientMessageSchema = z.object({
|
|
48
|
+
...QueryCompleteBaseMessageSchema.shape,
|
|
49
|
+
message: z.string(),
|
|
50
|
+
});
|
|
51
|
+
export const QueryCompleteBridgeMessageSchema = z.object({
|
|
52
|
+
...QueryCompleteBaseMessageSchema.shape,
|
|
53
|
+
message: z.string().optional(),
|
|
54
|
+
toolCalls: z.array(z.object({
|
|
55
|
+
tool: z.string(),
|
|
56
|
+
arguments: z.unknown(),
|
|
57
|
+
result: z.unknown()
|
|
58
|
+
})),
|
|
59
|
+
});
|
|
60
|
+
export const QueryFailureMessageSchema = z.object({
|
|
61
|
+
type: z.literal('query_failure').default('query_failure'),
|
|
62
|
+
uuid: z.string().describe('The query UUID'),
|
|
63
|
+
error: z.string().describe('The error code'),
|
|
64
|
+
reason: z.string().optional().describe('The reason for the failure'),
|
|
65
|
+
});
|
|
66
|
+
export const QueryCancelMessageSchema = z.object({
|
|
67
|
+
type: z.literal('query_cancel').default('query_cancel'),
|
|
68
|
+
uuid: z.string().describe('The query UUID to cancel'),
|
|
69
|
+
reason: z.string().optional().describe('The reason for the cancellation'),
|
|
70
|
+
});
|
|
71
|
+
//# sourceMappingURL=query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.js","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC,MAAM,CAAC;IACjD,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE;IAClB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAgC,CAAC,QAAQ,EAAE;IAC3D,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAClC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;CACpC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,MAAM,EAAE,CAAC,CAAC,MAAM,EAA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@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Re-export MCP SDK's standard Resource type for convenience.
|
|
4
|
+
*
|
|
5
|
+
* This is the wire protocol type used for resource definitions in MCP communication.
|
|
6
|
+
*/
|
|
7
|
+
export type { Resource, ListResourcesResult } from '@modelcontextprotocol/sdk/types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Handler function for reading a resource.
|
|
10
|
+
* Returns the resource content as a string or binary data.
|
|
11
|
+
*/
|
|
12
|
+
export type ResourceReadHandler = () => string | Uint8Array | Promise<string> | Promise<Uint8Array>;
|
|
13
|
+
/**
|
|
14
|
+
* Zod schema for resource definition validation.
|
|
15
|
+
*/
|
|
16
|
+
export declare const ResourceDefinitionSchema: z.ZodObject<{
|
|
17
|
+
uri: z.ZodString;
|
|
18
|
+
name: z.ZodString;
|
|
19
|
+
description: z.ZodOptional<z.ZodString>;
|
|
20
|
+
mimeType: z.ZodOptional<z.ZodString>;
|
|
21
|
+
handler: z.ZodCustom<ResourceReadHandler, ResourceReadHandler>;
|
|
22
|
+
}, z.core.$strip>;
|
|
23
|
+
/**
|
|
24
|
+
* Resource definition for client-side use with handler.
|
|
25
|
+
*
|
|
26
|
+
* This is the primary type used when registering resources with MCPWeb.
|
|
27
|
+
*/
|
|
28
|
+
export interface ResourceDefinition {
|
|
29
|
+
/** Unique URI for the resource (e.g., "ui://app-name/resource.html") */
|
|
30
|
+
uri: string;
|
|
31
|
+
/** Human-readable name for the resource */
|
|
32
|
+
name: string;
|
|
33
|
+
/** Description of the resource (shown to AI) */
|
|
34
|
+
description?: string;
|
|
35
|
+
/** MIME type of the resource content */
|
|
36
|
+
mimeType?: string;
|
|
37
|
+
/** Handler function that returns the resource content */
|
|
38
|
+
handler: ResourceReadHandler;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Resource metadata without handler, for wire protocol transmission.
|
|
42
|
+
*/
|
|
43
|
+
export declare const ResourceMetadataSchema: z.ZodObject<{
|
|
44
|
+
name: z.ZodString;
|
|
45
|
+
description: z.ZodOptional<z.ZodString>;
|
|
46
|
+
uri: z.ZodString;
|
|
47
|
+
mimeType: z.ZodOptional<z.ZodString>;
|
|
48
|
+
}, z.core.$strip>;
|
|
49
|
+
/** Resource metadata type (serializable, no handler) */
|
|
50
|
+
export type ResourceMetadata = z.infer<typeof ResourceMetadataSchema>;
|
|
51
|
+
/**
|
|
52
|
+
* Message sent from frontend to bridge to register a resource.
|
|
53
|
+
*/
|
|
54
|
+
export interface RegisterResourceMessage {
|
|
55
|
+
type: 'register-resource';
|
|
56
|
+
resource: ResourceMetadata;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Zod schema for register resource message validation.
|
|
60
|
+
*/
|
|
61
|
+
export declare const RegisterResourceMessageSchema: z.ZodObject<{
|
|
62
|
+
type: z.ZodLiteral<"register-resource">;
|
|
63
|
+
resource: z.ZodObject<{
|
|
64
|
+
name: z.ZodString;
|
|
65
|
+
description: z.ZodOptional<z.ZodString>;
|
|
66
|
+
uri: z.ZodString;
|
|
67
|
+
mimeType: z.ZodOptional<z.ZodString>;
|
|
68
|
+
}, z.core.$strip>;
|
|
69
|
+
}, z.core.$strip>;
|
|
70
|
+
/**
|
|
71
|
+
* Message sent from bridge to frontend to request resource content.
|
|
72
|
+
*/
|
|
73
|
+
export interface ResourceReadMessage {
|
|
74
|
+
type: 'resource-read';
|
|
75
|
+
requestId: string;
|
|
76
|
+
uri: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Zod schema for resource read message validation.
|
|
80
|
+
*/
|
|
81
|
+
export declare const ResourceReadMessageSchema: z.ZodObject<{
|
|
82
|
+
type: z.ZodLiteral<"resource-read">;
|
|
83
|
+
requestId: z.ZodString;
|
|
84
|
+
uri: z.ZodString;
|
|
85
|
+
}, z.core.$strip>;
|
|
86
|
+
/**
|
|
87
|
+
* Message sent from frontend to bridge with resource content.
|
|
88
|
+
*/
|
|
89
|
+
export interface ResourceResponseMessage {
|
|
90
|
+
type: 'resource-response';
|
|
91
|
+
requestId: string;
|
|
92
|
+
content?: string;
|
|
93
|
+
blob?: string;
|
|
94
|
+
mimeType: string;
|
|
95
|
+
error?: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Zod schema for resource response message validation.
|
|
99
|
+
*/
|
|
100
|
+
export declare const ResourceResponseMessageSchema: z.ZodObject<{
|
|
101
|
+
type: z.ZodLiteral<"resource-response">;
|
|
102
|
+
requestId: z.ZodString;
|
|
103
|
+
content: z.ZodOptional<z.ZodString>;
|
|
104
|
+
blob: z.ZodOptional<z.ZodString>;
|
|
105
|
+
mimeType: z.ZodString;
|
|
106
|
+
error: z.ZodOptional<z.ZodString>;
|
|
107
|
+
}, z.core.$strip>;
|
|
108
|
+
//# sourceMappingURL=resources.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../src/resources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;GAIG;AACH,YAAY,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAExF;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG,MAC9B,MAAM,GACN,UAAU,GACV,OAAO,CAAC,MAAM,CAAC,GACf,OAAO,CAAC,UAAU,CAAC,CAAC;AAExB;;GAEG;AACH,eAAO,MAAM,wBAAwB;;;;;;iBAcnC,CAAC;AAEH;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,wEAAwE;IACxE,GAAG,EAAE,MAAM,CAAC;IACZ,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,gDAAgD;IAChD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wCAAwC;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,yDAAyD;IACzD,OAAO,EAAE,mBAAmB,CAAC;CAC9B;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB;;;;;iBAAmD,CAAC;AAEvF,wDAAwD;AACxD,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAMtE;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,mBAAmB,CAAC;IAC1B,QAAQ,EAAE,gBAAgB,CAAC;CAC5B;AAED;;GAEG;AACH,eAAO,MAAM,6BAA6B;;;;;;;;iBAGxC,CAAC;AAEH;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,eAAe,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;GAEG;AACH,eAAO,MAAM,yBAAyB;;;;iBAIpC,CAAC;AAEH;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,mBAAmB,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,eAAO,MAAM,6BAA6B;;;;;;;iBAOxC,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Zod schema for resource definition validation.
|
|
4
|
+
*/
|
|
5
|
+
export const ResourceDefinitionSchema = z.object({
|
|
6
|
+
/** Unique URI for the resource (e.g., "ui://app-name/resource.html") */
|
|
7
|
+
uri: z.string().min(1, 'Resource URI is required'),
|
|
8
|
+
/** Human-readable name for the resource */
|
|
9
|
+
name: z.string().min(1, 'Resource name is required'),
|
|
10
|
+
/** Description of the resource (shown to AI) */
|
|
11
|
+
description: z.string().optional(),
|
|
12
|
+
/** MIME type of the resource content (defaults to text/html) */
|
|
13
|
+
mimeType: z.string().optional(),
|
|
14
|
+
/** Handler function that returns the resource content */
|
|
15
|
+
handler: z.custom((val) => typeof val === 'function', { message: 'Handler must be a function' }),
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* Resource metadata without handler, for wire protocol transmission.
|
|
19
|
+
*/
|
|
20
|
+
export const ResourceMetadataSchema = ResourceDefinitionSchema.omit({ handler: true });
|
|
21
|
+
/**
|
|
22
|
+
* Zod schema for register resource message validation.
|
|
23
|
+
*/
|
|
24
|
+
export const RegisterResourceMessageSchema = z.object({
|
|
25
|
+
type: z.literal('register-resource'),
|
|
26
|
+
resource: ResourceMetadataSchema,
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* Zod schema for resource read message validation.
|
|
30
|
+
*/
|
|
31
|
+
export const ResourceReadMessageSchema = z.object({
|
|
32
|
+
type: z.literal('resource-read'),
|
|
33
|
+
requestId: z.string(),
|
|
34
|
+
uri: z.string(),
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* Zod schema for resource response message validation.
|
|
38
|
+
*/
|
|
39
|
+
export const ResourceResponseMessageSchema = z.object({
|
|
40
|
+
type: z.literal('resource-response'),
|
|
41
|
+
requestId: z.string(),
|
|
42
|
+
content: z.string().optional(),
|
|
43
|
+
blob: z.string().optional(),
|
|
44
|
+
mimeType: z.string(),
|
|
45
|
+
error: z.string().optional(),
|
|
46
|
+
});
|
|
47
|
+
//# sourceMappingURL=resources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../src/resources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAmBxB;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/C,wEAAwE;IACxE,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,0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CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC7B,CAAC,CAAC"}
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Re-export MCP SDK's standard Tool type for convenience.
|
|
4
|
+
*
|
|
5
|
+
* This is the wire protocol type used for tool definitions in MCP communication.
|
|
6
|
+
* It differs from `ToolDefinition` which includes additional client-side
|
|
7
|
+
* properties like `handler` and `outputSchema` not in the MCP wire protocol.
|
|
8
|
+
*/
|
|
9
|
+
export type { ListToolsResult, Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
10
|
+
/** Schema for tool definitions with Zod schemas */
|
|
11
|
+
export declare const ToolDefinitionZodSchema: z.ZodObject<{
|
|
12
|
+
name: z.ZodString;
|
|
13
|
+
description: z.ZodString;
|
|
14
|
+
handler: z.ZodCustom<(...args: any[]) => any | Promise<any>, (...args: any[]) => any | Promise<any>>;
|
|
15
|
+
inputSchema: z.ZodOptional<z.ZodCustom<z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>, z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>>>;
|
|
16
|
+
outputSchema: z.ZodOptional<z.ZodCustom<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
|
|
17
|
+
}, z.core.$strip>;
|
|
18
|
+
/** Tool definition type for tools with Zod schemas (inferred from schema) */
|
|
19
|
+
export type ToolDefinitionZod = z.infer<typeof ToolDefinitionZodSchema>;
|
|
20
|
+
/** Schema for tool definitions with JSON Schema */
|
|
21
|
+
export declare const ToolDefinitionJsonSchema: z.ZodObject<{
|
|
22
|
+
name: z.ZodString;
|
|
23
|
+
description: z.ZodString;
|
|
24
|
+
handler: z.ZodCustom<(...args: any[]) => any | Promise<any>, (...args: any[]) => any | Promise<any>>;
|
|
25
|
+
inputSchema: z.ZodOptional<z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>>;
|
|
26
|
+
outputSchema: z.ZodOptional<z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>>;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
/** Runtime validation schema that accepts either Zod or JSON Schema */
|
|
29
|
+
export declare const ToolDefinitionSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
30
|
+
name: z.ZodString;
|
|
31
|
+
description: z.ZodString;
|
|
32
|
+
handler: z.ZodCustom<(...args: any[]) => any | Promise<any>, (...args: any[]) => any | Promise<any>>;
|
|
33
|
+
inputSchema: z.ZodOptional<z.ZodCustom<z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>, z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>>>;
|
|
34
|
+
outputSchema: z.ZodOptional<z.ZodCustom<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
|
|
35
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
36
|
+
name: z.ZodString;
|
|
37
|
+
description: z.ZodString;
|
|
38
|
+
handler: z.ZodCustom<(...args: any[]) => any | Promise<any>, (...args: any[]) => any | Promise<any>>;
|
|
39
|
+
inputSchema: z.ZodOptional<z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>>;
|
|
40
|
+
outputSchema: z.ZodOptional<z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>>;
|
|
41
|
+
}, z.core.$strip>]>;
|
|
42
|
+
/**
|
|
43
|
+
* Tool definition for client-side use with handler and optional schemas.
|
|
44
|
+
*
|
|
45
|
+
* This is the primary type used when registering tools with MCPWeb.
|
|
46
|
+
* Supports both Zod schemas (recommended) and JSON schemas.
|
|
47
|
+
*/
|
|
48
|
+
export interface ToolDefinition {
|
|
49
|
+
/** Unique name for the tool. */
|
|
50
|
+
name: string;
|
|
51
|
+
/** Description of what the tool does (shown to AI). */
|
|
52
|
+
description: string;
|
|
53
|
+
/** Function that executes the tool logic. */
|
|
54
|
+
handler: (input?: any) => any | Promise<any>;
|
|
55
|
+
/** Input parameter schema (Zod or JSON Schema). */
|
|
56
|
+
inputSchema?: z.ZodObject | Record<string, unknown>;
|
|
57
|
+
/** Output value schema (Zod or JSON Schema). */
|
|
58
|
+
outputSchema?: z.ZodType | Record<string, unknown>;
|
|
59
|
+
/**
|
|
60
|
+
* Tool metadata, forwarded to the MCP `tools/list` response.
|
|
61
|
+
* Used for MCP Apps to declare `_meta.ui.resourceUri`.
|
|
62
|
+
*/
|
|
63
|
+
_meta?: Record<string, unknown>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Tool metadata without handler, for wire protocol transmission.
|
|
67
|
+
* Schemas must be JSON Schema (not Zod) to be serializable.
|
|
68
|
+
*/
|
|
69
|
+
export declare const ToolMetadataZodSchema: z.ZodObject<{
|
|
70
|
+
name: z.ZodString;
|
|
71
|
+
description: z.ZodString;
|
|
72
|
+
inputSchema: z.ZodOptional<z.ZodCustom<z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>, z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>>>;
|
|
73
|
+
outputSchema: z.ZodOptional<z.ZodCustom<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
|
|
74
|
+
}, z.core.$strip>;
|
|
75
|
+
/** Tool metadata type with Zod schemas. */
|
|
76
|
+
export type ToolMetadataZod = z.infer<typeof ToolMetadataJsonSchema>;
|
|
77
|
+
/** Tool metadata schema with JSON Schema format. */
|
|
78
|
+
export declare const ToolMetadataJsonSchema: z.ZodObject<{
|
|
79
|
+
name: z.ZodString;
|
|
80
|
+
description: z.ZodString;
|
|
81
|
+
inputSchema: z.ZodOptional<z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>>;
|
|
82
|
+
outputSchema: z.ZodOptional<z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>>;
|
|
83
|
+
}, z.core.$strip>;
|
|
84
|
+
/** Tool metadata type with JSON schemas. */
|
|
85
|
+
export type ToolMetadataJson = z.infer<typeof ToolMetadataJsonSchema>;
|
|
86
|
+
/** Combined tool metadata schema accepting either format. */
|
|
87
|
+
export declare const ToolMetadataSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
88
|
+
name: z.ZodString;
|
|
89
|
+
description: z.ZodString;
|
|
90
|
+
inputSchema: z.ZodOptional<z.ZodCustom<z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>, z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>>>;
|
|
91
|
+
outputSchema: z.ZodOptional<z.ZodCustom<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
|
|
92
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
93
|
+
name: z.ZodString;
|
|
94
|
+
description: z.ZodString;
|
|
95
|
+
inputSchema: z.ZodOptional<z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>>;
|
|
96
|
+
outputSchema: z.ZodOptional<z.ZodCustom<z.core.JSONSchema.JSONSchema, z.core.JSONSchema.JSONSchema>>;
|
|
97
|
+
}, z.core.$strip>]>;
|
|
98
|
+
/** Tool metadata type (either Zod or JSON Schema format). */
|
|
99
|
+
export type ToolMetadata = z.infer<typeof ToolMetadataSchema>;
|
|
100
|
+
/**
|
|
101
|
+
* Internal processed tool definition with both Zod and JSON schemas.
|
|
102
|
+
* @internal Used by MCPWeb for tool registration and validation.
|
|
103
|
+
*/
|
|
104
|
+
export type ProcessedToolDefinition = ToolDefinition & {
|
|
105
|
+
/** Zod schema for input validation (if using Zod). */
|
|
106
|
+
inputZodSchema?: z.ZodObject;
|
|
107
|
+
/** Zod schema for output validation (if using Zod). */
|
|
108
|
+
outputZodSchema?: z.ZodType;
|
|
109
|
+
/** JSON Schema for input (always available after processing). */
|
|
110
|
+
inputJsonSchema?: z.core.JSONSchema.JSONSchema;
|
|
111
|
+
/** JSON Schema for output (always available after processing). */
|
|
112
|
+
outputJsonSchema?: z.core.JSONSchema.JSONSchema;
|
|
113
|
+
};
|
|
114
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;GAMG;AACH,YAAY,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,oCAAoC,CAAC;AAsChF,mDAAmD;AACnD,eAAO,MAAM,uBAAuB;;;mCAPN,GAAG,EAAE,KAAK,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,YAA5B,GAAG,EAAE,KAAK,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;;;iBAYxD,CAAC;AAEH,6EAA6E;AAC7E,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAExE,mDAAmD;AACnD,eAAO,MAAM,wBAAwB;;;mCAlBP,GAAG,EAAE,KAAK,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,YAA5B,GAAG,EAAE,KAAK,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;;;iBAuBxD,CAAC;AAEH,uEAAuE;AACvE,eAAO,MAAM,oBAAoB;;;mCA1BH,GAAG,EAAE,KAAK,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,YAA5B,GAAG,EAAE,KAAK,GA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uBAAuB,GAAG,cAAc,GAAG;IACrD,sDAAsD;IACtD,cAAc,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC;IAC7B,uDAAuD;IACvD,eAAe,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC;IAC5B,iEAAiE;IACjE,eAAe,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC;IAC/C,kEAAkE;IAClE,gBAAgB,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC;CACjD,CAAA"}
|
package/dist/tools.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Ajv } from 'ajv';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
const ajv = new Ajv({ strict: false });
|
|
4
|
+
const validateJsonSchema = (schema) => {
|
|
5
|
+
// Check if it's a JSON Schema
|
|
6
|
+
if (schema && typeof schema === 'object') {
|
|
7
|
+
// Allow schemas with explicit $schema to validate against their declared version
|
|
8
|
+
if ('$schema' in schema && schema.$schema) {
|
|
9
|
+
return ajv.validateSchema(schema);
|
|
10
|
+
}
|
|
11
|
+
// Default to Draft 7 for schemas without $schema
|
|
12
|
+
const schemaWithDraft = {
|
|
13
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
14
|
+
...schema
|
|
15
|
+
};
|
|
16
|
+
return ajv.validateSchema(schemaWithDraft);
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
};
|
|
20
|
+
/** Base schema for all tool definitions with common fields */
|
|
21
|
+
const ToolDefinitionBaseSchema = z.object({
|
|
22
|
+
/** The name of the tool. */
|
|
23
|
+
name: z.string().min(1, 'Tool name is required'),
|
|
24
|
+
/** The description of the tool. */
|
|
25
|
+
description: z.string().min(1, 'Tool description is required'),
|
|
26
|
+
/** The function that handles the tool execution. */
|
|
27
|
+
// biome-ignore lint/suspicious/noExplicitAny: Can literally be anything
|
|
28
|
+
handler: z.custom((val) => typeof val === 'function', { message: "Handler must be a function" }),
|
|
29
|
+
});
|
|
30
|
+
/** Schema for tool definitions with Zod schemas */
|
|
31
|
+
export const ToolDefinitionZodSchema = ToolDefinitionBaseSchema.extend({
|
|
32
|
+
/** The input schema for the tool (Zod object schema). */
|
|
33
|
+
inputSchema: z.instanceof(z.ZodObject).optional(),
|
|
34
|
+
/** The output schema for the tool (any Zod schema type). */
|
|
35
|
+
outputSchema: z.instanceof(z.ZodType).optional()
|
|
36
|
+
});
|
|
37
|
+
/** Schema for tool definitions with JSON Schema */
|
|
38
|
+
export const ToolDefinitionJsonSchema = ToolDefinitionBaseSchema.extend({
|
|
39
|
+
/** The input schema for the tool (JSON Schema). */
|
|
40
|
+
inputSchema: z.custom(validateJsonSchema, { message: "Must be valid JSON Schema Draft 7" }).optional(),
|
|
41
|
+
/** The output schema for the tool (JSON Schema). */
|
|
42
|
+
outputSchema: z.custom(validateJsonSchema, { message: "Must be valid JSON Schema Draft 7" }).optional()
|
|
43
|
+
});
|
|
44
|
+
/** Runtime validation schema that accepts either Zod or JSON Schema */
|
|
45
|
+
export const ToolDefinitionSchema = z.union([ToolDefinitionZodSchema, ToolDefinitionJsonSchema]);
|
|
46
|
+
/**
|
|
47
|
+
* Tool metadata without handler, for wire protocol transmission.
|
|
48
|
+
* Schemas must be JSON Schema (not Zod) to be serializable.
|
|
49
|
+
*/
|
|
50
|
+
export const ToolMetadataZodSchema = ToolDefinitionZodSchema.omit({ handler: true });
|
|
51
|
+
/** Tool metadata schema with JSON Schema format. */
|
|
52
|
+
export const ToolMetadataJsonSchema = ToolDefinitionJsonSchema.omit({ handler: true });
|
|
53
|
+
/** Combined tool metadata schema accepting either format. */
|
|
54
|
+
export const ToolMetadataSchema = z.union([ToolMetadataZodSchema, ToolMetadataJsonSchema]);
|
|
55
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,OAAO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