Skip to content

Commit 200776d

Browse files
committed
Disabled some unused code for now
1 parent 2caec10 commit 200776d

File tree

1 file changed

+92
-71
lines changed
  • packages/fetchcraft-mcp-server/src/fetchcraft/mcp

1 file changed

+92
-71
lines changed

packages/fetchcraft-mcp-server/src/fetchcraft/mcp/mcp_api.py

Lines changed: 92 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -52,74 +52,95 @@ async def find_files(
5252
Dictionary containing the list of matching files, total count, and offset
5353
If format_html=True, returns a dictionary with 'html' key containing the formatted HTML
5454
"""
55-
try:
56-
paginated_nodes = await find_files_service.find_files(
57-
query=query,
58-
num_results=num_results,
59-
offset=offset
60-
)
61-
62-
# Convert nodes to file results
63-
files = []
64-
for node in paginated_nodes:
65-
# Get filename from metadata
66-
source = node.node.metadata.get("source", "Unknown")
67-
filename = node.node.metadata.get("filename", Path(source).name)
68-
69-
# Get a sample. Using n first paragraphs
70-
text = node.node.text.replace("\r\n", "\n")
71-
paragraphs = text.split("\n\n")
72-
preview = "\n\n".join(paragraphs[:5])
73-
74-
files.append({
75-
"filename": filename,
76-
"source": source,
77-
"score": float(node.score) if node.score else 0.0,
78-
"text_preview": (
79-
preview + f" ....\n({max(len(paragraphs) - 5, 0)} more paragraphs)"
80-
)
81-
})
82-
83-
# Prepare data for frontend
84-
data = {
85-
"query": query,
86-
"files": files,
87-
"total": len(paginated_nodes),
88-
"offset": offset,
89-
"serverUrl": server_url
90-
}
91-
92-
# Get frontend asset filenames for external loading
93-
css_filename, js_filename = _get_frontend_asset_filenames()
94-
95-
# Escape the JSON data to prevent issues with </script> tags in content
96-
json_data = json.dumps(data, ensure_ascii=False)
97-
98-
# Build asset URLs
99-
css_url = f"{server_url}/assets/{css_filename}" if css_filename else ""
100-
js_url = f"{server_url}/assets/{js_filename}" if js_filename else ""
101-
102-
# Build the redirect URL
103-
redirect_url = f"{server_url}/find-files?query={query}&num_results={num_results}&offset={offset}"
104-
105-
# HTML content with meta refresh redirect
106-
html_content = f"""<html lang="en">
107-
<head>
108-
<meta http-equiv="refresh" content="0;url={redirect_url}">
109-
</head>
110-
<body>
111-
<p>Redirecting to search results...</p>
112-
<a href="{redirect_url}" target="_top">Click here if not redirected</a>
113-
</body>
114-
</html>"""
115-
116-
# Format for MCP with artifact syntax
117-
# Using application/vnd.external-app type and mcpServer attribute for secure external app rendering
118-
response_header = f"Your search results for query: {query}"
119-
search_id = "_".join(query.split())
120-
artifact_header = f':::artifact{{identifier="{search_id}" type="application/vnd.external-app" title="File Search Results" mcpServer="{mcp_server_name}"}}'
121-
result = f"{response_header}\n{artifact_header}\n```html\n{html_content}\n```\n:::"
122-
123-
return result
124-
except Exception as e:
125-
raise RuntimeError(f"Error searching files: {str(e)}")
55+
# Build the redirect URL
56+
redirect_url = f"{server_url}/find-files?query={query}&num_results={num_results}&offset={offset}"
57+
58+
# HTML content with meta refresh redirect
59+
html_content = f"""<html lang="en">
60+
<head>
61+
<meta http-equiv="refresh" content="0;url={redirect_url}">
62+
</head>
63+
<body>
64+
<p>Redirecting to search results...</p>
65+
<a href="{redirect_url}" target="_top">Click here if not redirected</a>
66+
</body>
67+
</html>"""
68+
69+
response_header = f"Your search results for query: {query}"
70+
search_id = "_".join(query.split())
71+
artifact_header = f':::artifact{{identifier="{search_id}" type="application/vnd.external-app" title="File Search Results" mcpServer="{mcp_server_name}"}}'
72+
result = f"{response_header}\n{artifact_header}\n```html\n{html_content}\n```\n:::"
73+
74+
return result
75+
76+
# try:
77+
# paginated_nodes = await find_files_service.find_files(
78+
# query=query,
79+
# num_results=num_results,
80+
# offset=offset
81+
# )
82+
#
83+
# # Convert nodes to file results
84+
# files = []
85+
# for node in paginated_nodes:
86+
# # Get filename from metadata
87+
# source = node.node.metadata.get("source", "Unknown")
88+
# filename = node.node.metadata.get("filename", Path(source).name)
89+
#
90+
# # Get a sample. Using n first paragraphs
91+
# text = node.node.text.replace("\r\n", "\n")
92+
# paragraphs = text.split("\n\n")
93+
# preview = "\n\n".join(paragraphs[:5])
94+
#
95+
# files.append({
96+
# "filename": filename,
97+
# "source": source,
98+
# "score": float(node.score) if node.score else 0.0,
99+
# "text_preview": (
100+
# preview + f" ....\n({max(len(paragraphs) - 5, 0)} more paragraphs)"
101+
# )
102+
# })
103+
#
104+
# # Prepare data for frontend
105+
# data = {
106+
# "query": query,
107+
# "files": files,
108+
# "total": len(paginated_nodes),
109+
# "offset": offset,
110+
# "serverUrl": server_url
111+
# }
112+
#
113+
# # Get frontend asset filenames for external loading
114+
# css_filename, js_filename = _get_frontend_asset_filenames()
115+
#
116+
# # Escape the JSON data to prevent issues with </script> tags in content
117+
# json_data = json.dumps(data, ensure_ascii=False)
118+
#
119+
# # Build asset URLs
120+
# css_url = f"{server_url}/assets/{css_filename}" if css_filename else ""
121+
# js_url = f"{server_url}/assets/{js_filename}" if js_filename else ""
122+
#
123+
# # Build the redirect URL
124+
# redirect_url = f"{server_url}/find-files?query={query}&num_results={num_results}&offset={offset}"
125+
#
126+
# # HTML content with meta refresh redirect
127+
# html_content = f"""<html lang="en">
128+
# <head>
129+
# <meta http-equiv="refresh" content="0;url={redirect_url}">
130+
# </head>
131+
# <body>
132+
# <p>Redirecting to search results...</p>
133+
# <a href="{redirect_url}" target="_top">Click here if not redirected</a>
134+
# </body>
135+
# </html>"""
136+
#
137+
# # Format for MCP with artifact syntax
138+
# # Using application/vnd.external-app type and mcpServer attribute for secure external app rendering
139+
# response_header = f"Your search results for query: {query}"
140+
# search_id = "_".join(query.split())
141+
# artifact_header = f':::artifact{{identifier="{search_id}" type="application/vnd.external-app" title="File Search Results" mcpServer="{mcp_server_name}"}}'
142+
# result = f"{response_header}\n{artifact_header}\n```html\n{html_content}\n```\n:::"
143+
#
144+
# return result
145+
# except Exception as e:
146+
# raise RuntimeError(f"Error searching files: {str(e)}")

0 commit comments

Comments
 (0)