Skip to content

Commit 021dab8

Browse files
ochafikclaude
andcommitted
refactor: move AppRequest/AppNotification/AppResult to types.ts
Move protocol type unions from app-bridge.ts to types.ts where they belong with other type definitions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 16fb2e4 commit 021dab8

File tree

4 files changed

+124
-81
lines changed

4 files changed

+124
-81
lines changed

src/app-bridge.ts

Lines changed: 3 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
CallToolRequestSchema,
66
CallToolResult,
77
CallToolResultSchema,
8-
EmptyResult,
98
Implementation,
109
ListPromptsRequest,
1110
ListPromptsRequestSchema,
@@ -19,8 +18,6 @@ import {
1918
ListResourceTemplatesRequestSchema,
2019
ListResourceTemplatesResult,
2120
ListResourceTemplatesResultSchema,
22-
ListToolsRequest,
23-
ListToolsResult,
2421
LoggingMessageNotification,
2522
LoggingMessageNotificationSchema,
2623
PingRequest,
@@ -43,6 +40,9 @@ import {
4340
} from "@modelcontextprotocol/sdk/shared/protocol.js";
4441

4542
import {
43+
type AppNotification,
44+
type AppRequest,
45+
type AppResult,
4646
type McpUiSandboxResourceReadyNotification,
4747
type McpUiSizeChangedNotification,
4848
type McpUiToolCancelledNotification,
@@ -76,73 +76,6 @@ export * from "./types";
7676
export { RESOURCE_URI_META_KEY, RESOURCE_MIME_TYPE } from "./app";
7777
export { PostMessageTransport } from "./message-transport";
7878

79-
/**
80-
* All request types in the MCP Apps protocol.
81-
*
82-
* Includes:
83-
* - MCP UI requests (initialize, open-link, message, resource-teardown)
84-
* - MCP server requests forwarded from the app (tools/call, resources/*, prompts/list)
85-
* - Protocol requests (ping)
86-
*/
87-
export type AppRequest =
88-
| McpUiInitializeRequest
89-
| McpUiOpenLinkRequest
90-
| McpUiMessageRequest
91-
| McpUiResourceTeardownRequest
92-
| CallToolRequest
93-
| ListToolsRequest
94-
| ListResourcesRequest
95-
| ListResourceTemplatesRequest
96-
| ReadResourceRequest
97-
| ListPromptsRequest
98-
| PingRequest;
99-
100-
/**
101-
* All notification types in the MCP Apps protocol.
102-
*
103-
* Host to app:
104-
* - Tool lifecycle (input, input-partial, result, cancelled)
105-
* - Host context changes
106-
* - MCP list changes (tools, resources, prompts)
107-
* - Sandbox resource ready
108-
*
109-
* App to host:
110-
* - Initialized, size-changed, sandbox-proxy-ready
111-
* - Logging messages
112-
*/
113-
export type AppNotification =
114-
// Sent to app
115-
| McpUiHostContextChangedNotification
116-
| McpUiToolInputNotification
117-
| McpUiToolInputPartialNotification
118-
| McpUiToolResultNotification
119-
| McpUiToolCancelledNotification
120-
| McpUiSandboxResourceReadyNotification
121-
| ToolListChangedNotification
122-
| ResourceListChangedNotification
123-
| PromptListChangedNotification
124-
// Received from app
125-
| McpUiInitializedNotification
126-
| McpUiSizeChangedNotification
127-
| McpUiSandboxProxyReadyNotification
128-
| LoggingMessageNotification;
129-
130-
/**
131-
* All result types in the MCP Apps protocol.
132-
*/
133-
export type AppResult =
134-
| McpUiInitializeResult
135-
| McpUiOpenLinkResult
136-
| McpUiMessageResult
137-
| McpUiResourceTeardownResult
138-
| CallToolResult
139-
| ListToolsResult
140-
| ListResourcesResult
141-
| ListResourceTemplatesResult
142-
| ReadResourceResult
143-
| ListPromptsResult
144-
| EmptyResult;
145-
14679
/**
14780
* Options for configuring AppBridge behavior.
14881
*

src/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
AppNotification,
2020
AppRequest,
2121
AppResult,
22-
} from "./app-bridge";
22+
} from "./types";
2323
import {
2424
LATEST_PROTOCOL_VERSION,
2525
McpUiAppCapabilities,

src/generated/schema.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,7 @@
12121212
"lastModified": {
12131213
"type": "string",
12141214
"format": "date-time",
1215-
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
1215+
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-]\\d{2}:\\d{2})))$"
12161216
}
12171217
},
12181218
"additionalProperties": false
@@ -1259,7 +1259,7 @@
12591259
"lastModified": {
12601260
"type": "string",
12611261
"format": "date-time",
1262-
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
1262+
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-]\\d{2}:\\d{2})))$"
12631263
}
12641264
},
12651265
"additionalProperties": false
@@ -1306,7 +1306,7 @@
13061306
"lastModified": {
13071307
"type": "string",
13081308
"format": "date-time",
1309-
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
1309+
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-]\\d{2}:\\d{2})))$"
13101310
}
13111311
},
13121312
"additionalProperties": false
@@ -1380,7 +1380,7 @@
13801380
"lastModified": {
13811381
"type": "string",
13821382
"format": "date-time",
1383-
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
1383+
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-]\\d{2}:\\d{2})))$"
13841384
}
13851385
},
13861386
"additionalProperties": false
@@ -1473,7 +1473,7 @@
14731473
"lastModified": {
14741474
"type": "string",
14751475
"format": "date-time",
1476-
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
1476+
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-]\\d{2}:\\d{2})))$"
14771477
}
14781478
},
14791479
"additionalProperties": false
@@ -1871,7 +1871,7 @@
18711871
"lastModified": {
18721872
"type": "string",
18731873
"format": "date-time",
1874-
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
1874+
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-]\\d{2}:\\d{2})))$"
18751875
}
18761876
},
18771877
"additionalProperties": false
@@ -1918,7 +1918,7 @@
19181918
"lastModified": {
19191919
"type": "string",
19201920
"format": "date-time",
1921-
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
1921+
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-]\\d{2}:\\d{2})))$"
19221922
}
19231923
},
19241924
"additionalProperties": false
@@ -1965,7 +1965,7 @@
19651965
"lastModified": {
19661966
"type": "string",
19671967
"format": "date-time",
1968-
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
1968+
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-]\\d{2}:\\d{2})))$"
19691969
}
19701970
},
19711971
"additionalProperties": false
@@ -2039,7 +2039,7 @@
20392039
"lastModified": {
20402040
"type": "string",
20412041
"format": "date-time",
2042-
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
2042+
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-]\\d{2}:\\d{2})))$"
20432043
}
20442044
},
20452045
"additionalProperties": false
@@ -2132,7 +2132,7 @@
21322132
"lastModified": {
21332133
"type": "string",
21342134
"format": "date-time",
2135-
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
2135+
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-]\\d{2}:\\d{2})))$"
21362136
}
21372137
},
21382138
"additionalProperties": false

src/types.ts

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,27 @@ export {
3838
type McpUiResourceMeta,
3939
} from "./spec.types.js";
4040

41+
// Import types needed for protocol type unions (not re-exported, just used internally)
42+
import type {
43+
McpUiInitializeRequest,
44+
McpUiOpenLinkRequest,
45+
McpUiMessageRequest,
46+
McpUiResourceTeardownRequest,
47+
McpUiHostContextChangedNotification,
48+
McpUiToolInputNotification,
49+
McpUiToolInputPartialNotification,
50+
McpUiToolResultNotification,
51+
McpUiToolCancelledNotification,
52+
McpUiSandboxResourceReadyNotification,
53+
McpUiInitializedNotification,
54+
McpUiSizeChangedNotification,
55+
McpUiSandboxProxyReadyNotification,
56+
McpUiInitializeResult,
57+
McpUiOpenLinkResult,
58+
McpUiMessageResult,
59+
McpUiResourceTeardownResult,
60+
} from "./spec.types.js";
61+
4162
// Re-export all schemas from generated/schema.ts (already PascalCase)
4263
export {
4364
McpUiThemeSchema,
@@ -65,3 +86,92 @@ export {
6586
McpUiResourceCspSchema,
6687
McpUiResourceMetaSchema,
6788
} from "./generated/schema.js";
89+
90+
// Re-export SDK types used in protocol type unions
91+
import {
92+
CallToolRequest,
93+
CallToolResult,
94+
EmptyResult,
95+
ListPromptsRequest,
96+
ListPromptsResult,
97+
ListResourcesRequest,
98+
ListResourcesResult,
99+
ListResourceTemplatesRequest,
100+
ListResourceTemplatesResult,
101+
ListToolsRequest,
102+
ListToolsResult,
103+
LoggingMessageNotification,
104+
PingRequest,
105+
PromptListChangedNotification,
106+
ReadResourceRequest,
107+
ReadResourceResult,
108+
ResourceListChangedNotification,
109+
ToolListChangedNotification,
110+
} from "@modelcontextprotocol/sdk/types.js";
111+
112+
/**
113+
* All request types in the MCP Apps protocol.
114+
*
115+
* Includes:
116+
* - MCP UI requests (initialize, open-link, message, resource-teardown)
117+
* - MCP server requests forwarded from the app (tools/call, resources/*, prompts/list)
118+
* - Protocol requests (ping)
119+
*/
120+
export type AppRequest =
121+
| McpUiInitializeRequest
122+
| McpUiOpenLinkRequest
123+
| McpUiMessageRequest
124+
| McpUiResourceTeardownRequest
125+
| CallToolRequest
126+
| ListToolsRequest
127+
| ListResourcesRequest
128+
| ListResourceTemplatesRequest
129+
| ReadResourceRequest
130+
| ListPromptsRequest
131+
| PingRequest;
132+
133+
/**
134+
* All notification types in the MCP Apps protocol.
135+
*
136+
* Host to app:
137+
* - Tool lifecycle (input, input-partial, result, cancelled)
138+
* - Host context changes
139+
* - MCP list changes (tools, resources, prompts)
140+
* - Sandbox resource ready
141+
*
142+
* App to host:
143+
* - Initialized, size-changed, sandbox-proxy-ready
144+
* - Logging messages
145+
*/
146+
export type AppNotification =
147+
// Sent to app
148+
| McpUiHostContextChangedNotification
149+
| McpUiToolInputNotification
150+
| McpUiToolInputPartialNotification
151+
| McpUiToolResultNotification
152+
| McpUiToolCancelledNotification
153+
| McpUiSandboxResourceReadyNotification
154+
| ToolListChangedNotification
155+
| ResourceListChangedNotification
156+
| PromptListChangedNotification
157+
// Received from app
158+
| McpUiInitializedNotification
159+
| McpUiSizeChangedNotification
160+
| McpUiSandboxProxyReadyNotification
161+
| LoggingMessageNotification;
162+
163+
/**
164+
* All result types in the MCP Apps protocol.
165+
*/
166+
export type AppResult =
167+
| McpUiInitializeResult
168+
| McpUiOpenLinkResult
169+
| McpUiMessageResult
170+
| McpUiResourceTeardownResult
171+
| CallToolResult
172+
| ListToolsResult
173+
| ListResourcesResult
174+
| ListResourceTemplatesResult
175+
| ReadResourceResult
176+
| ListPromptsResult
177+
| EmptyResult;

0 commit comments

Comments
 (0)