AI API MCP Server

AI API MCP Server

A FastMCP-based Model Context Protocol (MCP) server that provides unified access to multiple AI APIs including OpenAI GPT, Google Gemini, Anthropic Claude, and xAI Grok.

Category
访问服务器

README

AI API MCP Server

A FastMCP-based Model Context Protocol (MCP) server that provides unified access to multiple AI APIs including OpenAI GPT, Google Gemini, Anthropic Claude, and xAI Grok.

📚 Documentation

Features

  • Unified Interface: Single MCP interface for multiple AI providers
  • Multiple Providers: Support for OpenAI, Anthropic, Google, and xAI
  • Streaming Support: Real-time streaming responses from all providers
  • Model Comparison: Compare responses from multiple models simultaneously
  • Content Analysis: Analyze code, text, security, and performance
  • Content Generation: Generate code, documentation, and tests
  • Automatic Retry: Built-in retry logic with exponential backoff
  • Error Handling: Comprehensive error handling across all providers

Installation

Quick Install

Choose your preferred installation method:

Using NPX (Recommended)

npx @physics91org/ai-api-mcp

Using Bun

bunx @physics91org/ai-api-mcp

Using Docker

docker run -it --rm \
  -e OPENAI_API_KEY=your_key \
  -e ANTHROPIC_API_KEY=your_key \
  -e GOOGLE_API_KEY=your_key \
  -e GROK_API_KEY=your_key \
  ai-api-mcp

Using Docker Compose

# Clone the repository first
git clone https://github.com/yourusername/ai-api-mcp.git
cd ai-api-mcp

# Copy and edit .env file
cp .env.example .env

# Run with docker-compose
docker-compose up

Manual Installation

Prerequisites

  • Python 3.10 or higher
  • pip

Steps

  1. Clone the repository:
git clone https://github.com/yourusername/ai-api-mcp.git
cd ai-api-mcp
  1. Run the installation script:

Linux/macOS:

chmod +x install.sh
./install.sh

Windows:

python -m venv venv
venv\Scripts\activate
pip install -e .
  1. Set up environment variables:
cp .env.example .env
# Edit .env with your API keys

Development Installation

For development with hot-reload and editable installation:

# Create virtual environment
python -m venv venv

# Activate virtual environment
# Linux/macOS:
source venv/bin/activate
# Windows:
venv\Scripts\activate

# Install in development mode
pip install -e ".[dev]"

Configuration

Add your API keys to the .env file:

# AI API Keys
OPENAI_API_KEY=your_openai_api_key_here
ANTHROPIC_API_KEY=your_anthropic_api_key_here
GOOGLE_API_KEY=your_google_api_key_here
GROK_API_KEY=your_grok_api_key_here

# Optional: Custom API endpoints
# OPENAI_BASE_URL=https://api.openai.com/v1
# GROK_BASE_URL=https://api.x.ai/v1

# Retry Configuration
MAX_RETRIES=3
RETRY_DELAY=1.0

Usage

Running the Server

Choose your preferred method to run the server:

Using NPX/Bunx (No installation required)

# With npx
npx @physics91org/ai-api-mcp

# With bunx  
bunx @physics91org/ai-api-mcp

Using Node.js

npm start
# or
node run.js

Using Python

python -m src.server

Using Shell Script

./run.sh

Using Docker

# Build and run
docker build -t ai-api-mcp .
docker run -it --rm --env-file .env ai-api-mcp

# Or use docker-compose
docker-compose up

Available Tools

1. Chat

Send messages to AI models and get responses.

await mcp.chat(
    messages=[
        {"role": "system", "content": "You are a helpful assistant"},
        {"role": "user", "content": "Hello!"}
    ],
    model="gpt-4",
    temperature=0.7,
    max_tokens=1000
)

2. List Models

Get all available models from configured providers.

models = await mcp.list_models()

3. Compare

Compare responses from multiple models.

await mcp.compare(
    prompt="Explain quantum computing",
    models=["gpt-4", "claude-3-opus-20240229", "gemini-pro"],
    temperature=0.7
)

4. Analyze

Analyze content with specific focus.

await mcp.analyze(
    content="def factorial(n): return 1 if n <= 1 else n * factorial(n-1)",
    analysis_type="code",  # options: code, text, security, performance, general
    model="gpt-4"
)

5. Generate

Generate content of specific types.

await mcp.generate(
    prompt="Create a REST API for user management",
    generation_type="code",  # options: code, text, documentation, test
    model="gpt-4",
    language="python",
    framework="FastAPI"
)

Supported Models (2025)

OpenAI

Flagship GPT Models

  • gpt-4.1 - 1M context, multimodal with massive context
  • gpt-4o - 128K context, fast, intelligent, flexible
  • gpt-4o-audio-preview - 128K context, audio inputs/outputs
  • chatgpt-4o-latest - 128K context, ChatGPT version

Cost-Optimized Models

  • gpt-4.1-mini - 1M context, fast multimodal
  • gpt-4.1-nano - 1M context, ultra-fast
  • gpt-4o-mini - 128K context, fast and affordable
  • gpt-4o-mini-audio-preview - 128K context, audio support

Reasoning Models (o-series)

  • o4-mini - 200K context, faster reasoning
  • o3 - 200K context, most powerful reasoning
  • o3-pro - 200K context, deep thinking
  • o3-mini - 200K context, small reasoning alternative
  • o1 - 200K context, previous reasoning model
  • o1-mini - 128K context, small reasoning alternative
  • o1-pro - 200K context, enhanced reasoning

Older Models

  • gpt-4-turbo, gpt-4, gpt-3.5-turbo

Anthropic

Claude 4 Models (Latest Generation)

  • claude-opus-4-20250514 - Most powerful and capable model (32K output)
  • claude-sonnet-4-20250514 - High-performance with exceptional reasoning (64K output)

Claude 3.x Models

  • claude-3-7-sonnet-20250219 - High intelligence with extended thinking (64K output)
  • claude-3-5-sonnet-20241022 - Previous intelligent model v2 (8K output)
  • claude-3-5-sonnet-20240620 - Previous intelligent model (8K output)
  • claude-3-5-haiku-20241022 - Fastest model with intelligence (8K output)
  • claude-3-haiku-20240307 - Fast and compact for quick responses (4K output)

Google

Gemini 2.5 Series (Latest with Thinking)

  • gemini-2.5-pro - 1M context, advanced reasoning with deep thinking
  • gemini-2.5-flash - 1M context, fast advanced reasoning with thinking
  • gemini-2.5-flash-lite-preview-06-17 - 1M context, ultra-fast and cost-effective

Gemini 2.0 Series

  • gemini-2.0-flash - 1M context, real-time multimodal capabilities
  • gemini-2.0-flash-lite - 1M context, cost-effective and fast

Gemini 1.5 Series (Deprecated)

  • gemini-1.5-flash - 1M context, fast multimodal (deprecated)
  • gemini-1.5-flash-8b - 1M context, high volume processing (deprecated)
  • gemini-1.5-pro - 2M context, complex reasoning (deprecated)

xAI

Grok 4 Series (Latest Reasoning Models)

  • grok-4-0709 - 256K context, advanced reasoning with function calling

Grok 3 Series

  • grok-3 - 131K context, vision and function calling capabilities
  • grok-3-mini - 131K context, fast and efficient reasoning
  • grok-3-fast - 131K context, high-speed processing with regional availability
  • grok-3-mini-fast - 131K context, ultra-fast efficient processing

Grok 2 Series (Vision Models)

  • grok-2-vision-1212 - 32K context, vision capabilities with function calling

MCP Client Support

This server works with multiple MCP-supporting tools. See our MCP Installation Guide for detailed setup instructions.

Supported Clients

  • Claude Code (CLI) - Anthropic's official CLI with MCP support
  • Claude Desktop - Native desktop app with MCP integration
  • Cursor IDE - AI-powered IDE with built-in MCP support
  • VS Code - Via GitHub Copilot Chat extension
  • Windsurf Editor - Next-gen editor with MCP capabilities
  • Continue Extension - Open-source AI code assistant
  • And more...

Quick Configuration Example

{
  "mcpServers": {
    "ai-api": {
      "command": "npx",
      "args": ["@physics91org/ai-api-mcp"],
      "env": {
        "OPENAI_API_KEY": "your-key",
        "ANTHROPIC_API_KEY": "your-key",
        "GOOGLE_API_KEY": "your-key",
        "GROK_API_KEY": "your-key"
      }
    }
  }
}

Development

Project Structure

ai-api-mcp/
├── src/
│   ├── server.py           # FastMCP server implementation
│   ├── provider_manager.py # Manages all AI providers
│   ├── models.py          # Pydantic models
│   ├── utils.py           # Utility functions
│   └── providers/         # AI provider implementations
│       ├── base.py
│       ├── openai_provider.py
│       ├── gemini_provider.py
│       ├── anthropic_provider.py
│       └── grok_provider.py
├── .env.example
├── pyproject.toml
└── README.md

Adding New Providers

  1. Create a new provider class in src/providers/
  2. Inherit from AIProviderBase
  3. Implement required methods: chat, list_models, validate_model
  4. Add provider to ProviderManager in provider_manager.py

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选