You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have managed to display Graphing plots by using the image return however I cannot figure out how I would return a downloadable link to content or to link to a webpage using the MCP inspector.
My current code is.
I would appreciate any help.
`@mcp.tool()
def create_download(filename: str, var_name: str, mime_type: str = None) -> dict:
"""
Create a download link for a variable in the global namespace.
Args:
filename: Name for the file to download
var_name: Name of the variable containing the bytes data
mime_type: Optional MIME type (will guess from filename if not provided)
"""
try:
if var_name not in GLOBAL_NAMESPACE:
return {"error": f"Error: Variable '{var_name}' not found"}
content = GLOBAL_NAMESPACE[var_name]
if not isinstance(content, bytes):
return {"error": f"Error: Variable '{var_name}' must contain bytes data"}
# Use mime_type if provided, otherwise guess from filename
if mime_type is None:
mime_type = mimetypes.guess_type(filename)[0] or 'application/octet-stream'
# Return a structured response with file details
return {
"type": "download",
"filename": filename,
"mime_type": mime_type,
"content": base64.b64encode(content).decode('utf-8')
}
except Exception as e:
return {"error": f"Error creating download: {str(e)}"}`
The text was updated successfully, but these errors were encountered:
Good day,
I have managed to display Graphing plots by using the image return however I cannot figure out how I would return a downloadable link to content or to link to a webpage using the MCP inspector.
My current code is.
I would appreciate any help.
`@mcp.tool()
def create_download(filename: str, var_name: str, mime_type: str = None) -> dict:
"""
Create a download link for a variable in the global namespace.
Args:
filename: Name for the file to download
var_name: Name of the variable containing the bytes data
mime_type: Optional MIME type (will guess from filename if not provided)
"""
try:
if var_name not in GLOBAL_NAMESPACE:
return {"error": f"Error: Variable '{var_name}' not found"}
The text was updated successfully, but these errors were encountered: