Container MCP Server

Container MCP Server

Enables weather lookups, mathematical calculations, and context-aware operations through a containerized MCP server with HTTP transport. Optimized for Docker/Kubernetes deployment with health checks and no external dependencies.

Category
访问服务器

README

Container MCP Server

A Model Context Protocol (MCP) server designed for containerized deployment with HTTP transport. This server provides simple, dependency-free tools and prompts that can be used by MCP clients via streamable HTTP transport.

Features

  • HTTP Transport: Uses streamable HTTP transport for remote MCP server deployment
  • Container Ready: Optimized for Docker/Kubernetes deployment with health checks
  • Simple Tools: Weather data, mathematical calculations, and context-aware operations
  • Prompts: Reusable templates for weather reports and calculations
  • No External Dependencies: Mock data for easy testing and demonstration

Tools

1. get_weather

Get mock weather information for a city.

Parameters:

  • city (string, optional): City name (default: "San Francisco")

Returns: Weather data including temperature, condition, and humidity

2. sum_numbers

Add two numbers together.

Parameters:

  • a (float): First number
  • b (float): Second number

Returns: The sum of the two numbers

3. context_info

Demonstrate MCP context capabilities including logging, progress reporting, and metadata access.

Parameters:

  • message (string): A message to process
  • ctx (Context): MCP Context object (automatically injected)

Returns: Information about the context and processing

Prompts

1. weather_report

Generate weather report prompts for specified cities.

Arguments:

  • city (string): City name for the weather report
  • format (string): Report format ("brief", "detailed", or "forecast")

2. calculation_helper

Generate prompts for mathematical calculations.

Arguments:

  • operation (string): Type of mathematical operation
  • context (string): Additional context for the calculation

Installation & Development

Using Virtual Environment (Recommended)

  1. Create and activate virtual environment:

    # Create virtual environment
    python -m venv venv
    
    # Activate virtual environment
    # On Unix/macOS:
    source venv/bin/activate
    # On Windows:
    # venv\Scripts\activate
    
  2. Install dependencies:

    pip install -r requirements.txt
    
  3. Run in development mode:

    python -m src.server --port 8000 --log-level DEBUG
    
  4. Run tests:

    pytest
    
  5. Deactivate virtual environment when done:

    deactivate
    

Without Virtual Environment (Not Recommended)

  1. Install dependencies:

    pip install -r requirements.txt
    
  2. Run in development mode:

    python -m src.server --port 8000 --log-level DEBUG
    
  3. Run tests:

    pytest
    

Direct Execution

The server supports direct execution for development and testing:

# Basic execution
python src/server.py

# With custom options
python src/server.py --port 3000 --log-level DEBUG --json-response

Command-line options:

  • --port: Port to run the server on (default: 8000)
  • --log-level: Logging level (default: INFO)
  • --json-response: Use JSON responses instead of SSE streams

Container Deployment

Docker

  1. Build the container:

    docker build -t mcp-server .
    
  2. Run the container:

    docker run -p 8000:8000 mcp-server
    
  3. With custom environment:

    docker run -p 8000:8000 -e LOG_LEVEL=DEBUG mcp-server
    

Docker Compose

  1. Basic deployment:

    docker-compose up
    
  2. With production nginx proxy:

    docker-compose --profile production up
    

Kubernetes

Example deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mcp-server
spec:
  replicas: 3
  selector:
    matchLabels:
      app: mcp-server
  template:
    metadata:
      labels:
        app: mcp-server
    spec:
      containers:
      - name: mcp-server
        image: mcp-server:latest
        ports:
        - containerPort: 8000
        livenessProbe:
          httpGet:
            path: /health
            port: 8000
          initialDelaySeconds: 30
          periodSeconds: 10
---
apiVersion: v1
kind: Service
metadata:
  name: mcp-service
spec:
  selector:
    app: mcp-server
  ports:
  - port: 80
    targetPort: 8000
  type: LoadBalancer

API Endpoints

Health Check

  • URL: GET /health
  • Response: Server health status and metadata
  • Use: Container orchestration health checks

Server Info

  • URL: GET /
  • Response: Server information, available tools, and prompts
  • Use: Discovery and documentation

MCP Endpoint

  • URL: POST /mcp
  • Protocol: MCP over HTTP (JSON-RPC 2.0)
  • Transport: Streamable HTTP with SSE support
  • Use: MCP client connections

Connection Details

For MCP Clients

Server URL: http://localhost:8000/mcp

Transport: Streamable HTTP

Authentication: None (can be extended)

Example Client Connection (Python)

import asyncio
from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client

async def main():
    async with streamablehttp_client("http://localhost:8000/mcp") as (read, write, _):
        async with ClientSession(read, write) as session:
            await session.initialize()
            
            # List available tools
            tools = await session.list_tools()
            print(f"Available tools: {[tool.name for tool in tools.tools]}")
            
            # Call a tool
            result = await session.call_tool("get_weather", {"city": "New York"})
            print(f"Weather result: {result}")

if __name__ == "__main__":
    asyncio.run(main())

Testing

Unit Tests

pytest tests/

Integration Tests

# Start the server
python -m src.server --port 8001 &
SERVER_PID=$!

# Test health endpoint
curl http://localhost:8001/health

# Test server info
curl http://localhost:8001/

# Test MCP connection with a client
# (see example above)

# Cleanup
kill $SERVER_PID

Container Tests

# Test container build
docker build -t mcp-server-test .

# Test container run
docker run -d -p 8002:8000 --name mcp-test mcp-server-test

# Test health check
curl http://localhost:8002/health

# Cleanup
docker stop mcp-test && docker rm mcp-test

Monitoring

Health Checks

The server provides a /health endpoint that returns:

  • Server status
  • Tool and prompt counts
  • Transport information

Logging

Structured logging with configurable levels:

# Set log level via environment
export LOG_LEVEL=DEBUG
python -m src.server

# Or via command line
python -m src.server --log-level DEBUG

Metrics

For production deployments, consider adding:

  • Prometheus metrics endpoint
  • OpenTelemetry tracing
  • Request/response logging

Architecture

┌─────────────────┐    HTTP/SSE     ┌─────────────────┐
│   MCP Client    │ ◄──────────────► │   MCP Server    │
│                 │                 │                 │
│ - Claude Code   │                 │ - Tools         │
│ - Custom Client │                 │ - Prompts       │
│ - Web App       │                 │ - Health Check  │
└─────────────────┘                 └─────────────────┘
                                           │
                                           ▼
                                    ┌─────────────────┐
                                    │   Container     │
                                    │                 │
                                    │ - Docker        │
                                    │ - Kubernetes    │
                                    │ - Cloud Run     │
                                    └─────────────────┘

Security Considerations

  • The server runs as a non-root user in containers
  • No secrets or API keys are required for basic functionality
  • Consider adding authentication for production deployments
  • Network policies should restrict access to necessary ports only

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make changes with tests
  4. Run the test suite
  5. Submit a pull request

License

This project is available under the MIT License.

推荐服务器

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

官方
精选