Skip to content

feat: Implement a FastMCP server to expose NotebookLM functionalities for listing, creating, adding sources, and chatting.#156

Open
StudioPi048 wants to merge 1 commit intoteng-lin:mainfrom
StudioPi048:main
Open

feat: Implement a FastMCP server to expose NotebookLM functionalities for listing, creating, adding sources, and chatting.#156
StudioPi048 wants to merge 1 commit intoteng-lin:mainfrom
StudioPi048:main

Conversation

@StudioPi048
Copy link

No description provided.

… for listing, creating, adding sources, and chatting.
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new FastMCP server designed to expose core functionalities of NotebookLM. This integration allows for programmatic interaction with NotebookLM, enabling users and applications to list, create, and manage notebooks, add web-based sources, and engage in conversational AI through a standardized API. The change significantly enhances the extensibility and automation capabilities for NotebookLM.

Highlights

  • FastMCP Server Implementation: A new mcp_server.py file has been added to implement a FastMCP server, enabling external access to NotebookLM functionalities.
  • Notebook Management: Tools for listing existing NotebookLM notebooks and creating new ones are now exposed via the FastMCP server.
  • Source Integration: Functionality to add web URL sources to specified NotebookLM notebooks has been integrated.
  • Conversational AI: A chat interface is provided, allowing users to ask questions to NotebookLM notebooks and receive answers based on their sources.
Changelog
  • mcp_server.py
    • Implemented a new FastMCP server to provide an API for NotebookLM functionalities.
    • Added tools for listing and creating NotebookLM notebooks.
    • Included a tool to add web URL sources to notebooks.
    • Integrated a chat tool to interact with notebooks.
Activity
  • No specific activity (comments, reviews, progress updates) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a FastMCP server to expose NotebookLM functionalities. However, a potential path traversal vulnerability was identified in the add_source_url and chat_ask tools, where the notebook_id parameter is used to construct API request paths without validation, potentially allowing an attacker to manipulate the request path to call unintended endpoints on the Google domain. Additionally, the current management of the NotebookLMClient instance is inefficient due to new client creation for every request; a single, long-lived client instance is recommended for performance. There's also an opportunity to simplify the chat_ask function for better clarity and maintainability.

@mcp.tool()
async def list_notebooks():
"""List all NotebookLM notebooks available in the account."""
async with await NotebookLMClient.from_storage() as client:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The pattern async with await NotebookLMClient.from_storage() as client: is repeated in every tool function. This is inefficient for a server application because it creates a new NotebookLMClient instance for every API call. This involves I/O for reading storage state and setting up a new HTTP client each time. A NotebookLMClient is designed to be long-lived and should be reused across requests.

Consider creating a single client instance when the application starts and closing it on shutdown. This will significantly improve performance and resource management. You can likely achieve this using your server framework's startup and shutdown lifecycle events.

return {"id": nb.id, "title": nb.title}

@mcp.tool()
async def add_source_url(notebook_id: str, url: str):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-medium medium

The notebook_id parameter is used to construct the URL path for RPC calls to Google's NotebookLM API without any validation. An attacker could provide a malicious notebook_id containing path traversal sequences (e.g., ../../) to manipulate the request path and potentially call unintended API endpoints on the notebooklm.google.com domain using the user's authenticated session. This is possible because the notebook_id is directly interpolated into the source_path in the underlying library calls. Validate that notebook_id matches the expected format (e.g., a UUID or alphanumeric string) before using it in API calls.

return {"status": "success", "url": url}

@mcp.tool()
async def chat_ask(notebook_id: str, message: str):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-medium medium

The notebook_id parameter is used to construct the URL path for RPC calls to Google's NotebookLM API without any validation. An attacker could provide a malicious notebook_id containing path traversal sequences (e.g., ../../) to manipulate the request path and potentially call unintended API endpoints on the notebooklm.google.com domain using the user's authenticated session. This is possible because the notebook_id is directly interpolated into the source_path in the underlying library calls. Validate that notebook_id matches the expected format (e.g., a UUID or alphanumeric string) before using it in API calls.

"""Ask a question to the NotebookLM notebook and get an answer based on its sources."""
async with await NotebookLMClient.from_storage() as client:
result = await client.chat.ask(notebook_id, message)
return {"answer": result.text if hasattr(result, 'text') else result.answer}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The expression result.text if hasattr(result, 'text') else result.answer suggests uncertainty about the structure of the AskResult object. Based on the notebooklm library's implementation, client.chat.ask returns an AskResult object that consistently has an answer attribute. Relying on this attribute directly makes the code cleaner and easier to maintain. If there's a specific reason to check for a .text attribute (e.g., for backward compatibility), it would be helpful to add a comment explaining why.

Suggested change
return {"answer": result.text if hasattr(result, 'text') else result.answer}
return {"answer": result.answer}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant