reportflow-mcp bot commited on
Commit
eb69a42
·
1 Parent(s): f015cb7

Sync Space from reportflow-mcp@3614832

Browse files
Files changed (4) hide show
  1. README.md +23 -4
  2. app.py +64 -4
  3. gallery.py +63 -0
  4. requirements.txt +1 -1
README.md CHANGED
@@ -59,16 +59,35 @@ with the helper script in the repository and inject it as a header. The
59
  JavaScript client (`@huggingface/mcp-client`) works the same way — its server
60
  config nests under a `config` key rather than taking flat arguments.
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  ## The shortest path to a PDF
63
 
 
 
64
  ```
65
- list_templates → get_design_parameters → generate_pdf_sync
66
  ```
67
 
68
  Starting from an empty workspace, insert
69
- `search_gallery_templates → copy_gallery_template` to pull a template out of the
70
- public gallery first. Copy each template once and reuse the returned `designId`:
71
- every call creates a new design.
72
 
73
  ## Links
74
 
 
59
  JavaScript client (`@huggingface/mcp-client`) works the same way — its server
60
  config nests under a `config` key rather than taking flat arguments.
61
 
62
+ ## This Space as a Hub MCP server
63
+
64
+ Gradio is launched with `mcp_server=True`. Hub clients can add the Space via
65
+ the MCP badge, or:
66
+
67
+ `https://reportflow-readme.hf.space/gradio_api/mcp/`
68
+
69
+ Tools exposed here are **read-only public gallery** only:
70
+
71
+ | Tool | Purpose |
72
+ |---|---|
73
+ | `search_gallery_templates` | Keyword search over public templates |
74
+ | `get_gallery_template` | Detail for one `slug` |
75
+ | `get_register_url` | `https://re-port-flow.com/register` plus the product MCP URL |
76
+
77
+ They do not copy a template into a workspace and they do not render a
78
+ document. UI preview (PNG) is not an MCP tool.
79
+
80
  ## The shortest path to a PDF
81
 
82
+ Use the **product** MCP, not this Space:
83
+
84
  ```
85
+ list_templates → get_design_parameters → generate (sync)
86
  ```
87
 
88
  Starting from an empty workspace, insert
89
+ `search_gallery_templates → copy` (once per slug) on the product MCP to pull a
90
+ template out of the public gallery first. Reuse the returned `designId`.
 
91
 
92
  ## Links
93
 
app.py CHANGED
@@ -6,6 +6,7 @@ Does not generate PDFs. Sign-up and the hosted MCP server do that.
6
  from __future__ import annotations
7
 
8
  import io
 
9
 
10
  import gradio as gr
11
  from PIL import Image
@@ -17,6 +18,9 @@ from gallery import (
17
  fetch_thumbnail_png,
18
  get_template,
19
  list_categories,
 
 
 
20
  search_templates,
21
  )
22
 
@@ -124,9 +128,59 @@ def preview_template(slug: str) -> tuple[str, Image.Image | None]:
124
  return body, image
125
 
126
 
127
- def signup_cta() -> str:
128
- """Return the free-registration URL for generating PDFs after signup."""
129
- return REGISTER_URL
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
 
131
 
132
  def _category_choices() -> list[str]:
@@ -171,17 +225,23 @@ after you pick a template.
171
  fn=search_gallery,
172
  inputs=[query, category, sort],
173
  outputs=search_outputs,
 
174
  )
175
  query.submit(
176
  fn=search_gallery,
177
  inputs=[query, category, sort],
178
  outputs=search_outputs,
 
179
  )
180
  preview_btn.click(
181
  fn=preview_template,
182
  inputs=[slug],
183
  outputs=[detail, preview_image],
 
184
  )
 
 
 
185
 
186
  gr.Markdown(
187
  f"[Create a free account to generate PDFs]({REGISTER_URL}) · "
@@ -190,4 +250,4 @@ after you pick a template.
190
 
191
 
192
  if __name__ == "__main__":
193
- demo.launch()
 
6
  from __future__ import annotations
7
 
8
  import io
9
+ import json
10
 
11
  import gradio as gr
12
  from PIL import Image
 
18
  fetch_thumbnail_png,
19
  get_template,
20
  list_categories,
21
+ mcp_register,
22
+ mcp_search,
23
+ mcp_template,
24
  search_templates,
25
  )
26
 
 
128
  return body, image
129
 
130
 
131
+ def search_gallery_templates(
132
+ query: str = "",
133
+ category: str = "",
134
+ sort: str = "popular",
135
+ ) -> str:
136
+ """Search the public Re:port Flow template gallery (read-only, no login).
137
+
138
+ Does not copy a template or render a filled document. For those, the caller
139
+ must sign up and use the product MCP server in the returned mcpUrl.
140
+
141
+ Args:
142
+ query: Keyword matched against title, description, tags, category, slug.
143
+ category: Public category code, or empty / "(any)" for all categories.
144
+ sort: Either "popular" or "newest".
145
+
146
+ Returns:
147
+ JSON with items (slug, title, category, description), match counts,
148
+ registerUrl, and mcpUrl.
149
+ """
150
+ category_code = None if category in ("", "(any)") else category
151
+ try:
152
+ payload = mcp_search(query=query or "", category=category_code, sort=sort)
153
+ except GalleryError as err:
154
+ return json.dumps({"error": str(err)}, ensure_ascii=False)
155
+ return json.dumps(payload, ensure_ascii=False)
156
+
157
+
158
+ def get_gallery_template(slug: str) -> str:
159
+ """Get one public template by slug (read-only, no login).
160
+
161
+ The slug is not a workspace designId. This Space never copies a template
162
+ or renders a filled document.
163
+
164
+ Args:
165
+ slug: Template slug from search_gallery_templates.
166
+
167
+ Returns:
168
+ JSON with title, slug, category, version, description, registerUrl, mcpUrl.
169
+ """
170
+ try:
171
+ item = mcp_template(slug)
172
+ except GalleryError as err:
173
+ return json.dumps({"error": str(err)}, ensure_ascii=False)
174
+ return json.dumps(item, ensure_ascii=False)
175
+
176
+
177
+ def get_register_url() -> str:
178
+ """Return the free-registration URL and the product MCP endpoint.
179
+
180
+ Use this when the user wants to create a filled document. This Space
181
+ cannot do that.
182
+ """
183
+ return json.dumps(mcp_register(), ensure_ascii=False)
184
 
185
 
186
  def _category_choices() -> list[str]:
 
225
  fn=search_gallery,
226
  inputs=[query, category, sort],
227
  outputs=search_outputs,
228
+ show_api=False,
229
  )
230
  query.submit(
231
  fn=search_gallery,
232
  inputs=[query, category, sort],
233
  outputs=search_outputs,
234
+ show_api=False,
235
  )
236
  preview_btn.click(
237
  fn=preview_template,
238
  inputs=[slug],
239
  outputs=[detail, preview_image],
240
+ show_api=False,
241
  )
242
+ gr.api(search_gallery_templates, api_name="search_gallery_templates")
243
+ gr.api(get_gallery_template, api_name="get_gallery_template")
244
+ gr.api(get_register_url, api_name="get_register_url")
245
 
246
  gr.Markdown(
247
  f"[Create a free account to generate PDFs]({REGISTER_URL}) · "
 
250
 
251
 
252
  if __name__ == "__main__":
253
+ demo.launch(mcp_server=True)
gallery.py CHANGED
@@ -245,3 +245,66 @@ def fetch_thumbnail_png(slug: str, client: httpx.Client | None = None) -> bytes:
245
  except Exception as err:
246
  raise GalleryError("Could not render the public thumbnail PDF.") from err
247
  raise GalleryError("Public thumbnail was not an image or PDF.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
  except Exception as err:
246
  raise GalleryError("Could not render the public thumbnail PDF.") from err
247
  raise GalleryError("Public thumbnail was not an image or PDF.")
248
+
249
+
250
+ def mcp_search(
251
+ query: str = "",
252
+ category: str | None = None,
253
+ sort: str = "popular",
254
+ client: httpx.Client | None = None,
255
+ ) -> dict[str, Any]:
256
+ """JSON body for the Hub MCP search tool. Read-only public list."""
257
+ payload = search_templates(query=query, category=category, sort=sort, client=client)
258
+ items = []
259
+ for item in payload.get("items") or []:
260
+ if not isinstance(item, dict):
261
+ continue
262
+ items.append(
263
+ {
264
+ "slug": item.get("slug"),
265
+ "title": item.get("title"),
266
+ "category": item.get("category"),
267
+ "description": item.get("description"),
268
+ }
269
+ )
270
+ return {
271
+ "items": items,
272
+ "matched": payload.get("matched", len(items)),
273
+ "scanned": payload.get("scanned", 0),
274
+ "truncated": bool(payload.get("truncated")),
275
+ "registerUrl": REGISTER_URL,
276
+ "mcpUrl": MCP_URL,
277
+ "note": (
278
+ "These slugs cannot render a document from this Space. "
279
+ f"Sign up at {REGISTER_URL} and connect {MCP_URL}."
280
+ ),
281
+ }
282
+
283
+
284
+ def mcp_template(slug: str, client: httpx.Client | None = None) -> dict[str, Any]:
285
+ """JSON body for the Hub MCP detail tool. Read-only public detail."""
286
+ item = get_template(slug, client=client)
287
+ return {
288
+ "slug": item.get("slug"),
289
+ "title": item.get("title"),
290
+ "category": item.get("category"),
291
+ "version": item.get("version"),
292
+ "description": item.get("description"),
293
+ "registerUrl": REGISTER_URL,
294
+ "mcpUrl": MCP_URL,
295
+ "note": (
296
+ "To fill and render this template, sign up at "
297
+ f"{REGISTER_URL} then use {MCP_URL}."
298
+ ),
299
+ }
300
+
301
+
302
+ def mcp_register() -> dict[str, str]:
303
+ return {
304
+ "registerUrl": REGISTER_URL,
305
+ "mcpUrl": MCP_URL,
306
+ "note": (
307
+ "Create a free account, then connect the product MCP. "
308
+ "Do not send workspace credentials to this Space."
309
+ ),
310
+ }
requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
- gradio==5.50.0
2
  httpx>=0.27.0,<1
3
  pypdfium2>=4.30.0,<5
4
  pillow>=10.0.0,<12
 
1
+ gradio[mcp]==5.50.0
2
  httpx>=0.27.0,<1
3
  pypdfium2>=4.30.0,<5
4
  pillow>=10.0.0,<12