mcp-ui 0.1.0__py3-none-any.whl

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,306 @@
1
+ Metadata-Version: 2.4
2
+ Name: mcp-ui
3
+ Version: 0.1.0
4
+ Summary: A Python SDK for building MCP UI resources (iframe, panels, text blocks, etc.) in a type-safe way.
5
+ Project-URL: Homepage, https://github.com/jameszokah/mcp-ui
6
+ Project-URL: Repository, https://github.com/jameszokah/mcp-ui
7
+ Project-URL: Issues, https://github.com/jameszokah/mcp-ui/issues
8
+ Project-URL: Documentation, https://github.com/jameszokah/mcp-ui#readme
9
+ Author-email: James Zokah <jameszokah@gmail.com>
10
+ License: MIT
11
+ License-File: LICENSE
12
+ Keywords: agents,chat,iframe,mcp,python,sdk,ui
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Requires-Python: >=3.9
23
+ Description-Content-Type: text/markdown
24
+
25
+
26
+ # MCP-UI Python SDK
27
+
28
+ This library is a Python port of the MCP-UI TypeScript SDK.
29
+ It provides strongly typed helpers for creating UI resources and UI actions in MCP servers, with good DX (developer experience), type safety, and MCP-compatible JSON output.
30
+
31
+ ---
32
+
33
+ ## 📦 Installation
34
+
35
+ \`\`\`bash
36
+ pip install mcp-ui
37
+ \`\`\`
38
+
39
+ ---
40
+
41
+ ## 🚀 Core Concepts
42
+
43
+ ### What is a UI Resource?
44
+ A **UI resource** is a unit of UI data (e.g., an HTML snippet, iframe, or Remote DOM script) that MCP clients can render.
45
+ This SDK helps you create them consistently with correct metadata and encodings.
46
+
47
+ ### What is a UI Action?
48
+ A **UI action result** represents an action the MCP client should take (e.g., open a link, show a prompt, call a tool).
49
+
50
+ ---
51
+
52
+ ## 🔧 Usage
53
+
54
+ ### 1. Creating a UI Resource
55
+
56
+ #### Raw HTML
57
+
58
+ \`\`\`python
59
+ from mcp_ui import RawHtmlContent, CreateUIResourceOptions, create_ui_resource
60
+
61
+ options = CreateUIResourceOptions(
62
+ uri="ui://demo/html",
63
+ content=RawHtmlContent(type="rawHtml", htmlString="<h1>Hello MCP</h1>"),
64
+ encoding="text"
65
+ )
66
+
67
+ resource = create_ui_resource(options)
68
+ print(resource)
69
+ \`\`\`
70
+
71
+ **Output:**
72
+
73
+ \`\`\`json
74
+ {
75
+ "type": "resource",
76
+ "resource": {
77
+ "uri": "ui://demo/html",
78
+ "mimeType": "text/html",
79
+ "text": "<h1>Hello MCP</h1>",
80
+ "blob": null,
81
+ "_meta": null
82
+ }
83
+ }
84
+ \`\`\`
85
+
86
+ #### External URL (iframe)
87
+
88
+ \`\`\`python
89
+ from mcp_ui import ExternalUrlContent, CreateUIResourceOptions, create_ui_resource
90
+
91
+ options = CreateUIResourceOptions(
92
+ uri="ui://demo/frame",
93
+ content=ExternalUrlContent(type="externalUrl", iframeUrl="https://example.com"),
94
+ encoding="text"
95
+ )
96
+
97
+ iframe_res = create_ui_resource(options)
98
+ \`\`\`
99
+
100
+ **Output:**
101
+
102
+ \`\`\`json
103
+ {
104
+ "type": "resource",
105
+ "resource": {
106
+ "uri": "ui://demo/frame",
107
+ "mimeType": "text/uri-list",
108
+ "text": "https://example.com",
109
+ "blob": null,
110
+ "_meta": null
111
+ }
112
+ }
113
+ \`\`\`
114
+
115
+ #### Remote DOM (React)
116
+
117
+ \`\`\`python
118
+ from mcp_ui import RemoteDomContent, CreateUIResourceOptions, create_ui_resource
119
+
120
+ options = CreateUIResourceOptions(
121
+ uri="ui://demo/react",
122
+ content=RemoteDomContent(type="remoteDom", script="console.log('Hello')", framework="react"),
123
+ encoding="blob"
124
+ )
125
+
126
+ remote_res = create_ui_resource(options)
127
+ \`\`\`
128
+
129
+ **Output (blob is Base64-encoded):**
130
+
131
+ \`\`\`json
132
+ {
133
+ "type": "resource",
134
+ "resource": {
135
+ "uri": "ui://demo/react",
136
+ "mimeType": "application/vnd.mcp-ui.remote-dom+javascript; framework=react",
137
+ "blob": "Y29uc29sZS5sb2coJ0hlbGxvJyk=",
138
+ "text": null,
139
+ "_meta": null
140
+ }
141
+ }
142
+ \`\`\`
143
+
144
+ ---
145
+
146
+ ### 2. Adding Metadata
147
+
148
+ You can attach metadata to resources. Keys are automatically prefixed with \`mcpui.dev/ui-\`.
149
+
150
+ \`\`\`python
151
+ options = CreateUIResourceOptions(
152
+ uri="ui://demo/meta",
153
+ content=RawHtmlContent(type="rawHtml", htmlString="<p>Meta Example</p>"),
154
+ encoding="text",
155
+ uiMetadata={"PREFERRED_FRAME_SIZE": {"width": 500, "height": 300}}
156
+ )
157
+
158
+ meta_res = create_ui_resource(options)
159
+ \`\`\`
160
+
161
+ **Output includes \`_meta\`:**
162
+
163
+ \`\`\`json
164
+ {
165
+ "type": "resource",
166
+ "resource": {
167
+ "uri": "ui://demo/meta",
168
+ "mimeType": "text/html",
169
+ "text": "<p>Meta Example</p>",
170
+ "blob": null,
171
+ "_meta": {
172
+ "mcpui.dev/ui-preferred-frame-size": { "width": 500, "height": 300 }
173
+ }
174
+ }
175
+ }
176
+ \`\`\`
177
+
178
+ ---
179
+
180
+ ### 3. UI Action Results
181
+
182
+ #### Tool Call
183
+
184
+ \`\`\`python
185
+ from mcp_ui import ui_action_result_tool_call
186
+ action = ui_action_result_tool_call("searchTool", {"query": "MCP SDK"})
187
+ \`\`\`
188
+
189
+ **Output:**
190
+
191
+ \`\`\`json
192
+ {
193
+ "type": "tool",
194
+ "payload": {
195
+ "toolName": "searchTool",
196
+ "params": { "query": "MCP SDK" }
197
+ }
198
+ }
199
+ \`\`\`
200
+
201
+ #### Prompt
202
+
203
+ \`\`\`python
204
+ from mcp_ui import ui_action_result_prompt
205
+ action = ui_action_result_prompt("Please confirm your choice")
206
+ \`\`\`
207
+
208
+ **Output:**
209
+
210
+ \`\`\`json
211
+ {
212
+ "type": "prompt",
213
+ "payload": { "prompt": "Please confirm your choice" }
214
+ }
215
+ \`\`\`
216
+
217
+ #### Link
218
+
219
+ \`\`\`python
220
+ from mcp_ui import ui_action_result_link
221
+ action = ui_action_result_link("https://example.com")
222
+ \`\`\`
223
+
224
+ **Output:**
225
+
226
+ \`\`\`json
227
+ {
228
+ "type": "link",
229
+ "payload": { "url": "https://example.com" }
230
+ }
231
+ \`\`\`
232
+
233
+ #### Intent
234
+
235
+ \`\`\`python
236
+ from mcp_ui import ui_action_result_intent
237
+ action = ui_action_result_intent("share", {"platform": "twitter"})
238
+ \`\`\`
239
+
240
+ **Output:**
241
+
242
+ \`\`\`json
243
+ {
244
+ "type": "intent",
245
+ "payload": {
246
+ "intent": "share",
247
+ "params": { "platform": "twitter" }
248
+ }
249
+ }
250
+ \`\`\`
251
+
252
+ #### Notification
253
+
254
+ \`\`\`python
255
+ from mcp_ui import ui_action_result_notification
256
+ action = ui_action_result_notification("Saved successfully!")
257
+ \`\`\`
258
+
259
+ **Output:**
260
+
261
+ \`\`\`json
262
+ {
263
+ "type": "notify",
264
+ "payload": { "message": "Saved successfully!" }
265
+ }
266
+ \`\`\`
267
+
268
+ ---
269
+
270
+ ## 📖 API Reference
271
+
272
+ ### create_ui_resource(options: CreateUIResourceOptions) → Dict[str, Any]
273
+ Creates a UI resource for MCP. Returns a JSON-serializable dict.
274
+
275
+ **Parameters:**
276
+ - \`uri\`: must start with \`ui://\`
277
+ - \`content\`: one of \`RawHtmlContent\`, \`ExternalUrlContent\`, \`RemoteDomContent\`
278
+ - \`encoding\`: \`"text"\` or \`"blob"\`
279
+ - \`uiMetadata\`: UI-specific metadata (auto-prefixed)
280
+ - \`metadata\`: General metadata
281
+ - \`resourceProps\`: Extra resource fields
282
+
283
+ **Type System:**
284
+ - **Content payloads**:
285
+ - RawHtmlContent(htmlString)
286
+ - ExternalUrlContent(iframeUrl)
287
+ - RemoteDomContent(script, framework)
288
+ - **Resource encodings**:
289
+ - HTMLTextContent (text string)
290
+ - Base64BlobContent (blob string, base64)
291
+ - **UI Action Results**:
292
+ - tool, prompt, link, intent, notify
293
+
294
+ ---
295
+
296
+ ## ⚙️ Notes
297
+
298
+ - Internally uses dataclasses for type safety, but always returns dicts (via \`asdict()\`) for MCP compatibility.
299
+ - Enforces URI format (\`ui://\` prefix).
300
+ - Auto-encodes blob resources in Base64.
301
+
302
+ ---
303
+
304
+ ## 📄 License
305
+
306
+ MIT – same as the original MCP-UI SDK.
@@ -0,0 +1,4 @@
1
+ mcp_ui-0.1.0.dist-info/METADATA,sha256=AdeUTQHlblMMQdW8JJ7CzsbVY0a0PbPQCV7G01UN0mc,6724
2
+ mcp_ui-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
3
+ mcp_ui-0.1.0.dist-info/licenses/LICENSE,sha256=pAZXnNE2dxxwXFIduGyn1gpvPefJtUYOYZOi3yeGG94,1068
4
+ mcp_ui-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [year] [fullname]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.