AI Studio MCP服务器
模型上下文协议(MCP)服务器,与Google AI Studio/Genium API集成,提供支持文件、对话历史记录和系统提示的内容生成功能。
安装和使用
先决条件
- Node.js 20.0.0或更高版本
- Google 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配置
将Google 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 # 10 minutes
export GEMINI_MAX_OUTPUT_TOKENS=16384 # More output tokens
export GEMINI_MAX_FILES=5 # Limit to 5 files per request
export GEMINI_MAX_TOTAL_FILE_SIZE=100 # 100MB limit
export GEMINI_TEMPERATURE=0.7 # More creative responses可用工具
生成内容
使用Gemini生成内容,全面支持文件、对话历史和系统提示。支持各种文件类型,包括图像、PDF、Office文档和文本文件。
参数:
user_prompt(string,必填):生成用户提示system_prompt(字符串,可选):引导AI行为的系统提示files(array,可选):要包含在生成中的文件数组
- 每个文件对象必须具有 path 或 content - path (string):文件路径 - content (string):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许可证
麻省理工学院
