Nvidia NIM Nemotron Google Sheets Orchestrator

Nvidia NIM Nemotron Google Sheets Orchestrator

AI-driven chatbot orchestrator using Nvidia NIM Nemotron-3 (120B) to read and write Google Sheets via MCP and serverless Lambda.

Category
访问服务器

README

Nvidia NIM Nemotron Google Sheets Orchestrator: MCP & Serverless Lambda

This repository contains a production-ready, AI-driven chatbot orchestrator that can read and write data to a Google Sheet using the Nvidia NIM Nemotron-3 (120B) model. It supports two distinct architectural implementations:

  1. Local Multi-Container MCP Stack: Client-server separation using FastMCP and Server-Sent Events (SSE) private networks.
  2. Serverless AWS Lambda Container: Consolidated, event-driven Lambda function behind API Gateway, using AWS Secrets Manager for OAuth token storage.

🚀 Key Features

  • Brain (LLM): Integrates the state-of-the-art nvidia/nemotron-3-super-120b-a12b model via Nvidia NIM.
  • Decoupled MCP Architecture: FastMCP Google Sheets server communicating with a FastAPI agent client over Server-Sent Events (SSE).
  • Serverless Refactoring: Collapse the SSE network architecture into a single-process containerized AWS Lambda handler with in-process tool calling.
  • Security (Zero Secret Hardcoding): Google OAuth Client ID, Secret, and Refresh Token are fetched dynamically in-memory from AWS Secrets Manager at runtime (no token files baked into the image).
  • Telegram Webhook Reply: Optimized Lambda response payload supporting the Telegram Webhook Reply protocol (method: "sendMessage") for instant response routing.
  • Resilient OAuth Consent Helper: Native local helper script (refresh_oauth.py) to trigger browser consent flows on the host machine and instantly sync refreshed tokens to AWS Secrets Manager.

📐 Architectures

1. Local Multi-Container (MCP)

  [User] ──(Webhook)──> [FastAPI Client] ──(SSE Network Bridge)──> [FastMCP Server] ──> [Google Sheets API]
                             │
                      (Nvidia NIM API)
                             ▼
                    [Nemotron-3 LLM]

2. Serverless AWS Lambda (Production)

  [User] ──(Telegram POST)──> [API Gateway /webhook]
                                      │
                                      ▼
                             [AWS Lambda Function] (Container Image)
                                 │          │
                     (In-Process Call)    (boto3) ──> [Secrets Manager]
                                 ▼
                          [app/tools.py]
                                 │
                                 ▼
                        [Google Sheets API]

🛠️ Folder Structure

├── app/                  # Consolidated serverless Lambda source code
│   ├── __init__.py
│   ├── secrets.py        # Credentials resolver (LOCAL_DEV env vs Production Secrets Manager)
│   ├── tools.py          # Google Sheets API read/write tools (LangChain decorated)
│   ├── agent.py          # LangGraph ReAct agent binding tools to ChatNVIDIA
│   └── main.py           # Lambda entrypoint handler & local CLI REPL
├── client/               # Original local FastAPI Agent Client (MCP mode)
├── server/               # Original local FastMCP Google Sheets Server (MCP mode)
├── Dockerfile            # Packages the app/ module for AWS Lambda
├── template.yaml         # AWS SAM Template declaration
├── requirements.txt      # Consolidated dependencies for AWS Lambda
├── refresh_oauth.py      # Local OAuth browser consent helper & Secrets Manager syncer
└── .env                  # Local environment file (ignored by Git)

📦 Running Locally

Step 1: Initialize OAuth Credentials

  1. Go to the Google Cloud Console.
  2. Enable the Google Sheets API.
  3. Setup the OAuth Consent Screen (User Type: External, Status: Testing, add your email as a Test User).
  4. Create an OAuth Client ID of type Desktop app.
  5. Download the secret JSON, rename it to credentials.json, and place it in ./server/credentials.json.

Step 2: Perform Initial Consent & Run Local Stack

  1. Run the local consent flow:
    cd server
    pip install -r requirements.txt
    python sheets_mcp.py
    
    A browser window will open. Click 'Allow' to grant access. This generates the initial token.json file.
  2. Copy .env.example to .env in the root and fill in your keys:
    • NVIDIA_API_KEY: Your Nvidia API key.
    • SPREADSHEET_ID: Your default target spreadsheet ID.
    • TELEGRAM_BOT_TOKEN: Your Telegram Bot API token.
  3. Start the local multi-container stack:
    docker-compose up --build -d
    

☁️ Deploying to AWS Lambda (Serverless)

AWS Lambda container images require the Docker V2 Schema 2 format. Standard OCI manifests (with buildx attestations/SBOMs) will be rejected by AWS with an InvalidParameterValueException.

To compile, build ECR registries, build the container image securely, push, create IAM roles, upload credentials, and deploy your API Gateway triggers, a complete deployment helper is provided in the project history. You can perform these steps manually or use standard SAM CLI:

Manual SAM Build & Deploy

  1. Save Google Credentials to Secrets Manager: Create a secret in AWS Secrets Manager named sheets-orchestrator-google-oauth containing:
    {
      "client_id": "YOUR_CLIENT_ID",
      "client_secret": "YOUR_CLIENT_SECRET",
      "refresh_token": "YOUR_REFRESH_TOKEN"
    }
    
  2. Build and Deploy:
    sam build
    sam deploy --guided
    
    Provide your stack name, AWS Region, NvidiaApiKey, and the secret ARN. Once deployment is complete, SAM will output the public regional Webhook URL: https://<api-id>.execute-api.<region>.amazonaws.com/Prod/webhook

🔄 Refreshing OAuth Credentials (The 7-Day Limit)

If your Google Cloud Console project is in Testing publishing status, your Google refresh token will expire after 7 days.

To resolve token expiry errors without having to redeploy your code:

  1. Run the local OAuth syncer from your project root:
    python refresh_oauth.py
    
  2. Sign in via your web browser.
  3. The script will automatically fetch the new refresh token, write it to your local .env, connect to AWS, and update the secret in AWS Secrets Manager.
  4. The Lambda function will pick up the new credentials on its next execution.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选