mcpField
G
Google AI Studio MCP Server

Google AI Studio MCP Server

本地服务
github.com/eternnoir媒体与设计4167 周前更新

关于 Google AI Studio MCP Server

AI Studio MCP Server 是一个基于 Google AI Studio / Gemini API 的 MCP 服务,可通过 MCP 客户端调用 Gemini 生成内容,支持文件、对话历史和系统提示词。该项目面向需要在 MCP 工作流中处理图片、PDF、音频等文件的用户。

主要功能

  1. 01调用 Gemini 2.5 模型生成内容
  2. 02支持图片、视频、音频、PDF 与文本文件
  3. 03可通过 path 或 Base64 content 传入文件
  4. 04支持系统提示词与 temperature 等参数
  5. 05可通过环境变量配置模型、超时和文件限制

适用场景

  1. 01将 PDF 转换为 Markdown
  2. 02分析图片、截图或架构图
  3. 03转录音频文件

MCP 相关

该项目是一个 MCP 服务,向 MCP 客户端暴露 generate_content 工具,用于调用 Gemini 生成内容。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

mcp.json · 通用配置
{
"mcpServers": {
"aistudio": {
"command": "npx",
"args": [
"-y",
"aistudio-mcp-server"
],
"env": {
"GEMINI_API_KEY": "<GEMINI_API_KEY>",
"GEMINI_MODEL": "<GEMINI_MODEL>",
"GEMINI_TIMEOUT": "<GEMINI_TIMEOUT>",
"GEMINI_MAX_OUTPUT_TOKENS": "<GEMINI_MAX_OUTPUT_TOKENS>",
"GEMINI_MAX_FILES": "<GEMINI_MAX_FILES>",
"GEMINI_MAX_TOTAL_FILE_SIZE": "<GEMINI_MAX_TOTAL_FILE_SIZE>",
"GEMINI_TEMPERATURE": "<GEMINI_TEMPERATURE>"
}
}
}
}
启动命令npx -y aistudio-mcp-server
需要配置的环境变量
GEMINI_API_KEY密钥
GEMINI_MODEL
GEMINI_TIMEOUT
GEMINI_MAX_OUTPUT_TOKENS密钥
GEMINI_MAX_FILES
GEMINI_MAX_TOTAL_FILE_SIZE
GEMINI_TEMPERATURE

本地服务需要在你的电脑上安装运行环境(如 Node.js 18+)。各客户端的配置文件位置不同,请参考客户端文档。

安装包
npmaistudio-mcp-server

工具

1

收录的工具列表 · 更新于 2 周前

参数类型必填说明
filesarray否要包含在生成内容中的文件数组(可选)。支持图像、视频、音频、PDF 和文本文件。
modelstring否要使用的 Gemini 模型(可选)
only_imageboolean否为 true 时,仅返回图像,不返回文本(需要 enable_image_generation 为 true)
temperaturenumber否生成温度(0–2,默认值为 0.2)
user_promptstring是用于生成内容的用户提示词
system_promptstring否用于指导 AI 行为的系统提示词(可选)
image_save_pathstring否用于保存生成图像的可选目录路径。提供后,图像将保存到磁盘,且不会返回 data URI,以减少响应大小。未提供时,仅以 base64 data URI 的形式返回图像
thinking_budgetnumber否支持思考模式的模型的思考预算(-1 表示无限制)
enable_google_searchboolean否为模型启用 Google 搜索功能
enable_code_executionboolean否为模型启用代码执行功能
enable_image_generationboolean否启用图像生成能力(需要兼容的模型,例如 gemini-2.5-flash-image-preview)

详细介绍

AI Studio MCP 服务

一个模型上下文协议(MCP)服务,可与 Google AI Studio / Gemini 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

可用工具

generate_content

使用 Gemini 生成内容,全面支持文件、对话历史记录和系统提示词。支持多种文件类型,包括图像、PDF、Office 文档和文本文件。

参数:

  • 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(使用 Cloud Storage 时为 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

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。