🚀 AI Studio MCP 服務器
這是一個與谷歌 AI Studio / Gemini API 集成的模型上下文協議(MCP)服務器,它提供內容生成功能,支持文件、對話歷史和系統提示。
🚀 快速開始
前提條件
- Node.js 20.0.0 或更高版本
- 谷歌 AI Studio API 密鑰
使用 npx(推薦)
GEMINI_API_KEY=your_api_key npx -y aistudio-mcp-server
本地安裝
npm install -g aistudio-mcp-server
GEMINI_API_KEY=your_api_key aistudio-mcp-server
📦 安裝指南
配置
將你的谷歌 AI Studio API 密鑰設置為環境變量:
export GEMINI_API_KEY=your_api_key_here
可選配置
GEMINI_MODEL
:要使用的 Gemini 模型(默認:gemini-2.5-flash)
GEMINI_TIMEOUT
:請求超時時間(毫秒,默認:300000 = 5 分鐘)
GEMINI_MAX_OUTPUT_TOKENS
:最大輸出令牌數(默認:8192)
GEMINI_MAX_FILES
:每個請求的最大文件數(默認:10)
GEMINI_MAX_TOTAL_FILE_SIZE
:最大總文件大小(MB,默認:50)
GEMINI_TEMPERATURE
:生成溫度(0 - 2,默認:0.2)
示例:
export GEMINI_API_KEY=your_api_key_here
export GEMINI_MODEL=gemini-2.5-flash
export GEMINI_TIMEOUT=600000
export GEMINI_MAX_OUTPUT_TOKENS=16384
export GEMINI_MAX_FILES=5
export GEMINI_MAX_TOTAL_FILE_SIZE=100
export GEMINI_TEMPERATURE=0.7
💻 使用示例
基礎用法
generate_content
使用 Gemini 生成內容,全面支持文件、對話歷史和系統提示。支持多種文件類型,包括圖像、PDF、辦公文檔和文本文件。
參數:
user_prompt
(字符串,必需):用於生成的用戶提示
system_prompt
(字符串,可選):引導 AI 行為的系統提示
files
(數組,可選):要包含在生成中的文件數組
- 每個文件對象必須有
path
或 content
path
(字符串):文件路徑
content
(字符串):Base64 編碼的文件內容
type
(字符串,可選):MIME 類型(從文件擴展名自動檢測)
model
(字符串,可選):要使用的 Gemini 模型(默認:gemini-2.5-flash)
temperature
(數字,可選):生成溫度(0 - 2,默認:0.2)。較低的值產生更聚焦的響應,較高的值產生更具創造性的響應
支持的文件類型(Gemini 2.5 模型):
- 圖像:JPG、JPEG、PNG、GIF、WebP、SVG、BMP、TIFF
- 視頻:MP4、AVI、MOV、WEBM、FLV、MPG、WMV(每個請求最多 10 個文件)
- 音頻:MP3、WAV、AIFF、AAC、OGG、FLAC(每個文件最大 15MB)
- 文檔:PDF(視為圖像,一頁 = 一張圖像)
- 文本:TXT、MD、JSON、XML、CSV、HTML
文件限制:
- 最大文件大小:每個音頻/視頻/文檔文件 15MB
- 最大總請求大小:20MB(使用雲存儲時為 2GB)
- 視頻文件:每個請求最多 10 個
- PDF 文件遵循圖像定價(一頁 = 一張圖像)
基本示例:
{
"user_prompt": "Analyze this image and describe what you see",
"files": [
{
"path": "/path/to/image.jpg"
}
]
}
PDF 轉 Markdown:
{
"user_prompt": "Convert this PDF to well-formatted Markdown, preserving structure and formatting. Return only the Markdown content.",
"files": [
{
"path": "/path/to/document.pdf"
}
]
}
帶系統提示:
{
"system_prompt": "You are a helpful document analyst specialized in technical documentation",
"user_prompt": "Please provide a detailed explanation of the authentication methods shown in this document",
"files": [
{"path": "/api-docs.pdf"}
]
}
多文件示例:
{
"user_prompt": "Compare these documents and images",
"files": [
{"path": "/document.pdf"},
{"path": "/chart.png"},
{"content": "base64encodedcontent", "type": "image/jpeg"}
]
}
高級用法
常見用例
PDF 轉 Markdown
要將 PDF 文件轉換為 Markdown 格式,請使用 generate_content
工具並提供適當的提示:
{
"user_prompt": "Convert this PDF to well-formatted Markdown, preserving structure, headings, lists, and formatting. Include table of contents if the document has sections.",
"files": [
{
"path": "/path/to/document.pdf"
}
]
}
圖像分析
詳細分析圖像、圖表、示意圖或照片:
{
"system_prompt": "You are an expert image analyst. Provide detailed, accurate descriptions of visual content.",
"user_prompt": "Analyze this image and describe what you see. Include details about objects, people, text, colors, and composition.",
"files": [
{
"path": "/path/to/image.jpg"
}
]
}
對於截圖或技術示意圖:
{
"user_prompt": "Describe this system architecture diagram. Explain the components and their relationships.",
"files": [
{
"path": "/architecture-diagram.png"
}
]
}
音頻轉錄
從音頻文件生成轉錄內容:
{
"system_prompt": "You are a professional transcription service. Provide accurate, well-formatted transcripts.",
"user_prompt": "Please transcribe this audio file. Include speaker identification if multiple speakers are present, and format it with proper punctuation and paragraphs.",
"files": [
{
"path": "/meeting-recording.mp3"
}
]
}
對於面試或會議轉錄:
{
"user_prompt": "Transcribe this interview and provide a summary of key points discussed.",
"files": [
{
"path": "/interview.wav"
}
]
}
📚 詳細文檔
MCP 客戶端配置
將此服務器添加到你的 MCP 客戶端配置中:
{
"mcpServers": {
"aistudio": {
"command": "npx",
"args": ["-y", "aistudio-mcp-server"],
"env": {
"GEMINI_API_KEY": "your_api_key_here",
"GEMINI_MODEL": "gemini-2.5-flash",
"GEMINI_TIMEOUT": "600000",
"GEMINI_MAX_OUTPUT_TOKENS": "16384",
"GEMINI_MAX_FILES": "10",
"GEMINI_MAX_TOTAL_FILE_SIZE": "50",
"GEMINI_TEMPERATURE": "0.2"
}
}
}
}
開發
環境搭建
確保你已安裝 Node.js 20.0.0 或更高版本。
npm install
npm run build
本地運行
GEMINI_API_KEY=your_api_key npm run dev
📄 許可證
本項目採用 MIT 許可證。