Spaces:
Running
Running
Fix MCP tool exposure to show only search_web
Browse files- Add api_name=False to button click and demo.load to hide from API
- Use gr.api() to explicitly expose only search_web as MCP tool
- Move docstring to proper position after function signature
- Maintains GUI functionality while providing clean MCP interface
app.py
CHANGED
@@ -26,7 +26,6 @@ rate_limit = parse("360/hour")
|
|
26 |
async def search_web(
|
27 |
query: str, search_type: str = "search", num_results: Optional[int] = 4
|
28 |
) -> str:
|
29 |
-
await record_request()
|
30 |
"""
|
31 |
Search the web for information or fresh news, returning extracted content.
|
32 |
|
@@ -66,6 +65,7 @@ async def search_web(
|
|
66 |
- search_web("stock market today", "news", 10) - Get 10 news articles about today's market
|
67 |
- search_web("machine learning basics") - Get 4 general search results (all defaults)
|
68 |
"""
|
|
|
69 |
if not SERPER_API_KEY:
|
70 |
return "Error: SERPER_API_KEY environment variable is not set. Please set it to use this tool."
|
71 |
|
@@ -297,11 +297,15 @@ with gr.Blocks(title="Web Search MCP Server") as demo:
|
|
297 |
fn=search_and_log, # wrapper
|
298 |
inputs=[query_input, search_type_input, num_results_input],
|
299 |
outputs=[output, requests_plot], # update both
|
|
|
300 |
)
|
301 |
|
302 |
# Load fresh analytics data when the page loads
|
303 |
demo.load(fn=lambda: last_n_days_df(14), outputs=requests_plot, api_name=False)
|
304 |
|
|
|
|
|
|
|
305 |
|
306 |
if __name__ == "__main__":
|
307 |
# Launch with MCP server enabled
|
|
|
26 |
async def search_web(
|
27 |
query: str, search_type: str = "search", num_results: Optional[int] = 4
|
28 |
) -> str:
|
|
|
29 |
"""
|
30 |
Search the web for information or fresh news, returning extracted content.
|
31 |
|
|
|
65 |
- search_web("stock market today", "news", 10) - Get 10 news articles about today's market
|
66 |
- search_web("machine learning basics") - Get 4 general search results (all defaults)
|
67 |
"""
|
68 |
+
await record_request()
|
69 |
if not SERPER_API_KEY:
|
70 |
return "Error: SERPER_API_KEY environment variable is not set. Please set it to use this tool."
|
71 |
|
|
|
297 |
fn=search_and_log, # wrapper
|
298 |
inputs=[query_input, search_type_input, num_results_input],
|
299 |
outputs=[output, requests_plot], # update both
|
300 |
+
api_name=False, # Hide this endpoint from API & MCP
|
301 |
)
|
302 |
|
303 |
# Load fresh analytics data when the page loads
|
304 |
demo.load(fn=lambda: last_n_days_df(14), outputs=requests_plot, api_name=False)
|
305 |
|
306 |
+
# Expose search_web as the only MCP tool
|
307 |
+
gr.api(search_web, api_name="search_web")
|
308 |
+
|
309 |
|
310 |
if __name__ == "__main__":
|
311 |
# Launch with MCP server enabled
|