@mcp-b/global 1.0.13 → 1.0.15

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.
@@ -0,0 +1,206 @@
1
+ import { CallToolResult, Server, ToolAnnotations } from "@mcp-b/webmcp-ts-sdk";
2
+ import { z } from "zod";
3
+
4
+ //#region src/global.d.ts
5
+ /**
6
+ * Initialize the Web Model Context API (window.navigator.modelContext)
7
+ */
8
+ declare function initializeWebModelContext(): void;
9
+ /**
10
+ * Cleanup function (for testing/development)
11
+ */
12
+ declare function cleanupWebModelContext(): void;
13
+ //#endregion
14
+ //#region src/types.d.ts
15
+ /**
16
+ * JSON Schema definition for tool input parameters
17
+ */
18
+ interface InputSchema {
19
+ type: string;
20
+ properties?: Record<string, {
21
+ type: string;
22
+ description?: string;
23
+ [key: string]: unknown;
24
+ }>;
25
+ required?: string[];
26
+ [key: string]: unknown;
27
+ }
28
+ /**
29
+ * Zod schema object type (Record<string, ZodType>)
30
+ * Used for type-safe tool definitions
31
+ */
32
+ type ZodSchemaObject = Record<string, z.ZodTypeAny>;
33
+ /**
34
+ * Tool response format (Web API version)
35
+ * This is compatible with MCP SDK's CallToolResult
36
+ */
37
+ type ToolResponse = CallToolResult;
38
+ /**
39
+ * Tool descriptor for Web Model Context API
40
+ * Extended with full MCP protocol support
41
+ *
42
+ * Supports both JSON Schema (Web standard) and Zod schemas (type-safe)
43
+ *
44
+ * @template TInputSchema - If using Zod, the schema object type for type inference
45
+ * @template TOutputSchema - If using Zod, the output schema object type
46
+ */
47
+ interface ToolDescriptor<TInputSchema extends ZodSchemaObject = Record<string, never>, TOutputSchema extends ZodSchemaObject = Record<string, never>> {
48
+ /**
49
+ * Unique identifier for the tool
50
+ */
51
+ name: string;
52
+ /**
53
+ * Natural language description of what the tool does
54
+ */
55
+ description: string;
56
+ /**
57
+ * Input schema - accepts EITHER:
58
+ * - JSON Schema object (Web standard): { type: "object", properties: {...}, required: [...] }
59
+ * - Zod schema object (type-safe): { text: z.string(), priority: z.enum(...) }
60
+ *
61
+ * When using Zod, TypeScript will infer the execute parameter types automatically
62
+ */
63
+ inputSchema: InputSchema | TInputSchema;
64
+ /**
65
+ * Optional output schema - accepts EITHER:
66
+ * - JSON Schema object (Web standard): { type: "object", properties: {...} }
67
+ * - Zod schema object (type-safe): { result: z.string(), success: z.boolean() }
68
+ */
69
+ outputSchema?: InputSchema | TOutputSchema;
70
+ /**
71
+ * Optional annotations providing hints about tool behavior
72
+ */
73
+ annotations?: ToolAnnotations;
74
+ /**
75
+ * Function that executes the tool logic
76
+ *
77
+ * When using Zod schemas, the args parameter type is automatically inferred from TInputSchema
78
+ * When using JSON Schema, args is Record<string, unknown>
79
+ */
80
+ execute: (args: TInputSchema extends Record<string, never> ? Record<string, unknown> : z.infer<z.ZodObject<TInputSchema>>) => Promise<ToolResponse>;
81
+ }
82
+ /**
83
+ * Internal validated tool descriptor (used internally by the bridge)
84
+ * Always stores JSON Schema format for MCP protocol
85
+ * Plus Zod validators for runtime validation
86
+ */
87
+ interface ValidatedToolDescriptor {
88
+ name: string;
89
+ description: string;
90
+ inputSchema: InputSchema;
91
+ outputSchema?: InputSchema;
92
+ annotations?: ToolAnnotations;
93
+ execute: (args: Record<string, unknown>) => Promise<ToolResponse>;
94
+ inputValidator: z.ZodType;
95
+ outputValidator?: z.ZodType;
96
+ }
97
+ /**
98
+ * Context provided to models via provideContext()
99
+ * Contains the base set of tools (Bucket A)
100
+ */
101
+ interface ModelContextInput {
102
+ /**
103
+ * Array of tool descriptors
104
+ * Supports both JSON Schema and Zod schema formats
105
+ */
106
+ tools: ToolDescriptor<any, any>[];
107
+ }
108
+ /**
109
+ * Tool call event
110
+ */
111
+ interface ToolCallEvent extends Event {
112
+ /**
113
+ * Name of the tool being called
114
+ */
115
+ name: string;
116
+ /**
117
+ * Arguments passed to the tool
118
+ */
119
+ arguments: Record<string, unknown>;
120
+ /**
121
+ * Respond with a result
122
+ */
123
+ respondWith: (response: ToolResponse) => void;
124
+ }
125
+ /**
126
+ * ModelContext interface on window.navigator
127
+ * Implements the W3C Web Model Context API proposal
128
+ */
129
+ interface ModelContext {
130
+ /**
131
+ * Provide context (tools) to AI models
132
+ * Clears base tools (Bucket A) and replaces with the provided array.
133
+ * Dynamic tools (Bucket B) registered via registerTool() persist.
134
+ */
135
+ provideContext(context: ModelContextInput): void;
136
+ /**
137
+ * Register a single tool dynamically
138
+ * Returns an object with an unregister function to remove the tool
139
+ * Supports both JSON Schema and Zod schema formats
140
+ */
141
+ registerTool<TInputSchema extends ZodSchemaObject = Record<string, never>, TOutputSchema extends ZodSchemaObject = Record<string, never>>(tool: ToolDescriptor<TInputSchema, TOutputSchema>): {
142
+ unregister: () => void;
143
+ };
144
+ /**
145
+ * Add event listener for tool calls
146
+ */
147
+ addEventListener(type: 'toolcall', listener: (event: ToolCallEvent) => void | Promise<void>, options?: boolean | AddEventListenerOptions): void;
148
+ /**
149
+ * Remove event listener
150
+ */
151
+ removeEventListener(type: 'toolcall', listener: (event: ToolCallEvent) => void | Promise<void>, options?: boolean | EventListenerOptions): void;
152
+ /**
153
+ * Dispatch an event
154
+ */
155
+ dispatchEvent(event: Event): boolean;
156
+ /**
157
+ * Get the list of all registered tools
158
+ * Returns tools from both buckets (provideContext and registerTool)
159
+ */
160
+ listTools(): Array<{
161
+ name: string;
162
+ description: string;
163
+ inputSchema: InputSchema;
164
+ outputSchema?: InputSchema;
165
+ annotations?: ToolAnnotations;
166
+ }>;
167
+ }
168
+ /**
169
+ * Internal ModelContext interface with additional methods for MCP bridge
170
+ * Not exposed as part of the public Web Model Context API
171
+ */
172
+ interface InternalModelContext extends ModelContext {
173
+ /**
174
+ * Execute a tool (internal use only by MCP bridge)
175
+ * @internal
176
+ */
177
+ executeTool(toolName: string, args: Record<string, unknown>): Promise<ToolResponse>;
178
+ }
179
+ /**
180
+ * Internal MCP Bridge state
181
+ */
182
+ interface MCPBridge {
183
+ server: Server;
184
+ tools: Map<string, ValidatedToolDescriptor>;
185
+ modelContext: InternalModelContext;
186
+ isInitialized: boolean;
187
+ }
188
+ declare global {
189
+ interface Navigator {
190
+ /**
191
+ * Web Model Context API
192
+ * Provides tools and context to AI agents
193
+ */
194
+ modelContext: ModelContext;
195
+ }
196
+ interface Window {
197
+ /**
198
+ * Internal MCP server instance (for debugging/advanced use)
199
+ */
200
+ __mcpBridge?: MCPBridge;
201
+ }
202
+ }
203
+ //# sourceMappingURL=types.d.ts.map
204
+ //#endregion
205
+ export { type CallToolResult, InputSchema, InternalModelContext, MCPBridge, ModelContext, ModelContextInput, type ToolAnnotations, ToolCallEvent, ToolDescriptor, ToolResponse, ValidatedToolDescriptor, ZodSchemaObject, cleanupWebModelContext, initializeWebModelContext };
206
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/global.ts","../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;;iBAifgB,yBAAA,CAAA;AAAhB;AAyCA;;iBAAgB,sBAAA,CAAA;;;;;AAzChB;AAyCgB,UCjhBC,WAAA,CDihBqB;;eC/gBvB;;IAFE,WAAW,CAAA,EAAA,MAAA;IAkBhB,CAAA,GAAA,EAAA,MAAA,CAAA,EAAe,OAAA;EAgBf,CAAA,CAAA;EAWK,QAAA,CAAA,EAAA,MAAc,EAAA;EACR,CAAA,GAAA,EAAA,MAAA,CAAA,EAAA,OAAA;;;;;;AA2BN,KAvDL,eAAA,GAAkB,MAuDb,CAAA,MAAA,EAvD4B,CAAA,CAAE,UAuD9B,CAAA;;;;AAyBjB;AAGe,KAnEH,YAAA,GAAe,cAmEZ;;;;;;;;;AAcf;AAWiB,UAjFA,cAiFc,CAAA,qBAhFR,eAgFQ,GAhFU,MAgFV,CAAA,MAAA,EAAA,KAAA,CAAA,EAAA,sBA/EP,eA+EO,GA/EW,MA+EX,CAAA,MAAA,EAAA,KAAA,CAAA,CAAA,CAAA;EASlB;;;EAT+B,IAAA,EAAA,MAAA;EAqB3B;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