Skip to main content
Glama
mcp-server-demo

mcp-server-demo

MCP 服务器演示 (Python)

一个从零开始构建的本地 MCP 服务器,包含两个工具:

  • weather(city) → 通过 wttr.in 获取当前天气

  • query_db(sql) → 只读 SQLite SELECT 查询

1) 设置

python -m venv .venv
source .venv/bin/activate
pip install -U pip
pip install -e .

Related MCP server: Swiss Meteo MCP

2) 运行 MCP 服务器

mcp-server-demo

这将启动本地服务器并自动创建包含示例行的 demo.db。

3) 快速手动 MCP 检查(可选)

如果你安装了 MCP Inspector:

npx @modelcontextprotocol/inspector

然后连接到你的本地 Python 服务器。

4) OpenAI API 集成选项

  1. 复制 env 文件并填入密钥:

cp .env.example .env
  1. 在一个终端中启动服务器。

  2. 在第二个终端中运行:

python client_openai_api.py

注意:这使用了 OpenAI Responses API,其中 MCP 工具定义指向 http://localhost:8000/mcp。

工具行为

weather(city: str)

返回包含温度、体感温度、湿度、风速和简要天气状况的 JSON 摘要字段。

query_db(sql: str)

  • 仅允许 SELECT ... 查询。

  • 以 JSON 格式返回行数据。

  • 为了此入门演示的安全,拒绝非 SELECT 的 SQL 语句。

项目文件

  • server.py — FastMCP 服务器 + 工具定义。

  • client_openai_api.py — 可以调用 MCP 工具的简单 OpenAI API 调用。

  • pyproject.toml — 依赖项 + 脚本入口点。

Available Tools

10 tools
analyze_image_with_openaiC

Analyze an image file with an OpenAI vision-capable model.

Inputs: path (required), prompt (required), model. Returns: result

inspect_fileC

Return file metadata and content preview for text/csv/image workflows.

Inputs: path (required), preview_chars, include_base64. Returns: result

list_directoriesC

List directories directly inside a folder within MCP_FILE_OPS_ROOT.

Inputs: path. Returns: result

list_filesB

List files directly inside a folder within MCP_FILE_OPS_ROOT.

Inputs: path. Returns: result

make_directoryC

Create a directory inside MCP_FILE_OPS_ROOT.

Inputs: path (required). Returns: result

move_fileC

Move a file from source_path to destination_path inside MCP_FILE_OPS_ROOT.

Inputs: source_path (required), destination_path (required). Returns: result

move_files_by_globC

Move all files matching a glob pattern from source_dir into destination_dir.

Inputs: source_dir (required), pattern (required), destination_dir (required). Returns: result

query_dbA

Run a read-only SELECT query against local SQLite demo.db.

Inputs: sql (required). Returns: result

read_fileC

Read a UTF-8 text file inside MCP_FILE_OPS_ROOT.

Inputs: path (required). Returns: result

weatherB

Return current weather for a city using wttr.in.

Inputs: city (required). Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    C2.9/5.0

    Scored across 10 tools

    Disambiguation4/5

    Most tools have distinct purposes, but there is some overlap between inspect_file and read_file (both provide file content), and move_file vs move_files_by_glob are similar in name and action.

    Naming Consistency4/5

    Majority follow verb_noun pattern with underscores, but 'weather' is a lone noun and 'analyze_image_with_openai' is verbose and breaks the pattern.

    Tool Count4/5

    10 tools is a reasonable number, but the server covers multiple unrelated domains (files, DB, weather, image), making it feel a bit scattered.

    Completeness2/5

    File operations lack delete/copy, DB only has read-only query, weather and image analysis are single-tool services. The surface is incomplete for any single domain.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      C
      quality
      D
      maintenance
      An experimental MCP server that provides weather information tools, including temperature lookup via wttr.io, along with note-taking capabilities for learning MCP server development with GitHub Copilot.
      3
      -
    • F
      license
      Not graded
      quality
      D
      maintenance
      A demo MCP server that provides AI assistants access to live US weather data via the free National Weather Service API, offering forecast and alert tools without requiring an API key.
      -
    • F
      license
      Not graded
      quality
      D
      maintenance
      A lightweight MCP server providing tools for adding integers, getting current time, and fetching weather forecasts via wttr.in.
      -