Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I display a link for the user to 'download' a file or link to a webpage #72

Open
QMand opened this issue Dec 11, 2024 · 0 comments
Labels
question Further information is requested

Comments

@QMand
Copy link

QMand commented Dec 11, 2024

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"}

    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)}"}`
@github-actions github-actions bot added the question Further information is requested label Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant