Back to MCP directory
publicPublicdnsLocal runtime

aistudio-mcp-server

AI Studio MCP Server是一个集成Google AI Studio/Gemini API的模型上下文协议服务器,提供支持文件、对话历史和系统提示的内容生成功能。

article

README

🚀 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  # 10 分钟
export GEMINI_MAX_OUTPUT_TOKENS=16384  # 更多输出令牌
export GEMINI_MAX_FILES=5  # 每个请求限制为 5 个文件
export GEMINI_MAX_TOTAL_FILE_SIZE=100  # 限制为 100MB
export GEMINI_TEMPERATURE=0.7  # 更具创造性的响应

💻 使用示例

基础用法

generate_content

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

参数:

  • user_prompt(字符串,必需):用于生成的用户提示
  • system_prompt(字符串,可选):引导 AI 行为的系统提示
  • files(数组,可选):要包含在生成中的文件数组
    • 每个文件对象必须有 pathcontent
    • 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 许可证。

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client