Nymbo commited on
Commit
b1b6396
·
verified ·
1 Parent(s): 82f0069

fixing mcp tools

Browse files
Files changed (1) hide show
  1. app.py +80 -9
app.py CHANGED
@@ -251,7 +251,28 @@ def Fetch_Webpage( # <-- MCP tool #1 (Fetch)
251
  max_links: int = 20,
252
  ) -> str:
253
  """
254
- Given a URL, return a tight Markdown summary: title, key metadata, readable text, and links.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
255
  """
256
  if not url or not url.strip():
257
  return "Please enter a valid URL."
@@ -314,7 +335,18 @@ def Search_Structured( # <-- MCP tool #2 (Structured DDG)
314
  max_results: int = 5,
315
  ) -> List[Dict[Literal["snippet", "title", "link"], str]]:
316
  """
317
- Run a DuckDuckGo search and return a list of {snippet, title, link}.
 
 
 
 
 
 
 
 
 
 
 
318
  """
319
  if not input_query or not input_query.strip():
320
  return []
@@ -335,7 +367,15 @@ def Search_Raw( # <-- MCP tool #3 (Unstructured DDG)
335
  query: str,
336
  ) -> list[dict]:
337
  """
338
- Search using Native DDG client. Returns a plain list[dict] exactly like your separate space.
 
 
 
 
 
 
 
 
339
  """
340
  if not query or not query.strip():
341
  return []
@@ -357,14 +397,26 @@ def Search_Concise( # <-- MCP tool #4 (Concise DDG)
357
  title_chars: int = 80,
358
  ) -> str:
359
  """
360
- Minimal-output DuckDuckGo search designed to reduce tokens:
361
- - Returns newline-delimited JSON (JSONL) with short keys:
362
- t=title, u=url, s=snippet
 
 
 
 
 
 
 
 
 
363
 
364
  Returns:
365
- A compact string like:
366
- {"t":"Example","u":"https://example.com/x"}
367
- {"t":"Another…","u":"https://a.com/y","s":"Short snippet…"}
 
 
 
368
  """
369
 
370
  if not query or not query.strip():
@@ -425,6 +477,12 @@ fetch_interface = gr.Interface(
425
  outputs=gr.Markdown(label="Extracted Summary"),
426
  title="Fetch Webpage",
427
  description="Extract title, key metadata, readable text, and links. No noisy HTML.",
 
 
 
 
 
 
428
  allow_flagging="never",
429
  theme="Nymbo/Nymbo_Theme",
430
  )
@@ -439,6 +497,10 @@ websearch_interface = gr.Interface(
439
  outputs=gr.JSON(label="Search results"),
440
  title="DuckDuckGo Search (Structured)",
441
  description="Search the web using DuckDuckGo; returns snippet, title, and link.",
 
 
 
 
442
  allow_flagging="never",
443
  theme="Nymbo/Nymbo_Theme",
444
  )
@@ -450,6 +512,10 @@ unstructured_interface = gr.Interface(
450
  outputs=gr.Textbox(label="Results", interactive=False),
451
  title="DuckDuckGo Search (Raw)",
452
  description="Returns the raw list of results (list[dict]) shown as text.",
 
 
 
 
453
  allow_flagging="never",
454
  theme="Nymbo/Nymbo_Theme",
455
  submit_btn="Search",
@@ -469,6 +535,11 @@ concise_interface = gr.Interface(
469
  outputs=gr.Textbox(label="Results (JSONL)", interactive=False),
470
  title="DuckDuckGo Search (Concise)",
471
  description="Emits JSONL with short keys (t,u[,s]). Defaults avoid snippets and duplicate domains.",
 
 
 
 
 
472
  allow_flagging="never",
473
  theme="Nymbo/Nymbo_Theme",
474
  submit_btn="Search",
 
251
  max_links: int = 20,
252
  ) -> str:
253
  """
254
+ Fetch a web page and return a compact Markdown summary that includes title, key
255
+ metadata, readable main text, and outbound links.
256
+
257
+ Args:
258
+ url (str): The HTTP/HTTPS URL to fetch. Must be publicly reachable.
259
+ verbosity (str): Controls body length. One of: "Brief", "Standard", or "Full".
260
+ - Brief ≈ up to 1,200 chars
261
+ - Standard ≈ up to 3,000 chars
262
+ - Full = no cap (still limited by `max_chars` if smaller)
263
+ include_metadata (bool): If True, include a Metadata section with description,
264
+ site name, canonical URL, language, and fetched URL.
265
+ include_text (bool): If True, include the extracted readable body text.
266
+ include_links (bool): If True, include a list of outbound links found in the
267
+ readable section only (deduped and fragment-stripped).
268
+ max_chars (int): Hard cap for body text length. Numeric value between 400 and
269
+ 12000. The effective cap is the smaller of this value and the preset based
270
+ on `verbosity`.
271
+ max_links (int): Maximum number of links to include. Numeric value between 0 and 100.
272
+
273
+ Returns:
274
+ str: Markdown string containing the extracted summary. If the page cannot be
275
+ fetched or parsed, a short error message is returned instead.
276
  """
277
  if not url or not url.strip():
278
  return "Please enter a valid URL."
 
335
  max_results: int = 5,
336
  ) -> List[Dict[Literal["snippet", "title", "link"], str]]:
337
  """
338
+ Run a DuckDuckGo search and return structured results as a list of dictionaries.
339
+
340
+ Args:
341
+ input_query (str): The search query. Supports operators like site:, quotes,
342
+ and boolean keywords.
343
+ max_results (int): Number of results to return (1–20).
344
+
345
+ Returns:
346
+ List[Dict[Literal["snippet","title","link"], str]]: Each item contains:
347
+ - snippet: Short text snippet
348
+ - title: Result title
349
+ - link: Result URL
350
  """
351
  if not input_query or not input_query.strip():
352
  return []
 
367
  query: str,
368
  ) -> list[dict]:
369
  """
370
+ Run a DuckDuckGo search using the native `duckduckgo_search` client and return the
371
+ raw Python list of dictionaries from the library.
372
+
373
+ Args:
374
+ query (str): The search query string.
375
+
376
+ Returns:
377
+ list[dict]: The unmodified objects returned by `DDGS().text(...)`, typically
378
+ containing keys like: title, href/link, body/snippet, source, etc.
379
  """
380
  if not query or not query.strip():
381
  return []
 
397
  title_chars: int = 80,
398
  ) -> str:
399
  """
400
+ Run a DuckDuckGo search and return ultra-compact JSONL lines with short keys to
401
+ minimize tokens.
402
+
403
+ Args:
404
+ query (str): The search query string.
405
+ max_results (int): Maximum number of results to retrieve (1–20).
406
+ include_snippets (bool): If True, include a shortened snippet per result under
407
+ key "s".
408
+ max_snippet_chars (int): Hard cap for snippet length when `include_snippets`
409
+ is True. Range 20–200.
410
+ dedupe_domains (bool): If True, only keep the first result per domain.
411
+ title_chars (int): Hard cap for the title length. Range 20–120.
412
 
413
  Returns:
414
+ str: Newline-delimited JSON (JSONL). Each line is a compact JSON object with
415
+ short keys: "t" (title), "u" (URL), and optionally "s" (snippet).
416
+
417
+ Example lines:
418
+ {"t":"Example","u":"https://example.com/x"}
419
+ {"t":"Another…","u":"https://a.com/y","s":"Short snippet…"}
420
  """
421
 
422
  if not query or not query.strip():
 
477
  outputs=gr.Markdown(label="Extracted Summary"),
478
  title="Fetch Webpage",
479
  description="Extract title, key metadata, readable text, and links. No noisy HTML.",
480
+ api_description=(
481
+ "Fetch a web page and return a compact Markdown summary with title, key "
482
+ "metadata, readable body text, and outbound links. Parameters let you "
483
+ "control verbosity, whether to include metadata/text/links, and limits "
484
+ "for characters and number of links."
485
+ ),
486
  allow_flagging="never",
487
  theme="Nymbo/Nymbo_Theme",
488
  )
 
497
  outputs=gr.JSON(label="Search results"),
498
  title="DuckDuckGo Search (Structured)",
499
  description="Search the web using DuckDuckGo; returns snippet, title, and link.",
500
+ api_description=(
501
+ "Run a DuckDuckGo web search and return a list of objects with keys: "
502
+ "snippet, title, and link. Configure the number of results."
503
+ ),
504
  allow_flagging="never",
505
  theme="Nymbo/Nymbo_Theme",
506
  )
 
512
  outputs=gr.Textbox(label="Results", interactive=False),
513
  title="DuckDuckGo Search (Raw)",
514
  description="Returns the raw list of results (list[dict]) shown as text.",
515
+ api_description=(
516
+ "Run DuckDuckGo via the native client and return the raw list[dict] as "
517
+ "provided by duckduckgo_search (fields like title, href/link, body/snippet)."
518
+ ),
519
  allow_flagging="never",
520
  theme="Nymbo/Nymbo_Theme",
521
  submit_btn="Search",
 
535
  outputs=gr.Textbox(label="Results (JSONL)", interactive=False),
536
  title="DuckDuckGo Search (Concise)",
537
  description="Emits JSONL with short keys (t,u[,s]). Defaults avoid snippets and duplicate domains.",
538
+ api_description=(
539
+ "Run a DuckDuckGo search and return newline-delimited JSON with short keys: "
540
+ "t=title, u=url, optional s=snippet. Options control result count, "
541
+ "snippet inclusion and length, domain deduping, and title length."
542
+ ),
543
  allow_flagging="never",
544
  theme="Nymbo/Nymbo_Theme",
545
  submit_btn="Search",